Skip to content

Commit 0e5d902

Browse files
committed
Moved AzureASOManaged API to v1beta1
1 parent 3625700 commit 0e5d902

17 files changed

+1870
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
22+
)
23+
24+
const (
25+
// AzureASOManagedClusterKind is the kind for AzureASOManagedCluster.
26+
AzureASOManagedClusterKind = "AzureASOManagedCluster"
27+
28+
// AzureASOManagedControlPlaneFinalizer is the finalizer added to AzureASOManagedControlPlanes.
29+
AzureASOManagedControlPlaneFinalizer = "azureasomanagedcontrolplane.infrastructure.cluster.x-k8s.io"
30+
)
31+
32+
// AzureASOManagedClusterSpec defines the desired state of AzureASOManagedCluster.
33+
type AzureASOManagedClusterSpec struct {
34+
AzureASOManagedClusterTemplateResourceSpec `json:",inline"`
35+
36+
// ControlPlaneEndpoint is the location of the API server within the control plane. CAPZ manages this field
37+
// and it should not be set by the user. It fulfills Cluster API's cluster infrastructure provider contract.
38+
// Because this field is programmatically set by CAPZ after resource creation, we define it as +optional
39+
// in the API schema to permit resource admission.
40+
//+optional
41+
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`
42+
}
43+
44+
// AzureASOManagedClusterStatus defines the observed state of AzureASOManagedCluster.
45+
type AzureASOManagedClusterStatus struct {
46+
// Ready represents whether or not the cluster has been provisioned and is ready. It fulfills Cluster
47+
// API's cluster infrastructure provider contract.
48+
//+optional
49+
Ready bool `json:"ready"`
50+
51+
//+optional
52+
Resources []ResourceStatus `json:"resources,omitempty"`
53+
}
54+
55+
// ResourceStatus represents the status of a resource.
56+
type ResourceStatus struct {
57+
Resource StatusResource `json:"resource"`
58+
Ready bool `json:"ready"`
59+
}
60+
61+
// StatusResource is a handle to a resource.
62+
type StatusResource struct {
63+
Group string `json:"group"`
64+
Version string `json:"version"`
65+
Kind string `json:"kind"`
66+
Name string `json:"name"`
67+
}
68+
69+
// +kubebuilder:object:root=true
70+
// +kubebuilder:subresource:status
71+
// +kubebuilder:storageversion
72+
73+
// AzureASOManagedCluster is the Schema for the azureasomanagedclusters API.
74+
type AzureASOManagedCluster struct {
75+
metav1.TypeMeta `json:",inline"`
76+
metav1.ObjectMeta `json:"metadata,omitempty"`
77+
78+
Spec AzureASOManagedClusterSpec `json:"spec,omitempty"`
79+
Status AzureASOManagedClusterStatus `json:"status,omitempty"`
80+
}
81+
82+
// GetResourceStatuses returns the status of resources.
83+
func (a *AzureASOManagedCluster) GetResourceStatuses() []ResourceStatus {
84+
return a.Status.Resources
85+
}
86+
87+
// SetResourceStatuses sets the status of resources.
88+
func (a *AzureASOManagedCluster) SetResourceStatuses(r []ResourceStatus) {
89+
a.Status.Resources = r
90+
}
91+
92+
//+kubebuilder:object:root=true
93+
94+
// AzureASOManagedClusterList contains a list of AzureASOManagedCluster.
95+
type AzureASOManagedClusterList struct {
96+
metav1.TypeMeta `json:",inline"`
97+
metav1.ListMeta `json:"metadata,omitempty"`
98+
Items []AzureASOManagedCluster `json:"items"`
99+
}
100+
101+
func init() {
102+
SchemeBuilder.Register(&AzureASOManagedCluster{}, &AzureASOManagedClusterList{})
103+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
import (
20+
"context"
21+
"fmt"
22+
23+
apierrors "k8s.io/apimachinery/pkg/api/errors"
24+
"k8s.io/apimachinery/pkg/runtime"
25+
"k8s.io/apimachinery/pkg/util/validation/field"
26+
ctrl "sigs.k8s.io/controller-runtime"
27+
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
28+
29+
"sigs.k8s.io/cluster-api-provider-azure/feature"
30+
)
31+
32+
// SetupAzureASOManagedClusterWebhookWithManager sets up and registers the webhook with the manager.
33+
func SetupAzureASOManagedClusterWebhookWithManager(mgr ctrl.Manager) error {
34+
azureASOManagedClusterWebhook := &azureASOManagedClusterWebhook{}
35+
return ctrl.NewWebhookManagedBy(mgr).
36+
For(&AzureASOManagedCluster{}).
37+
WithValidator(azureASOManagedClusterWebhook).
38+
Complete()
39+
}
40+
41+
// azureASOManagedClusterWebhook implements a validating and defaulting webhook for AzureASOManagedCluster.
42+
type azureASOManagedClusterWebhook struct {
43+
}
44+
45+
// +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
46+
47+
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
48+
func (ampw *azureASOManagedClusterWebhook) ValidateCreate(_ context.Context, obj runtime.Object) (admission.Warnings, error) {
49+
_, ok := obj.(*AzureASOManagedCluster)
50+
if !ok {
51+
return nil, apierrors.NewBadRequest("expected an AzureASOManagedCluster")
52+
}
53+
if !feature.Gates.Enabled(feature.ASOAPI) {
54+
return nil, field.Forbidden(
55+
field.NewPath("spec"),
56+
fmt.Sprintf("can be set only if the %s feature flag is enabled", feature.ASOAPI),
57+
)
58+
}
59+
return nil, nil
60+
}
61+
62+
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
63+
func (ampw *azureASOManagedClusterWebhook) ValidateUpdate(_ context.Context, _, _ runtime.Object) (admission.Warnings, error) {
64+
return nil, nil
65+
}
66+
67+
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
68+
func (ampw *azureASOManagedClusterWebhook) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
69+
return nil, nil
70+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
"k8s.io/apimachinery/pkg/runtime"
22+
)
23+
24+
// AzureASOManagedClusterTemplateSpec defines the desired state of AzureASOManagedClusterTemplate.
25+
type AzureASOManagedClusterTemplateSpec struct {
26+
Template AzureASOManagedClusterTemplateResource `json:"template"`
27+
}
28+
29+
// AzureASOManagedClusterTemplateResource defines the templated resource.
30+
type AzureASOManagedClusterTemplateResource struct {
31+
Spec AzureASOManagedClusterTemplateResourceSpec `json:"spec,omitempty"`
32+
}
33+
34+
// AzureASOManagedClusterTemplateResourceSpec defines the desired state of the templated resource.
35+
type AzureASOManagedClusterTemplateResourceSpec struct {
36+
// Resources are embedded ASO resources to be managed by this resource.
37+
//+optional
38+
Resources []runtime.RawExtension `json:"resources,omitempty"`
39+
}
40+
41+
// +kubebuilder:object:root=true
42+
// +kubebuilder:subresource:status
43+
// +kubebuilder:storageversion
44+
45+
// AzureASOManagedClusterTemplate is the Schema for the azureasomanagedclustertemplates API.
46+
type AzureASOManagedClusterTemplate struct {
47+
metav1.TypeMeta `json:",inline"`
48+
metav1.ObjectMeta `json:"metadata,omitempty"`
49+
50+
Spec AzureASOManagedClusterTemplateSpec `json:"spec,omitempty"`
51+
}
52+
53+
//+kubebuilder:object:root=true
54+
55+
// AzureASOManagedClusterTemplateList contains a list of AzureASOManagedClusterTemplate.
56+
type AzureASOManagedClusterTemplateList struct {
57+
metav1.TypeMeta `json:",inline"`
58+
metav1.ListMeta `json:"metadata,omitempty"`
59+
Items []AzureASOManagedClusterTemplate `json:"items"`
60+
}
61+
62+
func init() {
63+
SchemeBuilder.Register(&AzureASOManagedClusterTemplate{}, &AzureASOManagedClusterTemplateList{})
64+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
22+
)
23+
24+
// AzureASOManagedControlPlaneKind is the kind for AzureASOManagedControlPlane.
25+
const AzureASOManagedControlPlaneKind = "AzureASOManagedControlPlane"
26+
27+
// AzureASOManagedControlPlaneSpec defines the desired state of AzureASOManagedControlPlane.
28+
type AzureASOManagedControlPlaneSpec struct {
29+
AzureASOManagedControlPlaneTemplateResourceSpec `json:",inline"`
30+
}
31+
32+
// AzureASOManagedControlPlaneStatus defines the observed state of AzureASOManagedControlPlane.
33+
type AzureASOManagedControlPlaneStatus struct {
34+
// Initialized represents whether or not the API server has been provisioned. It fulfills Cluster API's
35+
// control plane provider contract. For AKS, this is equivalent to `ready`.
36+
//+optional
37+
Initialized bool `json:"initialized"`
38+
39+
// Ready represents whether or not the API server is ready to receive requests. It fulfills Cluster API's
40+
// control plane provider contract. For AKS, this is equivalent to `initialized`.
41+
//+optional
42+
Ready bool `json:"ready"`
43+
44+
// Version is the observed Kubernetes version of the control plane. It fulfills Cluster API's control
45+
// plane provider contract.
46+
//+optional
47+
Version string `json:"version,omitempty"`
48+
49+
//+optional
50+
Resources []ResourceStatus `json:"resources,omitempty"`
51+
52+
// ControlPlaneEndpoint represents the endpoint for the cluster's API server.
53+
//+optional
54+
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`
55+
}
56+
57+
// +kubebuilder:object:root=true
58+
// +kubebuilder:subresource:status
59+
// +kubebuilder:storageversion
60+
61+
// AzureASOManagedControlPlane is the Schema for the azureasomanagedcontrolplanes API.
62+
type AzureASOManagedControlPlane struct {
63+
metav1.TypeMeta `json:",inline"`
64+
metav1.ObjectMeta `json:"metadata,omitempty"`
65+
66+
Spec AzureASOManagedControlPlaneSpec `json:"spec,omitempty"`
67+
Status AzureASOManagedControlPlaneStatus `json:"status,omitempty"`
68+
}
69+
70+
// GetResourceStatuses returns the status of resources.
71+
func (a *AzureASOManagedControlPlane) GetResourceStatuses() []ResourceStatus {
72+
return a.Status.Resources
73+
}
74+
75+
// SetResourceStatuses sets the status of resources.
76+
func (a *AzureASOManagedControlPlane) SetResourceStatuses(r []ResourceStatus) {
77+
a.Status.Resources = r
78+
}
79+
80+
//+kubebuilder:object:root=true
81+
82+
// AzureASOManagedControlPlaneList contains a list of AzureASOManagedControlPlane.
83+
type AzureASOManagedControlPlaneList struct {
84+
metav1.TypeMeta `json:",inline"`
85+
metav1.ListMeta `json:"metadata,omitempty"`
86+
Items []AzureASOManagedControlPlane `json:"items"`
87+
}
88+
89+
func init() {
90+
SchemeBuilder.Register(&AzureASOManagedControlPlane{}, &AzureASOManagedControlPlaneList{})
91+
}

0 commit comments

Comments
 (0)