6
6
"fmt"
7
7
"regexp"
8
8
"strings"
9
+ "time"
9
10
10
11
. "github.com/onsi/ginkgo"
11
12
. "github.com/onsi/gomega"
@@ -22,16 +23,16 @@ import (
22
23
const (
23
24
runtimeConstraintsVolumeMountName = "runtime-constraints"
24
25
runtimeConstraintsConfigMapName = "runtime-constraints"
25
- runtimeConstraintsFileName = "runtime_constraints.yaml "
26
+ runtimeConstraintsFileName = "runtime_constraints.json "
26
27
defaultOlmNamespace = "operator-lifecycle-manager"
27
- olmOperatorName = "olm -operator"
28
- olmContainerIndex = 0
28
+ catalogOperatorName = "catalog -operator"
29
+ catalogContainerIndex = 0
29
30
)
30
31
31
32
var (
32
33
olmOperatorKey = k8scontrollerclient.ObjectKey {
33
34
Namespace : defaultOlmNamespace ,
34
- Name : olmOperatorName ,
35
+ Name : catalogOperatorName ,
35
36
}
36
37
)
37
38
@@ -45,7 +46,7 @@ var _ = By
45
46
// Before each test:
46
47
// 1. Create a new config map in the operator-lifecycle-manager namespace that contains the
47
48
// 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
49
50
// 3. Update the deployment to include the environment variable pointing to the runtime constraints file
50
51
// 4. Wait for the deployment to finish updating
51
52
//
@@ -67,21 +68,29 @@ var _ = Describe("Cluster Runtime Constraints", func() {
67
68
68
69
AfterEach (func () {
69
70
teardownRuntimeConstraints (ctx .Ctx ().Client ())
71
+ time .Sleep (1 * time .Minute )
70
72
TeardownNamespace (generatedNamespace .GetName ())
71
73
})
72
74
73
75
It ("Runtime" , func () {
76
+ time .Sleep (2 * time .Minute )
74
77
require .Equal (GinkgoT (), true , true )
75
78
})
76
79
})
77
80
78
81
func mustDeployRuntimeConstraintsConfigMap (kubeClient k8scontrollerclient.Client ) {
79
82
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
+ |}` )
85
94
86
95
isImmutable := true
87
96
configMap := & corev1.ConfigMap {
@@ -122,16 +131,16 @@ func mustUndeployRuntimeConstraintsConfigMap(kubeClient k8scontrollerclient.Clie
122
131
}).Should (BeTrue ())
123
132
}
124
133
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 )
128
137
129
138
if err != nil {
130
139
panic (err )
131
140
}
132
141
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 ]
135
144
136
145
newVolume := corev1.Volume {
137
146
Name : runtimeConstraintsVolumeMountName ,
@@ -151,83 +160,84 @@ func mustPatchOlmDeployment(kubeClient k8scontrollerclient.Client) {
151
160
ReadOnly : true ,
152
161
}
153
162
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 {
157
166
Name : runtime_constraints .RuntimeConstraintEnvVarName ,
158
- Value : fmt .Sprintf ("/ %s/%s" , mountPath , runtimeConstraintsFileName ),
167
+ Value : fmt .Sprintf ("%s/%s" , mountPath , runtimeConstraintsFileName ),
159
168
})
160
169
161
- err = kubeClient .Update (context .TODO (), olmDeployment )
170
+ err = kubeClient .Update (context .TODO (), catalogDeployment )
162
171
163
172
if err != nil {
164
173
panic (err )
165
174
}
166
175
167
- waitForOLMDeploymentToUpdate (kubeClient )
176
+ waitForCatalogOperatorDeploymentToUpdate (kubeClient )
168
177
}
169
178
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 )
173
182
174
183
if err != nil {
175
184
panic (err )
176
185
}
177
186
178
187
// Remove volume
179
- volumes := olmDeployment .Spec .Template .Spec .Volumes
188
+ volumes := catalogDeployment .Spec .Template .Spec .Volumes
180
189
for index , volume := range volumes {
181
190
if volume .Name == runtimeConstraintsVolumeMountName {
182
191
volumes = append (volumes [:index ], volumes [index + 1 :]... )
183
192
break
184
193
}
185
194
}
186
- olmDeployment .Spec .Template .Spec .Volumes = volumes
195
+ catalogDeployment .Spec .Template .Spec .Volumes = volumes
187
196
188
197
// Remove volume mount
189
- volumeMounts := olmDeployment .Spec .Template .Spec .Containers [olmContainerIndex ].VolumeMounts
198
+ volumeMounts := catalogDeployment .Spec .Template .Spec .Containers [catalogContainerIndex ].VolumeMounts
190
199
for index , volumeMount := range volumeMounts {
191
200
if volumeMount .Name == runtimeConstraintsVolumeMountName {
192
201
volumeMounts = append (volumeMounts [:index ], volumeMounts [index + 1 :]... )
193
202
}
194
203
}
195
- olmDeployment .Spec .Template .Spec .Containers [olmContainerIndex ].VolumeMounts = volumeMounts
204
+ catalogDeployment .Spec .Template .Spec .Containers [catalogContainerIndex ].VolumeMounts = volumeMounts
196
205
197
206
// Remove environment variable
198
- envVars := olmDeployment .Spec .Template .Spec .Containers [olmContainerIndex ].Env
207
+ envVars := catalogDeployment .Spec .Template .Spec .Containers [catalogContainerIndex ].Env
199
208
for index , envVar := range envVars {
200
209
if envVar .Name == runtime_constraints .RuntimeConstraintEnvVarName {
201
210
envVars = append (envVars [:index ], envVars [index + 1 :]... )
202
211
}
203
212
}
213
+ catalogDeployment .Spec .Template .Spec .Containers [catalogContainerIndex ].Env = envVars
204
214
205
- err = kubeClient .Update (context .TODO (), olmDeployment )
215
+ err = kubeClient .Update (context .TODO (), catalogDeployment )
206
216
207
217
if err != nil {
208
218
panic (err )
209
219
}
210
220
211
- waitForOLMDeploymentToUpdate (kubeClient )
221
+ waitForCatalogOperatorDeploymentToUpdate (kubeClient )
212
222
}
213
223
214
224
func setupRuntimeConstraints (kubeClient k8scontrollerclient.Client ) {
215
225
mustDeployRuntimeConstraintsConfigMap (kubeClient )
216
- mustPatchOlmDeployment (kubeClient )
226
+ mustPatchCatalogOperatorDeployment (kubeClient )
217
227
}
218
228
219
229
func teardownRuntimeConstraints (kubeClient k8scontrollerclient.Client ) {
230
+ mustUnpatchCatalogOperatorDeployment (kubeClient )
220
231
mustUndeployRuntimeConstraintsConfigMap (kubeClient )
221
- mustUnpatchOlmDeployment (kubeClient )
222
232
}
223
233
224
234
func stripMargin (text string ) string {
225
235
regex := regexp .MustCompile (`([ \t]+)\|` )
226
236
return strings .TrimSpace (regex .ReplaceAllString (text , "" ))
227
237
}
228
238
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 ) {
231
241
Eventually (func () error {
232
242
deployment := & appsv1.Deployment {}
233
243
err := kubeClient .Get (context .TODO (), olmOperatorKey , deployment )
0 commit comments