Skip to content

Commit cd84125

Browse files
authored
Merge pull request #3046 from bmiguel-teixeira/main
feat/ add outboundType support
2 parents 0bf99e9 + ed15eaa commit cd84125

12 files changed

+135
-0
lines changed

api/v1alpha3/azuremanagedcontrolplane_conversion.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func (src *AzureManagedControlPlane) ConvertTo(dstRaw conversion.Hub) error {
4444
dst.Spec.VirtualNetwork.ResourceGroup = restored.Spec.VirtualNetwork.ResourceGroup
4545
dst.Spec.VirtualNetwork.Subnet.ServiceEndpoints = restored.Spec.VirtualNetwork.Subnet.ServiceEndpoints
4646
dst.Spec.AutoScalerProfile = restored.Spec.AutoScalerProfile
47+
dst.Spec.OutboundType = restored.Spec.OutboundType
4748

4849
dst.Status.LongRunningOperationStates = restored.Status.LongRunningOperationStates
4950
dst.Status.Conditions = restored.Status.Conditions

api/v1alpha3/zz_generated.conversion.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha4/azuremanagedcontrolplane_conversion.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func (src *AzureManagedControlPlane) ConvertTo(dstRaw conversion.Hub) error {
4141
dst.Spec.VirtualNetwork.ResourceGroup = restored.Spec.VirtualNetwork.ResourceGroup
4242
dst.Spec.VirtualNetwork.Subnet.ServiceEndpoints = restored.Spec.VirtualNetwork.Subnet.ServiceEndpoints
4343
dst.Spec.AutoScalerProfile = restored.Spec.AutoScalerProfile
44+
dst.Spec.OutboundType = restored.Spec.OutboundType
4445

4546
return nil
4647
}

api/v1alpha4/zz_generated.conversion.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta1/azuremanagedcontrolplane_types.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ const (
3434
PrivateDNSZoneModeNone string = "None"
3535
)
3636

37+
// ManagedControlPlaneOutboundType enumerates the values for the managed control plane OutboundType.
38+
type ManagedControlPlaneOutboundType string
39+
40+
const (
41+
// ManagedControlPlaneOutboundTypeLoadBalancer ...
42+
ManagedControlPlaneOutboundTypeLoadBalancer ManagedControlPlaneOutboundType = "loadBalancer"
43+
// ManagedControlPlaneOutboundTypeManagedNATGateway ...
44+
ManagedControlPlaneOutboundTypeManagedNATGateway ManagedControlPlaneOutboundType = "managedNATGateway"
45+
// ManagedControlPlaneOutboundTypeUserAssignedNATGateway ...
46+
ManagedControlPlaneOutboundTypeUserAssignedNATGateway ManagedControlPlaneOutboundType = "userAssignedNATGateway"
47+
// ManagedControlPlaneOutboundTypeUserDefinedRouting ...
48+
ManagedControlPlaneOutboundTypeUserDefinedRouting ManagedControlPlaneOutboundType = "userDefinedRouting"
49+
)
50+
3751
// AzureManagedControlPlaneSpec defines the desired state of AzureManagedControlPlane.
3852
type AzureManagedControlPlaneSpec struct {
3953
// Version defines the desired Kubernetes version.
@@ -79,6 +93,11 @@ type AzureManagedControlPlaneSpec struct {
7993
// +optional
8094
NetworkPolicy *string `json:"networkPolicy,omitempty"`
8195

96+
// Outbound configuration used by Nodes.
97+
// +kubebuilder:validation:Enum=loadBalancer;managedNATGateway;userAssignedNATGateway;userDefinedRouting
98+
// +optional
99+
OutboundType *ManagedControlPlaneOutboundType `json:"outboundType,omitempty"`
100+
82101
// SSHPublicKey is a string literal containing an ssh public key base64 encoded.
83102
SSHPublicKey string `json:"sshPublicKey"`
84103

api/v1beta1/azuremanagedcontrolplane_webhook.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,16 @@ func (m *AzureManagedControlPlane) ValidateUpdate(oldRaw runtime.Object, client
225225
}
226226
}
227227

228+
// Consider removing this once moves out of preview
229+
// Updating outboundType after cluster creation (PREVIEW)
230+
// https://learn.microsoft.com/en-us/azure/aks/egress-outboundtype#updating-outboundtype-after-cluster-creation-preview
231+
if err := webhookutils.ValidateImmutable(
232+
field.NewPath("Spec", "OutboundType"),
233+
old.Spec.OutboundType,
234+
m.Spec.OutboundType); err != nil {
235+
allErrs = append(allErrs, err)
236+
}
237+
228238
if errs := m.validateVirtualNetworkUpdate(old); len(errs) > 0 {
229239
allErrs = append(allErrs, errs...)
230240
}

api/v1beta1/azuremanagedcontrolplane_webhook_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,6 +1300,26 @@ func TestAzureManagedControlPlane_ValidateUpdate(t *testing.T) {
13001300
},
13011301
wantErr: true,
13021302
},
1303+
{
1304+
name: "OutboundType update",
1305+
oldAMCP: &AzureManagedControlPlane{
1306+
ObjectMeta: metav1.ObjectMeta{
1307+
Name: "test-cluster",
1308+
},
1309+
Spec: AzureManagedControlPlaneSpec{
1310+
OutboundType: (*ManagedControlPlaneOutboundType)(to.StringPtr(string(ManagedControlPlaneOutboundTypeUserDefinedRouting))),
1311+
},
1312+
},
1313+
amcp: &AzureManagedControlPlane{
1314+
ObjectMeta: metav1.ObjectMeta{
1315+
Name: "test-cluster",
1316+
},
1317+
Spec: AzureManagedControlPlaneSpec{
1318+
OutboundType: (*ManagedControlPlaneOutboundType)(to.StringPtr(string(ManagedControlPlaneOutboundTypeLoadBalancer))),
1319+
},
1320+
},
1321+
wantErr: true,
1322+
},
13031323
}
13041324
for _, tc := range tests {
13051325
t.Run(tc.name, func(t *testing.T) {

api/v1beta1/zz_generated.deepcopy.go

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

azure/scope/managedcontrolplane.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ func (s *ManagedControlPlaneScope) ManagedClusterSpec(ctx context.Context) azure
436436
s.ControlPlane.Spec.VirtualNetwork.Subnet.Name,
437437
),
438438
GetAllAgentPools: s.GetAllAgentPoolSpecs,
439+
OutboundType: s.ControlPlane.Spec.OutboundType,
439440
}
440441

441442
if s.ControlPlane.Spec.NetworkPlugin != nil {

azure/scope/managedcontrolplane_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,67 @@ import (
3434
"sigs.k8s.io/controller-runtime/pkg/client/fake"
3535
)
3636

37+
func TestManagedControlPlaneScope_OutboundType(t *testing.T) {
38+
scheme := runtime.NewScheme()
39+
_ = expv1.AddToScheme(scheme)
40+
_ = infrav1.AddToScheme(scheme)
41+
explicitOutboundType := infrav1.ManagedControlPlaneOutboundTypeUserDefinedRouting
42+
cases := []struct {
43+
Name string
44+
Input ManagedControlPlaneScopeParams
45+
Expected bool
46+
}{
47+
{
48+
Name: "With Explicit OutboundType defined",
49+
Input: ManagedControlPlaneScopeParams{
50+
Cluster: &clusterv1.Cluster{
51+
ObjectMeta: metav1.ObjectMeta{
52+
Name: "cluster1",
53+
Namespace: "default",
54+
},
55+
},
56+
ControlPlane: &infrav1.AzureManagedControlPlane{
57+
Spec: infrav1.AzureManagedControlPlaneSpec{
58+
SubscriptionID: "00000000-0000-0000-0000-000000000000",
59+
OutboundType: &explicitOutboundType,
60+
},
61+
},
62+
},
63+
Expected: false,
64+
},
65+
{
66+
Name: "Without OutboundType defined",
67+
Input: ManagedControlPlaneScopeParams{
68+
Cluster: &clusterv1.Cluster{
69+
ObjectMeta: metav1.ObjectMeta{
70+
Name: "cluster1",
71+
Namespace: "default",
72+
},
73+
},
74+
ControlPlane: &infrav1.AzureManagedControlPlane{
75+
Spec: infrav1.AzureManagedControlPlaneSpec{
76+
SubscriptionID: "00000000-0000-0000-0000-000000000000",
77+
},
78+
},
79+
},
80+
Expected: true,
81+
},
82+
}
83+
for _, c := range cases {
84+
c := c
85+
t.Run(c.Name, func(t *testing.T) {
86+
g := NewWithT(t)
87+
fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(c.Input.ControlPlane).Build()
88+
c.Input.Client = fakeClient
89+
s, err := NewManagedControlPlaneScope(context.TODO(), c.Input)
90+
g.Expect(err).To(Succeed())
91+
managedCluster := s.ManagedClusterSpec(context.TODO())
92+
result := managedCluster.(*managedclusters.ManagedClusterSpec).OutboundType == nil
93+
g.Expect(result).To(Equal(c.Expected))
94+
})
95+
}
96+
}
97+
3798
func TestManagedControlPlaneScope_PoolVersion(t *testing.T) {
3899
scheme := runtime.NewScheme()
39100
_ = expv1.AddToScheme(scheme)

0 commit comments

Comments
 (0)