@@ -18,6 +18,7 @@ import (
18
18
"github.com/openshift/origin/test/extended/util/image"
19
19
appsv1 "k8s.io/api/apps/v1"
20
20
corev1 "k8s.io/api/core/v1"
21
+ "k8s.io/apimachinery/pkg/api/errors"
21
22
"k8s.io/apimachinery/pkg/api/resource"
22
23
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23
24
"k8s.io/kubernetes/test/e2e/framework"
@@ -30,7 +31,9 @@ var _ = g.Describe("[Serial][sig-cli] oc adm upgrade recommend", g.Ordered, func
30
31
f := framework .NewDefaultFramework ("oc-adm-upgrade-recommend" )
31
32
oc := exutil .NewCLIWithFramework (f ).AsAdmin ()
32
33
var cv * configv1.ClusterVersion
33
- var restoreChannel , restoreUpstream bool
34
+ var proxy * configv1.Proxy
35
+ var newProxyCAs string
36
+ var restoreChannel , restoreUpstream , restoreProxy bool
34
37
35
38
g .BeforeAll (func () {
36
39
isMicroShift , err := exutil .IsMicroShiftCluster (oc .AdminKubeClient ())
@@ -41,6 +44,9 @@ var _ = g.Describe("[Serial][sig-cli] oc adm upgrade recommend", g.Ordered, func
41
44
42
45
cv , err = oc .AdminConfigClient ().ConfigV1 ().ClusterVersions ().Get (ctx , "version" , metav1.GetOptions {})
43
46
o .Expect (err ).NotTo (o .HaveOccurred ())
47
+
48
+ proxy , err = oc .AdminConfigClient ().ConfigV1 ().Proxies ().Get (ctx , "cluster" , metav1.GetOptions {})
49
+ o .Expect (err ).NotTo (o .HaveOccurred ())
44
50
})
45
51
46
52
g .AfterAll (func () {
@@ -51,6 +57,18 @@ var _ = g.Describe("[Serial][sig-cli] oc adm upgrade recommend", g.Ordered, func
51
57
if restoreUpstream {
52
58
oc .Run ("patch" , "clusterversions.config.openshift.io" , "version" , "--type" , "json" , "-p" , fmt .Sprintf (`[{"op": "add", "path": "/spec/upstream", "value": "%s"}]` , cv .Spec .Upstream )).Execute ()
53
59
}
60
+
61
+ if restoreProxy {
62
+ if proxy == nil {
63
+ oc .AdminConfigClient ().ConfigV1 ().Proxies ().Delete (ctx , "cluster" , metav1.DeleteOptions {})
64
+ } else {
65
+ oc .Run ("patch" , "proxies.config.openshift.io" , "version" , "--type" , "json" , "-p" , fmt .Sprintf (`[{"op": "add", "path": "/spec/trustedCA/name", "value": "%s"}]` , proxy .Spec .TrustedCA .Name )).Execute ()
66
+ }
67
+ }
68
+
69
+ if newProxyCAs != "" {
70
+ oc .AdminKubeClient ().CoreV1 ().ConfigMaps ("openshift-config" ).Delete (ctx , newProxyCAs , metav1.DeleteOptions {})
71
+ }
54
72
})
55
73
56
74
g .It ("runs successfully, even without upstream OpenShift Update Service customization" , func () {
@@ -80,7 +98,11 @@ var _ = g.Describe("[Serial][sig-cli] oc adm upgrade recommend", g.Ordered, func
80
98
}
81
99
82
100
graph := fmt .Sprintf (`{"nodes": [{"version": "%s","payload": "%s", "metadata": {"io.openshift.upgrades.graph.release.channels": "test-channel,other-channel"}}]}` , cv .Status .Desired .Version , cv .Status .Desired .Image )
83
- newUpstream , err := runUpdateService (ctx , oc , graph )
101
+ newUpstream , newProxyCASecret , err := runUpdateService (ctx , oc , graph , false )
102
+ if newProxyCASecret != "" {
103
+ restoreProxy = true
104
+ newProxyCAs = newProxyCASecret
105
+ }
84
106
o .Expect (err ).NotTo (o .HaveOccurred ())
85
107
86
108
err = oc .Run ("adm" , "upgrade" , "channel" , "test-channel" ).Execute ()
@@ -160,7 +182,11 @@ No updates available. You may still upgrade to a specific release image.*`)
160
182
o .Expect (err ).NotTo (o .HaveOccurred ())
161
183
graph := buf .String ()
162
184
163
- newUpstream , err := runUpdateService (ctx , oc , graph )
185
+ newUpstream , newProxyCASecret , err := runUpdateService (ctx , oc , graph , true )
186
+ if newProxyCASecret != "" {
187
+ restoreProxy = true
188
+ newProxyCAs = newProxyCASecret
189
+ }
164
190
o .Expect (err ).NotTo (o .HaveOccurred ())
165
191
166
192
err = oc .Run ("adm" , "upgrade" , "channel" , "test-channel" ).Execute ()
@@ -183,7 +209,7 @@ No updates available. You may still upgrade to a specific release image.*`)
183
209
o .Expect (err ).NotTo (o .HaveOccurred ())
184
210
err = matchRegexp (out , `Upstream update service: http://.*
185
211
Channel: test-channel [(]available channels: other-channel, test-channel[)]
186
-
212
+ FIXME
187
213
Updates to 4.[0-9]*:
188
214
189
215
Version: 4[.][0-9]*[.]0
@@ -216,7 +242,7 @@ Updates to 4[.][0-9]*:
216
242
217
243
Upstream update service: http://.*
218
244
Channel: test-channel [(]available channels: other-channel, test-channel[)]
219
-
245
+ FIXME
220
246
Update to 4[.][0-9]*[.]0 Recommended=False:
221
247
Image: example.com/test@sha256:cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
222
248
Release URL: https://example.com/release/4[.][0-9]*[.]0
@@ -228,7 +254,8 @@ Message: (?s:.*)This is a test risk. https://example.com/testRiskA`)
228
254
})
229
255
})
230
256
231
- func runUpdateService (ctx context.Context , oc * exutil.CLI , graph string ) (* url.URL , error ) {
257
+ func runUpdateService (ctx context.Context , oc * exutil.CLI , graph string , proxyTrustIngress bool ) (* url.URL , string , error ) {
258
+ newProxyCAs := ""
232
259
deployment , err := oc .AdminKubeClient ().AppsV1 ().Deployments (oc .Namespace ()).Create (ctx ,
233
260
& appsv1.Deployment {
234
261
ObjectMeta : metav1.ObjectMeta {
@@ -275,7 +302,7 @@ python3 -m http.server --bind ::
275
302
},
276
303
}, metav1.CreateOptions {})
277
304
if err != nil {
278
- return nil , err
305
+ return nil , newProxyCAs , err
279
306
}
280
307
281
308
service , err := oc .AdminKubeClient ().CoreV1 ().Services (oc .Namespace ()).Create (ctx ,
@@ -292,16 +319,83 @@ python3 -m http.server --bind ::
292
319
},
293
320
}, metav1.CreateOptions {})
294
321
if err != nil {
295
- return nil , err
322
+ return nil , newProxyCAs , err
323
+ }
324
+
325
+ if proxyTrustIngress {
326
+ defaultIngressSecretName , err := oc .Run ("get" ).Args ("--namespace=openshift-ingress-operator" , "-o" , "jsonpath={.spec.defaultCertificate.name}" , "ingresscontroller.operator.openshift.io" , "default" ).Output ()
327
+ if err != nil {
328
+ return nil , newProxyCAs , err
329
+ }
330
+
331
+ if defaultIngressSecretName == "" {
332
+ defaultIngressSecretName = "router-certs-default"
333
+ }
334
+
335
+ defaultIngressCert , err := oc .Run ("extract" ).Args ("--namespace=openshift-ingress" , fmt .Sprintf ("secret/%s" , defaultIngressSecretName ), "--keys=tls.crt" , "--to=-" ).Output ()
336
+ if err != nil {
337
+ return nil , newProxyCAs , err
338
+ }
339
+ framework .Logf ("default ingress certificate: %q" , defaultIngressCert )
340
+ updatedProxyCAs := defaultIngressCert
341
+
342
+ proxy , err := oc .AdminConfigClient ().ConfigV1 ().Proxies ().Get (ctx , "cluster" , metav1.GetOptions {})
343
+ if err != nil && errors .IsNotFound (err ) {
344
+ return nil , newProxyCAs , err
345
+ } else if proxy .Spec .TrustedCA .Name != "" {
346
+ originalProxyCAs , err := oc .Run ("extract" ).Args ("--namespace=openshift-config" , fmt .Sprintf ("secret/%s" , proxy .Spec .TrustedCA .Name ), "--keys=ca-bundle.crt" , "--to=-" ).Output ()
347
+ if err != nil {
348
+ return nil , newProxyCAs , err
349
+ }
350
+ framework .Logf ("original proxy CAs: %q" , originalProxyCAs )
351
+
352
+ updatedProxyCAs = fmt .Sprintf ("%s%s\n " , updatedProxyCAs , originalProxyCAs )
353
+ }
354
+
355
+ configMap , err := oc .AdminKubeClient ().CoreV1 ().ConfigMap ("openshift-config" ).Create (ctx ,
356
+ & corev1.ConfigMap {
357
+ ObjectMeta : metav1.ObjectMeta {
358
+ GenerateName : "test-proxy-and-ingress-cas-" ,
359
+ },
360
+ Data : map [string ]string {
361
+ "ca-bundle.crt" : updatedProxyCAs ,
362
+ },
363
+ }, metav1.CreateOptions {})
364
+ if err != nil {
365
+ return nil , newProxyCAs , err
366
+ }
367
+ newProxyCAs = configMap .ObjectMeta .Name
368
+
369
+ if proxy == nil {
370
+ proxy , err = oc .AdminConfigClient ().ConfigV1 ().Proxies ().Create (ctx ,
371
+ & configv1.Proxy {
372
+ ObjectMeta : metav1.ObjectMeta {
373
+ Name : "cluster" ,
374
+ },
375
+ Spec : configv1.ProxySpec {
376
+ TrustedCA : configv1.ConfigMapNameReference {
377
+ Name : newProxyCAs ,
378
+ },
379
+ },
380
+ }, metav1.CreateOptions {})
381
+ if err != nil {
382
+ return nil , newProxyCAs , err
383
+ }
384
+ } else {
385
+ err = oc .Run ("patch" , "proxies.config.openshift.io" , "version" , "--type" , "json" , "-p" , fmt .Sprintf (`[{"op": "add", "path": "/spec/trustedCA/name", "value": "%s"}]` , newProxyCAs )).Execute ()
386
+ if err != nil {
387
+ return nil , newProxyCAs , err
388
+ }
389
+ }
296
390
}
297
391
298
392
if err = exutil .WaitForDeploymentReady (oc , deployment .ObjectMeta .Name , oc .Namespace (), - 1 ); err != nil {
299
- return nil , err
393
+ return nil , newProxyCAs , err
300
394
}
301
395
302
396
return & url.URL {
303
397
Scheme : "http" ,
304
398
Host : net .JoinHostPort (service .Spec .ClusterIP , strconv .Itoa (int (service .Spec .Ports [0 ].Port ))),
305
399
Path : "graph" ,
306
- }, nil
400
+ }, newProxyCAs , nil
307
401
}
0 commit comments