Skip to content

Commit 56a5bba

Browse files
committed
Reconcile on CAPI v1beta2
1 parent 5455141 commit 56a5bba

File tree

95 files changed

+1503
-69679
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+1503
-69679
lines changed

.golangci.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ linters:
119119
# CAPZ
120120
- pkg: sigs.k8s.io/cluster-api-provider-azure/api/v1beta1
121121
alias: infrav1
122-
- pkg: sigs.k8s.io/cluster-api-provider-azure/util/v1beta1
123-
alias: clusterv1beta1util
124122
# CAPZ exp
125123
- pkg: sigs.k8s.io/cluster-api-provider-azure/exp/api/v1beta1
126124
alias: infrav1exp
@@ -310,7 +308,7 @@ linters:
310308
- linters:
311309
- staticcheck
312310
path: .*\.go$
313-
text: 'SA1019: "sigs.k8s.io/cluster-api/api/.*/v1beta1" is deprecated: This package is deprecated and is going to be removed when support for v1beta1 will be dropped.'
311+
text: 'SA1019: "sigs.k8s.io\/cluster-api/api/core/v1beta1" is deprecated: This package is deprecated and is going to be removed when support for v1beta1 will be dropped.'
314312
- linters:
315313
- staticcheck
316314
path: .*\.go$

api/v1beta1/azuremachine_default.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"golang.org/x/crypto/ssh"
2828
kerrors "k8s.io/apimachinery/pkg/util/errors"
2929
"k8s.io/apimachinery/pkg/util/uuid"
30-
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
30+
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
3131
"sigs.k8s.io/controller-runtime/pkg/client"
3232

3333
utilSSH "sigs.k8s.io/cluster-api-provider-azure/util/ssh"
@@ -172,7 +172,7 @@ func (s *AzureMachineSpec) SetNetworkInterfacesDefaults() {
172172
func GetOwnerAzureClusterNameAndNamespace(cli client.Client, clusterName string, namespace string, maxAttempts int) (azureClusterName string, azureClusterNamespace string, err error) {
173173
ctx := context.Background()
174174

175-
ownerCluster := &clusterv1beta1.Cluster{}
175+
ownerCluster := &clusterv1.Cluster{}
176176
key := client.ObjectKey{
177177
Namespace: namespace,
178178
Name: clusterName,
@@ -189,7 +189,7 @@ func GetOwnerAzureClusterNameAndNamespace(cli client.Client, clusterName string,
189189
break
190190
}
191191

192-
return ownerCluster.Spec.InfrastructureRef.Name, ownerCluster.Spec.InfrastructureRef.Namespace, nil
192+
return ownerCluster.Spec.InfrastructureRef.Name, ownerCluster.Namespace, nil
193193
}
194194

195195
// GetSubscriptionID returns the subscription ID for the AzureCluster given the cluster name and namespace.
@@ -223,7 +223,7 @@ func (m *AzureMachine) SetDefaults(client client.Client) error {
223223
}
224224

225225
// Fetch the Cluster.
226-
clusterName, ok := m.Labels[clusterv1beta1.ClusterNameLabel]
226+
clusterName, ok := m.Labels[clusterv1.ClusterNameLabel]
227227
if !ok {
228228
errs = append(errs, errors.Errorf("failed to fetch ClusterName for AzureMachine %s/%s", m.Namespace, m.Name))
229229
}

api/v1beta1/azuremachine_default_test.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@ import (
2626
"github.com/google/uuid"
2727
. "github.com/onsi/gomega"
2828
"github.com/pkg/errors"
29-
corev1 "k8s.io/api/core/v1"
3029
"k8s.io/apimachinery/pkg/api/resource"
3130
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3231
"k8s.io/utils/ptr"
33-
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
32+
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
3433
"sigs.k8s.io/controller-runtime/pkg/client"
3534
)
3635

@@ -564,15 +563,14 @@ func (m mockClient) Get(ctx context.Context, key client.ObjectKey, obj client.Ob
564563
switch obj := obj.(type) {
565564
case *AzureCluster:
566565
obj.Spec.SubscriptionID = "test-subscription-id"
567-
case *clusterv1beta1.Cluster:
568-
obj.Spec = clusterv1beta1.ClusterSpec{
569-
InfrastructureRef: &corev1.ObjectReference{
570-
Kind: AzureClusterKind,
571-
Name: "test-cluster",
572-
Namespace: "default",
566+
case *clusterv1.Cluster:
567+
obj.Spec = clusterv1.ClusterSpec{
568+
InfrastructureRef: clusterv1.ContractVersionedObjectReference{
569+
Kind: AzureClusterKind,
570+
Name: "test-cluster",
573571
},
574-
ClusterNetwork: &clusterv1beta1.ClusterNetwork{
575-
Services: &clusterv1beta1.NetworkRanges{
572+
ClusterNetwork: clusterv1.ClusterNetwork{
573+
Services: clusterv1.NetworkRanges{
576574
CIDRBlocks: []string{"192.168.0.0/26"},
577575
},
578576
},
@@ -607,7 +605,7 @@ func hardcodedAzureMachineWithSSHKey(sshPublicKey string) *AzureMachine {
607605
return &AzureMachine{
608606
ObjectMeta: metav1.ObjectMeta{
609607
Labels: map[string]string{
610-
clusterv1beta1.ClusterNameLabel: "test-cluster",
608+
clusterv1.ClusterNameLabel: "test-cluster",
611609
},
612610
},
613611
Spec: AzureMachineSpec{

api/v1beta1/azuremachine_webhook_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ import (
2323
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5"
2424
. "github.com/onsi/gomega"
2525
"github.com/pkg/errors"
26-
corev1 "k8s.io/api/core/v1"
2726
"k8s.io/apimachinery/pkg/api/resource"
2827
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2928
"k8s.io/utils/ptr"
30-
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
29+
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
3130
"sigs.k8s.io/controller-runtime/pkg/client"
3231
)
3332

@@ -947,8 +946,8 @@ func (m mockDefaultClient) Get(ctx context.Context, key client.ObjectKey, obj cl
947946
switch obj := obj.(type) {
948947
case *AzureCluster:
949948
obj.Spec.SubscriptionID = m.SubscriptionID
950-
case *clusterv1beta1.Cluster:
951-
obj.Spec.InfrastructureRef = &corev1.ObjectReference{
949+
case *clusterv1.Cluster:
950+
obj.Spec.InfrastructureRef = clusterv1.ContractVersionedObjectReference{
952951
Kind: AzureClusterKind,
953952
Name: "test-cluster",
954953
}
@@ -972,7 +971,7 @@ func TestAzureMachine_Default(t *testing.T) {
972971
publicKeyNotExistTest := test{machine: createMachineWithSSHPublicKey("")}
973972
testObjectMeta := metav1.ObjectMeta{
974973
Labels: map[string]string{
975-
clusterv1beta1.ClusterNameLabel: "test-cluster",
974+
clusterv1.ClusterNameLabel: "test-cluster",
976975
},
977976
}
978977

api/v1beta1/azuremanagedcontrolplane_default.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323

2424
"golang.org/x/crypto/ssh"
2525
"k8s.io/utils/ptr"
26-
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
26+
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
2727
ctrl "sigs.k8s.io/controller-runtime"
2828

2929
utilSSH "sigs.k8s.io/cluster-api-provider-azure/util/ssh"
@@ -43,7 +43,7 @@ const (
4343
// setDefaultResourceGroupName sets the default ResourceGroupName for an AzureManagedControlPlane.
4444
func (m *AzureManagedControlPlane) setDefaultResourceGroupName() {
4545
if m.Spec.ResourceGroupName == "" {
46-
if clusterName, ok := m.Labels[clusterv1beta1.ClusterNameLabel]; ok {
46+
if clusterName, ok := m.Labels[clusterv1.ClusterNameLabel]; ok {
4747
m.Spec.ResourceGroupName = clusterName
4848
}
4949
}
@@ -103,7 +103,7 @@ func (m *AzureManagedControlPlane) setDefaultSubnet() {
103103
func setDefaultFleetsMember(fleetsMember *FleetsMember, labels map[string]string) *FleetsMember {
104104
result := fleetsMember.DeepCopy()
105105
if fleetsMember != nil {
106-
if clusterName, ok := labels[clusterv1beta1.ClusterNameLabel]; ok && fleetsMember.Name == "" {
106+
if clusterName, ok := labels[clusterv1.ClusterNameLabel]; ok && fleetsMember.Name == "" {
107107
result.Name = clusterName
108108
}
109109
}

api/v1beta1/azuremanagedcontrolplane_webhook.go

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
"k8s.io/apimachinery/pkg/runtime"
3131
"k8s.io/apimachinery/pkg/util/validation/field"
3232
"k8s.io/utils/ptr"
33-
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
33+
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
3434
ctrl "sigs.k8s.io/controller-runtime"
3535
"sigs.k8s.io/controller-runtime/pkg/client"
3636
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
@@ -523,12 +523,12 @@ func validateManagedClusterNetwork(cli client.Client, labels map[string]string,
523523
ctx := context.Background()
524524

525525
// Fetch the Cluster.
526-
clusterName, ok := labels[clusterv1beta1.ClusterNameLabel]
526+
clusterName, ok := labels[clusterv1.ClusterNameLabel]
527527
if !ok {
528528
return nil
529529
}
530530

531-
ownerCluster := &clusterv1beta1.Cluster{}
531+
ownerCluster := &clusterv1.Cluster{}
532532
key := client.ObjectKey{
533533
Namespace: namespace,
534534
Name: clusterName,
@@ -539,24 +539,19 @@ func validateManagedClusterNetwork(cli client.Client, labels map[string]string,
539539
return allErrs
540540
}
541541

542-
if clusterNetwork := ownerCluster.Spec.ClusterNetwork; clusterNetwork != nil {
543-
if clusterNetwork.Services != nil {
544-
// A user may provide zero or one CIDR blocks. If they provide an empty array,
545-
// we ignore it and use the default. AKS doesn't support > 1 Service/Pod CIDR.
546-
if len(clusterNetwork.Services.CIDRBlocks) > 1 {
547-
allErrs = append(allErrs, field.TooMany(field.NewPath("Cluster", "spec", "clusterNetwork", "services", "cidrBlocks"), len(clusterNetwork.Services.CIDRBlocks), 1))
548-
}
549-
if len(clusterNetwork.Services.CIDRBlocks) == 1 {
550-
serviceCIDR = clusterNetwork.Services.CIDRBlocks[0]
551-
}
552-
}
553-
if clusterNetwork.Pods != nil {
554-
// A user may provide zero or one CIDR blocks. If they provide an empty array,
555-
// we ignore it and use the default. AKS doesn't support > 1 Service/Pod CIDR.
556-
if len(clusterNetwork.Pods.CIDRBlocks) > 1 {
557-
allErrs = append(allErrs, field.TooMany(field.NewPath("Cluster", "spec", "clusterNetwork", "pods", "cidrBlocks"), len(clusterNetwork.Pods.CIDRBlocks), 1))
558-
}
559-
}
542+
clusterNetwork := ownerCluster.Spec.ClusterNetwork
543+
// A user may provide zero or one CIDR blocks. If they provide an empty array,
544+
// we ignore it and use the default. AKS doesn't support > 1 Service/Pod CIDR.
545+
if len(clusterNetwork.Services.CIDRBlocks) > 1 {
546+
allErrs = append(allErrs, field.TooMany(field.NewPath("Cluster", "spec", "clusterNetwork", "services", "cidrBlocks"), len(clusterNetwork.Services.CIDRBlocks), 1))
547+
}
548+
if len(clusterNetwork.Services.CIDRBlocks) == 1 {
549+
serviceCIDR = clusterNetwork.Services.CIDRBlocks[0]
550+
}
551+
// A user may provide zero or one CIDR blocks. If they provide an empty array,
552+
// we ignore it and use the default. AKS doesn't support > 1 Service/Pod CIDR.
553+
if len(clusterNetwork.Pods.CIDRBlocks) > 1 {
554+
allErrs = append(allErrs, field.TooMany(field.NewPath("Cluster", "spec", "clusterNetwork", "pods", "cidrBlocks"), len(clusterNetwork.Pods.CIDRBlocks), 1))
560555
}
561556

562557
if dnsServiceIP != nil {

api/v1beta1/azuremanagedcontrolplane_webhook_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
utilfeature "k8s.io/component-base/featuregate/testing"
2626
"k8s.io/utils/ptr"
2727
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
28+
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
2829
capifeature "sigs.k8s.io/cluster-api/feature"
2930

3031
"sigs.k8s.io/cluster-api-provider-azure/feature"
@@ -38,7 +39,7 @@ func TestDefaultingWebhook(t *testing.T) {
3839
ObjectMeta: metav1.ObjectMeta{
3940
Name: "fooName",
4041
Labels: map[string]string{
41-
clusterv1beta1.ClusterNameLabel: "fooCluster",
42+
clusterv1.ClusterNameLabel: "fooCluster",
4243
},
4344
},
4445
Spec: AzureManagedControlPlaneSpec{
@@ -4037,7 +4038,7 @@ func TestValidateAMCPVirtualNetwork(t *testing.T) {
40374038
ObjectMeta: metav1.ObjectMeta{
40384039
Name: "fooName",
40394040
Labels: map[string]string{
4040-
clusterv1beta1.ClusterNameLabel: "fooCluster",
4041+
clusterv1.ClusterNameLabel: "fooCluster",
40414042
},
40424043
},
40434044
Spec: AzureManagedControlPlaneSpec{
@@ -4066,7 +4067,7 @@ func TestValidateAMCPVirtualNetwork(t *testing.T) {
40664067
ObjectMeta: metav1.ObjectMeta{
40674068
Name: "fooName",
40684069
Labels: map[string]string{
4069-
clusterv1beta1.ClusterNameLabel: "fooCluster",
4070+
clusterv1.ClusterNameLabel: "fooCluster",
40704071
},
40714072
},
40724073
Spec: AzureManagedControlPlaneSpec{
@@ -4095,7 +4096,7 @@ func TestValidateAMCPVirtualNetwork(t *testing.T) {
40954096
ObjectMeta: metav1.ObjectMeta{
40964097
Name: "fooName",
40974098
Labels: map[string]string{
4098-
clusterv1beta1.ClusterNameLabel: "fooCluster",
4099+
clusterv1.ClusterNameLabel: "fooCluster",
40994100
},
41004101
},
41014102
Spec: AzureManagedControlPlaneSpec{
@@ -4124,7 +4125,7 @@ func TestValidateAMCPVirtualNetwork(t *testing.T) {
41244125
ObjectMeta: metav1.ObjectMeta{
41254126
Name: "fooName",
41264127
Labels: map[string]string{
4127-
clusterv1beta1.ClusterNameLabel: "fooCluster",
4128+
clusterv1.ClusterNameLabel: "fooCluster",
41284129
},
41294130
},
41304131
Spec: AzureManagedControlPlaneSpec{

api/v1beta1/azuremanagedmachinepool_webhook.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
kerrors "k8s.io/apimachinery/pkg/util/errors"
3131
"k8s.io/apimachinery/pkg/util/validation/field"
3232
"k8s.io/utils/ptr"
33-
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
33+
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
3434
clusterctlv1alpha3 "sigs.k8s.io/cluster-api/cmd/clusterctl/api/v1alpha3"
3535
ctrl "sigs.k8s.io/controller-runtime"
3636
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -309,12 +309,12 @@ func validateLastSystemNodePool(cli client.Client, labels map[string]string, nam
309309
ctx := context.Background()
310310

311311
// Fetch the Cluster.
312-
clusterName, ok := labels[clusterv1beta1.ClusterNameLabel]
312+
clusterName, ok := labels[clusterv1.ClusterNameLabel]
313313
if !ok {
314314
return nil
315315
}
316316

317-
ownerCluster := &clusterv1beta1.Cluster{}
317+
ownerCluster := &clusterv1.Cluster{}
318318
key := client.ObjectKey{
319319
Namespace: namespace,
320320
Name: clusterName,
@@ -335,8 +335,8 @@ func validateLastSystemNodePool(cli client.Client, labels map[string]string, nam
335335

336336
opt1 := client.InNamespace(namespace)
337337
opt2 := client.MatchingLabels(map[string]string{
338-
clusterv1beta1.ClusterNameLabel: clusterName,
339-
LabelAgentPoolMode: string(NodePoolModeSystem),
338+
clusterv1.ClusterNameLabel: clusterName,
339+
LabelAgentPoolMode: string(NodePoolModeSystem),
340340
})
341341

342342
ammpList := &AzureManagedMachinePoolList{}

0 commit comments

Comments
 (0)