-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unset replicaCount when autoscale is enabled
Signed-off-by: Tianpeng Wang <tpwang@alauda.io>
- Loading branch information
Showing
4 changed files
with
211 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package translate | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"istio.io/api/operator/v1alpha1" | ||
v1alpha12 "istio.io/api/operator/v1alpha1" | ||
"istio.io/istio/operator/pkg/name" | ||
"istio.io/istio/operator/pkg/util" | ||
) | ||
|
||
func Test_skipReplicaCountWithAutoscaleEnabled(t *testing.T) { | ||
const valuesWithHPAndReplicaCountFormat = ` | ||
values: | ||
pilot: | ||
autoscaleEnabled: %t | ||
gateways: | ||
istio-ingressgateway: | ||
autoscaleEnabled: %t | ||
istio-egressgateway: | ||
autoscaleEnabled: %t | ||
components: | ||
pilot: | ||
k8s: | ||
replicaCount: 2 | ||
ingressGateways: | ||
- name: istio-ingressgateway | ||
enabled: true | ||
k8s: | ||
replicaCount: 2 | ||
egressGateways: | ||
- name: istio-egressgateway | ||
enabled: true | ||
k8s: | ||
replicaCount: 2 | ||
` | ||
|
||
cases := []struct { | ||
name string | ||
component name.ComponentName | ||
values string | ||
expectSkip bool | ||
}{ | ||
{ | ||
name: "hpa enabled for pilot without replicas", | ||
component: name.PilotComponentName, | ||
values: fmt.Sprintf(valuesWithHPAndReplicaCountFormat, false, false, false), | ||
expectSkip: false, | ||
}, | ||
{ | ||
name: "hpa enabled for ingressgateway without replica", | ||
component: name.IngressComponentName, | ||
values: fmt.Sprintf(valuesWithHPAndReplicaCountFormat, false, false, false), | ||
expectSkip: false, | ||
}, | ||
{ | ||
name: "hpa enabled for pilot without replicas", | ||
component: name.EgressComponentName, | ||
values: fmt.Sprintf(valuesWithHPAndReplicaCountFormat, false, false, false), | ||
expectSkip: false, | ||
}, | ||
{ | ||
name: "hpa enabled for pilot with replicas", | ||
component: name.PilotComponentName, | ||
values: fmt.Sprintf(valuesWithHPAndReplicaCountFormat, true, false, false), | ||
expectSkip: true, | ||
}, | ||
{ | ||
name: "hpa enabled for ingressgateway with replicass", | ||
component: name.IngressComponentName, | ||
values: fmt.Sprintf(valuesWithHPAndReplicaCountFormat, false, true, false), | ||
expectSkip: true, | ||
}, | ||
{ | ||
name: "hpa enabled for egressgateway with replicas", | ||
component: name.EgressComponentName, | ||
values: fmt.Sprintf(valuesWithHPAndReplicaCountFormat, true, false, true), | ||
expectSkip: true, | ||
}, | ||
} | ||
for _, tt := range cases { | ||
t.Run(tt.name, func(t *testing.T) { | ||
var iop *v1alpha1.IstioOperatorSpec | ||
if tt.values != "" { | ||
iop = &v1alpha12.IstioOperatorSpec{} | ||
if err := util.UnmarshalWithJSONPB(tt.values, iop, true); err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
got := skipReplicaCountWithAutoscaleEnabled(iop, tt.component) | ||
assert.Equal(t, tt.expectSkip, got) | ||
}) | ||
} | ||
} |