Skip to content

Commit fac6176

Browse files
committed
Fix e2e test harness
Signed-off-by: Per G. da Silva <[email protected]>
1 parent dca5343 commit fac6176

File tree

3 files changed

+48
-36
lines changed

3 files changed

+48
-36
lines changed

pkg/controller/registry/resolver/resolver.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ func NewDefaultSatResolver(rcp cache.SourceProvider, catsrcLister v1alpha1lister
4141
if err != nil {
4242
logger.Errorf("Error creating runtime constraints from file: %s", err)
4343
panic(err)
44+
} else {
45+
logger.Info("Cluster runtime constraints are in effect")
4446
}
4547

4648
// Two solutions:

pkg/controller/registry/resolver/runtime_constraints/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
const (
1414
maxRuntimeConstraints = 10
15-
RuntimeConstraintEnvVarName = "RUNTIME_CONSTRAINTS_FILE_PATH"
15+
RuntimeConstraintEnvVarName = "RUNTIME_CONSTRAINTS"
1616
)
1717

1818
type RuntimeConstraintsProvider struct {

test/e2e/runtime_constraints_e2e_test.go

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"regexp"
88
"strings"
9+
"time"
910

1011
. "github.com/onsi/ginkgo"
1112
. "github.com/onsi/gomega"
@@ -22,16 +23,16 @@ import (
2223
const (
2324
runtimeConstraintsVolumeMountName = "runtime-constraints"
2425
runtimeConstraintsConfigMapName = "runtime-constraints"
25-
runtimeConstraintsFileName = "runtime_constraints.yaml"
26+
runtimeConstraintsFileName = "runtime_constraints.json"
2627
defaultOlmNamespace = "operator-lifecycle-manager"
27-
olmOperatorName = "olm-operator"
28-
olmContainerIndex = 0
28+
catalogOperatorName = "catalog-operator"
29+
catalogContainerIndex = 0
2930
)
3031

3132
var (
3233
olmOperatorKey = k8scontrollerclient.ObjectKey{
3334
Namespace: defaultOlmNamespace,
34-
Name: olmOperatorName,
35+
Name: catalogOperatorName,
3536
}
3637
)
3738

@@ -45,7 +46,7 @@ var _ = By
4546
// Before each test:
4647
// 1. Create a new config map in the operator-lifecycle-manager namespace that contains the
4748
// runtime constraints
48-
// 2. Update the deployment to mount the contents of the config map to /constraints/runtime_constraints.yaml
49+
// 2. Update the deployment to mount the contents of the config map to /constraints/runtime_constraints.json
4950
// 3. Update the deployment to include the environment variable pointing to the runtime constraints file
5051
// 4. Wait for the deployment to finish updating
5152
//
@@ -67,21 +68,29 @@ var _ = Describe("Cluster Runtime Constraints", func() {
6768

6869
AfterEach(func() {
6970
teardownRuntimeConstraints(ctx.Ctx().Client())
71+
time.Sleep(1 * time.Minute)
7072
TeardownNamespace(generatedNamespace.GetName())
7173
})
7274

7375
It("Runtime", func() {
76+
time.Sleep(2 * time.Minute)
7477
require.Equal(GinkgoT(), true, true)
7578
})
7679
})
7780

7881
func mustDeployRuntimeConstraintsConfigMap(kubeClient k8scontrollerclient.Client) {
7982
runtimeConstraints := stripMargin(`
80-
|properties:
81-
| - type: olm.package
82-
| value:
83-
| packageName: etcd
84-
| version: 1.0.0`)
83+
|{
84+
| "properties": [
85+
| {
86+
| "type": "olm.package",
87+
| "value": {
88+
| "packageName": "",
89+
| "version": "1.0.0"
90+
| }
91+
| }
92+
| ]
93+
|}`)
8594

8695
isImmutable := true
8796
configMap := &corev1.ConfigMap{
@@ -122,16 +131,16 @@ func mustUndeployRuntimeConstraintsConfigMap(kubeClient k8scontrollerclient.Clie
122131
}).Should(BeTrue())
123132
}
124133

125-
func mustPatchOlmDeployment(kubeClient k8scontrollerclient.Client) {
126-
olmDeployment := &appsv1.Deployment{}
127-
err := kubeClient.Get(context.TODO(), olmOperatorKey, olmDeployment)
134+
func mustPatchCatalogOperatorDeployment(kubeClient k8scontrollerclient.Client) {
135+
catalogDeployment := &appsv1.Deployment{}
136+
err := kubeClient.Get(context.TODO(), olmOperatorKey, catalogDeployment)
128137

129138
if err != nil {
130139
panic(err)
131140
}
132141

133-
volumes := olmDeployment.Spec.Template.Spec.Volumes
134-
olmContainer := olmDeployment.Spec.Template.Spec.Containers[0]
142+
volumes := catalogDeployment.Spec.Template.Spec.Volumes
143+
olmContainer := catalogDeployment.Spec.Template.Spec.Containers[0]
135144

136145
newVolume := corev1.Volume{
137146
Name: runtimeConstraintsVolumeMountName,
@@ -151,83 +160,84 @@ func mustPatchOlmDeployment(kubeClient k8scontrollerclient.Client) {
151160
ReadOnly: true,
152161
}
153162

154-
olmDeployment.Spec.Template.Spec.Volumes = append(volumes, newVolume)
155-
olmDeployment.Spec.Template.Spec.Containers[olmContainerIndex].VolumeMounts = append(olmContainer.VolumeMounts, newVolumeMount)
156-
olmDeployment.Spec.Template.Spec.Containers[olmContainerIndex].Env = append(olmContainer.Env, corev1.EnvVar{
163+
catalogDeployment.Spec.Template.Spec.Volumes = append(volumes, newVolume)
164+
catalogDeployment.Spec.Template.Spec.Containers[catalogContainerIndex].VolumeMounts = append(olmContainer.VolumeMounts, newVolumeMount)
165+
catalogDeployment.Spec.Template.Spec.Containers[catalogContainerIndex].Env = append(olmContainer.Env, corev1.EnvVar{
157166
Name: runtime_constraints.RuntimeConstraintEnvVarName,
158-
Value: fmt.Sprintf("/%s/%s", mountPath, runtimeConstraintsFileName),
167+
Value: fmt.Sprintf("%s/%s", mountPath, runtimeConstraintsFileName),
159168
})
160169

161-
err = kubeClient.Update(context.TODO(), olmDeployment)
170+
err = kubeClient.Update(context.TODO(), catalogDeployment)
162171

163172
if err != nil {
164173
panic(err)
165174
}
166175

167-
waitForOLMDeploymentToUpdate(kubeClient)
176+
waitForCatalogOperatorDeploymentToUpdate(kubeClient)
168177
}
169178

170-
func mustUnpatchOlmDeployment(kubeClient k8scontrollerclient.Client) {
171-
olmDeployment := &appsv1.Deployment{}
172-
err := kubeClient.Get(context.TODO(), olmOperatorKey, olmDeployment)
179+
func mustUnpatchCatalogOperatorDeployment(kubeClient k8scontrollerclient.Client) {
180+
catalogDeployment := &appsv1.Deployment{}
181+
err := kubeClient.Get(context.TODO(), olmOperatorKey, catalogDeployment)
173182

174183
if err != nil {
175184
panic(err)
176185
}
177186

178187
// Remove volume
179-
volumes := olmDeployment.Spec.Template.Spec.Volumes
188+
volumes := catalogDeployment.Spec.Template.Spec.Volumes
180189
for index, volume := range volumes {
181190
if volume.Name == runtimeConstraintsVolumeMountName {
182191
volumes = append(volumes[:index], volumes[index+1:]...)
183192
break
184193
}
185194
}
186-
olmDeployment.Spec.Template.Spec.Volumes = volumes
195+
catalogDeployment.Spec.Template.Spec.Volumes = volumes
187196

188197
// Remove volume mount
189-
volumeMounts := olmDeployment.Spec.Template.Spec.Containers[olmContainerIndex].VolumeMounts
198+
volumeMounts := catalogDeployment.Spec.Template.Spec.Containers[catalogContainerIndex].VolumeMounts
190199
for index, volumeMount := range volumeMounts {
191200
if volumeMount.Name == runtimeConstraintsVolumeMountName {
192201
volumeMounts = append(volumeMounts[:index], volumeMounts[index+1:]...)
193202
}
194203
}
195-
olmDeployment.Spec.Template.Spec.Containers[olmContainerIndex].VolumeMounts = volumeMounts
204+
catalogDeployment.Spec.Template.Spec.Containers[catalogContainerIndex].VolumeMounts = volumeMounts
196205

197206
// Remove environment variable
198-
envVars := olmDeployment.Spec.Template.Spec.Containers[olmContainerIndex].Env
207+
envVars := catalogDeployment.Spec.Template.Spec.Containers[catalogContainerIndex].Env
199208
for index, envVar := range envVars {
200209
if envVar.Name == runtime_constraints.RuntimeConstraintEnvVarName {
201210
envVars = append(envVars[:index], envVars[index+1:]...)
202211
}
203212
}
213+
catalogDeployment.Spec.Template.Spec.Containers[catalogContainerIndex].Env = envVars
204214

205-
err = kubeClient.Update(context.TODO(), olmDeployment)
215+
err = kubeClient.Update(context.TODO(), catalogDeployment)
206216

207217
if err != nil {
208218
panic(err)
209219
}
210220

211-
waitForOLMDeploymentToUpdate(kubeClient)
221+
waitForCatalogOperatorDeploymentToUpdate(kubeClient)
212222
}
213223

214224
func setupRuntimeConstraints(kubeClient k8scontrollerclient.Client) {
215225
mustDeployRuntimeConstraintsConfigMap(kubeClient)
216-
mustPatchOlmDeployment(kubeClient)
226+
mustPatchCatalogOperatorDeployment(kubeClient)
217227
}
218228

219229
func teardownRuntimeConstraints(kubeClient k8scontrollerclient.Client) {
230+
mustUnpatchCatalogOperatorDeployment(kubeClient)
220231
mustUndeployRuntimeConstraintsConfigMap(kubeClient)
221-
mustUnpatchOlmDeployment(kubeClient)
222232
}
223233

224234
func stripMargin(text string) string {
225235
regex := regexp.MustCompile(`([ \t]+)\|`)
226236
return strings.TrimSpace(regex.ReplaceAllString(text, ""))
227237
}
228238

229-
// waitForOLMDeploymentToUpdate waits for the olm operator deployment to be ready after an update
230-
func waitForOLMDeploymentToUpdate(kubeClient k8scontrollerclient.Client) {
239+
// waitForCatalogOperatorDeploymentToUpdate waits for the olm operator deployment to be ready after an update
240+
func waitForCatalogOperatorDeploymentToUpdate(kubeClient k8scontrollerclient.Client) {
231241
Eventually(func() error {
232242
deployment := &appsv1.Deployment{}
233243
err := kubeClient.Get(context.TODO(), olmOperatorKey, deployment)

0 commit comments

Comments
 (0)