Skip to content

Migrated AzureASOManaged API to v1beta1 #5660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/v1alpha1/azureasomanagedcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type StatusResource struct {

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:deprecatedversion:warning="infrastructure.cluster.x-k8s.io/v1alpha1 AzureASOManagedCluster is deprecated. infrastructure.cluster.x-k8s.io/v1beta1 is equivalent and should be used instead."

// AzureASOManagedCluster is the Schema for the azureasomanagedclusters API.
type AzureASOManagedCluster struct {
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/azureasomanagedclustertemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type AzureASOManagedClusterTemplateResourceSpec struct {
}

//+kubebuilder:object:root=true
//+kubebuilder:deprecatedversion:warning="infrastructure.cluster.x-k8s.io/v1alpha1 AzureASOManagedClusterTemplate is deprecated. infrastructure.cluster.x-k8s.io/v1beta1 is equivalent and should be used instead."

// AzureASOManagedClusterTemplate is the Schema for the azureasomanagedclustertemplates API.
type AzureASOManagedClusterTemplate struct {
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/azureasomanagedcontrolplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type AzureASOManagedControlPlaneStatus struct {

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:deprecatedversion:warning="infrastructure.cluster.x-k8s.io/v1alpha1 AzureASOManagedControlPlane is deprecated. infrastructure.cluster.x-k8s.io/v1beta1 is equivalent and should be used instead."

// AzureASOManagedControlPlane is the Schema for the azureasomanagedcontrolplanes API.
type AzureASOManagedControlPlane struct {
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/azureasomanagedcontrolplanetemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type AzureASOManagedControlPlaneTemplateResourceSpec struct {
}

//+kubebuilder:object:root=true
//+kubebuilder:deprecatedversion:warning="infrastructure.cluster.x-k8s.io/v1alpha1 AzureASOManagedControlPlaneTemplate is deprecated. infrastructure.cluster.x-k8s.io/v1beta1 is equivalent and should be used instead."

// AzureASOManagedControlPlaneTemplate is the Schema for the azureasomanagedcontrolplanetemplates API.
type AzureASOManagedControlPlaneTemplate struct {
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/azureasomanagedmachinepool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type AzureASOManagedMachinePoolStatus struct {

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:deprecatedversion:warning="infrastructure.cluster.x-k8s.io/v1alpha1 AzureASOManagedMachinePool is deprecated. infrastructure.cluster.x-k8s.io/v1beta1 is equivalent and should be used instead."

// AzureASOManagedMachinePool is the Schema for the azureasomanagedmachinepools API.
type AzureASOManagedMachinePool struct {
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/azureasomanagedmachinepooltemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type AzureASOManagedMachinePoolTemplateResourceSpec struct {
}

//+kubebuilder:object:root=true
//+kubebuilder:deprecatedversion:warning="infrastructure.cluster.x-k8s.io/v1alpha1 AzureASOManagedMachinePoolTemplate is deprecated. infrastructure.cluster.x-k8s.io/v1beta1 is equivalent and should be used instead."

// AzureASOManagedMachinePoolTemplate is the Schema for the azureasomanagedmachinepooltemplates API.
type AzureASOManagedMachinePoolTemplate struct {
Expand Down
103 changes: 103 additions & 0 deletions api/v1beta1/azureasomanagedcluster_types.go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropping this here for myself to make sure no unexpected changes sneak in:

for alpha in api/v1alpha1/azureasomanaged*; do beta=${alpha/v1alpha1/v1beta1}; [ -f $beta ] && git diff --no-index $alpha $beta; done

Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
Copyright 2025 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1beta1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

const (
// AzureASOManagedClusterKind is the kind for AzureASOManagedCluster.
AzureASOManagedClusterKind = "AzureASOManagedCluster"

// AzureASOManagedControlPlaneFinalizer is the finalizer added to AzureASOManagedControlPlanes.
AzureASOManagedControlPlaneFinalizer = "azureasomanagedcontrolplane.infrastructure.cluster.x-k8s.io"
)

// AzureASOManagedClusterSpec defines the desired state of AzureASOManagedCluster.
type AzureASOManagedClusterSpec struct {
AzureASOManagedClusterTemplateResourceSpec `json:",inline"`

// ControlPlaneEndpoint is the location of the API server within the control plane. CAPZ manages this field
// and it should not be set by the user. It fulfills Cluster API's cluster infrastructure provider contract.
// Because this field is programmatically set by CAPZ after resource creation, we define it as +optional
// in the API schema to permit resource admission.
//+optional
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`
}

// AzureASOManagedClusterStatus defines the observed state of AzureASOManagedCluster.
type AzureASOManagedClusterStatus struct {
// Ready represents whether or not the cluster has been provisioned and is ready. It fulfills Cluster
// API's cluster infrastructure provider contract.
//+optional
Ready bool `json:"ready"`

//+optional
Resources []ResourceStatus `json:"resources,omitempty"`
}

// ResourceStatus represents the status of a resource.
type ResourceStatus struct {
Resource StatusResource `json:"resource"`
Ready bool `json:"ready"`
}

// StatusResource is a handle to a resource.
type StatusResource struct {
Group string `json:"group"`
Version string `json:"version"`
Kind string `json:"kind"`
Name string `json:"name"`
}

// +kubebuilder:object:root=true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should mark each of the v1alpha1 types as deprecated per https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definition-versioning/#version-deprecation.

I see kubebuilder makes that easy with a marker like this:

//+kubebuilder:deprecatedversion:warning="infrastructure.cluster.x-k8s.io/v1alpha1 AzureASOManagedCluster is deprecated. infrastructure.cluster.x-k8s.io/v1beta1 is equivalent and should be used instead."

Then that warning gets blasted whenever that API version is used to prompt people to update:

% kubectl get azureasomanagedcluster.v1alpha1.infrastructure.cluster.x-k8s.io  
Warning: infrastructure.cluster.x-k8s.io/v1alpha1 AzureASOManagedCluster is deprecated. infrastructure.cluster.x-k8s.io/v1beta1 should be used instead.
NAME           AGE
aks-aso-6548   45s

// +kubebuilder:subresource:status
// +kubebuilder:storageversion
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't covered in e2e atm, but we should at least manually verify that upgrading from a previous version of CAPZ that used v1alpha1 as the storage version doesn't break existing workload clusters when the CRD is updated to the new storage version.

We should definitely follow up soon after this though with automated tests if we absolutely have to cut the release with the rest of these changes before then.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finished manually verify that upgrading from a previous version of CAPZ that used v1alpha1 as the storage version doesn't break existing workload clusters when the CRD is updated to the new storage version.
Did this by

  1. switching to main branch that uses v1alpha1 and spinning up my management and workload aks-aso cluster
  2. switching to dev branch that uses v1beta1, rerunning make generate, and rerunning make tilt-up (this applied the updates correctly)
  3. used cli to verify storage versions and logs
  4. scaled the machine pools and worked
  5. added tags in the ManagedCluster in the AzureASOManagedControlPlane and it shows up in Azure Portal
  6. checked CAPZ and CAPI logs and only errors are the deprecated v1alpha1 warnings we added


// AzureASOManagedCluster is the Schema for the azureasomanagedclusters API.
type AzureASOManagedCluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec AzureASOManagedClusterSpec `json:"spec,omitempty"`
Status AzureASOManagedClusterStatus `json:"status,omitempty"`
}

// GetResourceStatuses returns the status of resources.
func (a *AzureASOManagedCluster) GetResourceStatuses() []ResourceStatus {
return a.Status.Resources

Check warning on line 84 in api/v1beta1/azureasomanagedcluster_types.go

View check run for this annotation

Codecov / codecov/patch

api/v1beta1/azureasomanagedcluster_types.go#L83-L84

Added lines #L83 - L84 were not covered by tests
}

// SetResourceStatuses sets the status of resources.
func (a *AzureASOManagedCluster) SetResourceStatuses(r []ResourceStatus) {
a.Status.Resources = r

Check warning on line 89 in api/v1beta1/azureasomanagedcluster_types.go

View check run for this annotation

Codecov / codecov/patch

api/v1beta1/azureasomanagedcluster_types.go#L88-L89

Added lines #L88 - L89 were not covered by tests
}

//+kubebuilder:object:root=true

// AzureASOManagedClusterList contains a list of AzureASOManagedCluster.
type AzureASOManagedClusterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []AzureASOManagedCluster `json:"items"`
}

func init() {
SchemeBuilder.Register(&AzureASOManagedCluster{}, &AzureASOManagedClusterList{})
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2024 The Kubernetes Authors.
Copyright 2025 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@
limitations under the License.
*/

package v1alpha1
package v1beta1

import (
"context"
Expand All @@ -31,18 +31,18 @@

// SetupAzureASOManagedClusterWebhookWithManager sets up and registers the webhook with the manager.
func SetupAzureASOManagedClusterWebhookWithManager(mgr ctrl.Manager) error {
w := &azureASOManagedClusterWebhook{}
azureASOManagedClusterWebhook := &azureASOManagedClusterWebhook{}

Check warning on line 34 in api/v1beta1/azureasomanagedcluster_webhook.go

View check run for this annotation

Codecov / codecov/patch

api/v1beta1/azureasomanagedcluster_webhook.go#L34

Added line #L34 was not covered by tests
return ctrl.NewWebhookManagedBy(mgr).
For(&AzureASOManagedCluster{}).
WithValidator(w).
WithValidator(azureASOManagedClusterWebhook).

Check warning on line 37 in api/v1beta1/azureasomanagedcluster_webhook.go

View check run for this annotation

Codecov / codecov/patch

api/v1beta1/azureasomanagedcluster_webhook.go#L37

Added line #L37 was not covered by tests
Complete()
}

// azureASOManagedClusterWebhook implements a validating and defaulting webhook for AzureASOManagedCluster.
type azureASOManagedClusterWebhook struct {
}

// +kubebuilder:webhook:verbs=create,path=/validate-infrastructure-cluster-x-k8s-io-v1alpha1-azureasomanagedcluster,mutating=false,failurePolicy=fail,groups=infrastructure.cluster.x-k8s.io,resources=azureasomanagedclusters,versions=v1alpha1,name=validation.azureasomanagedcluster.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
// +kubebuilder:webhook:verbs=create,path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-azureasomanagedcluster,mutating=false,failurePolicy=fail,groups=infrastructure.cluster.x-k8s.io,resources=azureasomanagedclusters,versions=v1beta1,name=validation.azureasomanagedcluster.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (ampw *azureASOManagedClusterWebhook) ValidateCreate(_ context.Context, obj runtime.Object) (admission.Warnings, error) {
Expand Down
63 changes: 63 additions & 0 deletions api/v1beta1/azureasomanagedclustertemplate_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Copyright 2025 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1beta1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)

// AzureASOManagedClusterTemplateSpec defines the desired state of AzureASOManagedClusterTemplate.
type AzureASOManagedClusterTemplateSpec struct {
Template AzureASOManagedClusterTemplateResource `json:"template"`
}

// AzureASOManagedClusterTemplateResource defines the templated resource.
type AzureASOManagedClusterTemplateResource struct {
Spec AzureASOManagedClusterTemplateResourceSpec `json:"spec,omitempty"`
}

// AzureASOManagedClusterTemplateResourceSpec defines the desired state of the templated resource.
type AzureASOManagedClusterTemplateResourceSpec struct {
// Resources are embedded ASO resources to be managed by this resource.
//+optional
Resources []runtime.RawExtension `json:"resources,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:storageversion

// AzureASOManagedClusterTemplate is the Schema for the azureasomanagedclustertemplates API.
type AzureASOManagedClusterTemplate struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec AzureASOManagedClusterTemplateSpec `json:"spec,omitempty"`
}

//+kubebuilder:object:root=true

// AzureASOManagedClusterTemplateList contains a list of AzureASOManagedClusterTemplate.
type AzureASOManagedClusterTemplateList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []AzureASOManagedClusterTemplate `json:"items"`
}

func init() {
SchemeBuilder.Register(&AzureASOManagedClusterTemplate{}, &AzureASOManagedClusterTemplateList{})
}
91 changes: 91 additions & 0 deletions api/v1beta1/azureasomanagedcontrolplane_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
Copyright 2025 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1beta1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

// AzureASOManagedControlPlaneKind is the kind for AzureASOManagedControlPlane.
const AzureASOManagedControlPlaneKind = "AzureASOManagedControlPlane"

// AzureASOManagedControlPlaneSpec defines the desired state of AzureASOManagedControlPlane.
type AzureASOManagedControlPlaneSpec struct {
AzureASOManagedControlPlaneTemplateResourceSpec `json:",inline"`
}

// AzureASOManagedControlPlaneStatus defines the observed state of AzureASOManagedControlPlane.
type AzureASOManagedControlPlaneStatus struct {
// Initialized represents whether or not the API server has been provisioned. It fulfills Cluster API's
// control plane provider contract. For AKS, this is equivalent to `ready`.
//+optional
Initialized bool `json:"initialized"`

// Ready represents whether or not the API server is ready to receive requests. It fulfills Cluster API's
// control plane provider contract. For AKS, this is equivalent to `initialized`.
//+optional
Ready bool `json:"ready"`

// Version is the observed Kubernetes version of the control plane. It fulfills Cluster API's control
// plane provider contract.
//+optional
Version string `json:"version,omitempty"`

//+optional
Resources []ResourceStatus `json:"resources,omitempty"`

// ControlPlaneEndpoint represents the endpoint for the cluster's API server.
//+optional
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:storageversion

// AzureASOManagedControlPlane is the Schema for the azureasomanagedcontrolplanes API.
type AzureASOManagedControlPlane struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec AzureASOManagedControlPlaneSpec `json:"spec,omitempty"`
Status AzureASOManagedControlPlaneStatus `json:"status,omitempty"`
}

// GetResourceStatuses returns the status of resources.
func (a *AzureASOManagedControlPlane) GetResourceStatuses() []ResourceStatus {
return a.Status.Resources

Check warning on line 72 in api/v1beta1/azureasomanagedcontrolplane_types.go

View check run for this annotation

Codecov / codecov/patch

api/v1beta1/azureasomanagedcontrolplane_types.go#L71-L72

Added lines #L71 - L72 were not covered by tests
}

// SetResourceStatuses sets the status of resources.
func (a *AzureASOManagedControlPlane) SetResourceStatuses(r []ResourceStatus) {
a.Status.Resources = r

Check warning on line 77 in api/v1beta1/azureasomanagedcontrolplane_types.go

View check run for this annotation

Codecov / codecov/patch

api/v1beta1/azureasomanagedcontrolplane_types.go#L76-L77

Added lines #L76 - L77 were not covered by tests
}

//+kubebuilder:object:root=true

// AzureASOManagedControlPlaneList contains a list of AzureASOManagedControlPlane.
type AzureASOManagedControlPlaneList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []AzureASOManagedControlPlane `json:"items"`
}

func init() {
SchemeBuilder.Register(&AzureASOManagedControlPlane{}, &AzureASOManagedControlPlaneList{})
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2024 The Kubernetes Authors.
Copyright 2025 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@
limitations under the License.
*/

package v1alpha1
package v1beta1

import (
"context"
Expand All @@ -31,18 +31,18 @@

// SetupAzureASOManagedControlPlaneWebhookWithManager sets up and registers the webhook with the manager.
func SetupAzureASOManagedControlPlaneWebhookWithManager(mgr ctrl.Manager) error {
w := &azureASOManagedControlPlaneWebhook{}
azureASOManagedControlPlaneWebhook := &azureASOManagedControlPlaneWebhook{}

Check warning on line 34 in api/v1beta1/azureasomanagedcontrolplane_webhook.go

View check run for this annotation

Codecov / codecov/patch

api/v1beta1/azureasomanagedcontrolplane_webhook.go#L34

Added line #L34 was not covered by tests
return ctrl.NewWebhookManagedBy(mgr).
For(&AzureASOManagedControlPlane{}).
WithValidator(w).
WithValidator(azureASOManagedControlPlaneWebhook).

Check warning on line 37 in api/v1beta1/azureasomanagedcontrolplane_webhook.go

View check run for this annotation

Codecov / codecov/patch

api/v1beta1/azureasomanagedcontrolplane_webhook.go#L37

Added line #L37 was not covered by tests
Complete()
}

// azureASOManagedControlPlaneWebhook implements a validating webhook for AzureASOManagedControlPlane.
type azureASOManagedControlPlaneWebhook struct {
}

// +kubebuilder:webhook:verbs=create,path=/validate-infrastructure-cluster-x-k8s-io-v1alpha1-azureasomanagedcontrolplane,mutating=false,failurePolicy=fail,groups=infrastructure.cluster.x-k8s.io,resources=azureasomanagedcontrolplanes,versions=v1alpha1,name=validation.azureasomanagedcontrolplane.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
// +kubebuilder:webhook:verbs=create,path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-azureasomanagedcontrolplane,mutating=false,failurePolicy=fail,groups=infrastructure.cluster.x-k8s.io,resources=azureasomanagedcontrolplanes,versions=v1beta1,name=validation.azureasomanagedcontrolplane.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (ampw *azureASOManagedControlPlaneWebhook) ValidateCreate(_ context.Context, obj runtime.Object) (admission.Warnings, error) {
Expand Down
Loading
Loading