44 "context"
55 "encoding/json"
66 "fmt"
7- "strings"
87 "testing"
98 "time"
109
@@ -184,18 +183,15 @@ func Test_Reconcile(t *testing.T) {
184183 }
185184
186185 gatewayclassesConfig := func (config string , gatewayclasses ... string ) json.RawMessage {
187- return json .RawMessage (fmt .Appendf (nil , `{%s}` , strings .Join (func () []string {
188- var result []string
189-
190- for _ , name := range gatewayclasses {
191- result = append (result , fmt .Sprintf (`"%s":%s` , name , config ))
192- }
193-
194- return result
195- }(), "," )))
186+ payload := make (map [string ]json.RawMessage , len (gatewayclasses ))
187+ for _ , name := range gatewayclasses {
188+ payload [name ] = json .RawMessage (config )
189+ }
190+ b , _ := json .Marshal (payload )
191+ return b
196192 }
197- hpaConfig := func (minReplicas int ) string {
198- return fmt .Sprintf (`{"horizontalPodAutoscaler":{"spec":{"maxReplicas":10,"minReplicas":%d}}}` , minReplicas )
193+ gatewayclassConfig := func (minReplicas int ) string {
194+ return fmt .Sprintf (`{"deployment":{"spec":{"template":{"spec":{"containers":[{"name":"istio-proxy","terminationMessagePolicy":"FallbackToLogsOnError"}]}}}}," horizontalPodAutoscaler":{"spec":{"maxReplicas":10,"minReplicas":%d}}}` , minReplicas )
199195 }
200196
201197 istioRevision := func () * sailv1.IstioRevision {
@@ -351,7 +347,7 @@ func Test_Reconcile(t *testing.T) {
351347 },
352348 expectCreate : []client.Object {
353349 subscription ("redhat-operators" , "stable" , "servicemeshoperator3.v3.0.1" ),
354- istio ("v1.24.4" , false , nil , gatewayclassesConfig (hpaConfig (2 ), "openshift-default" )),
350+ istio ("v1.24.4" , false , nil , gatewayclassesConfig (gatewayclassConfig (2 ), "openshift-default" )),
355351 manifests .IstiodAllowNetworkPolicy (),
356352 },
357353 expectUpdate : []client.Object {},
@@ -366,7 +362,7 @@ func Test_Reconcile(t *testing.T) {
366362 },
367363 expectCreate : []client.Object {
368364 subscription ("redhat-operators" , "stable" , "servicemeshoperator3.v3.0.1" ),
369- istio ("v1.24.4" , false , nil , gatewayclassesConfig (hpaConfig (1 ), "openshift-default" )),
365+ istio ("v1.24.4" , false , nil , gatewayclassesConfig (gatewayclassConfig (1 ), "openshift-default" )),
370366 manifests .IstiodAllowNetworkPolicy (),
371367 },
372368 expectUpdate : []client.Object {},
@@ -390,7 +386,7 @@ func Test_Reconcile(t *testing.T) {
390386 },
391387 expectCreate : []client.Object {
392388 subscription ("redhat-operators" , "stable" , "servicemeshoperator3.v3.0.1" ),
393- istio ("v1.24.4" , false , nil , gatewayclassesConfig (hpaConfig (2 ), "openshift-default" , "openshift-internal" )),
389+ istio ("v1.24.4" , false , nil , gatewayclassesConfig (gatewayclassConfig (2 ), "openshift-default" , "openshift-internal" )),
394390 manifests .IstiodAllowNetworkPolicy (),
395391 },
396392 expectUpdate : []client.Object {},
@@ -406,7 +402,7 @@ func Test_Reconcile(t *testing.T) {
406402 },
407403 expectCreate : []client.Object {
408404 subscription ("redhat-operators" , "stable" , "servicemeshoperator3.v3.0.1" ),
409- istio ("v1.24.4" , false , expectedProxyConfiguration , gatewayclassesConfig (hpaConfig (2 ), "openshift-default" )),
405+ istio ("v1.24.4" , false , expectedProxyConfiguration , gatewayclassesConfig (gatewayclassConfig (2 ), "openshift-default" )),
410406 manifests .IstiodAllowNetworkPolicy (),
411407 },
412408 expectUpdate : []client.Object {},
@@ -426,7 +422,7 @@ func Test_Reconcile(t *testing.T) {
426422 },
427423 expectCreate : []client.Object {
428424 subscription ("redhat-operators" , "stable" , "servicemeshoperator3.v3.0.1" ),
429- istio ("v1.24.4" , true , nil , gatewayclassesConfig (hpaConfig (2 ), "openshift-default" )),
425+ istio ("v1.24.4" , true , nil , gatewayclassesConfig (gatewayclassConfig (2 ), "openshift-default" )),
430426 manifests .IstiodAllowNetworkPolicy (),
431427 },
432428 expectUpdate : []client.Object {},
@@ -446,7 +442,7 @@ func Test_Reconcile(t *testing.T) {
446442 },
447443 expectCreate : []client.Object {
448444 subscription ("redhat-operators" , "stable" , "servicemeshoperator3.v3.0.1" ),
449- istio ("v1.24.4" , true , nil , gatewayclassesConfig (hpaConfig (2 ), "openshift-default" )),
445+ istio ("v1.24.4" , true , nil , gatewayclassesConfig (gatewayclassConfig (2 ), "openshift-default" )),
450446 manifests .IstiodAllowNetworkPolicy (),
451447 },
452448 expectUpdate : []client.Object {},
@@ -463,7 +459,7 @@ func Test_Reconcile(t *testing.T) {
463459 },
464460 expectCreate : []client.Object {
465461 subscription ("redhat-operators" , "stable" , "servicemeshoperator3.v3.0.1" ),
466- istio ("v1.24-latest" , false , nil , gatewayclassesConfig (hpaConfig (2 ), "openshift-default" )),
462+ istio ("v1.24-latest" , false , nil , gatewayclassesConfig (gatewayclassConfig (2 ), "openshift-default" )),
467463 manifests .IstiodAllowNetworkPolicy (),
468464 },
469465 expectUpdate : []client.Object {},
@@ -483,7 +479,7 @@ func Test_Reconcile(t *testing.T) {
483479 },
484480 expectCreate : []client.Object {
485481 subscription ("foo" , "bar" , "baz" ),
486- istio ("quux" , false , nil , gatewayclassesConfig (hpaConfig (2 ), "openshift-default" )),
482+ istio ("quux" , false , nil , gatewayclassesConfig (gatewayclassConfig (2 ), "openshift-default" )),
487483 manifests .IstiodAllowNetworkPolicy (),
488484 },
489485 expectUpdate : []client.Object {},
@@ -573,11 +569,11 @@ func Test_Reconcile(t *testing.T) {
573569 infraConfig (configv1 .HighlyAvailableTopologyMode ),
574570 gatewayClass ("openshift-default" , true , nil , nil , false ),
575571 istioCRD (),
576- istio ("v1.24.4" , true , nil , gatewayclassesConfig (hpaConfig (2 ), "openshift-default" )),
572+ istio ("v1.24.4" , true , nil , gatewayclassesConfig (gatewayclassConfig (2 ), "openshift-default" )),
577573 },
578574 expectPatched : []client.Object {},
579575 expectDelete : []client.Object {
580- istio ("v1.24.4" , true , nil , gatewayclassesConfig (hpaConfig (2 ), "openshift-default" )),
576+ istio ("v1.24.4" , true , nil , gatewayclassesConfig (gatewayclassConfig (2 ), "openshift-default" )),
581577 },
582578 expectedResult : reconcile.Result {
583579 RequeueAfter : 5 * time .Second ,
@@ -618,7 +614,7 @@ func Test_Reconcile(t *testing.T) {
618614 expectedStatusPatched : []client.Object {
619615 gatewayClass ("openshift-default" , true , nil , installedConditions (), false ),
620616 },
621- expectedSailLibraryOptions : expectedSailLibraryOptions ("v1.24.4" , false , nil , gatewayclassesConfig (hpaConfig (2 ), "openshift-default" )),
617+ expectedSailLibraryOptions : expectedSailLibraryOptions ("v1.24.4" , false , nil , gatewayclassesConfig (gatewayclassConfig (2 ), "openshift-default" )),
622618 },
623619 {
624620 name : "Sail Library: installs Istio (single replica)" ,
@@ -634,7 +630,7 @@ func Test_Reconcile(t *testing.T) {
634630 expectedStatusPatched : []client.Object {
635631 gatewayClass ("openshift-default" , true , nil , installedConditions (), false ),
636632 },
637- expectedSailLibraryOptions : expectedSailLibraryOptions ("v1.24.4" , false , nil , gatewayclassesConfig (hpaConfig (1 ), "openshift-default" )),
633+ expectedSailLibraryOptions : expectedSailLibraryOptions ("v1.24.4" , false , nil , gatewayclassesConfig (gatewayclassConfig (1 ), "openshift-default" )),
638634 },
639635 {
640636 name : "Sail Library: installs Istio (highly available)" ,
@@ -650,7 +646,7 @@ func Test_Reconcile(t *testing.T) {
650646 expectedStatusPatched : []client.Object {
651647 gatewayClass ("openshift-default" , true , nil , installedConditions (), false ),
652648 },
653- expectedSailLibraryOptions : expectedSailLibraryOptions ("v1.24.4" , false , nil , gatewayclassesConfig (hpaConfig (2 ), "openshift-default" )),
649+ expectedSailLibraryOptions : expectedSailLibraryOptions ("v1.24.4" , false , nil , gatewayclassesConfig (gatewayclassConfig (2 ), "openshift-default" )),
654650 },
655651 {
656652 name : "Sail Library: installs Istio with system proxy configuration" ,
@@ -667,7 +663,7 @@ func Test_Reconcile(t *testing.T) {
667663 expectedStatusPatched : []client.Object {
668664 gatewayClass ("openshift-default" , true , nil , installedConditions (), false ),
669665 },
670- expectedSailLibraryOptions : expectedSailLibraryOptions ("v1.24.4" , false , expectedProxyConfiguration , gatewayclassesConfig (hpaConfig (2 ), "openshift-default" )),
666+ expectedSailLibraryOptions : expectedSailLibraryOptions ("v1.24.4" , false , expectedProxyConfiguration , gatewayclassesConfig (gatewayclassConfig (2 ), "openshift-default" )),
671667 },
672668 {
673669 name : "Sail Library: installs Istio for multiple gatewayclasses in single-topology mode with system proxy configuration" ,
@@ -694,7 +690,7 @@ func Test_Reconcile(t *testing.T) {
694690 expectedStatusPatched : []client.Object {
695691 gatewayClass ("openshift-default" , true , nil , installedConditions (), false ),
696692 },
697- expectedSailLibraryOptions : expectedSailLibraryOptions ("v1.24.4" , false , expectedProxyConfiguration , gatewayclassesConfig (hpaConfig (1 ), "openshift-default" , "openshift-internal" , "openshift-custom" )),
693+ expectedSailLibraryOptions : expectedSailLibraryOptions ("v1.24.4" , false , expectedProxyConfiguration , gatewayclassesConfig (gatewayclassConfig (1 ), "openshift-default" , "openshift-internal" , "openshift-custom" )),
698694 },
699695 {
700696 name : "Sail Library: experimental InferencePool CRD" ,
@@ -715,7 +711,7 @@ func Test_Reconcile(t *testing.T) {
715711 expectedStatusPatched : []client.Object {
716712 gatewayClass ("openshift-default" , true , nil , installedConditions (), false ),
717713 },
718- expectedSailLibraryOptions : expectedSailLibraryOptions ("v1.24.4" , true , nil , gatewayclassesConfig (hpaConfig (2 ), "openshift-default" )),
714+ expectedSailLibraryOptions : expectedSailLibraryOptions ("v1.24.4" , true , nil , gatewayclassesConfig (gatewayclassConfig (2 ), "openshift-default" )),
719715 },
720716 {
721717 name : "Sail Library: stable InferencePool CRD" ,
@@ -736,7 +732,7 @@ func Test_Reconcile(t *testing.T) {
736732 expectedStatusPatched : []client.Object {
737733 gatewayClass ("openshift-default" , true , nil , installedConditions (), false ),
738734 },
739- expectedSailLibraryOptions : expectedSailLibraryOptions ("v1.24.4" , true , nil , gatewayclassesConfig (hpaConfig (2 ), "openshift-default" )),
735+ expectedSailLibraryOptions : expectedSailLibraryOptions ("v1.24.4" , true , nil , gatewayclassesConfig (gatewayclassConfig (2 ), "openshift-default" )),
740736 },
741737 {
742738 name : "Sail Library: Istio version override" ,
@@ -756,7 +752,7 @@ func Test_Reconcile(t *testing.T) {
756752 "unsupported.do-not-use.openshift.io/istio-version" : "v1.24-latest" ,
757753 }, installedConditions (), false ),
758754 },
759- expectedSailLibraryOptions : expectedSailLibraryOptions ("v1.24-latest" , false , nil , gatewayclassesConfig (hpaConfig (2 ), "openshift-default" )),
755+ expectedSailLibraryOptions : expectedSailLibraryOptions ("v1.24-latest" , false , nil , gatewayclassesConfig (gatewayclassConfig (2 ), "openshift-default" )),
760756 },
761757 {
762758 name : "Sail Library: full removal of last GatewayClass" ,
0 commit comments