21
"istio.io/api/operator/v1alpha1"
22
"istio.io/istio/operator/pkg/name"
23
"istio.io/istio/operator/pkg/object"
24
"istio.io/istio/operator/pkg/tpath"
25
"istio.io/istio/operator/pkg/util"
26
"istio.io/istio/pkg/test/util/assert"
29
func Test_skipReplicaCountWithAutoscaleEnabled(t *testing.T) {
30
const valuesWithHPAndReplicaCountFormat = `
44
- name: istio-ingressgateway
49
- name: istio-egressgateway
57
component name.ComponentName
62
name: "hpa enabled for pilot without replicas",
63
component: name.PilotComponentName,
64
values: fmt.Sprintf(valuesWithHPAndReplicaCountFormat, false, false, false),
68
name: "hpa enabled for ingressgateway without replica",
69
component: name.IngressComponentName,
70
values: fmt.Sprintf(valuesWithHPAndReplicaCountFormat, false, false, false),
74
name: "hpa enabled for pilot without replicas",
75
component: name.EgressComponentName,
76
values: fmt.Sprintf(valuesWithHPAndReplicaCountFormat, false, false, false),
80
name: "hpa enabled for pilot with replicas",
81
component: name.PilotComponentName,
82
values: fmt.Sprintf(valuesWithHPAndReplicaCountFormat, true, false, false),
86
name: "hpa enabled for ingressgateway with replicas",
87
component: name.IngressComponentName,
88
values: fmt.Sprintf(valuesWithHPAndReplicaCountFormat, false, true, false),
92
name: "hpa enabled for egressgateway with replicas",
93
component: name.EgressComponentName,
94
values: fmt.Sprintf(valuesWithHPAndReplicaCountFormat, true, false, true),
98
for _, tt := range cases {
99
t.Run(tt.name, func(t *testing.T) {
100
var iop *v1alpha1.IstioOperatorSpec
102
iop = &v1alpha1.IstioOperatorSpec{}
103
if err := util.UnmarshalWithJSONPB(tt.values, iop, true); err != nil {
108
got := skipReplicaCountWithAutoscaleEnabled(iop, tt.component)
109
assert.Equal(t, tt.expectSkip, got)
114
func Test_fixMergedObjectWithCustomServicePortOverlay_withAppProtocol(t *testing.T) {
115
const serviceString = `
119
name: istio-ingressgateway
120
namespace: istio-system
127
- name: istio-ingressgateway
139
- name: istio-ingressgateway
156
name: "without appProtocol",
157
iopString: iopString,
161
name: "with appProtocol",
162
iopString: iopString2,
168
for _, tt := range cases {
169
t.Run(tt.name, func(t *testing.T) {
170
var iop *v1alpha1.IstioOperatorSpec
171
if tt.iopString != "" {
172
iop = &v1alpha1.IstioOperatorSpec{}
173
if err := util.UnmarshalWithJSONPB(tt.iopString, iop, true); err != nil {
177
translator := NewTranslator()
178
serviceObj, err := object.ParseYAMLToK8sObject([]byte(serviceString))
179
assert.NoError(t, err)
180
obj, err := translator.fixMergedObjectWithCustomServicePortOverlay(serviceObj,
181
iop.Components.IngressGateways[0].GetK8S().GetService(), serviceObj)
182
assert.NoError(t, err)
183
val := obj.UnstructuredObject().Object["spec"].(map[string]interface{})["ports"].([]interface{})[0]
184
apVal, found, _ := tpath.GetFromStructPath(val, "appProtocol")
186
assert.Equal(t, found, false)
189
assert.Equal(t, apVal.(string), tt.expectValue)
191
assert.Equal(t, "", tt.expectValue)