Skip to content

Commit 1b1516e

Browse files
committed
Add ReplicaCount to AKODeploymentConfig
Signed-off-by: Christian Ang <[email protected]>
1 parent aeacc93 commit 1b1516e

8 files changed

+112
-1
lines changed

api/v1alpha1/akodeploymentconfig_types.go

+7
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ type AKODeploymentConfigSpec struct {
9898

9999
// ExtraConfigs contains extra configurations for AKO Deployment
100100
type ExtraConfigs struct {
101+
// Defines the number of AKO instances to deploy to allow of high availablity. Max number of replicas is two.
102+
// Default value: 1
103+
// +kubebuilder:validation:Minimum=1
104+
// +kubebuilder:validation:Maximum=2
105+
// +optional
106+
ReplicaCount *int `json:"replicaCount,omitempty"`
107+
101108
// Defines AKO instance is primary or not. Value `true` indicates that AKO instance is primary.
102109
// In a multiple AKO deployment in a cluster, only one AKO instance should be primary.
103110
// Default value: true.

api/v1alpha1/akodeploymentconfig_webhook.go

+22
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ func (r *AKODeploymentConfig) validateAVI(old *AKODeploymentConfig) field.ErrorL
178178
aviClient = client
179179
}
180180

181+
if err := r.validateReplicaCount(); err != nil {
182+
allErrs = append(allErrs, err)
183+
}
184+
181185
if old == nil {
182186
// when old is nil, it is creating a new AKODeploymentConfig object, check following fields
183187
if err := r.validateAviCloud(); err != nil {
@@ -223,6 +227,24 @@ func (r *AKODeploymentConfig) validateAVI(old *AKODeploymentConfig) field.ErrorL
223227
return allErrs
224228
}
225229

230+
// validateReplicaCount checks replica count is between 1 and 2 or is unset
231+
func (r *AKODeploymentConfig) validateReplicaCount() *field.Error {
232+
if r.Spec.ExtraConfigs.ReplicaCount == nil {
233+
return nil
234+
}
235+
if *r.Spec.ExtraConfigs.ReplicaCount < 1 {
236+
return field.Invalid(field.NewPath("spec", "extraConfigs", "replicaCount"),
237+
r.Spec.ExtraConfigs.ReplicaCount,
238+
"replica count must be 1 or 2")
239+
}
240+
if *r.Spec.ExtraConfigs.ReplicaCount > 2 {
241+
return field.Invalid(field.NewPath("spec", "extraConfigs", "replicaCount"),
242+
r.Spec.ExtraConfigs.ReplicaCount,
243+
"replica count must be 1 or 2")
244+
}
245+
return nil
246+
}
247+
226248
// validateAviSecret checks NSX Advanced Load Balancer related credentials or certificate secret is valid or not
227249
func (r *AKODeploymentConfig) validateAviSecret(secret *corev1.Secret, secretRef SecretReference) *field.Error {
228250
if err := kclient.Get(context.Background(), client.ObjectKey{

api/v1alpha1/akodeploymentconfig_webhook_test.go

+55
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,61 @@ func TestCreateNewAKODeploymentConfig(t *testing.T) {
359359
},
360360
expectErr: false,
361361
},
362+
{
363+
name: "replica count is unset",
364+
adminSecret: staticAdminSecret.DeepCopy(),
365+
certificateSecret: staticCASecret.DeepCopy(),
366+
adc: staticADC.DeepCopy(),
367+
customizeInput: func(adminSecret, certificateSecret *corev1.Secret, adc *AKODeploymentConfig) (*corev1.Secret, *corev1.Secret, *AKODeploymentConfig) {
368+
adc.Spec.ExtraConfigs.ReplicaCount = nil
369+
return adminSecret, certificateSecret, adc
370+
},
371+
expectErr: false,
372+
},
373+
{
374+
name: "replica count is 1",
375+
adminSecret: staticAdminSecret.DeepCopy(),
376+
certificateSecret: staticCASecret.DeepCopy(),
377+
adc: staticADC.DeepCopy(),
378+
customizeInput: func(adminSecret, certificateSecret *corev1.Secret, adc *AKODeploymentConfig) (*corev1.Secret, *corev1.Secret, *AKODeploymentConfig) {
379+
adc.Spec.ExtraConfigs.ReplicaCount = ptr.To(1)
380+
return adminSecret, certificateSecret, adc
381+
},
382+
expectErr: false,
383+
},
384+
{
385+
name: "replica count is 2",
386+
adminSecret: staticAdminSecret.DeepCopy(),
387+
certificateSecret: staticCASecret.DeepCopy(),
388+
adc: staticADC.DeepCopy(),
389+
customizeInput: func(adminSecret, certificateSecret *corev1.Secret, adc *AKODeploymentConfig) (*corev1.Secret, *corev1.Secret, *AKODeploymentConfig) {
390+
adc.Spec.ExtraConfigs.ReplicaCount = ptr.To(2)
391+
return adminSecret, certificateSecret, adc
392+
},
393+
expectErr: false,
394+
},
395+
{
396+
name: "should throw error if replica count is less than 1",
397+
adminSecret: staticAdminSecret.DeepCopy(),
398+
certificateSecret: staticCASecret.DeepCopy(),
399+
adc: staticADC.DeepCopy(),
400+
customizeInput: func(adminSecret, certificateSecret *corev1.Secret, adc *AKODeploymentConfig) (*corev1.Secret, *corev1.Secret, *AKODeploymentConfig) {
401+
adc.Spec.ExtraConfigs.ReplicaCount = ptr.To(0)
402+
return adminSecret, certificateSecret, adc
403+
},
404+
expectErr: true,
405+
},
406+
{
407+
name: "should throw error if replica count is greater than 2",
408+
adminSecret: staticAdminSecret.DeepCopy(),
409+
certificateSecret: staticCASecret.DeepCopy(),
410+
adc: staticADC.DeepCopy(),
411+
customizeInput: func(adminSecret, certificateSecret *corev1.Secret, adc *AKODeploymentConfig) (*corev1.Secret, *corev1.Secret, *AKODeploymentConfig) {
412+
adc.Spec.ExtraConfigs.ReplicaCount = ptr.To(3)
413+
return adminSecret, certificateSecret, adc
414+
},
415+
expectErr: true,
416+
},
362417
}
363418

364419
for _, tc := range testcases {

api/v1alpha1/zz_generated.deepcopy.go

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/networking.tkg.tanzu.vmware.com_akodeploymentconfigs.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,13 @@ spec:
461461
the PodSecurityPolicy
462462
type: string
463463
type: object
464+
replicaCount:
465+
description: |-
466+
Defines the number of AKO instances to deploy to allow of high availablity. Max number of replicas is two.
467+
Default value: 1
468+
maximum: 2
469+
minimum: 1
470+
type: integer
464471
servicesAPI:
465472
description: |-
466473
ServicesAPI specifies if enables AKO in services API mode: https://kubernetes-sigs.github.io/service-apis/.

config/ytt/static.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,13 @@ spec:
465465
the PodSecurityPolicy
466466
type: string
467467
type: object
468+
replicaCount:
469+
description: |-
470+
Defines the number of AKO instances to deploy to allow of high availablity. Max number of replicas is two.
471+
Default value: 1
472+
maximum: 2
473+
minimum: 1
474+
type: integer
468475
servicesAPI:
469476
description: |-
470477
ServicesAPI specifies if enables AKO in services API mode: https://kubernetes-sigs.github.io/service-apis/.

pkg/ako/values.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,18 @@ func NewValues(obj *akoov1alpha1.AKODeploymentConfig, clusterNameSpacedName stri
4949
rbac := NewRbac(obj.Spec.ExtraConfigs.Rbac)
5050
featureGates := NewFeatureGates(obj.Spec.ExtraConfigs.FeatureGates)
5151

52+
replicaCount := 1
53+
if obj.Spec.ExtraConfigs.ReplicaCount != nil {
54+
replicaCount = *obj.Spec.ExtraConfigs.ReplicaCount
55+
}
56+
5257
return &Values{
5358
LoadBalancerAndIngressService: LoadBalancerAndIngressService{
5459
Name: "ako-" + clusterNameSpacedName,
5560
Namespace: akoov1alpha1.AviNamespace,
5661
Config: Config{
5762
IsClusterService: "",
58-
ReplicaCount: 1,
63+
ReplicaCount: replicaCount,
5964
AKOSettings: akoSettings,
6065
NetworkSettings: networkSettings,
6166
L7Settings: l7Settings,

pkg/ako/values_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ var _ = Describe("AKO", func() {
7575
Expect(k).To(Equal(v))
7676
}
7777

78+
Expect(config.ReplicaCount).To(Equal(*akoDeploymentConfig.Spec.ExtraConfigs.ReplicaCount))
79+
7880
if len(akoDeploymentConfig.Spec.ExtraConfigs.IngressConfigs.NodeNetworkList) != 0 {
7981
nodeNetworkListJson, jsonerr := json.Marshal(akoDeploymentConfig.Spec.ExtraConfigs.IngressConfigs.NodeNetworkList)
8082
Expect(jsonerr).ShouldNot(HaveOccurred())
@@ -108,6 +110,7 @@ var _ = Describe("AKO", func() {
108110
CIDR: "10.1.0.0/24",
109111
},
110112
ExtraConfigs: akoov1alpha1.ExtraConfigs{
113+
ReplicaCount: ptr.To(2),
111114
FullSyncFrequency: "1900",
112115
Rbac: akoov1alpha1.AKORbacConfig{
113116
PspEnabled: ptr.To(true),

0 commit comments

Comments
 (0)