@@ -4,6 +4,7 @@ package e2e
44
55import (
66 "context"
7+ "encoding/json"
78 "fmt"
89 "os"
910 "os/exec"
@@ -223,16 +224,14 @@ const (
223224 controllerDeployment = "bootc-operator-controller-manager"
224225)
225226
226- // setTagResolutionInterval patches the controller deployment to use
227- // the given interval and waits for the rollout to complete. The
228- // original args are restored in t.Cleanup.
229- func setTagResolutionInterval (t * testing.T , interval string ) {
227+ // patchControllerTestFlags patches the controller deployment args for
228+ // testing and waits for the rollout to complete. The original args
229+ // are restored in t.Cleanup.
230+ func patchControllerTestFlags (t * testing.T , extraFlags ... string ) {
230231 t .Helper ()
231232
232233 kubeconfigPath := os .Getenv ("KUBECONFIG" )
233- flag := "--tag-resolution-interval=" + interval
234234
235- // Read current args to restore later.
236235 out , err := exec .Command ("kubectl" , "--kubeconfig" , kubeconfigPath ,
237236 "-n" , controllerNamespace , "get" , "deploy" , controllerDeployment ,
238237 "-o" , "jsonpath={.spec.template.spec.containers[0].args}" ).CombinedOutput ()
@@ -241,26 +240,29 @@ func setTagResolutionInterval(t *testing.T, interval string) {
241240 }
242241 originalArgs := string (out )
243242
244- // Patch args to include the interval flag.
245- patch := fmt .Sprintf (`{"spec":{"template":{"spec":{"containers":[{"name":"manager","args":["--leader-elect","--health-probe-bind-address=:8081","%s"]}]}}}}` , flag )
243+ baseArgs := []string {"--leader-elect" , "--health-probe-bind-address=:8081" }
244+ allArgs := append (baseArgs , extraFlags ... )
245+ argsJSON , err := json .Marshal (allArgs )
246+ if err != nil {
247+ t .Fatalf ("marshalling args: %v" , err )
248+ }
249+ patch := fmt .Sprintf (`{"spec":{"template":{"spec":{"containers":[{"name":"manager","args":%s}]}}}}` , argsJSON )
246250 if out , err := exec .Command ("kubectl" , "--kubeconfig" , kubeconfigPath ,
247251 "-n" , controllerNamespace , "patch" , "deploy" , controllerDeployment ,
248252 "--type=strategic" , "-p" , patch ).CombinedOutput (); err != nil {
249253 t .Fatalf ("patching deployment: %s: %v" , string (out ), err )
250254 }
251255
252- // Wait for rollout.
253256 if out , err := exec .Command ("kubectl" , "--kubeconfig" , kubeconfigPath ,
254257 "-n" , controllerNamespace , "rollout" , "status" , "deploy/" + controllerDeployment ,
255258 "--timeout=2m" ).CombinedOutput (); err != nil {
256259 t .Fatalf ("waiting for rollout: %s: %v" , string (out ), err )
257260 }
258261
259- t .Logf ("Set --tag-resolution-interval= %s (was %s)" , interval , originalArgs )
262+ t .Logf ("Patched controller args to %s (was %s)" , argsJSON , originalArgs )
260263
261264 t .Cleanup (func () {
262- // Restore original args.
263- patch := fmt .Sprintf (`{"spec":{"template":{"spec":{"containers":[{"name":"manager","args":["--leader-elect","--health-probe-bind-address=:8081"]}]}}}}` )
265+ patch := fmt .Sprintf (`{"spec":{"template":{"spec":{"containers":[{"name":"manager","args":%s}]}}}}` , originalArgs )
264266 if out , err := exec .Command ("kubectl" , "--kubeconfig" , kubeconfigPath ,
265267 "-n" , controllerNamespace , "patch" , "deploy" , controllerDeployment ,
266268 "--type=strategic" , "-p" , patch ).CombinedOutput (); err != nil {
@@ -288,7 +290,7 @@ func TestTagResolution(t *testing.T) {
288290 ctx := context .Background ()
289291
290292 // Shorten the tag resolution interval so re-resolution happens quickly.
291- setTagResolutionInterval (t , "10s" )
293+ patchControllerTestFlags (t , "--tag-resolution-interval= 10s" )
292294
293295 nodeName := env .AddNode (t )
294296
0 commit comments