diff --git a/pkg/api/types.go b/pkg/api/types.go index 88ec37c76e..dff770a12f 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -32,7 +32,6 @@ var ( prowv1.FailureState, prowv1.ErrorState, } - DefaultSlackReporterReportTemplate = `{{if eq .Status.State "success"}} :slack-green: Job *{{.Spec.Job}}* ended with *{{.Status.State}}*. <{{.Status.URL}}|View logs> {{else}} :failed: Job *{{.Spec.Job}}* ended with *{{.Status.State}}*. <{{.Status.URL}}|View logs> {{end}}` ) type SlackReporterConfig struct { @@ -2809,6 +2808,9 @@ type ImageConfiguration struct { // The image name (To field) should match the cmd tool name for this to work correctly. BuildIfAffected bool `json:"build_if_affected,omitempty"` + // SlackReporterConfig configures Slack notifications for the auto-generated images jobs. + SlackReporterConfig *SlackReporterConfig `json:"reporter_config,omitempty"` + // Items is the list of images to build. Items []ProjectDirectoryImageBuildStepConfiguration `json:"items,omitempty"` } diff --git a/pkg/api/zz_generated.deepcopy.go b/pkg/api/zz_generated.deepcopy.go index 2dee030a6a..6afd53e113 100644 --- a/pkg/api/zz_generated.deepcopy.go +++ b/pkg/api/zz_generated.deepcopy.go @@ -670,6 +670,11 @@ func (in *ImageBuildInputs) DeepCopy() *ImageBuildInputs { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ImageConfiguration) DeepCopyInto(out *ImageConfiguration) { *out = *in + if in.SlackReporterConfig != nil { + in, out := &in.SlackReporterConfig, &out.SlackReporterConfig + *out = new(SlackReporterConfig) + (*in).DeepCopyInto(*out) + } if in.Items != nil { in, out := &in.Items, &out.Items *out = make([]ProjectDirectoryImageBuildStepConfiguration, len(*in)) diff --git a/pkg/prowgen/prowgen.go b/pkg/prowgen/prowgen.go index 061e8c8e8d..96ffd3c700 100644 --- a/pkg/prowgen/prowgen.go +++ b/pkg/prowgen/prowgen.go @@ -153,6 +153,7 @@ func GenerateJobs(configSpec *cioperatorapi.ReleaseBuildConfiguration, info *Pro options.skipIfOnlyChanged = configSpec.Images.SkipIfOnlyChanged options.pipelineRunIfChanged = configSpec.Images.PipelineRunIfChanged options.pipelineSkipIfOnlyChanged = configSpec.Images.PipelineSkipIfOnlyChanged + options.slackReporterConfig = configSpec.Images.SlackReporterConfig })) if configSpec.PromotionConfiguration != nil { @@ -160,8 +161,9 @@ func GenerateJobs(configSpec *cioperatorapi.ReleaseBuildConfiguration, info *Pro injectCapabilitiesForImgJobs(jobBaseGen, configSpec.Images.Items) jobBaseGen.PodSpec.Add(Promotion(), Targets(imageTargets.UnsortedList()...)) - // Note: Slack reporter config for images postsubmit is now handled in generatePostsubmitForTest - postsubmit := generatePostsubmitForTest(jobBaseGen, info) + postsubmit := generatePostsubmitForTest(jobBaseGen, info, func(options *generatePostsubmitOptions) { + options.slackReporterConfig = configSpec.Images.SlackReporterConfig + }) postsubmit.MaxConcurrency = 1 if postsubmit.Labels == nil { postsubmit.Labels = map[string]string{} @@ -275,15 +277,11 @@ func slackReporterConfig(jobName, testName string, testSlackConfig *cioperatorap if len(jobStatesToReport) == 0 { jobStatesToReport = cioperatorapi.DefaultSlackReporterJobStatesToReport } - reportTemplate := testSlackConfig.ReportTemplate - if reportTemplate == "" { - reportTemplate = cioperatorapi.DefaultSlackReporterReportTemplate - } return &prowv1.ReporterConfig{ Slack: &prowv1.SlackReporterConfig{ Channel: testSlackConfig.Channel, JobStatesToReport: jobStatesToReport, - ReportTemplate: reportTemplate, + ReportTemplate: testSlackConfig.ReportTemplate, }, } } diff --git a/pkg/webreg/zz_generated.ci_operator_reference.go b/pkg/webreg/zz_generated.ci_operator_reference.go index bd82b1f01a..6f711f2a6b 100644 --- a/pkg/webreg/zz_generated.ci_operator_reference.go +++ b/pkg/webreg/zz_generated.ci_operator_reference.go @@ -247,6 +247,16 @@ const ciOperatorReferenceYaml = "# The list of base images describe\n" + " # PipelineSkipIfOnlyChanged is a regex that will cause the auto-generated images\n" + " # presubmit to be skipped in the second stage of the pipeline if all changed files match the regex.\n" + " pipeline_skip_if_only_changed: ' '\n" + + " # SlackReporterConfig configures Slack notifications for the auto-generated images jobs.\n" + + " reporter_config:\n" + + " channel: ' '\n" + + " job_states_to_report:\n" + + " - \"\"\n" + + " # ReportPresubmit controls whether the presubmit job generated from a\n" + + " # periodic test with `presubmit: true` also gets this slack config.\n" + + " # Only valid when the test has `presubmit: true`.\n" + + " report_presubmit: true\n" + + " report_template: ' '\n" + " # RunIfChanged is a regex that will cause the auto-generated images\n" + " # presubmit to only run if a file matching the regex is changed.\n" + " run_if_changed: ' '\n" + diff --git a/test/integration/ci-operator-prowgen/input/config/slack-report-inline/duper/slack-report-inline-duper-master.yaml b/test/integration/ci-operator-prowgen/input/config/slack-report-inline/duper/slack-report-inline-duper-master.yaml index 0af1cc89be..c2f74ce405 100644 --- a/test/integration/ci-operator-prowgen/input/config/slack-report-inline/duper/slack-report-inline-duper-master.yaml +++ b/test/integration/ci-operator-prowgen/input/config/slack-report-inline/duper/slack-report-inline-duper-master.yaml @@ -14,6 +14,19 @@ resources: cpu: 500Mi requests: cpu: 10Mi +images: + items: + - from: base + to: test-image + reporter_config: + channel: "#images-channel" + job_states_to_report: + - failure + - error +promotion: + to: + - namespace: ci + tag: latest tag_specification: name: origin-v4.0 namespace: openshift diff --git a/test/integration/ci-operator-prowgen/output/jobs/slack-report-inline/duper/slack-report-inline-duper-master-periodics.yaml b/test/integration/ci-operator-prowgen/output/jobs/slack-report-inline/duper/slack-report-inline-duper-master-periodics.yaml index 4e8deff934..ce8ef6f20e 100644 --- a/test/integration/ci-operator-prowgen/output/jobs/slack-report-inline/duper/slack-report-inline-duper-master-periodics.yaml +++ b/test/integration/ci-operator-prowgen/output/jobs/slack-report-inline/duper/slack-report-inline-duper-master-periodics.yaml @@ -17,10 +17,6 @@ periodics: channel: '#periodic-only-channel' job_states_to_report: - error - report_template: '{{if eq .Status.State "success"}} :slack-green: Job *{{.Spec.Job}}* - ended with *{{.Status.State}}*. <{{.Status.URL}}|View logs> {{else}} :failed: - Job *{{.Spec.Job}}* ended with *{{.Status.State}}*. <{{.Status.URL}}|View - logs> {{end}}' spec: containers: - args: @@ -88,10 +84,6 @@ periodics: - success - failure - error - report_template: '{{if eq .Status.State "success"}} :slack-green: Job *{{.Spec.Job}}* - ended with *{{.Status.State}}*. <{{.Status.URL}}|View logs> {{else}} :failed: - Job *{{.Spec.Job}}* ended with *{{.Status.State}}*. <{{.Status.URL}}|View - logs> {{end}}' spec: containers: - args: diff --git a/test/integration/ci-operator-prowgen/output/jobs/slack-report-inline/duper/slack-report-inline-duper-master-postsubmits.yaml b/test/integration/ci-operator-prowgen/output/jobs/slack-report-inline/duper/slack-report-inline-duper-master-postsubmits.yaml index 9c72001706..17d1122d42 100644 --- a/test/integration/ci-operator-prowgen/output/jobs/slack-report-inline/duper/slack-report-inline-duper-master-postsubmits.yaml +++ b/test/integration/ci-operator-prowgen/output/jobs/slack-report-inline/duper/slack-report-inline-duper-master-postsubmits.yaml @@ -1,5 +1,70 @@ postsubmits: slack-report-inline/duper: + - agent: kubernetes + always_run: true + branches: + - ^master$ + decorate: true + decoration_config: + skip_cloning: true + labels: + ci-operator.openshift.io/is-promotion: "true" + ci.openshift.io/generator: prowgen + max_concurrency: 1 + name: branch-ci-slack-report-inline-duper-master-images + reporter_config: + slack: + channel: '#images-channel' + job_states_to_report: + - failure + - error + spec: + containers: + - args: + - --gcs-upload-secret=/secrets/gcs/service-account.json + - --image-import-pull-secret=/etc/pull-secret/.dockerconfigjson + - --image-mirror-push-secret=/etc/push-secret/.dockerconfigjson + - --promote + - --report-credentials-file=/etc/report/credentials + - --target=[images] + command: + - ci-operator + image: quay-proxy.ci.openshift.org/openshift/ci:ci_ci-operator_latest + imagePullPolicy: Always + name: "" + resources: + requests: + cpu: 10m + volumeMounts: + - mountPath: /secrets/gcs + name: gcs-credentials + readOnly: true + - mountPath: /secrets/manifest-tool + name: manifest-tool-local-pusher + readOnly: true + - mountPath: /etc/pull-secret + name: pull-secret + readOnly: true + - mountPath: /etc/push-secret + name: push-secret + readOnly: true + - mountPath: /etc/report + name: result-aggregator + readOnly: true + serviceAccountName: ci-operator + volumes: + - name: manifest-tool-local-pusher + secret: + secretName: manifest-tool-local-pusher + - name: pull-secret + secret: + secretName: registry-pull-credentials + - name: push-secret + secret: + secretName: registry-push-credentials-ci-central + - name: result-aggregator + secret: + secretName: result-aggregator - agent: kubernetes always_run: true branches: @@ -16,10 +81,6 @@ postsubmits: channel: '#postsubmit-channel' job_states_to_report: - failure - report_template: '{{if eq .Status.State "success"}} :slack-green: Job *{{.Spec.Job}}* - ended with *{{.Status.State}}*. <{{.Status.URL}}|View logs> {{else}} :failed: - Job *{{.Spec.Job}}* ended with *{{.Status.State}}*. <{{.Status.URL}}|View - logs> {{end}}' spec: containers: - args: diff --git a/test/integration/ci-operator-prowgen/output/jobs/slack-report-inline/duper/slack-report-inline-duper-master-presubmits.yaml b/test/integration/ci-operator-prowgen/output/jobs/slack-report-inline/duper/slack-report-inline-duper-master-presubmits.yaml index 574959127f..277d84dcb9 100644 --- a/test/integration/ci-operator-prowgen/output/jobs/slack-report-inline/duper/slack-report-inline-duper-master-presubmits.yaml +++ b/test/integration/ci-operator-prowgen/output/jobs/slack-report-inline/duper/slack-report-inline-duper-master-presubmits.yaml @@ -62,6 +62,66 @@ presubmits: secret: secretName: result-aggregator trigger: (?m)^/test( | .* )e2e,?($|\s.*) + - agent: kubernetes + always_run: true + branches: + - ^master$ + - ^master- + context: ci/prow/images + decorate: true + decoration_config: + skip_cloning: true + labels: + ci.openshift.io/generator: prowgen + pj-rehearse.openshift.io/can-be-rehearsed: "true" + name: pull-ci-slack-report-inline-duper-master-images + reporter_config: + slack: + channel: '#images-channel' + job_states_to_report: + - failure + - error + rerun_command: /test images + spec: + containers: + - args: + - --gcs-upload-secret=/secrets/gcs/service-account.json + - --image-import-pull-secret=/etc/pull-secret/.dockerconfigjson + - --report-credentials-file=/etc/report/credentials + - --target=[images] + command: + - ci-operator + image: quay-proxy.ci.openshift.org/openshift/ci:ci_ci-operator_latest + imagePullPolicy: Always + name: "" + resources: + requests: + cpu: 10m + volumeMounts: + - mountPath: /secrets/gcs + name: gcs-credentials + readOnly: true + - mountPath: /secrets/manifest-tool + name: manifest-tool-local-pusher + readOnly: true + - mountPath: /etc/pull-secret + name: pull-secret + readOnly: true + - mountPath: /etc/report + name: result-aggregator + readOnly: true + serviceAccountName: ci-operator + volumes: + - name: manifest-tool-local-pusher + secret: + secretName: manifest-tool-local-pusher + - name: pull-secret + secret: + secretName: registry-pull-credentials + - name: result-aggregator + secret: + secretName: result-aggregator + trigger: (?m)^/test( | .* )images,?($|\s.*) - agent: kubernetes always_run: true branches: @@ -143,10 +203,6 @@ presubmits: job_states_to_report: - failure - error - report_template: '{{if eq .Status.State "success"}} :slack-green: Job *{{.Spec.Job}}* - ended with *{{.Status.State}}*. <{{.Status.URL}}|View logs> {{else}} :failed: - Job *{{.Spec.Job}}* ended with *{{.Status.State}}*. <{{.Status.URL}}|View - logs> {{end}}' rerun_command: /test unit spec: containers: @@ -216,10 +272,6 @@ presubmits: - success - failure - error - report_template: '{{if eq .Status.State "success"}} :slack-green: Job *{{.Spec.Job}}* - ended with *{{.Status.State}}*. <{{.Status.URL}}|View logs> {{else}} :failed: - Job *{{.Spec.Job}}* ended with *{{.Status.State}}*. <{{.Status.URL}}|View - logs> {{end}}' rerun_command: /test verify spec: containers: