Skip to content

Commit

Permalink
wip: stuff
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Case <[email protected]>
  • Loading branch information
richardcase committed Feb 15, 2024
1 parent af25e3b commit 2b6f47e
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,8 @@ func newAMCP(name string) *ekscontrolplanev1.AWSManagedControlPlane {
Namespace: "default",
},
Spec: ekscontrolplanev1.AWSManagedControlPlaneSpec{
AWSManagedControlPlaneClassSpec: ekscontrolplanev1.AWSManagedControlPlaneClassSpec{
EKSClusterName: generatedName,
},
EKSClusterName: generatedName,
AWSManagedControlPlaneClassSpec: ekscontrolplanev1.AWSManagedControlPlaneClassSpec{},
},
}
}
9 changes: 9 additions & 0 deletions controlplane/eks/api/v1beta2/awsmanagedcontrolplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ const (
type AWSManagedControlPlaneSpec struct { //nolint: maligned
AWSManagedControlPlaneClassSpec `json:",inline"`

// EKSClusterName allows you to specify the name of the EKS cluster in
// AWS. If you don't specify a name then a default name will be created
// based on the namespace and name of the managed control plane.
// +optional
EKSClusterName string `json:"eksClusterName,omitempty"`

// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
// +optional
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`
Expand Down Expand Up @@ -142,6 +148,9 @@ type AWSManagedControlPlaneStatus struct {
// associated identity provider
// +optional
IdentityProviderStatus IdentityProviderStatus `json:"identityProviderStatus,omitempty"`
// Version defines the Kubernetes version for the control plane instance.
// +optional
Version string `json:"version"`
}

// +kubebuilder:object:root=true
Expand Down
120 changes: 61 additions & 59 deletions controlplane/eks/api/v1beta2/awsmanagedcontrolplane_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,26 @@ func TestDefaultingWebhook(t *testing.T) {
resourceName: "cluster1",
resourceNS: "default",
expectHash: false,
expectSpec: AWSManagedControlPlaneSpec{AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{
EKSClusterName: "default_cluster1", Bastion: defaultTestBastion, IdentityRef: defaultIdentityRef, NetworkSpec: defaultNetworkSpec, TokenMethod: &EKSTokenMethodIAMAuthenticator,
expectSpec: AWSManagedControlPlaneSpec{EKSClusterName: "default_cluster1", AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{
Bastion: defaultTestBastion, IdentityRef: defaultIdentityRef, NetworkSpec: defaultNetworkSpec, TokenMethod: &EKSTokenMethodIAMAuthenticator,
}},
},
{
name: "less than 100 chars, dot in name",
resourceName: "team1.cluster1",
resourceNS: "default",
expectHash: false,
expectSpec: AWSManagedControlPlaneSpec{AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{
EKSClusterName: "default_team1_cluster1", Bastion: defaultTestBastion, IdentityRef: defaultIdentityRef, NetworkSpec: defaultNetworkSpec, TokenMethod: &EKSTokenMethodIAMAuthenticator,
expectSpec: AWSManagedControlPlaneSpec{EKSClusterName: "default_team1_cluster1", AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{
Bastion: defaultTestBastion, IdentityRef: defaultIdentityRef, NetworkSpec: defaultNetworkSpec, TokenMethod: &EKSTokenMethodIAMAuthenticator,
}},
},
{
name: "more than 100 chars",
resourceName: "abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde",
resourceNS: "default",
expectHash: true,
expectSpec: AWSManagedControlPlaneSpec{AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{
EKSClusterName: "capi_", Bastion: defaultTestBastion, IdentityRef: defaultIdentityRef, NetworkSpec: defaultNetworkSpec, TokenMethod: &EKSTokenMethodIAMAuthenticator,
expectSpec: AWSManagedControlPlaneSpec{EKSClusterName: "capi_", AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{
Bastion: defaultTestBastion, IdentityRef: defaultIdentityRef, NetworkSpec: defaultNetworkSpec, TokenMethod: &EKSTokenMethodIAMAuthenticator,
}},
},
{
Expand All @@ -112,8 +112,8 @@ func TestDefaultingWebhook(t *testing.T) {
resourceNS: "default",
expectHash: false,
spec: AWSManagedControlPlaneSpec{AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{Version: &vV1_17_1}},
expectSpec: AWSManagedControlPlaneSpec{AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{
EKSClusterName: "default_cluster1", Bastion: defaultTestBastion, Version: &vV1_17_1, IdentityRef: defaultIdentityRef, NetworkSpec: defaultNetworkSpec, TokenMethod: &EKSTokenMethodIAMAuthenticator,
expectSpec: AWSManagedControlPlaneSpec{EKSClusterName: "default_cluster1", AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{
Bastion: defaultTestBastion, Version: &vV1_17_1, IdentityRef: defaultIdentityRef, NetworkSpec: defaultNetworkSpec, TokenMethod: &EKSTokenMethodIAMAuthenticator,
}},
},
{
Expand All @@ -122,22 +122,22 @@ func TestDefaultingWebhook(t *testing.T) {
resourceNS: "default",
expectHash: false,
spec: AWSManagedControlPlaneSpec{AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{Bastion: infrav1.Bastion{AllowedCIDRBlocks: []string{"100.100.100.100/0"}}}},
expectSpec: AWSManagedControlPlaneSpec{AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{EKSClusterName: "default_cluster1", IdentityRef: defaultIdentityRef, Bastion: infrav1.Bastion{AllowedCIDRBlocks: []string{"100.100.100.100/0"}}, NetworkSpec: defaultNetworkSpec, TokenMethod: &EKSTokenMethodIAMAuthenticator}},
expectSpec: AWSManagedControlPlaneSpec{EKSClusterName: "default_cluster1", AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{IdentityRef: defaultIdentityRef, Bastion: infrav1.Bastion{AllowedCIDRBlocks: []string{"100.100.100.100/0"}}, NetworkSpec: defaultNetworkSpec, TokenMethod: &EKSTokenMethodIAMAuthenticator}},
},
{
name: "with CNI on network",
resourceName: "cluster1",
resourceNS: "default",
expectHash: false,
spec: AWSManagedControlPlaneSpec{AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{NetworkSpec: infrav1.NetworkSpec{CNI: &infrav1.CNISpec{}}}},
expectSpec: AWSManagedControlPlaneSpec{AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{EKSClusterName: "default_cluster1", IdentityRef: defaultIdentityRef, Bastion: defaultTestBastion, NetworkSpec: infrav1.NetworkSpec{CNI: &infrav1.CNISpec{}, VPC: defaultVPCSpec}, TokenMethod: &EKSTokenMethodIAMAuthenticator}},
expectSpec: AWSManagedControlPlaneSpec{EKSClusterName: "default_cluster1", AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{IdentityRef: defaultIdentityRef, Bastion: defaultTestBastion, NetworkSpec: infrav1.NetworkSpec{CNI: &infrav1.CNISpec{}, VPC: defaultVPCSpec}, TokenMethod: &EKSTokenMethodIAMAuthenticator}},
},
{
name: "secondary CIDR",
resourceName: "cluster1",
resourceNS: "default",
expectHash: false,
expectSpec: AWSManagedControlPlaneSpec{AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{EKSClusterName: "default_cluster1", IdentityRef: defaultIdentityRef, Bastion: defaultTestBastion, NetworkSpec: defaultNetworkSpec, SecondaryCidrBlock: nil, TokenMethod: &EKSTokenMethodIAMAuthenticator}},
expectSpec: AWSManagedControlPlaneSpec{EKSClusterName: "default_cluster1", AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{IdentityRef: defaultIdentityRef, Bastion: defaultTestBastion, NetworkSpec: defaultNetworkSpec, SecondaryCidrBlock: nil, TokenMethod: &EKSTokenMethodIAMAuthenticator}},
},
}

Expand Down Expand Up @@ -331,8 +331,8 @@ func TestWebhookCreate(t *testing.T) {
Namespace: "default",
},
Spec: AWSManagedControlPlaneSpec{
EKSClusterName: tc.eksClusterName,
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{
EKSClusterName: tc.eksClusterName,
KubeProxy: tc.kubeProxy,
AdditionalTags: tc.additionalTags,
VpcCni: tc.vpcCNI,
Expand Down Expand Up @@ -493,11 +493,11 @@ func TestWebhookCreateIPv6Details(t *testing.T) {
Namespace: "default",
},
Spec: AWSManagedControlPlaneSpec{
EKSClusterName: "test-cluster",
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{
EKSClusterName: "test-cluster",
Addons: tc.addons,
NetworkSpec: tc.networkSpec,
Version: aws.String(tc.kubeVersion),
Addons: tc.addons,
NetworkSpec: tc.networkSpec,
Version: aws.String(tc.kubeVersion),
},
},
}
Expand Down Expand Up @@ -526,109 +526,113 @@ func TestWebhookUpdate(t *testing.T) {
{
name: "ekscluster specified, same cluster names",
oldClusterSpec: AWSManagedControlPlaneSpec{
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{EKSClusterName: "default_cluster1"},
EKSClusterName: "default_cluster1",
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{},
},
newClusterSpec: AWSManagedControlPlaneSpec{
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{EKSClusterName: "default_cluster1"},
EKSClusterName: "default_cluster1",
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{},
},
expectError: false,
},
{
name: "ekscluster specified, different cluster names",
oldClusterSpec: AWSManagedControlPlaneSpec{
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{EKSClusterName: "default_cluster1"},
EKSClusterName: "default_cluster1",
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{},
},
newClusterSpec: AWSManagedControlPlaneSpec{
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{EKSClusterName: "default_cluster2"},
EKSClusterName: "default_cluster2",
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{},
},
expectError: true,
},
{
name: "old ekscluster specified, no new cluster name",
oldClusterSpec: AWSManagedControlPlaneSpec{
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{EKSClusterName: "default_cluster1"},
EKSClusterName: "default_cluster1",
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{},
},
newClusterSpec: AWSManagedControlPlaneSpec{
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{EKSClusterName: ""},
EKSClusterName: "",
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{},
},
expectError: true,
},
{
name: "older version",
oldClusterSpec: AWSManagedControlPlaneSpec{
EKSClusterName: "default_cluster1",
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{
EKSClusterName: "default_cluster1",
Version: &vV1_17,
Version: &vV1_17,
},
},
newClusterSpec: AWSManagedControlPlaneSpec{
EKSClusterName: "default_cluster1",
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{
EKSClusterName: "default_cluster1",
Version: &vV1_16,
Version: &vV1_16,
},
},
expectError: true,
},
{
name: "same version",
oldClusterSpec: AWSManagedControlPlaneSpec{
EKSClusterName: "default_cluster1",
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{
EKSClusterName: "default_cluster1",
Version: &vV1_17,
Version: &vV1_17,
},
},
newClusterSpec: AWSManagedControlPlaneSpec{
EKSClusterName: "default_cluster1",
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{
EKSClusterName: "default_cluster1",
Version: &vV1_17,
Version: &vV1_17,
},
},
expectError: false,
},
{
name: "newer version",
oldClusterSpec: AWSManagedControlPlaneSpec{
EKSClusterName: "default_cluster1",
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{
EKSClusterName: "default_cluster1",
Version: &vV1_16,
Version: &vV1_16,
},
},
newClusterSpec: AWSManagedControlPlaneSpec{
EKSClusterName: "default_cluster1",
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{
EKSClusterName: "default_cluster1",
Version: &vV1_17,
Version: &vV1_17,
},
},
expectError: false,
},
{
name: "change in encryption config to nil",
oldClusterSpec: AWSManagedControlPlaneSpec{
EKSClusterName: "default_cluster1",
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{
EKSClusterName: "default_cluster1",
EncryptionConfig: &EncryptionConfig{
Provider: pointer.String("provider"),
Resources: []*string{pointer.String("foo"), pointer.String("bar")},
},
},
},
newClusterSpec: AWSManagedControlPlaneSpec{
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{
EKSClusterName: "default_cluster1",
},
EKSClusterName: "default_cluster1",
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{},
},
expectError: true,
},
{
name: "change in encryption config from nil to valid encryption-config",
oldClusterSpec: AWSManagedControlPlaneSpec{
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{
EKSClusterName: "default_cluster1",
},
EKSClusterName: "default_cluster1",
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{},
},
newClusterSpec: AWSManagedControlPlaneSpec{
EKSClusterName: "default_cluster1",
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{
EKSClusterName: "default_cluster1",
EncryptionConfig: &EncryptionConfig{
Provider: pointer.String("provider"),
Resources: []*string{pointer.String("foo"), pointer.String("bar")},
Expand All @@ -640,17 +644,17 @@ func TestWebhookUpdate(t *testing.T) {
{
name: "change in provider of encryption config",
oldClusterSpec: AWSManagedControlPlaneSpec{
EKSClusterName: "default_cluster1",
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{
EKSClusterName: "default_cluster1",
EncryptionConfig: &EncryptionConfig{
Provider: pointer.String("provider"),
Resources: []*string{pointer.String("foo"), pointer.String("bar")},
},
},
},
newClusterSpec: AWSManagedControlPlaneSpec{
EKSClusterName: "default_cluster1",
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{
EKSClusterName: "default_cluster1",
EncryptionConfig: &EncryptionConfig{
Provider: pointer.String("new-provider"),
Resources: []*string{pointer.String("foo"), pointer.String("bar")},
Expand All @@ -662,16 +666,16 @@ func TestWebhookUpdate(t *testing.T) {
{
name: "no change in provider of encryption config",
oldClusterSpec: AWSManagedControlPlaneSpec{
EKSClusterName: "default_cluster1",
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{
EKSClusterName: "default_cluster1",
EncryptionConfig: &EncryptionConfig{
Provider: pointer.String("provider"),
},
},
},
newClusterSpec: AWSManagedControlPlaneSpec{
EKSClusterName: "default_cluster1",
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{
EKSClusterName: "default_cluster1",
EncryptionConfig: &EncryptionConfig{
Provider: pointer.String("provider"),
},
Expand All @@ -682,13 +686,12 @@ func TestWebhookUpdate(t *testing.T) {
{
name: "ekscluster specified, same name, invalid tags",
oldClusterSpec: AWSManagedControlPlaneSpec{
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{
EKSClusterName: "default_cluster1",
},
EKSClusterName: "default_cluster1",
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{},
},
newClusterSpec: AWSManagedControlPlaneSpec{
EKSClusterName: "default_cluster1",
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{
EKSClusterName: "default_cluster1",
AdditionalTags: infrav1.Tags{
"key-1": "value-1",
"": "value-2",
Expand All @@ -702,17 +705,17 @@ func TestWebhookUpdate(t *testing.T) {
{
name: "changing ipv6 enabled is not allowed after it has been set - false, true",
oldClusterSpec: AWSManagedControlPlaneSpec{
EKSClusterName: "default_cluster1",
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{
EKSClusterName: "default_cluster1",
NetworkSpec: infrav1.NetworkSpec{
VPC: infrav1.VPCSpec{},
},
Version: pointer.String("1.22"),
},
},
newClusterSpec: AWSManagedControlPlaneSpec{
EKSClusterName: "default_cluster1",
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{
EKSClusterName: "default_cluster1",
NetworkSpec: infrav1.NetworkSpec{
VPC: infrav1.VPCSpec{
IPv6: &infrav1.IPv6{},
Expand All @@ -725,8 +728,8 @@ func TestWebhookUpdate(t *testing.T) {
{
name: "changing ipv6 enabled is not allowed after it has been set - true, false",
oldClusterSpec: AWSManagedControlPlaneSpec{
EKSClusterName: "default_cluster1",
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{
EKSClusterName: "default_cluster1",
NetworkSpec: infrav1.NetworkSpec{
VPC: infrav1.VPCSpec{
IPv6: &infrav1.IPv6{},
Expand All @@ -742,8 +745,8 @@ func TestWebhookUpdate(t *testing.T) {
},
},
newClusterSpec: AWSManagedControlPlaneSpec{
EKSClusterName: "default_cluster1",
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{
EKSClusterName: "default_cluster1",
NetworkSpec: infrav1.NetworkSpec{
VPC: infrav1.VPCSpec{},
},
Expand Down Expand Up @@ -827,9 +830,8 @@ func TestValidatingWebhookCreateSecondaryCidr(t *testing.T) {

mcp := &AWSManagedControlPlane{
Spec: AWSManagedControlPlaneSpec{
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{
EKSClusterName: "default_cluster1",
},
EKSClusterName: "default_cluster1",
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{},
},
}
if tc.cidrRange != "" {
Expand Down Expand Up @@ -897,16 +899,16 @@ func TestValidatingWebhookUpdateSecondaryCidr(t *testing.T) {

newMCP := &AWSManagedControlPlane{
Spec: AWSManagedControlPlaneSpec{
EKSClusterName: "default_cluster1",
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{
EKSClusterName: "default_cluster1",
SecondaryCidrBlock: aws.String(tc.cidrRange),
},
},
}
oldMCP := &AWSManagedControlPlane{
Spec: AWSManagedControlPlaneSpec{
EKSClusterName: "default_cluster1",
AWSManagedControlPlaneClassSpec: AWSManagedControlPlaneClassSpec{
EKSClusterName: "default_cluster1",
SecondaryCidrBlock: nil,
},
},
Expand Down
Loading

0 comments on commit 2b6f47e

Please sign in to comment.