44 "context"
55 "encoding/json"
66 "fmt"
7- "strings"
87 "testing"
98 "time"
109
@@ -184,18 +183,18 @@ 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 , err := json . Marshal ( payload )
191+ if err != nil {
192+ t . Fatalf ( "an error occurred during json creation for gatewayclassesConfig: %s" , err )
193+ }
194+ return b
196195 }
197- hpaConfig := func (minReplicas int ) string {
198- return fmt .Sprintf (`{"horizontalPodAutoscaler":{"spec":{"maxReplicas":10,"minReplicas":%d}}}` , minReplicas )
196+ gatewayclassConfig := func (minReplicas int ) string {
197+ return fmt .Sprintf (`{"deployment":{"spec":{"template":{"spec":{"containers":[{"name":"istio-proxy","resources":{"limits":null}}]}}}}," horizontalPodAutoscaler":{"spec":{"maxReplicas":10,"minReplicas":%d}}}` , minReplicas )
199198 }
200199
201200 istioRevision := func () * sailv1.IstioRevision {
@@ -351,7 +350,7 @@ func Test_Reconcile(t *testing.T) {
351350 },
352351 expectCreate : []client.Object {
353352 subscription ("redhat-operators" , "stable" , "servicemeshoperator3.v3.0.1" ),
354- istio ("v1.24.4" , false , nil , gatewayclassesConfig (hpaConfig (2 ), "openshift-default" )),
353+ istio ("v1.24.4" , false , nil , gatewayclassesConfig (gatewayclassConfig (2 ), "openshift-default" )),
355354 manifests .IstiodAllowNetworkPolicy (),
356355 },
357356 expectUpdate : []client.Object {},
@@ -366,7 +365,7 @@ func Test_Reconcile(t *testing.T) {
366365 },
367366 expectCreate : []client.Object {
368367 subscription ("redhat-operators" , "stable" , "servicemeshoperator3.v3.0.1" ),
369- istio ("v1.24.4" , false , nil , gatewayclassesConfig (hpaConfig (1 ), "openshift-default" )),
368+ istio ("v1.24.4" , false , nil , gatewayclassesConfig (gatewayclassConfig (1 ), "openshift-default" )),
370369 manifests .IstiodAllowNetworkPolicy (),
371370 },
372371 expectUpdate : []client.Object {},
@@ -390,7 +389,7 @@ func Test_Reconcile(t *testing.T) {
390389 },
391390 expectCreate : []client.Object {
392391 subscription ("redhat-operators" , "stable" , "servicemeshoperator3.v3.0.1" ),
393- istio ("v1.24.4" , false , nil , gatewayclassesConfig (hpaConfig (2 ), "openshift-default" , "openshift-internal" )),
392+ istio ("v1.24.4" , false , nil , gatewayclassesConfig (gatewayclassConfig (2 ), "openshift-default" , "openshift-internal" )),
394393 manifests .IstiodAllowNetworkPolicy (),
395394 },
396395 expectUpdate : []client.Object {},
@@ -406,7 +405,7 @@ func Test_Reconcile(t *testing.T) {
406405 },
407406 expectCreate : []client.Object {
408407 subscription ("redhat-operators" , "stable" , "servicemeshoperator3.v3.0.1" ),
409- istio ("v1.24.4" , false , expectedProxyConfiguration , gatewayclassesConfig (hpaConfig (2 ), "openshift-default" )),
408+ istio ("v1.24.4" , false , expectedProxyConfiguration , gatewayclassesConfig (gatewayclassConfig (2 ), "openshift-default" )),
410409 manifests .IstiodAllowNetworkPolicy (),
411410 },
412411 expectUpdate : []client.Object {},
@@ -426,7 +425,7 @@ func Test_Reconcile(t *testing.T) {
426425 },
427426 expectCreate : []client.Object {
428427 subscription ("redhat-operators" , "stable" , "servicemeshoperator3.v3.0.1" ),
429- istio ("v1.24.4" , true , nil , gatewayclassesConfig (hpaConfig (2 ), "openshift-default" )),
428+ istio ("v1.24.4" , true , nil , gatewayclassesConfig (gatewayclassConfig (2 ), "openshift-default" )),
430429 manifests .IstiodAllowNetworkPolicy (),
431430 },
432431 expectUpdate : []client.Object {},
@@ -446,7 +445,7 @@ func Test_Reconcile(t *testing.T) {
446445 },
447446 expectCreate : []client.Object {
448447 subscription ("redhat-operators" , "stable" , "servicemeshoperator3.v3.0.1" ),
449- istio ("v1.24.4" , true , nil , gatewayclassesConfig (hpaConfig (2 ), "openshift-default" )),
448+ istio ("v1.24.4" , true , nil , gatewayclassesConfig (gatewayclassConfig (2 ), "openshift-default" )),
450449 manifests .IstiodAllowNetworkPolicy (),
451450 },
452451 expectUpdate : []client.Object {},
@@ -463,7 +462,7 @@ func Test_Reconcile(t *testing.T) {
463462 },
464463 expectCreate : []client.Object {
465464 subscription ("redhat-operators" , "stable" , "servicemeshoperator3.v3.0.1" ),
466- istio ("v1.24-latest" , false , nil , gatewayclassesConfig (hpaConfig (2 ), "openshift-default" )),
465+ istio ("v1.24-latest" , false , nil , gatewayclassesConfig (gatewayclassConfig (2 ), "openshift-default" )),
467466 manifests .IstiodAllowNetworkPolicy (),
468467 },
469468 expectUpdate : []client.Object {},
@@ -483,7 +482,7 @@ func Test_Reconcile(t *testing.T) {
483482 },
484483 expectCreate : []client.Object {
485484 subscription ("foo" , "bar" , "baz" ),
486- istio ("quux" , false , nil , gatewayclassesConfig (hpaConfig (2 ), "openshift-default" )),
485+ istio ("quux" , false , nil , gatewayclassesConfig (gatewayclassConfig (2 ), "openshift-default" )),
487486 manifests .IstiodAllowNetworkPolicy (),
488487 },
489488 expectUpdate : []client.Object {},
@@ -573,11 +572,11 @@ func Test_Reconcile(t *testing.T) {
573572 infraConfig (configv1 .HighlyAvailableTopologyMode ),
574573 gatewayClass ("openshift-default" , true , nil , nil , false ),
575574 istioCRD (),
576- istio ("v1.24.4" , true , nil , gatewayclassesConfig (hpaConfig (2 ), "openshift-default" )),
575+ istio ("v1.24.4" , true , nil , gatewayclassesConfig (gatewayclassConfig (2 ), "openshift-default" )),
577576 },
578577 expectPatched : []client.Object {},
579578 expectDelete : []client.Object {
580- istio ("v1.24.4" , true , nil , gatewayclassesConfig (hpaConfig (2 ), "openshift-default" )),
579+ istio ("v1.24.4" , true , nil , gatewayclassesConfig (gatewayclassConfig (2 ), "openshift-default" )),
581580 },
582581 expectedResult : reconcile.Result {
583582 RequeueAfter : 5 * time .Second ,
@@ -618,7 +617,7 @@ func Test_Reconcile(t *testing.T) {
618617 expectedStatusPatched : []client.Object {
619618 gatewayClass ("openshift-default" , true , nil , installedConditions (), false ),
620619 },
621- expectedSailLibraryOptions : expectedSailLibraryOptions ("v1.24.4" , false , nil , gatewayclassesConfig (hpaConfig (2 ), "openshift-default" )),
620+ expectedSailLibraryOptions : expectedSailLibraryOptions ("v1.24.4" , false , nil , gatewayclassesConfig (gatewayclassConfig (2 ), "openshift-default" )),
622621 },
623622 {
624623 name : "Sail Library: installs Istio (single replica)" ,
@@ -634,7 +633,7 @@ func Test_Reconcile(t *testing.T) {
634633 expectedStatusPatched : []client.Object {
635634 gatewayClass ("openshift-default" , true , nil , installedConditions (), false ),
636635 },
637- expectedSailLibraryOptions : expectedSailLibraryOptions ("v1.24.4" , false , nil , gatewayclassesConfig (hpaConfig (1 ), "openshift-default" )),
636+ expectedSailLibraryOptions : expectedSailLibraryOptions ("v1.24.4" , false , nil , gatewayclassesConfig (gatewayclassConfig (1 ), "openshift-default" )),
638637 },
639638 {
640639 name : "Sail Library: installs Istio (highly available)" ,
@@ -650,7 +649,7 @@ func Test_Reconcile(t *testing.T) {
650649 expectedStatusPatched : []client.Object {
651650 gatewayClass ("openshift-default" , true , nil , installedConditions (), false ),
652651 },
653- expectedSailLibraryOptions : expectedSailLibraryOptions ("v1.24.4" , false , nil , gatewayclassesConfig (hpaConfig (2 ), "openshift-default" )),
652+ expectedSailLibraryOptions : expectedSailLibraryOptions ("v1.24.4" , false , nil , gatewayclassesConfig (gatewayclassConfig (2 ), "openshift-default" )),
654653 },
655654 {
656655 name : "Sail Library: installs Istio with system proxy configuration" ,
@@ -667,7 +666,7 @@ func Test_Reconcile(t *testing.T) {
667666 expectedStatusPatched : []client.Object {
668667 gatewayClass ("openshift-default" , true , nil , installedConditions (), false ),
669668 },
670- expectedSailLibraryOptions : expectedSailLibraryOptions ("v1.24.4" , false , expectedProxyConfiguration , gatewayclassesConfig (hpaConfig (2 ), "openshift-default" )),
669+ expectedSailLibraryOptions : expectedSailLibraryOptions ("v1.24.4" , false , expectedProxyConfiguration , gatewayclassesConfig (gatewayclassConfig (2 ), "openshift-default" )),
671670 },
672671 {
673672 name : "Sail Library: installs Istio for multiple gatewayclasses in single-topology mode with system proxy configuration" ,
@@ -694,7 +693,7 @@ func Test_Reconcile(t *testing.T) {
694693 expectedStatusPatched : []client.Object {
695694 gatewayClass ("openshift-default" , true , nil , installedConditions (), false ),
696695 },
697- expectedSailLibraryOptions : expectedSailLibraryOptions ("v1.24.4" , false , expectedProxyConfiguration , gatewayclassesConfig (hpaConfig (1 ), "openshift-default" , "openshift-internal" , "openshift-custom" )),
696+ expectedSailLibraryOptions : expectedSailLibraryOptions ("v1.24.4" , false , expectedProxyConfiguration , gatewayclassesConfig (gatewayclassConfig (1 ), "openshift-default" , "openshift-internal" , "openshift-custom" )),
698697 },
699698 {
700699 name : "Sail Library: experimental InferencePool CRD" ,
@@ -715,7 +714,7 @@ func Test_Reconcile(t *testing.T) {
715714 expectedStatusPatched : []client.Object {
716715 gatewayClass ("openshift-default" , true , nil , installedConditions (), false ),
717716 },
718- expectedSailLibraryOptions : expectedSailLibraryOptions ("v1.24.4" , true , nil , gatewayclassesConfig (hpaConfig (2 ), "openshift-default" )),
717+ expectedSailLibraryOptions : expectedSailLibraryOptions ("v1.24.4" , true , nil , gatewayclassesConfig (gatewayclassConfig (2 ), "openshift-default" )),
719718 },
720719 {
721720 name : "Sail Library: stable InferencePool CRD" ,
@@ -736,7 +735,7 @@ func Test_Reconcile(t *testing.T) {
736735 expectedStatusPatched : []client.Object {
737736 gatewayClass ("openshift-default" , true , nil , installedConditions (), false ),
738737 },
739- expectedSailLibraryOptions : expectedSailLibraryOptions ("v1.24.4" , true , nil , gatewayclassesConfig (hpaConfig (2 ), "openshift-default" )),
738+ expectedSailLibraryOptions : expectedSailLibraryOptions ("v1.24.4" , true , nil , gatewayclassesConfig (gatewayclassConfig (2 ), "openshift-default" )),
740739 },
741740 {
742741 name : "Sail Library: Istio version override" ,
@@ -756,7 +755,7 @@ func Test_Reconcile(t *testing.T) {
756755 "unsupported.do-not-use.openshift.io/istio-version" : "v1.24-latest" ,
757756 }, installedConditions (), false ),
758757 },
759- expectedSailLibraryOptions : expectedSailLibraryOptions ("v1.24-latest" , false , nil , gatewayclassesConfig (hpaConfig (2 ), "openshift-default" )),
758+ expectedSailLibraryOptions : expectedSailLibraryOptions ("v1.24-latest" , false , nil , gatewayclassesConfig (gatewayclassConfig (2 ), "openshift-default" )),
760759 },
761760 {
762761 name : "Sail Library: full removal of last GatewayClass" ,
0 commit comments