Skip to content

Commit

Permalink
🐛subnets: use "owned" k8s tag value for managed subnets.
Browse files Browse the repository at this point in the history
The "shared" value will be used for unmanaged subnets.
  • Loading branch information
r4f4 committed Jul 15, 2024
1 parent d375b7d commit 60dea7e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 28 deletions.
8 changes: 4 additions & 4 deletions controllers/awscluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ func mockedCallsForMissingEverything(m *mocks.MockEC2APIMockRecorder, e *mocks.M
},
{
Key: aws.String("kubernetes.io/cluster/test-cluster"),
Value: aws.String("shared"),
Value: aws.String("owned"),
},
{
Key: aws.String("kubernetes.io/role/internal-elb"),
Expand Down Expand Up @@ -1035,7 +1035,7 @@ func mockedCallsForMissingEverything(m *mocks.MockEC2APIMockRecorder, e *mocks.M
},
{
Key: aws.String("kubernetes.io/cluster/test-cluster"),
Value: aws.String("shared"),
Value: aws.String("owned"),
},
{
Key: aws.String("kubernetes.io/role/internal-elb"),
Expand Down Expand Up @@ -1071,7 +1071,7 @@ func mockedCallsForMissingEverything(m *mocks.MockEC2APIMockRecorder, e *mocks.M
},
{
Key: aws.String("kubernetes.io/cluster/test-cluster"),
Value: aws.String("shared"),
Value: aws.String("owned"),
},
{
Key: aws.String("kubernetes.io/role/elb"),
Expand Down Expand Up @@ -1102,7 +1102,7 @@ func mockedCallsForMissingEverything(m *mocks.MockEC2APIMockRecorder, e *mocks.M
},
{
Key: aws.String("kubernetes.io/cluster/test-cluster"),
Value: aws.String("shared"),
Value: aws.String("owned"),
},
{
Key: aws.String("kubernetes.io/role/elb"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ func mockedCallsForMissingEverything(ec2Rec *mocks.MockEC2APIMockRecorder, subne
},
{
Key: aws.String("kubernetes.io/cluster/test-cluster"),
Value: aws.String("shared"),
Value: aws.String("owned"),
},
{
Key: aws.String(kubernetesRoleTagKey),
Expand Down Expand Up @@ -390,7 +390,7 @@ func mockedCallsForMissingEverything(ec2Rec *mocks.MockEC2APIMockRecorder, subne
},
{
Key: aws.String("kubernetes.io/cluster/test-cluster"),
Value: aws.String("shared"),
Value: aws.String("owned"),
},
{
Key: aws.String("kubernetes.io/role/elb"),
Expand Down
6 changes: 5 additions & 1 deletion pkg/cloud/services/network/subnets.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,11 @@ func (s *Service) getSubnetTagParams(unmanagedVPC bool, id string, public bool,
}
}
// Add tag needed for Service type=LoadBalancer
additionalTags[infrav1.ClusterAWSCloudProviderTagKey(s.scope.KubernetesClusterName())] = string(infrav1.ResourceLifecycleShared)
if unmanagedVPC {
additionalTags[infrav1.ClusterAWSCloudProviderTagKey(s.scope.KubernetesClusterName())] = string(infrav1.ResourceLifecycleShared)
} else {
additionalTags[infrav1.ClusterAWSCloudProviderTagKey(s.scope.KubernetesClusterName())] = string(infrav1.ResourceLifecycleOwned)
}
}

if !unmanagedVPC {
Expand Down
42 changes: 21 additions & 21 deletions pkg/cloud/services/network/subnets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ func TestReconcileSubnets(t *testing.T) {
},
{
Key: aws.String("kubernetes.io/cluster/test-cluster"),
Value: aws.String("shared"),
Value: aws.String("owned"),
},
{
Key: aws.String("kubernetes.io/role/internal-elb"),
Expand Down Expand Up @@ -1391,7 +1391,7 @@ func TestReconcileSubnets(t *testing.T) {
},
{
Key: aws.String("kubernetes.io/cluster/test-cluster"),
Value: aws.String("shared"),
Value: aws.String("owned"),
},
{
Key: aws.String("kubernetes.io/role/elb"),
Expand Down Expand Up @@ -1584,7 +1584,7 @@ func TestReconcileSubnets(t *testing.T) {
},
{
Key: aws.String("kubernetes.io/cluster/test-cluster"),
Value: aws.String("shared"),
Value: aws.String("owned"),
},
{
Key: aws.String("kubernetes.io/role/elb"),
Expand Down Expand Up @@ -1639,7 +1639,7 @@ func TestReconcileSubnets(t *testing.T) {
},
{
Key: aws.String("kubernetes.io/cluster/test-cluster"),
Value: aws.String("shared"),
Value: aws.String("owned"),
},
{
Key: aws.String("kubernetes.io/role/internal-elb"),
Expand Down Expand Up @@ -1758,7 +1758,7 @@ func TestReconcileSubnets(t *testing.T) {
},
{
Key: aws.String("kubernetes.io/cluster/test-cluster"),
Value: aws.String("shared"),
Value: aws.String("owned"),
},
{
Key: aws.String("kubernetes.io/role/elb"),
Expand Down Expand Up @@ -1842,7 +1842,7 @@ func TestReconcileSubnets(t *testing.T) {
},
{
Key: aws.String("kubernetes.io/cluster/test-cluster"),
Value: aws.String("shared"),
Value: aws.String("owned"),
},
{
Key: aws.String("kubernetes.io/role/internal-elb"),
Expand Down Expand Up @@ -1981,7 +1981,7 @@ func TestReconcileSubnets(t *testing.T) {
},
{
Key: aws.String("kubernetes.io/cluster/test-cluster"),
Value: aws.String("shared"),
Value: aws.String("owned"),
},
{
Key: aws.String("kubernetes.io/role/elb"),
Expand Down Expand Up @@ -2036,7 +2036,7 @@ func TestReconcileSubnets(t *testing.T) {
},
{
Key: aws.String("kubernetes.io/cluster/test-cluster"),
Value: aws.String("shared"),
Value: aws.String("owned"),
},
{
Key: aws.String("kubernetes.io/role/internal-elb"),
Expand Down Expand Up @@ -2095,7 +2095,7 @@ func TestReconcileSubnets(t *testing.T) {
},
{
Key: aws.String("kubernetes.io/cluster/test-cluster"),
Value: aws.String("shared"),
Value: aws.String("owned"),
},
{
Key: aws.String("kubernetes.io/role/elb"),
Expand Down Expand Up @@ -2150,7 +2150,7 @@ func TestReconcileSubnets(t *testing.T) {
},
{
Key: aws.String("kubernetes.io/cluster/test-cluster"),
Value: aws.String("shared"),
Value: aws.String("owned"),
},
{
Key: aws.String("kubernetes.io/role/internal-elb"),
Expand Down Expand Up @@ -2254,7 +2254,7 @@ func TestReconcileSubnets(t *testing.T) {
},
{
Key: aws.String("kubernetes.io/cluster/test-cluster"),
Value: aws.String("shared"),
Value: aws.String("owned"),
},
{
Key: aws.String("kubernetes.io/role/elb"),
Expand Down Expand Up @@ -2309,7 +2309,7 @@ func TestReconcileSubnets(t *testing.T) {
},
{
Key: aws.String("kubernetes.io/cluster/test-cluster"),
Value: aws.String("shared"),
Value: aws.String("owned"),
},
{
Key: aws.String("kubernetes.io/role/internal-elb"),
Expand Down Expand Up @@ -2400,7 +2400,7 @@ func TestReconcileSubnets(t *testing.T) {
},
{
Key: aws.String("kubernetes.io/cluster/test-cluster"),
Value: aws.String("shared"),
Value: aws.String("owned"),
},
},
},
Expand Down Expand Up @@ -2439,7 +2439,7 @@ func TestReconcileSubnets(t *testing.T) {
},
{
Key: aws.String("kubernetes.io/cluster/test-cluster"),
Value: aws.String("shared"),
Value: aws.String("owned"),
},
{
Key: aws.String("kubernetes.io/role/internal-elb"),
Expand Down Expand Up @@ -2542,7 +2542,7 @@ func TestReconcileSubnets(t *testing.T) {
},
{
Key: aws.String("kubernetes.io/cluster/test-cluster"),
Value: aws.String("shared"),
Value: aws.String("owned"),
},
},
},
Expand Down Expand Up @@ -2581,7 +2581,7 @@ func TestReconcileSubnets(t *testing.T) {
},
{
Key: aws.String("kubernetes.io/cluster/test-cluster"),
Value: aws.String("shared"),
Value: aws.String("owned"),
},
{
Key: aws.String("kubernetes.io/role/internal-elb"),
Expand Down Expand Up @@ -2711,7 +2711,7 @@ func TestReconcileSubnets(t *testing.T) {
},
{
Key: aws.String("kubernetes.io/cluster/test-eks-cluster"),
Value: aws.String("shared"),
Value: aws.String("owned"),
},
{
Key: aws.String("kubernetes.io/role/elb"),
Expand Down Expand Up @@ -2766,7 +2766,7 @@ func TestReconcileSubnets(t *testing.T) {
},
{
Key: aws.String("kubernetes.io/cluster/test-eks-cluster"),
Value: aws.String("shared"),
Value: aws.String("owned"),
},
{
Key: aws.String("kubernetes.io/role/internal-elb"),
Expand Down Expand Up @@ -2813,7 +2813,7 @@ func TestReconcileSubnets(t *testing.T) {
},
{
Key: aws.String("kubernetes.io/cluster/test-eks-cluster"),
Value: aws.String("shared"),
Value: aws.String("owned"),
},
{
Key: aws.String("kubernetes.io/role/elb"),
Expand Down Expand Up @@ -2880,7 +2880,7 @@ func TestReconcileSubnets(t *testing.T) {
},
{
Key: aws.String("kubernetes.io/cluster/test-eks-cluster"),
Value: aws.String("shared"),
Value: aws.String("owned"),
},
{
Key: aws.String("kubernetes.io/role/internal-elb"),
Expand Down Expand Up @@ -3803,7 +3803,7 @@ func TestService_retrieveZoneInfo(t *testing.T) {
func stubGetTags(prefix, role, zone string, isEdge bool) []*ec2.Tag {
tags := []*ec2.Tag{
{Key: aws.String("Name"), Value: aws.String(fmt.Sprintf("%s-subnet-%s-%s", prefix, role, zone))},
{Key: aws.String("kubernetes.io/cluster/test-cluster"), Value: aws.String("shared")},
{Key: aws.String("kubernetes.io/cluster/test-cluster"), Value: aws.String("owned")},
}
// tags are returned ordered, inserting LB subnets to prevent diffs...
if !isEdge {
Expand Down

0 comments on commit 60dea7e

Please sign in to comment.