diff --git a/pkg/rehearse/jobs.go b/pkg/rehearse/jobs.go index 8ce13c29b5c..364f65ddc82 100644 --- a/pkg/rehearse/jobs.go +++ b/pkg/rehearse/jobs.go @@ -266,38 +266,15 @@ func getResolvedConfigForTest(ciopConfigs config.DataByFilename, resolver regist // being also changed by the tested PR. func inlineCiOpConfig(container *v1.Container, ciopConfigs config.DataByFilename, resolver registry.Resolver, metadata api.Metadata, testname string, loggers Loggers) (apihelper.ImageStreamTagMap, error) { allImageStreamTags := apihelper.ImageStreamTagMap{} - configSpecSet := false // replace all ConfigMapKeyRef mounts with inline config maps for index := range container.Env { env := &(container.Env[index]) if env.Name == "CONFIG_SPEC" { - configSpecSet = true + // if CONFIG_SPEC has already been set, do not add new CONFIG_SPEC section + return allImageStreamTags, nil } - if env.ValueFrom == nil { - continue - } - if env.ValueFrom.ConfigMapKeyRef == nil { - continue - } - if api.IsCiopConfigCM(env.ValueFrom.ConfigMapKeyRef.Name) { - filename := env.ValueFrom.ConfigMapKeyRef.Key - - loggers.Debug.WithField(logCiopConfigFile, filename).Debug("Rehearsal job uses ci-operator config ConfigMap, needed content will be inlined") - ciOpConfigContent, imageStreamTags, err := getResolvedConfigForTest(ciopConfigs, resolver, filename, testname) - if err != nil { - loggers.Job.WithError(err).Error("Failed to get resolved config for test") - return nil, err - } - apihelper.MergeImageStreamTagMaps(allImageStreamTags, imageStreamTags) - - env.Value = ciOpConfigContent - env.ValueFrom = nil - } - } - // if CONFIG_SPEC has already been set, do not add new CONFIG_SPEC section - if configSpecSet { - return allImageStreamTags, nil } + // inline CONFIG_SPEC for all ci-operator jobs if container.Command != nil && container.Command[0] == "ci-operator" { if err := metadata.IsComplete(); err != nil { diff --git a/pkg/rehearse/jobs_test.go b/pkg/rehearse/jobs_test.go index 784a4e435c4..b34e828073a 100644 --- a/pkg/rehearse/jobs_test.go +++ b/pkg/rehearse/jobs_test.go @@ -158,20 +158,6 @@ func TestInlineCiopConfig(t *testing.T) { As: "test2", }}, } - testCiopConfigTest1 := api.ReleaseBuildConfiguration{Tests: []api.TestStepConfiguration{testCiopConfig.Tests[0]}} - testCiopConfigContentTest1, err := yaml.Marshal(&testCiopConfigTest1) - if err != nil { - t.Fatal("Failed to marshal ci-operator config") - } - testCiopConfigTest2 := api.ReleaseBuildConfiguration{ - Tests: []api.TestStepConfiguration{{ - As: "test2", - }}, - } - testCiopConfigContentTest2, err := yaml.Marshal(&testCiopConfigTest2) - if err != nil { - t.Fatal("Failed to marshal ci-operator config") - } testCases := []struct { description string @@ -199,25 +185,17 @@ func TestInlineCiopConfig(t *testing.T) { sourceEnv: []v1.EnvVar{{Name: "T", ValueFrom: makeCMReference("test-cm", "key")}}, configs: config.DataByFilename{}, expectedEnv: []v1.EnvVar{{Name: "T", ValueFrom: makeCMReference("test-cm", "key")}}, - }, { - description: "CM reference to ci-operator-configs -> cm content inlined; test1", - testname: "test1", - sourceEnv: []v1.EnvVar{{Name: "T", ValueFrom: makeCMReference(testCiopConfigInfo.ConfigMapName(), "filename")}}, - configs: config.DataByFilename{"filename": {Info: config.Info{Metadata: testCiopConfigInfo}, Configuration: testCiopConfig}}, - expectedEnv: []v1.EnvVar{{Name: "T", Value: string(testCiopConfigContentTest1)}}, - expectedImageStreamTagMap: apihelper.ImageStreamTagMap{"fancy/willem:first": types.NamespacedName{Namespace: "fancy", Name: "willem:first"}}, - }, { - description: "CM reference to ci-operator-configs -> cm content inlined; test2", - testname: "test2", - sourceEnv: []v1.EnvVar{{Name: "T", ValueFrom: makeCMReference(testCiopConfigInfo.ConfigMapName(), "filename")}}, - configs: config.DataByFilename{"filename": {Info: config.Info{Metadata: testCiopConfigInfo}, Configuration: testCiopConfig}}, - expectedEnv: []v1.EnvVar{{Name: "T", Value: string(testCiopConfigContentTest2)}}, - }, { - description: "bad CM key is handled", - sourceEnv: []v1.EnvVar{{Name: "T", ValueFrom: makeCMReference(testCiopConfigInfo.ConfigMapName(), "filename")}}, - configs: config.DataByFilename{}, - expectedError: true, - }} + }, + { + // After DPTP-1685: jobs are not expected to refer to ci-operator CMs directly anymore, so + // rehearsals do not need to support that cases anymore + description: "CM reference to ci-operator-configs -> no changes; test1", + testname: "test1", + sourceEnv: []v1.EnvVar{{Name: "T", ValueFrom: makeCMReference(testCiopConfigInfo.ConfigMapName(), "filename")}}, + configs: config.DataByFilename{"filename": {Info: config.Info{Metadata: testCiopConfigInfo}, Configuration: testCiopConfig}}, + expectedEnv: []v1.EnvVar{{Name: "T", ValueFrom: makeCMReference(testCiopConfigInfo.ConfigMapName(), "filename")}}, + }, + } references, chains, workflows, _, _, observers, err := load.Registry(testingRegistry, false) if err != nil { diff --git a/test/integration/pj-rehearse/candidate/ci-operator/jobs/super/duper/super-duper-periodics.yaml b/test/integration/pj-rehearse/candidate/ci-operator/jobs/super/duper/super-duper-periodics.yaml index 005c3493792..5df3b6755b5 100644 --- a/test/integration/pj-rehearse/candidate/ci-operator/jobs/super/duper/super-duper-periodics.yaml +++ b/test/integration/pj-rehearse/candidate/ci-operator/jobs/super/duper/super-duper-periodics.yaml @@ -68,12 +68,6 @@ periodics: - --CHANGED command: - no-ci-op - env: - - name: CONFIG_SPEC - valueFrom: - configMapKeyRef: - key: super-duper-ciop-cfg-change.yaml - name: ci-operator-misc-configs image: ci-operator:latest imagePullPolicy: Always name: "" diff --git a/test/integration/pj-rehearse/expected.yaml b/test/integration/pj-rehearse/expected.yaml index 4f5cf07042f..51cbd4488f0 100644 --- a/test/integration/pj-rehearse/expected.yaml +++ b/test/integration/pj-rehearse/expected.yaml @@ -323,37 +323,6 @@ - --CHANGED command: - no-ci-op - env: - - name: CONFIG_SPEC - value: | - base_images: - base: - name: origin-v4.0 - namespace: openshift - tag: base - build_root: - image_stream_tag: - name: release - namespace: openshift - tag: golang-1.10 - images: - - from: base - to: test-image - - from: base - to: change-should-cause-rehearsal-of-all-jobs-that-use-this-cfg - resources: - '*': - limits: - cpu: 500Mi - requests: - cpu: 10Mi - tag_specification: - name: origin-v4.0 - namespace: openshift - zz_generated_metadata: - branch: ciop-cfg-change - org: super - repo: duper image: ci-operator:latest imagePullPolicy: Always name: "" diff --git a/test/integration/pj-rehearse/master/ci-operator/jobs/super/duper/super-duper-periodics.yaml b/test/integration/pj-rehearse/master/ci-operator/jobs/super/duper/super-duper-periodics.yaml index 6d6ccb3608a..964b355b724 100644 --- a/test/integration/pj-rehearse/master/ci-operator/jobs/super/duper/super-duper-periodics.yaml +++ b/test/integration/pj-rehearse/master/ci-operator/jobs/super/duper/super-duper-periodics.yaml @@ -59,11 +59,6 @@ periodics: command: - no-ci-op env: - - name: CONFIG_SPEC - valueFrom: - configMapKeyRef: - key: super-duper-ciop-cfg-change.yaml - name: ci-operator-misc-configs image: ci-operator:latest imagePullPolicy: Always name: ""