Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 3 additions & 26 deletions pkg/rehearse/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
44 changes: 11 additions & 33 deletions pkg/rehearse/jobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: ""
Expand Down
31 changes: 0 additions & 31 deletions test/integration/pj-rehearse/expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: ""
Expand Down