Skip to content

Commit 0b55547

Browse files
authored
Merge pull request #3846 from Ankitasw/vpccni
Refactor VPC CNI in managed control plane
2 parents bc57291 + 92e99a9 commit 0b55547

8 files changed

+107
-62
lines changed

config/crd/bases/controlplane.cluster.x-k8s.io_awsmanagedcontrolplanes.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,15 +1430,6 @@ spec:
14301430
- host
14311431
- port
14321432
type: object
1433-
disableVPCCNI:
1434-
default: false
1435-
description: DisableVPCCNI indicates that the Amazon VPC CNI should
1436-
be disabled. With EKS clusters the Amazon VPC CNI is automatically
1437-
installed into the cluster. For clusters where you want to use an
1438-
alternate CNI this option provides a way to specify that the Amazon
1439-
VPC CNI should be deleted. You cannot set this to true if you are
1440-
using the Amazon VPC CNI addon.
1441-
type: boolean
14421433
eksClusterName:
14431434
description: EKSClusterName allows you to specify the name of the
14441435
EKS cluster in AWS. If you don't specify a name then a default name
@@ -1905,6 +1896,15 @@ spec:
19051896
description: VpcCni is used to set configuration options for the VPC
19061897
CNI plugin
19071898
properties:
1899+
disable:
1900+
default: false
1901+
description: Disable indicates that the Amazon VPC CNI should
1902+
be disabled. With EKS clusters the Amazon VPC CNI is automatically
1903+
installed into the cluster. For clusters where you want to use
1904+
an alternate CNI this option provides a way to specify that
1905+
the Amazon VPC CNI should be deleted. You cannot set this to
1906+
true if you are using the Amazon VPC CNI addon.
1907+
type: boolean
19081908
env:
19091909
description: Env defines a list of environment variables to apply
19101910
to the `aws-node` DaemonSet

controlplane/eks/api/v1beta1/conversion.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
infrav1beta1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta1"
2222
infrav1beta2 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
2323
ekscontrolplanev1 "sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/eks/api/v1beta2"
24+
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
2425
"sigs.k8s.io/controller-runtime/pkg/conversion"
2526
)
2627

@@ -31,6 +32,13 @@ func (r *AWSManagedControlPlane) ConvertTo(dstRaw conversion.Hub) error {
3132
if err := Convert_v1beta1_AWSManagedControlPlane_To_v1beta2_AWSManagedControlPlane(r, dst, nil); err != nil {
3233
return err
3334
}
35+
36+
// Manually restore data.
37+
restored := &ekscontrolplanev1.AWSManagedControlPlane{}
38+
if ok, err := utilconversion.UnmarshalData(r, restored); err != nil || !ok {
39+
return err
40+
}
41+
dst.Spec.VpcCni.Disable = r.Spec.DisableVPCCNI
3442

3543
return nil
3644
}
@@ -42,6 +50,11 @@ func (r *AWSManagedControlPlane) ConvertFrom(srcRaw conversion.Hub) error {
4250
if err := Convert_v1beta2_AWSManagedControlPlane_To_v1beta1_AWSManagedControlPlane(src, r, nil); err != nil {
4351
return err
4452
}
53+
54+
r.Spec.DisableVPCCNI = src.Spec.VpcCni.Disable
55+
if err := utilconversion.MarshalData(src, r); err != nil {
56+
return err
57+
}
4558

4659
return nil
4760
}
@@ -89,3 +102,11 @@ func Convert_v1beta1_Bastion_To_v1beta2_Bastion(in *infrav1beta1.Bastion, out *i
89102
func Convert_v1beta2_Bastion_To_v1beta1_Bastion(in *infrav1beta2.Bastion, out *infrav1beta1.Bastion, s apiconversion.Scope) error {
90103
return infrav1beta1.Convert_v1beta2_Bastion_To_v1beta1_Bastion(in, out, s)
91104
}
105+
106+
func Convert_v1beta1_AWSManagedControlPlaneSpec_To_v1beta2_AWSManagedControlPlaneSpec(in *AWSManagedControlPlaneSpec, out *ekscontrolplanev1.AWSManagedControlPlaneSpec, s apiconversion.Scope) error {
107+
return autoConvert_v1beta1_AWSManagedControlPlaneSpec_To_v1beta2_AWSManagedControlPlaneSpec(in, out, s)
108+
}
109+
110+
func Convert_v1beta2_VpcCni_To_v1beta1_VpcCni(in *ekscontrolplanev1.VpcCni, out *VpcCni, s apiconversion.Scope) error {
111+
return autoConvert_v1beta2_VpcCni_To_v1beta1_VpcCni(in, out, s)
112+
}

controlplane/eks/api/v1beta1/conversion_test.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,28 @@ package v1beta1
1818

1919
import (
2020
"testing"
21-
21+
2222
. "github.com/onsi/gomega"
23-
24-
runtime "k8s.io/apimachinery/pkg/runtime"
25-
v1beta2 "sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/eks/api/v1beta2"
23+
24+
fuzz "github.com/google/gofuzz"
25+
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
26+
"k8s.io/apimachinery/pkg/runtime"
27+
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
28+
"sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/eks/api/v1beta2"
2629
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
2730
)
2831

32+
func fuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
33+
return []interface{}{
34+
AWSManagedControlPlaneFuzzer,
35+
}
36+
}
37+
38+
func AWSManagedControlPlaneFuzzer(obj *AWSManagedControlPlane, c fuzz.Continue) {
39+
c.FuzzNoCustom(obj)
40+
obj.Spec.DisableVPCCNI = false
41+
}
42+
2943
func TestFuzzyConversion(t *testing.T) {
3044
g := NewWithT(t)
3145
scheme := runtime.NewScheme()
@@ -36,5 +50,6 @@ func TestFuzzyConversion(t *testing.T) {
3650
Scheme: scheme,
3751
Hub: &v1beta2.AWSManagedControlPlane{},
3852
Spoke: &AWSManagedControlPlane{},
53+
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzFuncs},
3954
}))
4055
}

controlplane/eks/api/v1beta1/zz_generated.conversion.go

Lines changed: 31 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controlplane/eks/api/v1beta2/awsmanagedcontrolplane_types.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,6 @@ type AWSManagedControlPlaneSpec struct { //nolint: maligned
163163
// +optional
164164
OIDCIdentityProviderConfig *OIDCIdentityProviderConfig `json:"oidcIdentityProviderConfig,omitempty"`
165165

166-
// DisableVPCCNI indicates that the Amazon VPC CNI should be disabled. With EKS clusters the
167-
// Amazon VPC CNI is automatically installed into the cluster. For clusters where you want
168-
// to use an alternate CNI this option provides a way to specify that the Amazon VPC CNI
169-
// should be deleted. You cannot set this to true if you are using the
170-
// Amazon VPC CNI addon.
171-
// +kubebuilder:default=false
172-
DisableVPCCNI bool `json:"disableVPCCNI,omitempty"`
173-
174166
// VpcCni is used to set configuration options for the VPC CNI plugin
175167
// +optional
176168
VpcCni VpcCni `json:"vpcCni,omitempty"`
@@ -192,6 +184,13 @@ type KubeProxy struct {
192184

193185
// VpcCni specifies configuration related to the VPC CNI.
194186
type VpcCni struct {
187+
// Disable indicates that the Amazon VPC CNI should be disabled. With EKS clusters the
188+
// Amazon VPC CNI is automatically installed into the cluster. For clusters where you want
189+
// to use an alternate CNI this option provides a way to specify that the Amazon VPC CNI
190+
// should be deleted. You cannot set this to true if you are using the
191+
// Amazon VPC CNI addon.
192+
// +kubebuilder:default=false
193+
Disable bool `json:"disable,omitempty"`
195194
// Env defines a list of environment variables to apply to the `aws-node` DaemonSet
196195
// +optional
197196
Env []corev1.EnvVar `json:"env,omitempty"`

controlplane/eks/api/v1beta2/awsmanagedcontrolplane_webhook.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,13 +369,13 @@ func (r *AWSManagedControlPlane) validateKubeProxy() field.ErrorList {
369369
func (r *AWSManagedControlPlane) validateDisableVPCCNI() field.ErrorList {
370370
var allErrs field.ErrorList
371371

372-
if r.Spec.DisableVPCCNI {
373-
disableField := field.NewPath("spec", "disableVPCCNI")
372+
if r.Spec.VpcCni.Disable {
373+
disableField := field.NewPath("spec", "vpcCni", "disable")
374374

375375
if r.Spec.Addons != nil {
376376
for _, addon := range *r.Spec.Addons {
377377
if addon.Name == vpcCniAddon {
378-
allErrs = append(allErrs, field.Invalid(disableField, r.Spec.DisableVPCCNI, "cannot disable vpc cni if the vpc-cni addon is specified"))
378+
allErrs = append(allErrs, field.Invalid(disableField, r.Spec.VpcCni.Disable, "cannot disable vpc cni if the vpc-cni addon is specified"))
379379
break
380380
}
381381
}

0 commit comments

Comments
 (0)