diff --git a/Makefile b/Makefile index 3daa218f5b65..097e0c363784 100644 --- a/Makefile +++ b/Makefile @@ -387,7 +387,7 @@ generate-go-deepcopy: ## Run all generate-go-deepcopy-* targets .PHONY: generate-go-deepcopy-core generate-go-deepcopy-core: $(CONTROLLER_GEN) ## Generate deepcopy go code for core - $(MAKE) clean-generated-deepcopy SRC_DIRS="./api,./$(EXP_DIR)/api,./$(EXP_DIR)/addons/api,./$(EXP_DIR)/runtime/api,./$(EXP_DIR)/runtime/hooks/api" + $(MAKE) clean-generated-deepcopy SRC_DIRS="./api,./$(EXP_DIR)/api,./$(EXP_DIR)/addons/api,./$(EXP_DIR)/runtime/api,./$(EXP_DIR)/runtime/hooks/api,./internal/apis/core" $(CONTROLLER_GEN) \ object:headerFile=./hack/boilerplate/boilerplate.generatego.txt \ paths=./api/... \ @@ -396,6 +396,7 @@ generate-go-deepcopy-core: $(CONTROLLER_GEN) ## Generate deepcopy go code for co paths=./$(EXP_DIR)/ipam/api/... \ paths=./$(EXP_DIR)/runtime/api/... \ paths=./$(EXP_DIR)/runtime/hooks/api/... \ + paths=./internal/apis/core/... \ paths=./internal/runtime/test/... \ paths=./cmd/clusterctl/... \ paths=./internal/test/builder/... diff --git a/api/v1beta1/condition_consts.go b/api/v1beta1/condition_consts.go index 57d8324c1864..1d089147ab68 100644 --- a/api/v1beta1/condition_consts.go +++ b/api/v1beta1/condition_consts.go @@ -351,3 +351,14 @@ const ( // the corresponding CRD). ClusterClassOutdatedRefVersionsReason = "OutdatedRefVersions" ) + +// Conditions and condition Reasons for the MachinePool object. + +const ( + // ReplicasReadyCondition reports an aggregate of current status of the replicas controlled by the MachinePool. + ReplicasReadyCondition ConditionType = "ReplicasReady" + + // WaitingForReplicasReadyReason (Severity=Info) documents a machinepool waiting for the required replicas + // to be ready. + WaitingForReplicasReadyReason = "WaitingForReplicasReady" +) diff --git a/api/v1beta1/conversion.go b/api/v1beta1/conversion.go index cbbc3b35d7b5..55ab9632d0a9 100644 --- a/api/v1beta1/conversion.go +++ b/api/v1beta1/conversion.go @@ -22,6 +22,8 @@ func (*ClusterClass) Hub() {} func (*ClusterClassList) Hub() {} func (*Machine) Hub() {} func (*MachineList) Hub() {} +func (*MachinePool) Hub() {} +func (*MachinePoolList) Hub() {} func (*MachineSet) Hub() {} func (*MachineSetList) Hub() {} func (*MachineDeployment) Hub() {} diff --git a/api/v1beta1/index/machinepool.go b/api/v1beta1/index/machinepool.go index b877d5cbdaca..8b9a3868bce4 100644 --- a/api/v1beta1/index/machinepool.go +++ b/api/v1beta1/index/machinepool.go @@ -24,7 +24,7 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" ) const ( @@ -39,7 +39,7 @@ const ( // ByMachinePoolNode adds the machinepool node name index to the // managers cache. func ByMachinePoolNode(ctx context.Context, mgr ctrl.Manager) error { - if err := mgr.GetCache().IndexField(ctx, &expv1.MachinePool{}, + if err := mgr.GetCache().IndexField(ctx, &clusterv1.MachinePool{}, MachinePoolNodeNameField, MachinePoolByNodeName, ); err != nil { @@ -51,7 +51,7 @@ func ByMachinePoolNode(ctx context.Context, mgr ctrl.Manager) error { // MachinePoolByNodeName contains the logic to index MachinePools by Node name. func MachinePoolByNodeName(o client.Object) []string { - machinepool, ok := o.(*expv1.MachinePool) + machinepool, ok := o.(*clusterv1.MachinePool) if !ok { panic(fmt.Sprintf("Expected a MachinePool but got a %T", o)) } @@ -70,7 +70,7 @@ func MachinePoolByNodeName(o client.Object) []string { // ByMachinePoolProviderID adds the machinepool providerID index to the // managers cache. func ByMachinePoolProviderID(ctx context.Context, mgr ctrl.Manager) error { - if err := mgr.GetCache().IndexField(ctx, &expv1.MachinePool{}, + if err := mgr.GetCache().IndexField(ctx, &clusterv1.MachinePool{}, MachinePoolProviderIDField, machinePoolByProviderID, ); err != nil { @@ -81,7 +81,7 @@ func ByMachinePoolProviderID(ctx context.Context, mgr ctrl.Manager) error { } func machinePoolByProviderID(o client.Object) []string { - machinepool, ok := o.(*expv1.MachinePool) + machinepool, ok := o.(*clusterv1.MachinePool) if !ok { panic(fmt.Sprintf("Expected a MachinePool but got a %T", o)) } diff --git a/api/v1beta1/index/machinepool_test.go b/api/v1beta1/index/machinepool_test.go index 09ab8769acc8..f2edf67c029f 100644 --- a/api/v1beta1/index/machinepool_test.go +++ b/api/v1beta1/index/machinepool_test.go @@ -23,7 +23,7 @@ import ( corev1 "k8s.io/api/core/v1" "sigs.k8s.io/controller-runtime/pkg/client" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" ) func TestIndexMachinePoolByNodeName(t *testing.T) { @@ -34,13 +34,13 @@ func TestIndexMachinePoolByNodeName(t *testing.T) { }{ { name: "when the machinepool has no NodeRef", - object: &expv1.MachinePool{}, + object: &clusterv1.MachinePool{}, expected: []string{}, }, { name: "when the machinepool has valid NodeRefs", - object: &expv1.MachinePool{ - Status: expv1.MachinePoolStatus{ + object: &clusterv1.MachinePool{ + Status: clusterv1.MachinePoolStatus{ NodeRefs: []corev1.ObjectReference{ { Name: "node1", @@ -75,13 +75,13 @@ func TestIndexMachinePoolByProviderID(t *testing.T) { }{ { name: "MachinePool has no providerID", - object: &expv1.MachinePool{}, + object: &clusterv1.MachinePool{}, expected: nil, }, { name: "MachinePool has invalid providerID", - object: &expv1.MachinePool{ - Spec: expv1.MachinePoolSpec{ + object: &clusterv1.MachinePool{ + Spec: clusterv1.MachinePoolSpec{ ProviderIDList: []string{""}, }, }, @@ -89,8 +89,8 @@ func TestIndexMachinePoolByProviderID(t *testing.T) { }, { name: "MachinePool has valid providerIDs", - object: &expv1.MachinePool{ - Spec: expv1.MachinePoolSpec{ + object: &clusterv1.MachinePool{ + Spec: clusterv1.MachinePoolSpec{ ProviderIDList: []string{validProviderID, otherValidProviderID}, }, }, diff --git a/exp/api/v1beta1/machinepool_types.go b/api/v1beta1/machinepool_types.go similarity index 96% rename from exp/api/v1beta1/machinepool_types.go rename to api/v1beta1/machinepool_types.go index 0c7839998afa..d9450e1282fe 100644 --- a/exp/api/v1beta1/machinepool_types.go +++ b/api/v1beta1/machinepool_types.go @@ -20,7 +20,6 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" capierrors "sigs.k8s.io/cluster-api/errors" ) @@ -43,7 +42,7 @@ type MachinePoolSpec struct { Replicas *int32 `json:"replicas,omitempty"` // Template describes the machines that will be created. - Template clusterv1.MachineTemplateSpec `json:"template"` + Template MachineTemplateSpec `json:"template"` // Minimum number of seconds for which a newly created machine instances should // be ready. @@ -121,7 +120,7 @@ type MachinePoolStatus struct { // Conditions define the current service state of the MachinePool. // +optional - Conditions clusterv1.Conditions `json:"conditions,omitempty"` + Conditions Conditions `json:"conditions,omitempty"` } // ANCHOR_END: MachinePoolStatus @@ -229,12 +228,12 @@ type MachinePool struct { } // GetConditions returns the set of conditions for this object. -func (m *MachinePool) GetConditions() clusterv1.Conditions { +func (m *MachinePool) GetConditions() Conditions { return m.Status.Conditions } // SetConditions sets the conditions on this object. -func (m *MachinePool) SetConditions(conditions clusterv1.Conditions) { +func (m *MachinePool) SetConditions(conditions Conditions) { m.Status.Conditions = conditions } diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index aa62c8fb9f4f..8abafb37f7f0 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -1502,6 +1502,33 @@ func (in *MachineList) DeepCopyObject() runtime.Object { return nil } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MachinePool) DeepCopyInto(out *MachinePool) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachinePool. +func (in *MachinePool) DeepCopy() *MachinePool { + if in == nil { + return nil + } + out := new(MachinePool) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *MachinePool) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *MachinePoolClass) DeepCopyInto(out *MachinePoolClass) { *out = *in @@ -1586,6 +1613,111 @@ func (in *MachinePoolClassTemplate) DeepCopy() *MachinePoolClassTemplate { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MachinePoolList) DeepCopyInto(out *MachinePoolList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]MachinePool, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachinePoolList. +func (in *MachinePoolList) DeepCopy() *MachinePoolList { + if in == nil { + return nil + } + out := new(MachinePoolList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *MachinePoolList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MachinePoolSpec) DeepCopyInto(out *MachinePoolSpec) { + *out = *in + if in.Replicas != nil { + in, out := &in.Replicas, &out.Replicas + *out = new(int32) + **out = **in + } + in.Template.DeepCopyInto(&out.Template) + if in.MinReadySeconds != nil { + in, out := &in.MinReadySeconds, &out.MinReadySeconds + *out = new(int32) + **out = **in + } + if in.ProviderIDList != nil { + in, out := &in.ProviderIDList, &out.ProviderIDList + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.FailureDomains != nil { + in, out := &in.FailureDomains, &out.FailureDomains + *out = make([]string, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachinePoolSpec. +func (in *MachinePoolSpec) DeepCopy() *MachinePoolSpec { + if in == nil { + return nil + } + out := new(MachinePoolSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MachinePoolStatus) DeepCopyInto(out *MachinePoolStatus) { + *out = *in + if in.NodeRefs != nil { + in, out := &in.NodeRefs, &out.NodeRefs + *out = make([]v1.ObjectReference, len(*in)) + copy(*out, *in) + } + if in.FailureReason != nil { + in, out := &in.FailureReason, &out.FailureReason + *out = new(errors.MachinePoolStatusFailure) + **out = **in + } + if in.FailureMessage != nil { + in, out := &in.FailureMessage, &out.FailureMessage + *out = new(string) + **out = **in + } + if in.Conditions != nil { + in, out := &in.Conditions, &out.Conditions + *out = make(Conditions, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachinePoolStatus. +func (in *MachinePoolStatus) DeepCopy() *MachinePoolStatus { + if in == nil { + return nil + } + out := new(MachinePoolStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *MachinePoolTopology) DeepCopyInto(out *MachinePoolTopology) { *out = *in diff --git a/api/v1beta1/zz_generated.openapi.go b/api/v1beta1/zz_generated.openapi.go index 4953306c2985..b18d4962023c 100644 --- a/api/v1beta1/zz_generated.openapi.go +++ b/api/v1beta1/zz_generated.openapi.go @@ -75,9 +75,13 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "sigs.k8s.io/cluster-api/api/v1beta1.MachineHealthCheckStatus": schema_sigsk8sio_cluster_api_api_v1beta1_MachineHealthCheckStatus(ref), "sigs.k8s.io/cluster-api/api/v1beta1.MachineHealthCheckTopology": schema_sigsk8sio_cluster_api_api_v1beta1_MachineHealthCheckTopology(ref), "sigs.k8s.io/cluster-api/api/v1beta1.MachineList": schema_sigsk8sio_cluster_api_api_v1beta1_MachineList(ref), + "sigs.k8s.io/cluster-api/api/v1beta1.MachinePool": schema_sigsk8sio_cluster_api_api_v1beta1_MachinePool(ref), "sigs.k8s.io/cluster-api/api/v1beta1.MachinePoolClass": schema_sigsk8sio_cluster_api_api_v1beta1_MachinePoolClass(ref), "sigs.k8s.io/cluster-api/api/v1beta1.MachinePoolClassNamingStrategy": schema_sigsk8sio_cluster_api_api_v1beta1_MachinePoolClassNamingStrategy(ref), "sigs.k8s.io/cluster-api/api/v1beta1.MachinePoolClassTemplate": schema_sigsk8sio_cluster_api_api_v1beta1_MachinePoolClassTemplate(ref), + "sigs.k8s.io/cluster-api/api/v1beta1.MachinePoolList": schema_sigsk8sio_cluster_api_api_v1beta1_MachinePoolList(ref), + "sigs.k8s.io/cluster-api/api/v1beta1.MachinePoolSpec": schema_sigsk8sio_cluster_api_api_v1beta1_MachinePoolSpec(ref), + "sigs.k8s.io/cluster-api/api/v1beta1.MachinePoolStatus": schema_sigsk8sio_cluster_api_api_v1beta1_MachinePoolStatus(ref), "sigs.k8s.io/cluster-api/api/v1beta1.MachinePoolTopology": schema_sigsk8sio_cluster_api_api_v1beta1_MachinePoolTopology(ref), "sigs.k8s.io/cluster-api/api/v1beta1.MachinePoolVariables": schema_sigsk8sio_cluster_api_api_v1beta1_MachinePoolVariables(ref), "sigs.k8s.io/cluster-api/api/v1beta1.MachineRollingUpdateDeployment": schema_sigsk8sio_cluster_api_api_v1beta1_MachineRollingUpdateDeployment(ref), @@ -2573,6 +2577,53 @@ func schema_sigsk8sio_cluster_api_api_v1beta1_MachineList(ref common.ReferenceCa } } +func schema_sigsk8sio_cluster_api_api_v1beta1_MachinePool(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "MachinePool is the Schema for the machinepools API.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "kind": { + SchemaProps: spec.SchemaProps{ + Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", + Type: []string{"string"}, + Format: "", + }, + }, + "apiVersion": { + SchemaProps: spec.SchemaProps{ + Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", + Type: []string{"string"}, + Format: "", + }, + }, + "metadata": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"), + }, + }, + "spec": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("sigs.k8s.io/cluster-api/api/v1beta1.MachinePoolSpec"), + }, + }, + "status": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("sigs.k8s.io/cluster-api/api/v1beta1.MachinePoolStatus"), + }, + }, + }, + }, + }, + Dependencies: []string{ + "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta", "sigs.k8s.io/cluster-api/api/v1beta1.MachinePoolSpec", "sigs.k8s.io/cluster-api/api/v1beta1.MachinePoolStatus"}, + } +} + func schema_sigsk8sio_cluster_api_api_v1beta1_MachinePoolClass(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -2707,6 +2758,246 @@ func schema_sigsk8sio_cluster_api_api_v1beta1_MachinePoolClassTemplate(ref commo } } +func schema_sigsk8sio_cluster_api_api_v1beta1_MachinePoolList(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "MachinePoolList contains a list of MachinePool.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "kind": { + SchemaProps: spec.SchemaProps{ + Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", + Type: []string{"string"}, + Format: "", + }, + }, + "apiVersion": { + SchemaProps: spec.SchemaProps{ + Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", + Type: []string{"string"}, + Format: "", + }, + }, + "metadata": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"), + }, + }, + "items": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("sigs.k8s.io/cluster-api/api/v1beta1.MachinePool"), + }, + }, + }, + }, + }, + }, + Required: []string{"items"}, + }, + }, + Dependencies: []string{ + "k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta", "sigs.k8s.io/cluster-api/api/v1beta1.MachinePool"}, + } +} + +func schema_sigsk8sio_cluster_api_api_v1beta1_MachinePoolSpec(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "MachinePoolSpec defines the desired state of MachinePool.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "clusterName": { + SchemaProps: spec.SchemaProps{ + Description: "ClusterName is the name of the Cluster this object belongs to.", + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "replicas": { + SchemaProps: spec.SchemaProps{ + Description: "Number of desired machines. Defaults to 1. This is a pointer to distinguish between explicit zero and not specified.", + Type: []string{"integer"}, + Format: "int32", + }, + }, + "template": { + SchemaProps: spec.SchemaProps{ + Description: "Template describes the machines that will be created.", + Default: map[string]interface{}{}, + Ref: ref("sigs.k8s.io/cluster-api/api/v1beta1.MachineTemplateSpec"), + }, + }, + "minReadySeconds": { + SchemaProps: spec.SchemaProps{ + Description: "Minimum number of seconds for which a newly created machine instances should be ready. Defaults to 0 (machine instance will be considered available as soon as it is ready)", + Type: []string{"integer"}, + Format: "int32", + }, + }, + "providerIDList": { + SchemaProps: spec.SchemaProps{ + Description: "ProviderIDList are the identification IDs of machine instances provided by the provider. This field must match the provider IDs as seen on the node objects corresponding to a machine pool's machine instances.", + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + "failureDomains": { + SchemaProps: spec.SchemaProps{ + Description: "FailureDomains is the list of failure domains this MachinePool should be attached to.", + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + }, + Required: []string{"clusterName", "template"}, + }, + }, + Dependencies: []string{ + "sigs.k8s.io/cluster-api/api/v1beta1.MachineTemplateSpec"}, + } +} + +func schema_sigsk8sio_cluster_api_api_v1beta1_MachinePoolStatus(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "MachinePoolStatus defines the observed state of MachinePool.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "nodeRefs": { + SchemaProps: spec.SchemaProps{ + Description: "NodeRefs will point to the corresponding Nodes if it they exist.", + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("k8s.io/api/core/v1.ObjectReference"), + }, + }, + }, + }, + }, + "replicas": { + SchemaProps: spec.SchemaProps{ + Description: "Replicas is the most recently observed number of replicas.", + Default: 0, + Type: []string{"integer"}, + Format: "int32", + }, + }, + "readyReplicas": { + SchemaProps: spec.SchemaProps{ + Description: "The number of ready replicas for this MachinePool. A machine is considered ready when the node has been created and is \"Ready\".", + Type: []string{"integer"}, + Format: "int32", + }, + }, + "availableReplicas": { + SchemaProps: spec.SchemaProps{ + Description: "The number of available replicas (ready for at least minReadySeconds) for this MachinePool.", + Type: []string{"integer"}, + Format: "int32", + }, + }, + "unavailableReplicas": { + SchemaProps: spec.SchemaProps{ + Description: "Total number of unavailable machine instances targeted by this machine pool. This is the total number of machine instances that are still required for the machine pool to have 100% available capacity. They may either be machine instances that are running but not yet available or machine instances that still have not been created.", + Type: []string{"integer"}, + Format: "int32", + }, + }, + "failureReason": { + SchemaProps: spec.SchemaProps{ + Description: "FailureReason indicates that there is a problem reconciling the state, and will be set to a token value suitable for programmatic interpretation.", + Type: []string{"string"}, + Format: "", + }, + }, + "failureMessage": { + SchemaProps: spec.SchemaProps{ + Description: "FailureMessage indicates that there is a problem reconciling the state, and will be set to a descriptive error message.", + Type: []string{"string"}, + Format: "", + }, + }, + "phase": { + SchemaProps: spec.SchemaProps{ + Description: "Phase represents the current phase of cluster actuation. E.g. Pending, Running, Terminating, Failed etc.", + Type: []string{"string"}, + Format: "", + }, + }, + "bootstrapReady": { + SchemaProps: spec.SchemaProps{ + Description: "BootstrapReady is the state of the bootstrap provider.", + Default: false, + Type: []string{"boolean"}, + Format: "", + }, + }, + "infrastructureReady": { + SchemaProps: spec.SchemaProps{ + Description: "InfrastructureReady is the state of the infrastructure provider.", + Default: false, + Type: []string{"boolean"}, + Format: "", + }, + }, + "observedGeneration": { + SchemaProps: spec.SchemaProps{ + Description: "ObservedGeneration is the latest generation observed by the controller.", + Type: []string{"integer"}, + Format: "int64", + }, + }, + "conditions": { + SchemaProps: spec.SchemaProps{ + Description: "Conditions define the current service state of the MachinePool.", + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("sigs.k8s.io/cluster-api/api/v1beta1.Condition"), + }, + }, + }, + }, + }, + }, + }, + }, + Dependencies: []string{ + "k8s.io/api/core/v1.ObjectReference", "sigs.k8s.io/cluster-api/api/v1beta1.Condition"}, + } +} + func schema_sigsk8sio_cluster_api_api_v1beta1_MachinePoolTopology(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ diff --git a/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go b/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go index b8788f7ad34f..5ccb60eaa299 100644 --- a/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go +++ b/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go @@ -49,7 +49,6 @@ import ( kubeadmtypes "sigs.k8s.io/cluster-api/bootstrap/kubeadm/types" bsutil "sigs.k8s.io/cluster-api/bootstrap/util" "sigs.k8s.io/cluster-api/controllers/remote" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/feature" "sigs.k8s.io/cluster-api/internal/util/taints" "sigs.k8s.io/cluster-api/util" @@ -118,7 +117,7 @@ func (r *KubeadmConfigReconciler) SetupWithManager(ctx context.Context, mgr ctrl if feature.Gates.Enabled(feature.MachinePool) { b = b.Watches( - &expv1.MachinePool{}, + &clusterv1.MachinePool{}, handler.EnqueueRequestsFromMapFunc(r.MachinePoolToBootstrapMapFunc), ) } @@ -905,7 +904,7 @@ func (r *KubeadmConfigReconciler) ClusterToKubeadmConfigs(ctx context.Context, o } if feature.Gates.Enabled(feature.MachinePool) { - machinePoolList := &expv1.MachinePoolList{} + machinePoolList := &clusterv1.MachinePoolList{} if err := r.Client.List(ctx, machinePoolList, selectors...); err != nil { return nil } @@ -941,7 +940,7 @@ func (r *KubeadmConfigReconciler) MachineToBootstrapMapFunc(_ context.Context, o // MachinePoolToBootstrapMapFunc is a handler.ToRequestsFunc to be used to enqueue // request for reconciliation of KubeadmConfig. func (r *KubeadmConfigReconciler) MachinePoolToBootstrapMapFunc(_ context.Context, o client.Object) []ctrl.Request { - m, ok := o.(*expv1.MachinePool) + m, ok := o.(*clusterv1.MachinePool) if !ok { panic(fmt.Sprintf("Expected a MachinePool but got a %T", o)) } diff --git a/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller_test.go b/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller_test.go index a2f02c3cc1a0..9ab0c3b2b98e 100644 --- a/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller_test.go +++ b/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller_test.go @@ -731,7 +731,7 @@ func TestReconcileIfJoinNodePoolsAndControlPlaneIsReady(t *testing.T) { useCases := []struct { name string - machinePool *expv1.MachinePool + machinePool *clusterv1.MachinePool configName string configBuilder func(string, string) *bootstrapv1.KubeadmConfig }{ @@ -1270,7 +1270,7 @@ func TestBootstrapTokenRotationMachinePool(t *testing.T) { } objects = append(objects, createSecrets(t, cluster, initConfig)...) - myclient := fake.NewClientBuilder().WithObjects(objects...).WithStatusSubresource(&bootstrapv1.KubeadmConfig{}, &expv1.MachinePool{}).Build() + myclient := fake.NewClientBuilder().WithObjects(objects...).WithStatusSubresource(&bootstrapv1.KubeadmConfig{}, &clusterv1.MachinePool{}).Build() remoteClient := fake.NewClientBuilder().Build() k := &KubeadmConfigReconciler{ Client: myclient, @@ -2297,7 +2297,7 @@ func newControlPlaneMachine(cluster *clusterv1.Cluster, name string) *clusterv1. } // newMachinePool return a MachinePool object with the passed Cluster information and a basic bootstrap template. -func newMachinePool(cluster *clusterv1.Cluster, name string) *expv1.MachinePool { +func newMachinePool(cluster *clusterv1.Cluster, name string) *clusterv1.MachinePool { m := builder.MachinePool(cluster.Namespace, name). WithClusterName(cluster.Name). WithLabels(map[string]string{clusterv1.ClusterNameLabel: cluster.Name}). @@ -2308,7 +2308,7 @@ func newMachinePool(cluster *clusterv1.Cluster, name string) *expv1.MachinePool } // newWorkerMachinePoolForCluster returns a MachinePool with the passed Cluster's information and a pre-configured name. -func newWorkerMachinePoolForCluster(cluster *clusterv1.Cluster) *expv1.MachinePool { +func newWorkerMachinePoolForCluster(cluster *clusterv1.Cluster) *clusterv1.MachinePool { return newMachinePool(cluster, "worker-machinepool") } @@ -2367,7 +2367,7 @@ func addKubeadmConfigToMachine(config *bootstrapv1.KubeadmConfig, machine *clust } // addKubeadmConfigToMachine adds the config details to the passed MachinePool and adds the Machine to the KubeadmConfig as an ownerReference. -func addKubeadmConfigToMachinePool(config *bootstrapv1.KubeadmConfig, machinePool *expv1.MachinePool) { +func addKubeadmConfigToMachinePool(config *bootstrapv1.KubeadmConfig, machinePool *clusterv1.MachinePool) { if machinePool == nil { panic("no machinePool passed to function") } diff --git a/bootstrap/util/configowner_test.go b/bootstrap/util/configowner_test.go index 7263e9513bd6..3d393d43945a 100644 --- a/bootstrap/util/configowner_test.go +++ b/bootstrap/util/configowner_test.go @@ -90,7 +90,7 @@ func TestGetConfigOwner(t *testing.T) { _ = feature.MutableGates.Set("MachinePool=true") g := NewWithT(t) - myPool := &expv1.MachinePool{ + myPool := &clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: "my-machine-pool", Namespace: metav1.NamespaceDefault, @@ -98,7 +98,7 @@ func TestGetConfigOwner(t *testing.T) { clusterv1.MachineControlPlaneLabel: "", }, }, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ ClusterName: "my-cluster", Template: clusterv1.MachineTemplateSpec{ Spec: clusterv1.MachineSpec{ @@ -106,7 +106,7 @@ func TestGetConfigOwner(t *testing.T) { }, }, }, - Status: expv1.MachinePoolStatus{ + Status: clusterv1.MachinePoolStatus{ InfrastructureReady: true, }, } @@ -235,7 +235,7 @@ func TestHasNodeRefs(t *testing.T) { }) t.Run("should return false if nodes are missing from MachinePool", func(t *testing.T) { g := NewWithT(t) - machinePools := []expv1.MachinePool{ + machinePools := []clusterv1.MachinePool{ { // No replicas specified (default is 1). No nodeRefs either. TypeMeta: metav1.TypeMeta{ @@ -257,7 +257,7 @@ func TestHasNodeRefs(t *testing.T) { Namespace: metav1.NamespaceDefault, Name: "machine-pool-name", }, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ Replicas: ptr.To[int32](1), }, }, @@ -271,10 +271,10 @@ func TestHasNodeRefs(t *testing.T) { Namespace: metav1.NamespaceDefault, Name: "machine-pool-name", }, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ Replicas: ptr.To[int32](2), }, - Status: expv1.MachinePoolStatus{ + Status: clusterv1.MachinePoolStatus{ NodeRefs: []corev1.ObjectReference{ { Kind: "Node", @@ -301,7 +301,7 @@ func TestHasNodeRefs(t *testing.T) { }) t.Run("should return true if MachinePool has nodeRefs for all replicas", func(t *testing.T) { g := NewWithT(t) - machinePools := []expv1.MachinePool{ + machinePools := []clusterv1.MachinePool{ { // 1 replica (default) and 1 nodeRef TypeMeta: metav1.TypeMeta{ @@ -312,7 +312,7 @@ func TestHasNodeRefs(t *testing.T) { Namespace: metav1.NamespaceDefault, Name: "machine-pool-name", }, - Status: expv1.MachinePoolStatus{ + Status: clusterv1.MachinePoolStatus{ NodeRefs: []corev1.ObjectReference{ { Kind: "Node", @@ -332,10 +332,10 @@ func TestHasNodeRefs(t *testing.T) { Namespace: metav1.NamespaceDefault, Name: "machine-pool-name", }, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ Replicas: ptr.To[int32](2), }, - Status: expv1.MachinePoolStatus{ + Status: clusterv1.MachinePoolStatus{ NodeRefs: []corev1.ObjectReference{ { Kind: "Node", @@ -360,7 +360,7 @@ func TestHasNodeRefs(t *testing.T) { Namespace: metav1.NamespaceDefault, Name: "machine-pool-name", }, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ Replicas: ptr.To[int32](0), }, }, diff --git a/cmd/clusterctl/client/tree/discovery.go b/cmd/clusterctl/client/tree/discovery.go index 09feb1960440..9e0297ea6e9a 100644 --- a/cmd/clusterctl/client/tree/discovery.go +++ b/cmd/clusterctl/client/tree/discovery.go @@ -28,7 +28,6 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/controllers/external" addonsv1 "sigs.k8s.io/cluster-api/exp/addons/api/v1beta1" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/util" ) @@ -275,7 +274,7 @@ func addMachineDeploymentToObjectTree(ctx context.Context, c client.Client, clus return nil } -func addMachinePoolsToObjectTree(ctx context.Context, c client.Client, namespace string, workers *unstructured.Unstructured, machinePoolList *expv1.MachinePoolList, machinesList *clusterv1.MachineList, tree *ObjectTree, addMachineFunc func(parent client.Object, m *clusterv1.Machine)) { +func addMachinePoolsToObjectTree(ctx context.Context, c client.Client, namespace string, workers *unstructured.Unstructured, machinePoolList *clusterv1.MachinePoolList, machinesList *clusterv1.MachineList, tree *ObjectTree, addMachineFunc func(parent client.Object, m *clusterv1.Machine)) { for i := range machinePoolList.Items { mp := &machinePoolList.Items[i] _, visible := tree.Add(workers, mp, GroupingObject(true)) @@ -360,12 +359,12 @@ func getMachineSetsInCluster(ctx context.Context, c client.Client, namespace, na return machineSetList, nil } -func getMachinePoolsInCluster(ctx context.Context, c client.Client, namespace, name string) (*expv1.MachinePoolList, error) { +func getMachinePoolsInCluster(ctx context.Context, c client.Client, namespace, name string) (*clusterv1.MachinePoolList, error) { if name == "" { return nil, nil } - machinePoolList := &expv1.MachinePoolList{} + machinePoolList := &clusterv1.MachinePoolList{} labels := map[string]string{clusterv1.ClusterNameLabel: name} if err := c.List(ctx, machinePoolList, client.InNamespace(namespace), client.MatchingLabels(labels)); err != nil { diff --git a/cmd/clusterctl/internal/test/fake_objects.go b/cmd/clusterctl/internal/test/fake_objects.go index 0299d67dd9c9..10d6bc1d8159 100644 --- a/cmd/clusterctl/internal/test/fake_objects.go +++ b/cmd/clusterctl/internal/test/fake_objects.go @@ -480,7 +480,7 @@ func (f *FakeMachinePool) Objs(cluster *clusterv1.Cluster) []client.Object { bootstrapConfig = NewBootstrapConfigTemplate(machinePoolBootstrap) } - machinePool := &expv1.MachinePool{ + machinePool := &clusterv1.MachinePool{ TypeMeta: metav1.TypeMeta{ Kind: "MachinePool", APIVersion: expv1.GroupVersion.String(), @@ -500,7 +500,7 @@ func (f *FakeMachinePool) Objs(cluster *clusterv1.Cluster) []client.Object { clusterv1.ClusterNameLabel: cluster.Name, // Added by the machinePool controller (mirrors machinePoolt.spec.ClusterName) -- RECONCILED }, }, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ Template: clusterv1.MachineTemplateSpec{ Spec: clusterv1.MachineSpec{ InfrastructureRef: corev1.ObjectReference{ @@ -883,7 +883,7 @@ func (f *FakeMachine) WithStaticBootstrapConfig() *FakeMachine { return f } -func (f *FakeMachine) Objs(cluster *clusterv1.Cluster, generateCerts bool, machineSet *clusterv1.MachineSet, machinePool *expv1.MachinePool, controlPlane *fakecontrolplane.GenericControlPlane) []client.Object { +func (f *FakeMachine) Objs(cluster *clusterv1.Cluster, generateCerts bool, machineSet *clusterv1.MachineSet, machinePool *clusterv1.MachinePool, controlPlane *fakecontrolplane.GenericControlPlane) []client.Object { machineInfrastructure := &fakeinfrastructure.GenericInfrastructureMachine{ TypeMeta: metav1.TypeMeta{ APIVersion: fakeinfrastructure.GroupVersion.String(), diff --git a/config/webhook/manifests.yaml b/config/webhook/manifests.yaml index a5d7a028af79..6beb2731189e 100644 --- a/config/webhook/manifests.yaml +++ b/config/webhook/manifests.yaml @@ -121,10 +121,10 @@ webhooks: service: name: webhook-service namespace: system - path: /mutate-cluster-x-k8s-io-v1beta1-machineset + path: /mutate-cluster-x-k8s-io-v1beta1-machinepool failurePolicy: Fail matchPolicy: Equivalent - name: default.machineset.cluster.x-k8s.io + name: default.machinepool.cluster.x-k8s.io rules: - apiGroups: - cluster.x-k8s.io @@ -134,7 +134,7 @@ webhooks: - CREATE - UPDATE resources: - - machinesets + - machinepools sideEffects: None - admissionReviewVersions: - v1 @@ -143,20 +143,20 @@ webhooks: service: name: webhook-service namespace: system - path: /mutate-runtime-cluster-x-k8s-io-v1alpha1-extensionconfig + path: /mutate-cluster-x-k8s-io-v1beta1-machineset failurePolicy: Fail matchPolicy: Equivalent - name: default.extensionconfig.runtime.addons.cluster.x-k8s.io + name: default.machineset.cluster.x-k8s.io rules: - apiGroups: - - runtime.cluster.x-k8s.io + - cluster.x-k8s.io apiVersions: - - v1alpha1 + - v1beta1 operations: - CREATE - UPDATE resources: - - extensionconfigs + - machinesets sideEffects: None - admissionReviewVersions: - v1 @@ -165,20 +165,20 @@ webhooks: service: name: webhook-service namespace: system - path: /mutate-cluster-x-k8s-io-v1beta1-machinepool + path: /mutate-runtime-cluster-x-k8s-io-v1alpha1-extensionconfig failurePolicy: Fail matchPolicy: Equivalent - name: default.machinepool.cluster.x-k8s.io + name: default.extensionconfig.runtime.addons.cluster.x-k8s.io rules: - apiGroups: - - cluster.x-k8s.io + - runtime.cluster.x-k8s.io apiVersions: - - v1beta1 + - v1alpha1 operations: - CREATE - UPDATE resources: - - machinepools + - extensionconfigs sideEffects: None - admissionReviewVersions: - v1 @@ -327,10 +327,10 @@ webhooks: service: name: webhook-service namespace: system - path: /validate-cluster-x-k8s-io-v1beta1-machineset + path: /validate-cluster-x-k8s-io-v1beta1-machinepool failurePolicy: Fail matchPolicy: Equivalent - name: validation.machineset.cluster.x-k8s.io + name: validation.machinepool.cluster.x-k8s.io rules: - apiGroups: - cluster.x-k8s.io @@ -340,7 +340,7 @@ webhooks: - CREATE - UPDATE resources: - - machinesets + - machinepools sideEffects: None - admissionReviewVersions: - v1 @@ -349,20 +349,20 @@ webhooks: service: name: webhook-service namespace: system - path: /validate-runtime-cluster-x-k8s-io-v1alpha1-extensionconfig + path: /validate-cluster-x-k8s-io-v1beta1-machineset failurePolicy: Fail matchPolicy: Equivalent - name: validation.extensionconfig.runtime.cluster.x-k8s.io + name: validation.machineset.cluster.x-k8s.io rules: - apiGroups: - - runtime.cluster.x-k8s.io + - cluster.x-k8s.io apiVersions: - - v1alpha1 + - v1beta1 operations: - CREATE - UPDATE resources: - - extensionconfigs + - machinesets sideEffects: None - admissionReviewVersions: - v1 @@ -371,20 +371,20 @@ webhooks: service: name: webhook-service namespace: system - path: /validate-cluster-x-k8s-io-v1beta1-machinepool + path: /validate-runtime-cluster-x-k8s-io-v1alpha1-extensionconfig failurePolicy: Fail matchPolicy: Equivalent - name: validation.machinepool.cluster.x-k8s.io + name: validation.extensionconfig.runtime.cluster.x-k8s.io rules: - apiGroups: - - cluster.x-k8s.io + - runtime.cluster.x-k8s.io apiVersions: - - v1beta1 + - v1alpha1 operations: - CREATE - UPDATE resources: - - machinepools + - extensionconfigs sideEffects: None - admissionReviewVersions: - v1 diff --git a/controllers/alias.go b/controllers/alias.go index 322d9b22a56e..0efefd728a78 100644 --- a/controllers/alias.go +++ b/controllers/alias.go @@ -30,6 +30,7 @@ import ( machinecontroller "sigs.k8s.io/cluster-api/internal/controllers/machine" machinedeploymentcontroller "sigs.k8s.io/cluster-api/internal/controllers/machinedeployment" machinehealthcheckcontroller "sigs.k8s.io/cluster-api/internal/controllers/machinehealthcheck" + machinepoolcontroller "sigs.k8s.io/cluster-api/internal/controllers/machinepool" machinesetcontroller "sigs.k8s.io/cluster-api/internal/controllers/machineset" clustertopologycontroller "sigs.k8s.io/cluster-api/internal/controllers/topology/cluster" machinedeploymenttopologycontroller "sigs.k8s.io/cluster-api/internal/controllers/topology/machinedeployment" @@ -120,6 +121,25 @@ func (r *MachineDeploymentReconciler) SetupWithManager(ctx context.Context, mgr }).SetupWithManager(ctx, mgr, options) } +// MachinePoolReconciler reconciles a MachinePool object. +type MachinePoolReconciler struct { + Client client.Client + APIReader client.Reader + Tracker *remote.ClusterCacheTracker + + // WatchFilterValue is the label value used to filter events prior to reconciliation. + WatchFilterValue string +} + +func (r *MachinePoolReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error { + return (&machinepoolcontroller.Reconciler{ + Client: r.Client, + APIReader: r.APIReader, + Tracker: r.Tracker, + WatchFilterValue: r.WatchFilterValue, + }).SetupWithManager(ctx, mgr, options) +} + // MachineHealthCheckReconciler reconciles a MachineHealthCheck object. type MachineHealthCheckReconciler struct { Client client.Client diff --git a/controlplane/kubeadm/internal/cluster.go b/controlplane/kubeadm/internal/cluster.go index 67a6d3aa3882..7b10d9d74c9a 100644 --- a/controlplane/kubeadm/internal/cluster.go +++ b/controlplane/kubeadm/internal/cluster.go @@ -31,7 +31,6 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/controllers/remote" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/util/collections" "sigs.k8s.io/cluster-api/util/secret" ) @@ -46,7 +45,7 @@ type ManagementCluster interface { client.Reader GetMachinesForCluster(ctx context.Context, cluster *clusterv1.Cluster, filters ...collections.Func) (collections.Machines, error) - GetMachinePoolsForCluster(ctx context.Context, cluster *clusterv1.Cluster) (*expv1.MachinePoolList, error) + GetMachinePoolsForCluster(ctx context.Context, cluster *clusterv1.Cluster) (*clusterv1.MachinePoolList, error) GetWorkloadCluster(ctx context.Context, clusterKey client.ObjectKey) (WorkloadCluster, error) } @@ -88,14 +87,14 @@ func (m *Management) GetMachinesForCluster(ctx context.Context, cluster *cluster } // GetMachinePoolsForCluster returns a list of machine pools owned by the cluster. -func (m *Management) GetMachinePoolsForCluster(ctx context.Context, cluster *clusterv1.Cluster) (*expv1.MachinePoolList, error) { +func (m *Management) GetMachinePoolsForCluster(ctx context.Context, cluster *clusterv1.Cluster) (*clusterv1.MachinePoolList, error) { selectors := []client.ListOption{ client.InNamespace(cluster.GetNamespace()), client.MatchingLabels{ clusterv1.ClusterNameLabel: cluster.GetName(), }, } - machinePoolList := &expv1.MachinePoolList{} + machinePoolList := &clusterv1.MachinePoolList{} err := m.Client.List(ctx, machinePoolList, selectors...) return machinePoolList, err } diff --git a/controlplane/kubeadm/internal/controllers/controller.go b/controlplane/kubeadm/internal/controllers/controller.go index a77071841c34..28ce0e495ccc 100644 --- a/controlplane/kubeadm/internal/controllers/controller.go +++ b/controlplane/kubeadm/internal/controllers/controller.go @@ -43,7 +43,6 @@ import ( "sigs.k8s.io/cluster-api/controllers/remote" controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1" "sigs.k8s.io/cluster-api/controlplane/kubeadm/internal" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/feature" "sigs.k8s.io/cluster-api/internal/contract" "sigs.k8s.io/cluster-api/internal/util/ssa" @@ -545,7 +544,7 @@ func (r *KubeadmControlPlaneReconciler) reconcileDelete(ctx context.Context, con return ctrl.Result{}, err } - allMachinePools := &expv1.MachinePoolList{} + allMachinePools := &clusterv1.MachinePoolList{} // Get all machine pools. if feature.Gates.Enabled(feature.MachinePool) { allMachinePools, err = r.managementCluster.GetMachinePoolsForCluster(ctx, controlPlane.Cluster) diff --git a/controlplane/kubeadm/internal/controllers/controller_test.go b/controlplane/kubeadm/internal/controllers/controller_test.go index 5a3c8971f632..22603e96dc8d 100644 --- a/controlplane/kubeadm/internal/controllers/controller_test.go +++ b/controlplane/kubeadm/internal/controllers/controller_test.go @@ -49,7 +49,6 @@ import ( controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1" "sigs.k8s.io/cluster-api/controlplane/kubeadm/internal" controlplanev1webhooks "sigs.k8s.io/cluster-api/controlplane/kubeadm/internal/webhooks" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/feature" "sigs.k8s.io/cluster-api/internal/contract" "sigs.k8s.io/cluster-api/internal/test/builder" @@ -2199,7 +2198,7 @@ func TestKubeadmControlPlaneReconciler_reconcileDelete(t *testing.T) { cluster, kcp, _ := createClusterWithControlPlane(metav1.NamespaceDefault) controllerutil.AddFinalizer(kcp, controlplanev1.KubeadmControlPlaneFinalizer) - workerMachinePool := &expv1.MachinePool{ + workerMachinePool := &clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: "worker", Namespace: cluster.Namespace, diff --git a/controlplane/kubeadm/internal/controllers/fakes_test.go b/controlplane/kubeadm/internal/controllers/fakes_test.go index cf9fcbafe66e..d73652cdf6a5 100644 --- a/controlplane/kubeadm/internal/controllers/fakes_test.go +++ b/controlplane/kubeadm/internal/controllers/fakes_test.go @@ -27,7 +27,6 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1" "sigs.k8s.io/cluster-api/controlplane/kubeadm/internal" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/util/collections" ) @@ -35,7 +34,7 @@ type fakeManagementCluster struct { // TODO: once all client interactions are moved to the Management cluster this can go away Management *internal.Management Machines collections.Machines - MachinePools *expv1.MachinePoolList + MachinePools *clusterv1.MachinePoolList Workload fakeWorkloadCluster Reader client.Reader } @@ -59,7 +58,7 @@ func (f *fakeManagementCluster) GetMachinesForCluster(c context.Context, cluster return f.Machines, nil } -func (f *fakeManagementCluster) GetMachinePoolsForCluster(c context.Context, cluster *clusterv1.Cluster) (*expv1.MachinePoolList, error) { +func (f *fakeManagementCluster) GetMachinePoolsForCluster(c context.Context, cluster *clusterv1.Cluster) (*clusterv1.MachinePoolList, error) { if f.Management != nil { return f.Management.GetMachinePoolsForCluster(c, cluster) } diff --git a/exp/api/v1beta1/condition_consts.go b/exp/api/v1beta1/condition_consts.go index 18e29600ab5d..d55ab5609a7b 100644 --- a/exp/api/v1beta1/condition_consts.go +++ b/exp/api/v1beta1/condition_consts.go @@ -15,16 +15,3 @@ limitations under the License. */ package v1beta1 - -import clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - -// Conditions and condition Reasons for the MachinePool object. - -const ( - // ReplicasReadyCondition reports an aggregate of current status of the replicas controlled by the MachinePool. - ReplicasReadyCondition clusterv1.ConditionType = "ReplicasReady" - - // WaitingForReplicasReadyReason (Severity=Info) documents a machinepool waiting for the required replicas - // to be ready. - WaitingForReplicasReadyReason = "WaitingForReplicasReady" -) diff --git a/exp/api/v1beta1/conversion.go b/exp/api/v1beta1/conversion.go index 91e5b549c388..d55ab5609a7b 100644 --- a/exp/api/v1beta1/conversion.go +++ b/exp/api/v1beta1/conversion.go @@ -15,6 +15,3 @@ limitations under the License. */ package v1beta1 - -func (*MachinePool) Hub() {} -func (*MachinePoolList) Hub() {} diff --git a/exp/api/v1beta1/zz_generated.deepcopy.go b/exp/api/v1beta1/zz_generated.deepcopy.go deleted file mode 100644 index 68cfe8fc8c3c..000000000000 --- a/exp/api/v1beta1/zz_generated.deepcopy.go +++ /dev/null @@ -1,160 +0,0 @@ -//go:build !ignore_autogenerated - -/* -Copyright 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. -*/ - -// Code generated by controller-gen. DO NOT EDIT. - -package v1beta1 - -import ( - "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/runtime" - apiv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1" - "sigs.k8s.io/cluster-api/errors" -) - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MachinePool) DeepCopyInto(out *MachinePool) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - in.Status.DeepCopyInto(&out.Status) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachinePool. -func (in *MachinePool) DeepCopy() *MachinePool { - if in == nil { - return nil - } - out := new(MachinePool) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *MachinePool) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MachinePoolList) DeepCopyInto(out *MachinePoolList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]MachinePool, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachinePoolList. -func (in *MachinePoolList) DeepCopy() *MachinePoolList { - if in == nil { - return nil - } - out := new(MachinePoolList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *MachinePoolList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MachinePoolSpec) DeepCopyInto(out *MachinePoolSpec) { - *out = *in - if in.Replicas != nil { - in, out := &in.Replicas, &out.Replicas - *out = new(int32) - **out = **in - } - in.Template.DeepCopyInto(&out.Template) - if in.MinReadySeconds != nil { - in, out := &in.MinReadySeconds, &out.MinReadySeconds - *out = new(int32) - **out = **in - } - if in.ProviderIDList != nil { - in, out := &in.ProviderIDList, &out.ProviderIDList - *out = make([]string, len(*in)) - copy(*out, *in) - } - if in.FailureDomains != nil { - in, out := &in.FailureDomains, &out.FailureDomains - *out = make([]string, len(*in)) - copy(*out, *in) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachinePoolSpec. -func (in *MachinePoolSpec) DeepCopy() *MachinePoolSpec { - if in == nil { - return nil - } - out := new(MachinePoolSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MachinePoolStatus) DeepCopyInto(out *MachinePoolStatus) { - *out = *in - if in.NodeRefs != nil { - in, out := &in.NodeRefs, &out.NodeRefs - *out = make([]v1.ObjectReference, len(*in)) - copy(*out, *in) - } - if in.FailureReason != nil { - in, out := &in.FailureReason, &out.FailureReason - *out = new(errors.MachinePoolStatusFailure) - **out = **in - } - if in.FailureMessage != nil { - in, out := &in.FailureMessage, &out.FailureMessage - *out = new(string) - **out = **in - } - if in.Conditions != nil { - in, out := &in.Conditions, &out.Conditions - *out = make(apiv1beta1.Conditions, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachinePoolStatus. -func (in *MachinePoolStatus) DeepCopy() *MachinePoolStatus { - if in == nil { - return nil - } - out := new(MachinePoolStatus) - in.DeepCopyInto(out) - return out -} diff --git a/exp/controllers/alias.go b/exp/controllers/alias.go index 0db7dfb5f090..dac5dea6919e 100644 --- a/exp/controllers/alias.go +++ b/exp/controllers/alias.go @@ -15,33 +15,3 @@ limitations under the License. */ package controllers - -import ( - "context" - - ctrl "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/controller" - - "sigs.k8s.io/cluster-api/controllers/remote" - machinepool "sigs.k8s.io/cluster-api/exp/internal/controllers" -) - -// MachinePoolReconciler reconciles a MachinePool object. -type MachinePoolReconciler struct { - Client client.Client - APIReader client.Reader - Tracker *remote.ClusterCacheTracker - - // WatchFilterValue is the label value used to filter events prior to reconciliation. - WatchFilterValue string -} - -func (r *MachinePoolReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error { - return (&machinepool.MachinePoolReconciler{ - Client: r.Client, - APIReader: r.APIReader, - Tracker: r.Tracker, - WatchFilterValue: r.WatchFilterValue, - }).SetupWithManager(ctx, mgr, options) -} diff --git a/exp/topology/desiredstate/desired_state.go b/exp/topology/desiredstate/desired_state.go index d3925ef355b2..050c0218a470 100644 --- a/exp/topology/desiredstate/desired_state.go +++ b/exp/topology/desiredstate/desired_state.go @@ -32,7 +32,6 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/controllers/external" "sigs.k8s.io/cluster-api/controllers/remote" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" runtimecatalog "sigs.k8s.io/cluster-api/exp/runtime/catalog" runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1" "sigs.k8s.io/cluster-api/exp/topology/scope" @@ -1071,16 +1070,16 @@ func (g *generator) computeMachinePool(_ context.Context, s *scope.Scope, machin return nil, errors.Wrap(err, "failed to generate name for MachinePool") } - desiredMachinePoolObj := &expv1.MachinePool{ + desiredMachinePoolObj := &clusterv1.MachinePool{ TypeMeta: metav1.TypeMeta{ - APIVersion: expv1.GroupVersion.String(), + APIVersion: clusterv1.GroupVersion.String(), Kind: "MachinePool", }, ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: s.Current.Cluster.Namespace, }, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ ClusterName: s.Current.Cluster.Name, MinReadySeconds: minReadySeconds, FailureDomains: failureDomains, diff --git a/exp/topology/desiredstate/desired_state_test.go b/exp/topology/desiredstate/desired_state_test.go index dc0aecb69456..a7d95b26570c 100644 --- a/exp/topology/desiredstate/desired_state_test.go +++ b/exp/topology/desiredstate/desired_state_test.go @@ -1923,11 +1923,11 @@ func TestComputeMachinePool(t *testing.T) { s.Blueprint = blueprint currentReplicas := int32(3) - currentMp := &expv1.MachinePool{ + currentMp := &clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: "existing-pool-1", }, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ Replicas: ¤tReplicas, Template: clusterv1.MachineTemplateSpec{ Spec: clusterv1.MachineSpec{ @@ -2082,7 +2082,7 @@ func TestComputeMachinePool(t *testing.T) { mp := builder.MachinePool("test-namespace", "big-pool-of-machines"). WithReplicas(2). WithVersion(*tt.currentMPVersion). - WithStatus(expv1.MachinePoolStatus{ + WithStatus(clusterv1.MachinePoolStatus{ ObservedGeneration: 2, Replicas: 2, ReadyReplicas: 2, diff --git a/exp/topology/scope/state.go b/exp/topology/scope/state.go index 00ebc04bbbb5..99bdd85e4abd 100644 --- a/exp/topology/scope/state.go +++ b/exp/topology/scope/state.go @@ -24,7 +24,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/internal/topology/check" ) @@ -125,7 +124,7 @@ func (mps MachinePoolsStateMap) Upgrading(ctx context.Context, c client.Reader) // MachinePoolState holds all the objects representing the state of a managed pool. type MachinePoolState struct { // Object holds the MachinePool object. - Object *expv1.MachinePool + Object *clusterv1.MachinePool // BootstrapObject holds the MachinePool bootstrap object. BootstrapObject *unstructured.Unstructured diff --git a/exp/topology/scope/state_test.go b/exp/topology/scope/state_test.go index 874610c7615a..7305b3c7cbf7 100644 --- a/exp/topology/scope/state_test.go +++ b/exp/topology/scope/state_test.go @@ -77,6 +77,7 @@ func TestMPUpgrading(t *testing.T) { scheme := runtime.NewScheme() g.Expect(expv1.AddToScheme(scheme)).To(Succeed()) g.Expect(corev1.AddToScheme(scheme)).To(Succeed()) + g.Expect(clusterv1.AddToScheme(scheme)).To(Succeed()) ctx := context.Background() @@ -84,7 +85,7 @@ func TestMPUpgrading(t *testing.T) { stableMP := builder.MachinePool("ns", "stableMP"). WithClusterName("cluster1"). WithVersion("v1.2.3"). - WithStatus(expv1.MachinePoolStatus{ + WithStatus(clusterv1.MachinePoolStatus{ NodeRefs: []corev1.ObjectReference{ { Name: "stableMP-node1", @@ -103,7 +104,7 @@ func TestMPUpgrading(t *testing.T) { upgradingMP := builder.MachinePool("ns", "upgradingMP"). WithClusterName("cluster2"). WithVersion("v1.2.3"). - WithStatus(expv1.MachinePoolStatus{ + WithStatus(clusterv1.MachinePoolStatus{ NodeRefs: []corev1.ObjectReference{ { Name: "upgradingMP-node1", diff --git a/exp/util/util.go b/exp/util/util.go index aa201cc4d846..dc8dea1d4b68 100644 --- a/exp/util/util.go +++ b/exp/util/util.go @@ -30,12 +30,11 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/util/labels/format" ) // GetOwnerMachinePool returns the MachinePool objects owning the current resource. -func GetOwnerMachinePool(ctx context.Context, c client.Client, obj metav1.ObjectMeta) (*expv1.MachinePool, error) { +func GetOwnerMachinePool(ctx context.Context, c client.Client, obj metav1.ObjectMeta) (*clusterv1.MachinePool, error) { for _, ref := range obj.GetOwnerReferences() { if ref.Kind != "MachinePool" { continue @@ -44,7 +43,7 @@ func GetOwnerMachinePool(ctx context.Context, c client.Client, obj metav1.Object if err != nil { return nil, errors.WithStack(err) } - if gv.Group == expv1.GroupVersion.Group { + if gv.Group == clusterv1.GroupVersion.Group { return GetMachinePoolByName(ctx, c, obj.Namespace, ref.Name) } } @@ -52,8 +51,8 @@ func GetOwnerMachinePool(ctx context.Context, c client.Client, obj metav1.Object } // GetMachinePoolByName finds and returns a MachinePool object using the specified params. -func GetMachinePoolByName(ctx context.Context, c client.Client, namespace, name string) (*expv1.MachinePool, error) { - m := &expv1.MachinePool{} +func GetMachinePoolByName(ctx context.Context, c client.Client, namespace, name string) (*clusterv1.MachinePool, error) { + m := &clusterv1.MachinePool{} key := client.ObjectKey{Name: name, Namespace: namespace} if err := c.Get(ctx, key, m); err != nil { return nil, err @@ -63,14 +62,14 @@ func GetMachinePoolByName(ctx context.Context, c client.Client, namespace, name // GetMachinePoolByLabels finds and returns a MachinePool object using the value of clusterv1.MachinePoolNameLabel. // This differs from GetMachinePoolByName as the label value can be a hash. -func GetMachinePoolByLabels(ctx context.Context, c client.Client, namespace string, labels map[string]string) (*expv1.MachinePool, error) { +func GetMachinePoolByLabels(ctx context.Context, c client.Client, namespace string, labels map[string]string) (*clusterv1.MachinePool, error) { selector := map[string]string{} if clusterName, ok := labels[clusterv1.ClusterNameLabel]; ok { selector = map[string]string{clusterv1.ClusterNameLabel: clusterName} } if poolNameHash, ok := labels[clusterv1.MachinePoolNameLabel]; ok { - machinePoolList := &expv1.MachinePoolList{} + machinePoolList := &clusterv1.MachinePoolList{} if err := c.List(ctx, machinePoolList, client.InNamespace(namespace), client.MatchingLabels(selector)); err != nil { return nil, errors.Wrapf(err, "failed to list MachinePools using labels %v", selector) } @@ -92,7 +91,7 @@ func GetMachinePoolByLabels(ctx context.Context, c client.Client, namespace stri func MachinePoolToInfrastructureMapFunc(ctx context.Context, gvk schema.GroupVersionKind) handler.MapFunc { log := ctrl.LoggerFrom(ctx) return func(_ context.Context, o client.Object) []reconcile.Request { - m, ok := o.(*expv1.MachinePool) + m, ok := o.(*clusterv1.MachinePool) if !ok { log.V(4).Info("Not a machine pool", "Object", klog.KObj(o)) return nil diff --git a/exp/util/util_test.go b/exp/util/util_test.go index cf5c2f648ecb..cfdeb3b8e8c1 100644 --- a/exp/util/util_test.go +++ b/exp/util/util_test.go @@ -27,12 +27,12 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client/fake" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/util/labels/format" ) func TestGetMachinePoolByLabels(t *testing.T) { g := NewWithT(t) + g.Expect(clusterv1.AddToScheme(fakeScheme)).To(Succeed()) longMachinePoolName := "this-is-a-very-long-machinepool-name-that-will-turned-into-a-hash-because-it-is-longer-than-63-characters" namespace := "default" @@ -50,13 +50,13 @@ func TestGetMachinePoolByLabels(t *testing.T) { clusterv1.MachinePoolNameLabel: "test-pool", }, machinePools: []client.Object{ - &expv1.MachinePool{ + &clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: "test-pool", Namespace: "default", }, }, - &expv1.MachinePool{ + &clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: "other-pool", Namespace: "default", @@ -72,7 +72,7 @@ func TestGetMachinePoolByLabels(t *testing.T) { clusterv1.ClusterNameLabel: "test-cluster", }, machinePools: []client.Object{ - &expv1.MachinePool{ + &clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: "test-pool", Namespace: "default", @@ -81,7 +81,7 @@ func TestGetMachinePoolByLabels(t *testing.T) { }, }, }, - &expv1.MachinePool{ + &clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: "other-pool", Namespace: "default", @@ -99,13 +99,13 @@ func TestGetMachinePoolByLabels(t *testing.T) { clusterv1.MachinePoolNameLabel: format.MustFormatValue(longMachinePoolName), }, machinePools: []client.Object{ - &expv1.MachinePool{ + &clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: longMachinePoolName, Namespace: "default", }, }, - &expv1.MachinePool{ + &clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: "other-pool", Namespace: "default", diff --git a/exp/webhooks/alias.go b/exp/webhooks/alias.go index 21deef6e7651..c9f8f826ee39 100644 --- a/exp/webhooks/alias.go +++ b/exp/webhooks/alias.go @@ -15,17 +15,3 @@ limitations under the License. */ package webhooks - -import ( - ctrl "sigs.k8s.io/controller-runtime" - - "sigs.k8s.io/cluster-api/exp/internal/webhooks" -) - -// MachinePool implements a validating and defaulting webhook for MachinePool. -type MachinePool struct{} - -// SetupWebhookWithManager sets up MachinePool webhooks. -func (webhook *MachinePool) SetupWebhookWithManager(mgr ctrl.Manager) error { - return (&webhooks.MachinePool{}).SetupWebhookWithManager(mgr) -} diff --git a/internal/apis/core/exp/addons/v1alpha3/zz_generated.deepcopy.go b/internal/apis/core/exp/addons/v1alpha3/zz_generated.deepcopy.go index 399550914539..5fd53a192ca3 100644 --- a/internal/apis/core/exp/addons/v1alpha3/zz_generated.deepcopy.go +++ b/internal/apis/core/exp/addons/v1alpha3/zz_generated.deepcopy.go @@ -22,7 +22,7 @@ package v1alpha3 import ( runtime "k8s.io/apimachinery/pkg/runtime" - apiv1alpha3 "sigs.k8s.io/cluster-api/internal/apis/core/v1alpha3" + corev1alpha3 "sigs.k8s.io/cluster-api/internal/apis/core/v1alpha3" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -194,7 +194,7 @@ func (in *ClusterResourceSetStatus) DeepCopyInto(out *ClusterResourceSetStatus) *out = *in if in.Conditions != nil { in, out := &in.Conditions, &out.Conditions - *out = make(apiv1alpha3.Conditions, len(*in)) + *out = make(corev1alpha3.Conditions, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } diff --git a/internal/apis/core/exp/addons/v1alpha4/zz_generated.deepcopy.go b/internal/apis/core/exp/addons/v1alpha4/zz_generated.deepcopy.go index a06e334452a4..42f8bb711b01 100644 --- a/internal/apis/core/exp/addons/v1alpha4/zz_generated.deepcopy.go +++ b/internal/apis/core/exp/addons/v1alpha4/zz_generated.deepcopy.go @@ -22,7 +22,7 @@ package v1alpha4 import ( "k8s.io/apimachinery/pkg/runtime" - apiv1alpha4 "sigs.k8s.io/cluster-api/internal/apis/core/v1alpha4" + corev1alpha4 "sigs.k8s.io/cluster-api/internal/apis/core/v1alpha4" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -194,7 +194,7 @@ func (in *ClusterResourceSetStatus) DeepCopyInto(out *ClusterResourceSetStatus) *out = *in if in.Conditions != nil { in, out := &in.Conditions, &out.Conditions - *out = make(apiv1alpha4.Conditions, len(*in)) + *out = make(corev1alpha4.Conditions, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } diff --git a/internal/apis/core/exp/v1alpha3/condition_consts.go b/internal/apis/core/exp/v1alpha3/condition_consts.go index 839771c271b3..e072c3ecbea5 100644 --- a/internal/apis/core/exp/v1alpha3/condition_consts.go +++ b/internal/apis/core/exp/v1alpha3/condition_consts.go @@ -15,16 +15,3 @@ limitations under the License. */ package v1alpha3 - -import clusterv1alpha3 "sigs.k8s.io/cluster-api/internal/apis/core/v1alpha3" - -// Conditions and condition Reasons for the MachinePool object. - -const ( - // ReplicasReadyCondition reports an aggregate of current status of the replicas controlled by the MachinePool. - ReplicasReadyCondition clusterv1alpha3.ConditionType = "ReplicasReady" - - // WaitingForReplicasReadyReason (Severity=Info) documents a machinepool waiting for the required replicas - // to be ready. - WaitingForReplicasReadyReason = "WaitingForReplicasReady" -) diff --git a/internal/apis/core/exp/v1alpha3/conversion.go b/internal/apis/core/exp/v1alpha3/conversion.go index 1aae52b47bee..4feaa3b52e79 100644 --- a/internal/apis/core/exp/v1alpha3/conversion.go +++ b/internal/apis/core/exp/v1alpha3/conversion.go @@ -18,87 +18,11 @@ package v1alpha3 import ( apimachineryconversion "k8s.io/apimachinery/pkg/conversion" - "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - "sigs.k8s.io/controller-runtime/pkg/conversion" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" clusterv1alpha3 "sigs.k8s.io/cluster-api/internal/apis/core/v1alpha3" - utilconversion "sigs.k8s.io/cluster-api/util/conversion" ) -// Convert_v1alpha3_MachinePoolSpec_To_v1beta1_MachinePoolSpec is an autogenerated conversion function. -func Convert_v1alpha3_MachinePoolSpec_To_v1beta1_MachinePoolSpec(in *MachinePoolSpec, out *expv1.MachinePoolSpec, s apimachineryconversion.Scope) error { - return autoConvert_v1alpha3_MachinePoolSpec_To_v1beta1_MachinePoolSpec(in, out, s) -} - -func Convert_v1alpha3_MachinePool_To_v1beta1_MachinePool(in *MachinePool, out *expv1.MachinePool, s apimachineryconversion.Scope) error { - if err := autoConvert_v1alpha3_MachinePool_To_v1beta1_MachinePool(in, out, s); err != nil { - return err - } - - // Replace v1alpha3 finalizer to allow old MachinePools to get deleted. - if controllerutil.ContainsFinalizer(out, MachinePoolFinalizer) { - controllerutil.RemoveFinalizer(out, MachinePoolFinalizer) - controllerutil.AddFinalizer(out, expv1.MachinePoolFinalizer) - } - - return nil -} - -func Convert_v1beta1_MachinePool_To_v1alpha3_MachinePool(in *expv1.MachinePool, out *MachinePool, s apimachineryconversion.Scope) error { - if err := autoConvert_v1beta1_MachinePool_To_v1alpha3_MachinePool(in, out, s); err != nil { - return err - } - - // Replace v1beta1 finalizer to allow old MachinePools to get deleted. - if controllerutil.ContainsFinalizer(out, expv1.MachinePoolFinalizer) { - controllerutil.RemoveFinalizer(out, expv1.MachinePoolFinalizer) - controllerutil.AddFinalizer(out, MachinePoolFinalizer) - } - - return nil -} - -func (src *MachinePool) ConvertTo(dstRaw conversion.Hub) error { - dst := dstRaw.(*expv1.MachinePool) - - if err := Convert_v1alpha3_MachinePool_To_v1beta1_MachinePool(src, dst, nil); err != nil { - return err - } - - // Manually restore data. - restored := &expv1.MachinePool{} - if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok { - return err - } - dst.Spec.Template.Spec.NodeDeletionTimeout = restored.Spec.Template.Spec.NodeDeletionTimeout - dst.Spec.Template.Spec.NodeVolumeDetachTimeout = restored.Spec.Template.Spec.NodeVolumeDetachTimeout - return nil -} - -func (dst *MachinePool) ConvertFrom(srcRaw conversion.Hub) error { - src := srcRaw.(*expv1.MachinePool) - - if err := Convert_v1beta1_MachinePool_To_v1alpha3_MachinePool(src, dst, nil); err != nil { - return err - } - - return utilconversion.MarshalData(src, dst) -} - -func (src *MachinePoolList) ConvertTo(dstRaw conversion.Hub) error { - dst := dstRaw.(*expv1.MachinePoolList) - - return Convert_v1alpha3_MachinePoolList_To_v1beta1_MachinePoolList(src, dst, nil) -} - -func (dst *MachinePoolList) ConvertFrom(srcRaw conversion.Hub) error { - src := srcRaw.(*expv1.MachinePoolList) - - return Convert_v1beta1_MachinePoolList_To_v1alpha3_MachinePoolList(src, dst, nil) -} - func Convert_v1alpha3_MachineTemplateSpec_To_v1beta1_MachineTemplateSpec(in *clusterv1alpha3.MachineTemplateSpec, out *clusterv1.MachineTemplateSpec, s apimachineryconversion.Scope) error { return clusterv1alpha3.Convert_v1alpha3_MachineTemplateSpec_To_v1beta1_MachineTemplateSpec(in, out, s) } diff --git a/internal/apis/core/exp/v1alpha3/conversion_test.go b/internal/apis/core/exp/v1alpha3/conversion_test.go index 6df28a82fba7..9cca4aa46303 100644 --- a/internal/apis/core/exp/v1alpha3/conversion_test.go +++ b/internal/apis/core/exp/v1alpha3/conversion_test.go @@ -20,26 +20,17 @@ import ( "testing" fuzz "github.com/google/gofuzz" - "k8s.io/apimachinery/pkg/api/apitesting/fuzzer" runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" clusterv1alpha3 "sigs.k8s.io/cluster-api/internal/apis/core/v1alpha3" - utilconversion "sigs.k8s.io/cluster-api/util/conversion" ) func TestFuzzyConversion(t *testing.T) { - t.Run("for MachinePool", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ - Hub: &expv1.MachinePool{}, - Spoke: &MachinePool{}, - FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzFuncs}, - })) } func fuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} { return []interface{}{ BootstrapFuzzer, - MachinePoolSpecFuzzer, ObjectMetaFuzzer, } } @@ -61,11 +52,3 @@ func ObjectMetaFuzzer(in *clusterv1alpha3.ObjectMeta, c fuzz.Continue) { in.Namespace = "" in.OwnerReferences = nil } - -func MachinePoolSpecFuzzer(in *MachinePoolSpec, c fuzz.Continue) { - c.Fuzz(in) - - // These fields have been removed in v1beta1 - // data is going to be lost, so we're forcing zero values here. - in.Strategy = nil -} diff --git a/internal/apis/core/exp/v1alpha3/zz_generated.conversion.go b/internal/apis/core/exp/v1alpha3/zz_generated.conversion.go index 35410aaf1175..1615e119ee89 100644 --- a/internal/apis/core/exp/v1alpha3/zz_generated.conversion.go +++ b/internal/apis/core/exp/v1alpha3/zz_generated.conversion.go @@ -22,15 +22,10 @@ limitations under the License. package v1alpha3 import ( - unsafe "unsafe" - - v1 "k8s.io/api/core/v1" conversion "k8s.io/apimachinery/pkg/conversion" runtime "k8s.io/apimachinery/pkg/runtime" - apiv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1" - errors "sigs.k8s.io/cluster-api/errors" - v1beta1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" - corev1alpha3 "sigs.k8s.io/cluster-api/internal/apis/core/v1alpha3" + v1beta1 "sigs.k8s.io/cluster-api/api/v1beta1" + v1alpha3 "sigs.k8s.io/cluster-api/internal/apis/core/v1alpha3" ) func init() { @@ -40,191 +35,15 @@ func init() { // RegisterConversions adds conversion functions to the given scheme. // Public to allow building arbitrary schemes. func RegisterConversions(s *runtime.Scheme) error { - if err := s.AddGeneratedConversionFunc((*MachinePoolList)(nil), (*v1beta1.MachinePoolList)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha3_MachinePoolList_To_v1beta1_MachinePoolList(a.(*MachinePoolList), b.(*v1beta1.MachinePoolList), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*v1beta1.MachinePoolList)(nil), (*MachinePoolList)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta1_MachinePoolList_To_v1alpha3_MachinePoolList(a.(*v1beta1.MachinePoolList), b.(*MachinePoolList), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*v1beta1.MachinePoolSpec)(nil), (*MachinePoolSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta1_MachinePoolSpec_To_v1alpha3_MachinePoolSpec(a.(*v1beta1.MachinePoolSpec), b.(*MachinePoolSpec), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*MachinePoolStatus)(nil), (*v1beta1.MachinePoolStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha3_MachinePoolStatus_To_v1beta1_MachinePoolStatus(a.(*MachinePoolStatus), b.(*v1beta1.MachinePoolStatus), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*v1beta1.MachinePoolStatus)(nil), (*MachinePoolStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta1_MachinePoolStatus_To_v1alpha3_MachinePoolStatus(a.(*v1beta1.MachinePoolStatus), b.(*MachinePoolStatus), scope) - }); err != nil { - return err - } - if err := s.AddConversionFunc((*MachinePoolSpec)(nil), (*v1beta1.MachinePoolSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha3_MachinePoolSpec_To_v1beta1_MachinePoolSpec(a.(*MachinePoolSpec), b.(*v1beta1.MachinePoolSpec), scope) - }); err != nil { - return err - } - if err := s.AddConversionFunc((*MachinePool)(nil), (*v1beta1.MachinePool)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha3_MachinePool_To_v1beta1_MachinePool(a.(*MachinePool), b.(*v1beta1.MachinePool), scope) + if err := s.AddConversionFunc((*v1alpha3.MachineTemplateSpec)(nil), (*v1beta1.MachineTemplateSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha3_MachineTemplateSpec_To_v1beta1_MachineTemplateSpec(a.(*v1alpha3.MachineTemplateSpec), b.(*v1beta1.MachineTemplateSpec), scope) }); err != nil { return err } - if err := s.AddConversionFunc((*corev1alpha3.MachineTemplateSpec)(nil), (*apiv1beta1.MachineTemplateSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha3_MachineTemplateSpec_To_v1beta1_MachineTemplateSpec(a.(*corev1alpha3.MachineTemplateSpec), b.(*apiv1beta1.MachineTemplateSpec), scope) + if err := s.AddConversionFunc((*v1beta1.MachineTemplateSpec)(nil), (*v1alpha3.MachineTemplateSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_MachineTemplateSpec_To_v1alpha3_MachineTemplateSpec(a.(*v1beta1.MachineTemplateSpec), b.(*v1alpha3.MachineTemplateSpec), scope) }); err != nil { return err } - if err := s.AddConversionFunc((*v1beta1.MachinePool)(nil), (*MachinePool)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta1_MachinePool_To_v1alpha3_MachinePool(a.(*v1beta1.MachinePool), b.(*MachinePool), scope) - }); err != nil { - return err - } - if err := s.AddConversionFunc((*apiv1beta1.MachineTemplateSpec)(nil), (*corev1alpha3.MachineTemplateSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta1_MachineTemplateSpec_To_v1alpha3_MachineTemplateSpec(a.(*apiv1beta1.MachineTemplateSpec), b.(*corev1alpha3.MachineTemplateSpec), scope) - }); err != nil { - return err - } - return nil -} - -func autoConvert_v1alpha3_MachinePool_To_v1beta1_MachinePool(in *MachinePool, out *v1beta1.MachinePool, s conversion.Scope) error { - out.ObjectMeta = in.ObjectMeta - if err := Convert_v1alpha3_MachinePoolSpec_To_v1beta1_MachinePoolSpec(&in.Spec, &out.Spec, s); err != nil { - return err - } - if err := Convert_v1alpha3_MachinePoolStatus_To_v1beta1_MachinePoolStatus(&in.Status, &out.Status, s); err != nil { - return err - } return nil } - -func autoConvert_v1beta1_MachinePool_To_v1alpha3_MachinePool(in *v1beta1.MachinePool, out *MachinePool, s conversion.Scope) error { - out.ObjectMeta = in.ObjectMeta - if err := Convert_v1beta1_MachinePoolSpec_To_v1alpha3_MachinePoolSpec(&in.Spec, &out.Spec, s); err != nil { - return err - } - if err := Convert_v1beta1_MachinePoolStatus_To_v1alpha3_MachinePoolStatus(&in.Status, &out.Status, s); err != nil { - return err - } - return nil -} - -func autoConvert_v1alpha3_MachinePoolList_To_v1beta1_MachinePoolList(in *MachinePoolList, out *v1beta1.MachinePoolList, s conversion.Scope) error { - out.ListMeta = in.ListMeta - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]v1beta1.MachinePool, len(*in)) - for i := range *in { - if err := Convert_v1alpha3_MachinePool_To_v1beta1_MachinePool(&(*in)[i], &(*out)[i], s); err != nil { - return err - } - } - } else { - out.Items = nil - } - return nil -} - -// Convert_v1alpha3_MachinePoolList_To_v1beta1_MachinePoolList is an autogenerated conversion function. -func Convert_v1alpha3_MachinePoolList_To_v1beta1_MachinePoolList(in *MachinePoolList, out *v1beta1.MachinePoolList, s conversion.Scope) error { - return autoConvert_v1alpha3_MachinePoolList_To_v1beta1_MachinePoolList(in, out, s) -} - -func autoConvert_v1beta1_MachinePoolList_To_v1alpha3_MachinePoolList(in *v1beta1.MachinePoolList, out *MachinePoolList, s conversion.Scope) error { - out.ListMeta = in.ListMeta - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]MachinePool, len(*in)) - for i := range *in { - if err := Convert_v1beta1_MachinePool_To_v1alpha3_MachinePool(&(*in)[i], &(*out)[i], s); err != nil { - return err - } - } - } else { - out.Items = nil - } - return nil -} - -// Convert_v1beta1_MachinePoolList_To_v1alpha3_MachinePoolList is an autogenerated conversion function. -func Convert_v1beta1_MachinePoolList_To_v1alpha3_MachinePoolList(in *v1beta1.MachinePoolList, out *MachinePoolList, s conversion.Scope) error { - return autoConvert_v1beta1_MachinePoolList_To_v1alpha3_MachinePoolList(in, out, s) -} - -func autoConvert_v1alpha3_MachinePoolSpec_To_v1beta1_MachinePoolSpec(in *MachinePoolSpec, out *v1beta1.MachinePoolSpec, s conversion.Scope) error { - out.ClusterName = in.ClusterName - out.Replicas = (*int32)(unsafe.Pointer(in.Replicas)) - if err := Convert_v1alpha3_MachineTemplateSpec_To_v1beta1_MachineTemplateSpec(&in.Template, &out.Template, s); err != nil { - return err - } - // WARNING: in.Strategy requires manual conversion: does not exist in peer-type - out.MinReadySeconds = (*int32)(unsafe.Pointer(in.MinReadySeconds)) - out.ProviderIDList = *(*[]string)(unsafe.Pointer(&in.ProviderIDList)) - out.FailureDomains = *(*[]string)(unsafe.Pointer(&in.FailureDomains)) - return nil -} - -func autoConvert_v1beta1_MachinePoolSpec_To_v1alpha3_MachinePoolSpec(in *v1beta1.MachinePoolSpec, out *MachinePoolSpec, s conversion.Scope) error { - out.ClusterName = in.ClusterName - out.Replicas = (*int32)(unsafe.Pointer(in.Replicas)) - if err := Convert_v1beta1_MachineTemplateSpec_To_v1alpha3_MachineTemplateSpec(&in.Template, &out.Template, s); err != nil { - return err - } - out.MinReadySeconds = (*int32)(unsafe.Pointer(in.MinReadySeconds)) - out.ProviderIDList = *(*[]string)(unsafe.Pointer(&in.ProviderIDList)) - out.FailureDomains = *(*[]string)(unsafe.Pointer(&in.FailureDomains)) - return nil -} - -// Convert_v1beta1_MachinePoolSpec_To_v1alpha3_MachinePoolSpec is an autogenerated conversion function. -func Convert_v1beta1_MachinePoolSpec_To_v1alpha3_MachinePoolSpec(in *v1beta1.MachinePoolSpec, out *MachinePoolSpec, s conversion.Scope) error { - return autoConvert_v1beta1_MachinePoolSpec_To_v1alpha3_MachinePoolSpec(in, out, s) -} - -func autoConvert_v1alpha3_MachinePoolStatus_To_v1beta1_MachinePoolStatus(in *MachinePoolStatus, out *v1beta1.MachinePoolStatus, s conversion.Scope) error { - out.NodeRefs = *(*[]v1.ObjectReference)(unsafe.Pointer(&in.NodeRefs)) - out.Replicas = in.Replicas - out.ReadyReplicas = in.ReadyReplicas - out.AvailableReplicas = in.AvailableReplicas - out.UnavailableReplicas = in.UnavailableReplicas - out.FailureReason = (*errors.MachinePoolStatusFailure)(unsafe.Pointer(in.FailureReason)) - out.FailureMessage = (*string)(unsafe.Pointer(in.FailureMessage)) - out.Phase = in.Phase - out.BootstrapReady = in.BootstrapReady - out.InfrastructureReady = in.InfrastructureReady - out.ObservedGeneration = in.ObservedGeneration - out.Conditions = *(*apiv1beta1.Conditions)(unsafe.Pointer(&in.Conditions)) - return nil -} - -// Convert_v1alpha3_MachinePoolStatus_To_v1beta1_MachinePoolStatus is an autogenerated conversion function. -func Convert_v1alpha3_MachinePoolStatus_To_v1beta1_MachinePoolStatus(in *MachinePoolStatus, out *v1beta1.MachinePoolStatus, s conversion.Scope) error { - return autoConvert_v1alpha3_MachinePoolStatus_To_v1beta1_MachinePoolStatus(in, out, s) -} - -func autoConvert_v1beta1_MachinePoolStatus_To_v1alpha3_MachinePoolStatus(in *v1beta1.MachinePoolStatus, out *MachinePoolStatus, s conversion.Scope) error { - out.NodeRefs = *(*[]v1.ObjectReference)(unsafe.Pointer(&in.NodeRefs)) - out.Replicas = in.Replicas - out.ReadyReplicas = in.ReadyReplicas - out.AvailableReplicas = in.AvailableReplicas - out.UnavailableReplicas = in.UnavailableReplicas - out.FailureReason = (*errors.MachinePoolStatusFailure)(unsafe.Pointer(in.FailureReason)) - out.FailureMessage = (*string)(unsafe.Pointer(in.FailureMessage)) - out.Phase = in.Phase - out.BootstrapReady = in.BootstrapReady - out.InfrastructureReady = in.InfrastructureReady - out.ObservedGeneration = in.ObservedGeneration - out.Conditions = *(*corev1alpha3.Conditions)(unsafe.Pointer(&in.Conditions)) - return nil -} - -// Convert_v1beta1_MachinePoolStatus_To_v1alpha3_MachinePoolStatus is an autogenerated conversion function. -func Convert_v1beta1_MachinePoolStatus_To_v1alpha3_MachinePoolStatus(in *v1beta1.MachinePoolStatus, out *MachinePoolStatus, s conversion.Scope) error { - return autoConvert_v1beta1_MachinePoolStatus_To_v1alpha3_MachinePoolStatus(in, out, s) -} diff --git a/internal/apis/core/exp/v1alpha3/zz_generated.deepcopy.go b/internal/apis/core/exp/v1alpha3/zz_generated.deepcopy.go deleted file mode 100644 index bbcfc6d76752..000000000000 --- a/internal/apis/core/exp/v1alpha3/zz_generated.deepcopy.go +++ /dev/null @@ -1,165 +0,0 @@ -//go:build !ignore_autogenerated - -/* -Copyright 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. -*/ - -// Code generated by controller-gen. DO NOT EDIT. - -package v1alpha3 - -import ( - "k8s.io/api/core/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - apiv1alpha3 "sigs.k8s.io/cluster-api/internal/apis/core/v1alpha3" - "sigs.k8s.io/cluster-api/errors" -) - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MachinePool) DeepCopyInto(out *MachinePool) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - in.Status.DeepCopyInto(&out.Status) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachinePool. -func (in *MachinePool) DeepCopy() *MachinePool { - if in == nil { - return nil - } - out := new(MachinePool) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *MachinePool) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MachinePoolList) DeepCopyInto(out *MachinePoolList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]MachinePool, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachinePoolList. -func (in *MachinePoolList) DeepCopy() *MachinePoolList { - if in == nil { - return nil - } - out := new(MachinePoolList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *MachinePoolList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MachinePoolSpec) DeepCopyInto(out *MachinePoolSpec) { - *out = *in - if in.Replicas != nil { - in, out := &in.Replicas, &out.Replicas - *out = new(int32) - **out = **in - } - in.Template.DeepCopyInto(&out.Template) - if in.Strategy != nil { - in, out := &in.Strategy, &out.Strategy - *out = new(apiv1alpha3.MachineDeploymentStrategy) - (*in).DeepCopyInto(*out) - } - if in.MinReadySeconds != nil { - in, out := &in.MinReadySeconds, &out.MinReadySeconds - *out = new(int32) - **out = **in - } - if in.ProviderIDList != nil { - in, out := &in.ProviderIDList, &out.ProviderIDList - *out = make([]string, len(*in)) - copy(*out, *in) - } - if in.FailureDomains != nil { - in, out := &in.FailureDomains, &out.FailureDomains - *out = make([]string, len(*in)) - copy(*out, *in) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachinePoolSpec. -func (in *MachinePoolSpec) DeepCopy() *MachinePoolSpec { - if in == nil { - return nil - } - out := new(MachinePoolSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MachinePoolStatus) DeepCopyInto(out *MachinePoolStatus) { - *out = *in - if in.NodeRefs != nil { - in, out := &in.NodeRefs, &out.NodeRefs - *out = make([]v1.ObjectReference, len(*in)) - copy(*out, *in) - } - if in.FailureReason != nil { - in, out := &in.FailureReason, &out.FailureReason - *out = new(errors.MachinePoolStatusFailure) - **out = **in - } - if in.FailureMessage != nil { - in, out := &in.FailureMessage, &out.FailureMessage - *out = new(string) - **out = **in - } - if in.Conditions != nil { - in, out := &in.Conditions, &out.Conditions - *out = make(apiv1alpha3.Conditions, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachinePoolStatus. -func (in *MachinePoolStatus) DeepCopy() *MachinePoolStatus { - if in == nil { - return nil - } - out := new(MachinePoolStatus) - in.DeepCopyInto(out) - return out -} diff --git a/internal/apis/core/exp/v1alpha4/condition_consts.go b/internal/apis/core/exp/v1alpha4/condition_consts.go index 05bb01055c7c..b0efd4cde559 100644 --- a/internal/apis/core/exp/v1alpha4/condition_consts.go +++ b/internal/apis/core/exp/v1alpha4/condition_consts.go @@ -15,16 +15,3 @@ limitations under the License. */ package v1alpha4 - -import clusterv1alpha4 "sigs.k8s.io/cluster-api/internal/apis/core/v1alpha4" - -// Conditions and condition Reasons for the MachinePool object. - -const ( - // ReplicasReadyCondition reports an aggregate of current status of the replicas controlled by the MachinePool. - ReplicasReadyCondition clusterv1alpha4.ConditionType = "ReplicasReady" - - // WaitingForReplicasReadyReason (Severity=Info) documents a machinepool waiting for the required replicas - // to be ready. - WaitingForReplicasReadyReason = "WaitingForReplicasReady" -) diff --git a/internal/apis/core/exp/v1alpha4/conversion.go b/internal/apis/core/exp/v1alpha4/conversion.go index 70d9bde60f00..88aee944268f 100644 --- a/internal/apis/core/exp/v1alpha4/conversion.go +++ b/internal/apis/core/exp/v1alpha4/conversion.go @@ -15,59 +15,3 @@ limitations under the License. */ package v1alpha4 - -import ( - apimachineryconversion "k8s.io/apimachinery/pkg/conversion" - "sigs.k8s.io/controller-runtime/pkg/conversion" - - clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" - clusterv1alpha4 "sigs.k8s.io/cluster-api/internal/apis/core/v1alpha4" - utilconversion "sigs.k8s.io/cluster-api/util/conversion" -) - -func (src *MachinePool) ConvertTo(dstRaw conversion.Hub) error { - dst := dstRaw.(*expv1.MachinePool) - - if err := Convert_v1alpha4_MachinePool_To_v1beta1_MachinePool(src, dst, nil); err != nil { - return err - } - - // Manually restore data. - restored := &expv1.MachinePool{} - if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok { - return err - } - dst.Spec.Template.Spec.NodeDeletionTimeout = restored.Spec.Template.Spec.NodeDeletionTimeout - dst.Spec.Template.Spec.NodeVolumeDetachTimeout = restored.Spec.Template.Spec.NodeVolumeDetachTimeout - return nil -} - -func (dst *MachinePool) ConvertFrom(srcRaw conversion.Hub) error { - src := srcRaw.(*expv1.MachinePool) - - if err := Convert_v1beta1_MachinePool_To_v1alpha4_MachinePool(src, dst, nil); err != nil { - return err - } - return utilconversion.MarshalData(src, dst) -} - -func (src *MachinePoolList) ConvertTo(dstRaw conversion.Hub) error { - dst := dstRaw.(*expv1.MachinePoolList) - - return Convert_v1alpha4_MachinePoolList_To_v1beta1_MachinePoolList(src, dst, nil) -} - -func (dst *MachinePoolList) ConvertFrom(srcRaw conversion.Hub) error { - src := srcRaw.(*expv1.MachinePoolList) - - return Convert_v1beta1_MachinePoolList_To_v1alpha4_MachinePoolList(src, dst, nil) -} - -func Convert_v1alpha4_MachineTemplateSpec_To_v1beta1_MachineTemplateSpec(in *clusterv1alpha4.MachineTemplateSpec, out *clusterv1.MachineTemplateSpec, s apimachineryconversion.Scope) error { - return clusterv1alpha4.Convert_v1alpha4_MachineTemplateSpec_To_v1beta1_MachineTemplateSpec(in, out, s) -} - -func Convert_v1beta1_MachineTemplateSpec_To_v1alpha4_MachineTemplateSpec(in *clusterv1.MachineTemplateSpec, out *clusterv1alpha4.MachineTemplateSpec, s apimachineryconversion.Scope) error { - return clusterv1alpha4.Convert_v1beta1_MachineTemplateSpec_To_v1alpha4_MachineTemplateSpec(in, out, s) -} diff --git a/internal/apis/core/exp/v1alpha4/conversion_test.go b/internal/apis/core/exp/v1alpha4/conversion_test.go index bfba3b1fb598..f2e96d178b24 100644 --- a/internal/apis/core/exp/v1alpha4/conversion_test.go +++ b/internal/apis/core/exp/v1alpha4/conversion_test.go @@ -18,17 +18,7 @@ package v1alpha4 import ( "testing" - - "k8s.io/apimachinery/pkg/api/apitesting/fuzzer" - - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" - utilconversion "sigs.k8s.io/cluster-api/util/conversion" ) func TestFuzzyConversion(t *testing.T) { - t.Run("for MachinePool", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ - Hub: &expv1.MachinePool{}, - Spoke: &MachinePool{}, - FuzzerFuncs: []fuzzer.FuzzerFuncs{}, - })) } diff --git a/internal/apis/core/exp/v1alpha4/zz_generated.conversion.go b/internal/apis/core/exp/v1alpha4/zz_generated.conversion.go index 2d0dff177b01..bd205f8b45a4 100644 --- a/internal/apis/core/exp/v1alpha4/zz_generated.conversion.go +++ b/internal/apis/core/exp/v1alpha4/zz_generated.conversion.go @@ -22,15 +22,7 @@ limitations under the License. package v1alpha4 import ( - unsafe "unsafe" - - v1 "k8s.io/api/core/v1" - conversion "k8s.io/apimachinery/pkg/conversion" runtime "k8s.io/apimachinery/pkg/runtime" - apiv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1" - errors "sigs.k8s.io/cluster-api/errors" - v1beta1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" - corev1alpha4 "sigs.k8s.io/cluster-api/internal/apis/core/v1alpha4" ) func init() { @@ -40,205 +32,5 @@ func init() { // RegisterConversions adds conversion functions to the given scheme. // Public to allow building arbitrary schemes. func RegisterConversions(s *runtime.Scheme) error { - if err := s.AddGeneratedConversionFunc((*MachinePool)(nil), (*v1beta1.MachinePool)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha4_MachinePool_To_v1beta1_MachinePool(a.(*MachinePool), b.(*v1beta1.MachinePool), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*v1beta1.MachinePool)(nil), (*MachinePool)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta1_MachinePool_To_v1alpha4_MachinePool(a.(*v1beta1.MachinePool), b.(*MachinePool), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*MachinePoolList)(nil), (*v1beta1.MachinePoolList)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha4_MachinePoolList_To_v1beta1_MachinePoolList(a.(*MachinePoolList), b.(*v1beta1.MachinePoolList), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*v1beta1.MachinePoolList)(nil), (*MachinePoolList)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta1_MachinePoolList_To_v1alpha4_MachinePoolList(a.(*v1beta1.MachinePoolList), b.(*MachinePoolList), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*MachinePoolSpec)(nil), (*v1beta1.MachinePoolSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha4_MachinePoolSpec_To_v1beta1_MachinePoolSpec(a.(*MachinePoolSpec), b.(*v1beta1.MachinePoolSpec), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*v1beta1.MachinePoolSpec)(nil), (*MachinePoolSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta1_MachinePoolSpec_To_v1alpha4_MachinePoolSpec(a.(*v1beta1.MachinePoolSpec), b.(*MachinePoolSpec), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*MachinePoolStatus)(nil), (*v1beta1.MachinePoolStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha4_MachinePoolStatus_To_v1beta1_MachinePoolStatus(a.(*MachinePoolStatus), b.(*v1beta1.MachinePoolStatus), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*v1beta1.MachinePoolStatus)(nil), (*MachinePoolStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta1_MachinePoolStatus_To_v1alpha4_MachinePoolStatus(a.(*v1beta1.MachinePoolStatus), b.(*MachinePoolStatus), scope) - }); err != nil { - return err - } - if err := s.AddConversionFunc((*corev1alpha4.MachineTemplateSpec)(nil), (*apiv1beta1.MachineTemplateSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha4_MachineTemplateSpec_To_v1beta1_MachineTemplateSpec(a.(*corev1alpha4.MachineTemplateSpec), b.(*apiv1beta1.MachineTemplateSpec), scope) - }); err != nil { - return err - } - if err := s.AddConversionFunc((*apiv1beta1.MachineTemplateSpec)(nil), (*corev1alpha4.MachineTemplateSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta1_MachineTemplateSpec_To_v1alpha4_MachineTemplateSpec(a.(*apiv1beta1.MachineTemplateSpec), b.(*corev1alpha4.MachineTemplateSpec), scope) - }); err != nil { - return err - } - return nil -} - -func autoConvert_v1alpha4_MachinePool_To_v1beta1_MachinePool(in *MachinePool, out *v1beta1.MachinePool, s conversion.Scope) error { - out.ObjectMeta = in.ObjectMeta - if err := Convert_v1alpha4_MachinePoolSpec_To_v1beta1_MachinePoolSpec(&in.Spec, &out.Spec, s); err != nil { - return err - } - if err := Convert_v1alpha4_MachinePoolStatus_To_v1beta1_MachinePoolStatus(&in.Status, &out.Status, s); err != nil { - return err - } return nil } - -// Convert_v1alpha4_MachinePool_To_v1beta1_MachinePool is an autogenerated conversion function. -func Convert_v1alpha4_MachinePool_To_v1beta1_MachinePool(in *MachinePool, out *v1beta1.MachinePool, s conversion.Scope) error { - return autoConvert_v1alpha4_MachinePool_To_v1beta1_MachinePool(in, out, s) -} - -func autoConvert_v1beta1_MachinePool_To_v1alpha4_MachinePool(in *v1beta1.MachinePool, out *MachinePool, s conversion.Scope) error { - out.ObjectMeta = in.ObjectMeta - if err := Convert_v1beta1_MachinePoolSpec_To_v1alpha4_MachinePoolSpec(&in.Spec, &out.Spec, s); err != nil { - return err - } - if err := Convert_v1beta1_MachinePoolStatus_To_v1alpha4_MachinePoolStatus(&in.Status, &out.Status, s); err != nil { - return err - } - return nil -} - -// Convert_v1beta1_MachinePool_To_v1alpha4_MachinePool is an autogenerated conversion function. -func Convert_v1beta1_MachinePool_To_v1alpha4_MachinePool(in *v1beta1.MachinePool, out *MachinePool, s conversion.Scope) error { - return autoConvert_v1beta1_MachinePool_To_v1alpha4_MachinePool(in, out, s) -} - -func autoConvert_v1alpha4_MachinePoolList_To_v1beta1_MachinePoolList(in *MachinePoolList, out *v1beta1.MachinePoolList, s conversion.Scope) error { - out.ListMeta = in.ListMeta - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]v1beta1.MachinePool, len(*in)) - for i := range *in { - if err := Convert_v1alpha4_MachinePool_To_v1beta1_MachinePool(&(*in)[i], &(*out)[i], s); err != nil { - return err - } - } - } else { - out.Items = nil - } - return nil -} - -// Convert_v1alpha4_MachinePoolList_To_v1beta1_MachinePoolList is an autogenerated conversion function. -func Convert_v1alpha4_MachinePoolList_To_v1beta1_MachinePoolList(in *MachinePoolList, out *v1beta1.MachinePoolList, s conversion.Scope) error { - return autoConvert_v1alpha4_MachinePoolList_To_v1beta1_MachinePoolList(in, out, s) -} - -func autoConvert_v1beta1_MachinePoolList_To_v1alpha4_MachinePoolList(in *v1beta1.MachinePoolList, out *MachinePoolList, s conversion.Scope) error { - out.ListMeta = in.ListMeta - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]MachinePool, len(*in)) - for i := range *in { - if err := Convert_v1beta1_MachinePool_To_v1alpha4_MachinePool(&(*in)[i], &(*out)[i], s); err != nil { - return err - } - } - } else { - out.Items = nil - } - return nil -} - -// Convert_v1beta1_MachinePoolList_To_v1alpha4_MachinePoolList is an autogenerated conversion function. -func Convert_v1beta1_MachinePoolList_To_v1alpha4_MachinePoolList(in *v1beta1.MachinePoolList, out *MachinePoolList, s conversion.Scope) error { - return autoConvert_v1beta1_MachinePoolList_To_v1alpha4_MachinePoolList(in, out, s) -} - -func autoConvert_v1alpha4_MachinePoolSpec_To_v1beta1_MachinePoolSpec(in *MachinePoolSpec, out *v1beta1.MachinePoolSpec, s conversion.Scope) error { - out.ClusterName = in.ClusterName - out.Replicas = (*int32)(unsafe.Pointer(in.Replicas)) - if err := Convert_v1alpha4_MachineTemplateSpec_To_v1beta1_MachineTemplateSpec(&in.Template, &out.Template, s); err != nil { - return err - } - out.MinReadySeconds = (*int32)(unsafe.Pointer(in.MinReadySeconds)) - out.ProviderIDList = *(*[]string)(unsafe.Pointer(&in.ProviderIDList)) - out.FailureDomains = *(*[]string)(unsafe.Pointer(&in.FailureDomains)) - return nil -} - -// Convert_v1alpha4_MachinePoolSpec_To_v1beta1_MachinePoolSpec is an autogenerated conversion function. -func Convert_v1alpha4_MachinePoolSpec_To_v1beta1_MachinePoolSpec(in *MachinePoolSpec, out *v1beta1.MachinePoolSpec, s conversion.Scope) error { - return autoConvert_v1alpha4_MachinePoolSpec_To_v1beta1_MachinePoolSpec(in, out, s) -} - -func autoConvert_v1beta1_MachinePoolSpec_To_v1alpha4_MachinePoolSpec(in *v1beta1.MachinePoolSpec, out *MachinePoolSpec, s conversion.Scope) error { - out.ClusterName = in.ClusterName - out.Replicas = (*int32)(unsafe.Pointer(in.Replicas)) - if err := Convert_v1beta1_MachineTemplateSpec_To_v1alpha4_MachineTemplateSpec(&in.Template, &out.Template, s); err != nil { - return err - } - out.MinReadySeconds = (*int32)(unsafe.Pointer(in.MinReadySeconds)) - out.ProviderIDList = *(*[]string)(unsafe.Pointer(&in.ProviderIDList)) - out.FailureDomains = *(*[]string)(unsafe.Pointer(&in.FailureDomains)) - return nil -} - -// Convert_v1beta1_MachinePoolSpec_To_v1alpha4_MachinePoolSpec is an autogenerated conversion function. -func Convert_v1beta1_MachinePoolSpec_To_v1alpha4_MachinePoolSpec(in *v1beta1.MachinePoolSpec, out *MachinePoolSpec, s conversion.Scope) error { - return autoConvert_v1beta1_MachinePoolSpec_To_v1alpha4_MachinePoolSpec(in, out, s) -} - -func autoConvert_v1alpha4_MachinePoolStatus_To_v1beta1_MachinePoolStatus(in *MachinePoolStatus, out *v1beta1.MachinePoolStatus, s conversion.Scope) error { - out.NodeRefs = *(*[]v1.ObjectReference)(unsafe.Pointer(&in.NodeRefs)) - out.Replicas = in.Replicas - out.ReadyReplicas = in.ReadyReplicas - out.AvailableReplicas = in.AvailableReplicas - out.UnavailableReplicas = in.UnavailableReplicas - out.FailureReason = (*errors.MachinePoolStatusFailure)(unsafe.Pointer(in.FailureReason)) - out.FailureMessage = (*string)(unsafe.Pointer(in.FailureMessage)) - out.Phase = in.Phase - out.BootstrapReady = in.BootstrapReady - out.InfrastructureReady = in.InfrastructureReady - out.ObservedGeneration = in.ObservedGeneration - out.Conditions = *(*apiv1beta1.Conditions)(unsafe.Pointer(&in.Conditions)) - return nil -} - -// Convert_v1alpha4_MachinePoolStatus_To_v1beta1_MachinePoolStatus is an autogenerated conversion function. -func Convert_v1alpha4_MachinePoolStatus_To_v1beta1_MachinePoolStatus(in *MachinePoolStatus, out *v1beta1.MachinePoolStatus, s conversion.Scope) error { - return autoConvert_v1alpha4_MachinePoolStatus_To_v1beta1_MachinePoolStatus(in, out, s) -} - -func autoConvert_v1beta1_MachinePoolStatus_To_v1alpha4_MachinePoolStatus(in *v1beta1.MachinePoolStatus, out *MachinePoolStatus, s conversion.Scope) error { - out.NodeRefs = *(*[]v1.ObjectReference)(unsafe.Pointer(&in.NodeRefs)) - out.Replicas = in.Replicas - out.ReadyReplicas = in.ReadyReplicas - out.AvailableReplicas = in.AvailableReplicas - out.UnavailableReplicas = in.UnavailableReplicas - out.FailureReason = (*errors.MachinePoolStatusFailure)(unsafe.Pointer(in.FailureReason)) - out.FailureMessage = (*string)(unsafe.Pointer(in.FailureMessage)) - out.Phase = in.Phase - out.BootstrapReady = in.BootstrapReady - out.InfrastructureReady = in.InfrastructureReady - out.ObservedGeneration = in.ObservedGeneration - out.Conditions = *(*corev1alpha4.Conditions)(unsafe.Pointer(&in.Conditions)) - return nil -} - -// Convert_v1beta1_MachinePoolStatus_To_v1alpha4_MachinePoolStatus is an autogenerated conversion function. -func Convert_v1beta1_MachinePoolStatus_To_v1alpha4_MachinePoolStatus(in *v1beta1.MachinePoolStatus, out *MachinePoolStatus, s conversion.Scope) error { - return autoConvert_v1beta1_MachinePoolStatus_To_v1alpha4_MachinePoolStatus(in, out, s) -} diff --git a/internal/apis/core/exp/v1alpha4/zz_generated.deepcopy.go b/internal/apis/core/exp/v1alpha4/zz_generated.deepcopy.go deleted file mode 100644 index d45abf813815..000000000000 --- a/internal/apis/core/exp/v1alpha4/zz_generated.deepcopy.go +++ /dev/null @@ -1,160 +0,0 @@ -//go:build !ignore_autogenerated - -/* -Copyright 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. -*/ - -// Code generated by controller-gen. DO NOT EDIT. - -package v1alpha4 - -import ( - "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/runtime" - apiv1alpha4 "sigs.k8s.io/cluster-api/internal/apis/core/v1alpha4" - "sigs.k8s.io/cluster-api/errors" -) - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MachinePool) DeepCopyInto(out *MachinePool) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - in.Status.DeepCopyInto(&out.Status) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachinePool. -func (in *MachinePool) DeepCopy() *MachinePool { - if in == nil { - return nil - } - out := new(MachinePool) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *MachinePool) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MachinePoolList) DeepCopyInto(out *MachinePoolList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]MachinePool, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachinePoolList. -func (in *MachinePoolList) DeepCopy() *MachinePoolList { - if in == nil { - return nil - } - out := new(MachinePoolList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *MachinePoolList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MachinePoolSpec) DeepCopyInto(out *MachinePoolSpec) { - *out = *in - if in.Replicas != nil { - in, out := &in.Replicas, &out.Replicas - *out = new(int32) - **out = **in - } - in.Template.DeepCopyInto(&out.Template) - if in.MinReadySeconds != nil { - in, out := &in.MinReadySeconds, &out.MinReadySeconds - *out = new(int32) - **out = **in - } - if in.ProviderIDList != nil { - in, out := &in.ProviderIDList, &out.ProviderIDList - *out = make([]string, len(*in)) - copy(*out, *in) - } - if in.FailureDomains != nil { - in, out := &in.FailureDomains, &out.FailureDomains - *out = make([]string, len(*in)) - copy(*out, *in) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachinePoolSpec. -func (in *MachinePoolSpec) DeepCopy() *MachinePoolSpec { - if in == nil { - return nil - } - out := new(MachinePoolSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MachinePoolStatus) DeepCopyInto(out *MachinePoolStatus) { - *out = *in - if in.NodeRefs != nil { - in, out := &in.NodeRefs, &out.NodeRefs - *out = make([]v1.ObjectReference, len(*in)) - copy(*out, *in) - } - if in.FailureReason != nil { - in, out := &in.FailureReason, &out.FailureReason - *out = new(errors.MachinePoolStatusFailure) - **out = **in - } - if in.FailureMessage != nil { - in, out := &in.FailureMessage, &out.FailureMessage - *out = new(string) - **out = **in - } - if in.Conditions != nil { - in, out := &in.Conditions, &out.Conditions - *out = make(apiv1alpha4.Conditions, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachinePoolStatus. -func (in *MachinePoolStatus) DeepCopy() *MachinePoolStatus { - if in == nil { - return nil - } - out := new(MachinePoolStatus) - in.DeepCopyInto(out) - return out -} diff --git a/internal/apis/core/v1alpha3/condition_consts.go b/internal/apis/core/v1alpha3/condition_consts.go index 3c0b6195e510..368e739e1ebe 100644 --- a/internal/apis/core/v1alpha3/condition_consts.go +++ b/internal/apis/core/v1alpha3/condition_consts.go @@ -184,3 +184,14 @@ const ( // from making any further remediations. TooManyUnhealthyReason = "TooManyUnhealthy" ) + +// Conditions and condition Reasons for the MachinePool object. + +const ( + // ReplicasReadyCondition reports an aggregate of current status of the replicas controlled by the MachinePool. + ReplicasReadyCondition ConditionType = "ReplicasReady" + + // WaitingForReplicasReadyReason (Severity=Info) documents a machinepool waiting for the required replicas + // to be ready. + WaitingForReplicasReadyReason = "WaitingForReplicasReady" +) diff --git a/internal/apis/core/v1alpha3/conversion.go b/internal/apis/core/v1alpha3/conversion.go index 405cf123f813..3a58d42ffda8 100644 --- a/internal/apis/core/v1alpha3/conversion.go +++ b/internal/apis/core/v1alpha3/conversion.go @@ -18,6 +18,7 @@ package v1alpha3 import ( apiconversion "k8s.io/apimachinery/pkg/conversion" + "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/conversion" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" @@ -341,3 +342,75 @@ func Convert_v1beta1_MachineDeploymentStrategy_To_v1alpha3_MachineDeploymentStra func Convert_v1beta1_MachineSetSpec_To_v1alpha3_MachineSetSpec(in *clusterv1.MachineSetSpec, out *MachineSetSpec, s apiconversion.Scope) error { return autoConvert_v1beta1_MachineSetSpec_To_v1alpha3_MachineSetSpec(in, out, s) } + +// Convert_v1alpha3_MachinePoolSpec_To_v1beta1_MachinePoolSpec is an autogenerated conversion function. +func Convert_v1alpha3_MachinePoolSpec_To_v1beta1_MachinePoolSpec(in *MachinePoolSpec, out *clusterv1.MachinePoolSpec, s apiconversion.Scope) error { + return autoConvert_v1alpha3_MachinePoolSpec_To_v1beta1_MachinePoolSpec(in, out, s) +} + +func Convert_v1alpha3_MachinePool_To_v1beta1_MachinePool(in *MachinePool, out *clusterv1.MachinePool, s apiconversion.Scope) error { + if err := autoConvert_v1alpha3_MachinePool_To_v1beta1_MachinePool(in, out, s); err != nil { + return err + } + + // Replace v1alpha3 finalizer to allow old MachinePools to get deleted. + if controllerutil.ContainsFinalizer(out, MachinePoolFinalizer) { + controllerutil.RemoveFinalizer(out, MachinePoolFinalizer) + controllerutil.AddFinalizer(out, clusterv1.MachinePoolFinalizer) + } + + return nil +} + +func Convert_v1beta1_MachinePool_To_v1alpha3_MachinePool(in *clusterv1.MachinePool, out *MachinePool, s apiconversion.Scope) error { + if err := autoConvert_v1beta1_MachinePool_To_v1alpha3_MachinePool(in, out, s); err != nil { + return err + } + + // Replace v1beta1 finalizer to allow old MachinePools to get deleted. + if controllerutil.ContainsFinalizer(out, clusterv1.MachinePoolFinalizer) { + controllerutil.RemoveFinalizer(out, clusterv1.MachinePoolFinalizer) + controllerutil.AddFinalizer(out, MachinePoolFinalizer) + } + + return nil +} + +func (src *MachinePool) ConvertTo(dstRaw conversion.Hub) error { + dst := dstRaw.(*clusterv1.MachinePool) + + if err := Convert_v1alpha3_MachinePool_To_v1beta1_MachinePool(src, dst, nil); err != nil { + return err + } + + // Manually restore data. + restored := &clusterv1.MachinePool{} + if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok { + return err + } + dst.Spec.Template.Spec.NodeDeletionTimeout = restored.Spec.Template.Spec.NodeDeletionTimeout + dst.Spec.Template.Spec.NodeVolumeDetachTimeout = restored.Spec.Template.Spec.NodeVolumeDetachTimeout + return nil +} + +func (dst *MachinePool) ConvertFrom(srcRaw conversion.Hub) error { + src := srcRaw.(*clusterv1.MachinePool) + + if err := Convert_v1beta1_MachinePool_To_v1alpha3_MachinePool(src, dst, nil); err != nil { + return err + } + + return utilconversion.MarshalData(src, dst) +} + +func (src *MachinePoolList) ConvertTo(dstRaw conversion.Hub) error { + dst := dstRaw.(*clusterv1.MachinePoolList) + + return Convert_v1alpha3_MachinePoolList_To_v1beta1_MachinePoolList(src, dst, nil) +} + +func (dst *MachinePoolList) ConvertFrom(srcRaw conversion.Hub) error { + src := srcRaw.(*clusterv1.MachinePoolList) + + return Convert_v1beta1_MachinePoolList_To_v1alpha3_MachinePoolList(src, dst, nil) +} diff --git a/internal/apis/core/v1alpha3/conversion_test.go b/internal/apis/core/v1alpha3/conversion_test.go index f685a42566dd..e840ffe72e58 100644 --- a/internal/apis/core/v1alpha3/conversion_test.go +++ b/internal/apis/core/v1alpha3/conversion_test.go @@ -55,6 +55,12 @@ func TestFuzzyConversion(t *testing.T) { FuzzerFuncs: []fuzzer.FuzzerFuncs{BootstrapFuzzFuncs, CustomObjectMetaFuzzFunc}, })) + t.Run("for MachinePool", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ + Hub: &clusterv1.MachinePool{}, + Spoke: &MachinePool{}, + FuzzerFuncs: []fuzzer.FuzzerFuncs{BootstrapFuzzFuncs, MachinePoolSpecFuzzFuncs, CustomObjectMetaFuzzFunc}, + })) + t.Run("for MachineHealthCheck", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ Hub: &clusterv1.MachineHealthCheck{}, Spoke: &MachineHealthCheck{}, @@ -139,3 +145,17 @@ func ClusterVariableFuzzer(in *clusterv1.ClusterVariable, c fuzz.Continue) { // Not every random byte array is valid JSON, e.g. a string without `""`,so we're setting a valid value. in.Value = apiextensionsv1.JSON{Raw: []byte("\"test-string\"")} } + +func MachinePoolSpecFuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} { + return []interface{}{ + MachinePoolSpecFuzzer, + } +} + +func MachinePoolSpecFuzzer(in *MachinePoolSpec, c fuzz.Continue) { + c.Fuzz(in) + + // These fields have been removed in v1beta1 + // data is going to be lost, so we're forcing zero values here. + in.Strategy = nil +} diff --git a/internal/apis/core/exp/v1alpha3/machinepool_types.go b/internal/apis/core/v1alpha3/machinepool_types.go similarity index 95% rename from internal/apis/core/exp/v1alpha3/machinepool_types.go rename to internal/apis/core/v1alpha3/machinepool_types.go index 42ad1ac8952d..435b4901d186 100644 --- a/internal/apis/core/exp/v1alpha3/machinepool_types.go +++ b/internal/apis/core/v1alpha3/machinepool_types.go @@ -21,7 +21,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" capierrors "sigs.k8s.io/cluster-api/errors" - clusterv1alpha3 "sigs.k8s.io/cluster-api/internal/apis/core/v1alpha3" ) const ( @@ -42,12 +41,12 @@ type MachinePoolSpec struct { Replicas *int32 `json:"replicas,omitempty"` // Template describes the machines that will be created. - Template clusterv1alpha3.MachineTemplateSpec `json:"template"` + Template MachineTemplateSpec `json:"template"` // The deployment strategy to use to replace existing machine instances with // new ones. // +optional - Strategy *clusterv1alpha3.MachineDeploymentStrategy `json:"strategy,omitempty"` + Strategy *MachineDeploymentStrategy `json:"strategy,omitempty"` // Minimum number of seconds for which a newly created machine instances should // be ready. @@ -124,7 +123,7 @@ type MachinePoolStatus struct { // Conditions define the current service state of the MachinePool. // +optional - Conditions clusterv1alpha3.Conditions `json:"conditions,omitempty"` + Conditions Conditions `json:"conditions,omitempty"` } // ANCHOR_END: MachinePoolStatus @@ -226,12 +225,12 @@ type MachinePool struct { } // GetConditions returns the set of conditions for this object. -func (m *MachinePool) GetConditions() clusterv1alpha3.Conditions { +func (m *MachinePool) GetConditions() Conditions { return m.Status.Conditions } // SetConditions sets the conditions on this object. -func (m *MachinePool) SetConditions(conditions clusterv1alpha3.Conditions) { +func (m *MachinePool) SetConditions(conditions Conditions) { m.Status.Conditions = conditions } diff --git a/internal/apis/core/v1alpha3/zz_generated.conversion.go b/internal/apis/core/v1alpha3/zz_generated.conversion.go index 1d8c7451e31c..13a1940f9b6e 100644 --- a/internal/apis/core/v1alpha3/zz_generated.conversion.go +++ b/internal/apis/core/v1alpha3/zz_generated.conversion.go @@ -215,6 +215,31 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddGeneratedConversionFunc((*MachinePoolList)(nil), (*v1beta1.MachinePoolList)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha3_MachinePoolList_To_v1beta1_MachinePoolList(a.(*MachinePoolList), b.(*v1beta1.MachinePoolList), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*v1beta1.MachinePoolList)(nil), (*MachinePoolList)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_MachinePoolList_To_v1alpha3_MachinePoolList(a.(*v1beta1.MachinePoolList), b.(*MachinePoolList), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*v1beta1.MachinePoolSpec)(nil), (*MachinePoolSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_MachinePoolSpec_To_v1alpha3_MachinePoolSpec(a.(*v1beta1.MachinePoolSpec), b.(*MachinePoolSpec), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*MachinePoolStatus)(nil), (*v1beta1.MachinePoolStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha3_MachinePoolStatus_To_v1beta1_MachinePoolStatus(a.(*MachinePoolStatus), b.(*v1beta1.MachinePoolStatus), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*v1beta1.MachinePoolStatus)(nil), (*MachinePoolStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_MachinePoolStatus_To_v1alpha3_MachinePoolStatus(a.(*v1beta1.MachinePoolStatus), b.(*MachinePoolStatus), scope) + }); err != nil { + return err + } if err := s.AddGeneratedConversionFunc((*MachineRollingUpdateDeployment)(nil), (*v1beta1.MachineRollingUpdateDeployment)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha3_MachineRollingUpdateDeployment_To_v1beta1_MachineRollingUpdateDeployment(a.(*MachineRollingUpdateDeployment), b.(*v1beta1.MachineRollingUpdateDeployment), scope) }); err != nil { @@ -300,6 +325,16 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*MachinePoolSpec)(nil), (*v1beta1.MachinePoolSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha3_MachinePoolSpec_To_v1beta1_MachinePoolSpec(a.(*MachinePoolSpec), b.(*v1beta1.MachinePoolSpec), scope) + }); err != nil { + return err + } + if err := s.AddConversionFunc((*MachinePool)(nil), (*v1beta1.MachinePool)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha3_MachinePool_To_v1beta1_MachinePool(a.(*MachinePool), b.(*v1beta1.MachinePool), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*MachineStatus)(nil), (*v1beta1.MachineStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha3_MachineStatus_To_v1beta1_MachineStatus(a.(*MachineStatus), b.(*v1beta1.MachineStatus), scope) }); err != nil { @@ -335,6 +370,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*v1beta1.MachinePool)(nil), (*MachinePool)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_MachinePool_To_v1alpha3_MachinePool(a.(*v1beta1.MachinePool), b.(*MachinePool), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*v1beta1.MachineRollingUpdateDeployment)(nil), (*MachineRollingUpdateDeployment)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1beta1_MachineRollingUpdateDeployment_To_v1alpha3_MachineRollingUpdateDeployment(a.(*v1beta1.MachineRollingUpdateDeployment), b.(*MachineRollingUpdateDeployment), scope) }); err != nil { @@ -1029,6 +1069,142 @@ func Convert_v1beta1_MachineList_To_v1alpha3_MachineList(in *v1beta1.MachineList return autoConvert_v1beta1_MachineList_To_v1alpha3_MachineList(in, out, s) } +func autoConvert_v1alpha3_MachinePool_To_v1beta1_MachinePool(in *MachinePool, out *v1beta1.MachinePool, s conversion.Scope) error { + out.ObjectMeta = in.ObjectMeta + if err := Convert_v1alpha3_MachinePoolSpec_To_v1beta1_MachinePoolSpec(&in.Spec, &out.Spec, s); err != nil { + return err + } + if err := Convert_v1alpha3_MachinePoolStatus_To_v1beta1_MachinePoolStatus(&in.Status, &out.Status, s); err != nil { + return err + } + return nil +} + +func autoConvert_v1beta1_MachinePool_To_v1alpha3_MachinePool(in *v1beta1.MachinePool, out *MachinePool, s conversion.Scope) error { + out.ObjectMeta = in.ObjectMeta + if err := Convert_v1beta1_MachinePoolSpec_To_v1alpha3_MachinePoolSpec(&in.Spec, &out.Spec, s); err != nil { + return err + } + if err := Convert_v1beta1_MachinePoolStatus_To_v1alpha3_MachinePoolStatus(&in.Status, &out.Status, s); err != nil { + return err + } + return nil +} + +func autoConvert_v1alpha3_MachinePoolList_To_v1beta1_MachinePoolList(in *MachinePoolList, out *v1beta1.MachinePoolList, s conversion.Scope) error { + out.ListMeta = in.ListMeta + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]v1beta1.MachinePool, len(*in)) + for i := range *in { + if err := Convert_v1alpha3_MachinePool_To_v1beta1_MachinePool(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } + return nil +} + +// Convert_v1alpha3_MachinePoolList_To_v1beta1_MachinePoolList is an autogenerated conversion function. +func Convert_v1alpha3_MachinePoolList_To_v1beta1_MachinePoolList(in *MachinePoolList, out *v1beta1.MachinePoolList, s conversion.Scope) error { + return autoConvert_v1alpha3_MachinePoolList_To_v1beta1_MachinePoolList(in, out, s) +} + +func autoConvert_v1beta1_MachinePoolList_To_v1alpha3_MachinePoolList(in *v1beta1.MachinePoolList, out *MachinePoolList, s conversion.Scope) error { + out.ListMeta = in.ListMeta + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]MachinePool, len(*in)) + for i := range *in { + if err := Convert_v1beta1_MachinePool_To_v1alpha3_MachinePool(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } + return nil +} + +// Convert_v1beta1_MachinePoolList_To_v1alpha3_MachinePoolList is an autogenerated conversion function. +func Convert_v1beta1_MachinePoolList_To_v1alpha3_MachinePoolList(in *v1beta1.MachinePoolList, out *MachinePoolList, s conversion.Scope) error { + return autoConvert_v1beta1_MachinePoolList_To_v1alpha3_MachinePoolList(in, out, s) +} + +func autoConvert_v1alpha3_MachinePoolSpec_To_v1beta1_MachinePoolSpec(in *MachinePoolSpec, out *v1beta1.MachinePoolSpec, s conversion.Scope) error { + out.ClusterName = in.ClusterName + out.Replicas = (*int32)(unsafe.Pointer(in.Replicas)) + if err := Convert_v1alpha3_MachineTemplateSpec_To_v1beta1_MachineTemplateSpec(&in.Template, &out.Template, s); err != nil { + return err + } + // WARNING: in.Strategy requires manual conversion: does not exist in peer-type + out.MinReadySeconds = (*int32)(unsafe.Pointer(in.MinReadySeconds)) + out.ProviderIDList = *(*[]string)(unsafe.Pointer(&in.ProviderIDList)) + out.FailureDomains = *(*[]string)(unsafe.Pointer(&in.FailureDomains)) + return nil +} + +func autoConvert_v1beta1_MachinePoolSpec_To_v1alpha3_MachinePoolSpec(in *v1beta1.MachinePoolSpec, out *MachinePoolSpec, s conversion.Scope) error { + out.ClusterName = in.ClusterName + out.Replicas = (*int32)(unsafe.Pointer(in.Replicas)) + if err := Convert_v1beta1_MachineTemplateSpec_To_v1alpha3_MachineTemplateSpec(&in.Template, &out.Template, s); err != nil { + return err + } + out.MinReadySeconds = (*int32)(unsafe.Pointer(in.MinReadySeconds)) + out.ProviderIDList = *(*[]string)(unsafe.Pointer(&in.ProviderIDList)) + out.FailureDomains = *(*[]string)(unsafe.Pointer(&in.FailureDomains)) + return nil +} + +// Convert_v1beta1_MachinePoolSpec_To_v1alpha3_MachinePoolSpec is an autogenerated conversion function. +func Convert_v1beta1_MachinePoolSpec_To_v1alpha3_MachinePoolSpec(in *v1beta1.MachinePoolSpec, out *MachinePoolSpec, s conversion.Scope) error { + return autoConvert_v1beta1_MachinePoolSpec_To_v1alpha3_MachinePoolSpec(in, out, s) +} + +func autoConvert_v1alpha3_MachinePoolStatus_To_v1beta1_MachinePoolStatus(in *MachinePoolStatus, out *v1beta1.MachinePoolStatus, s conversion.Scope) error { + out.NodeRefs = *(*[]v1.ObjectReference)(unsafe.Pointer(&in.NodeRefs)) + out.Replicas = in.Replicas + out.ReadyReplicas = in.ReadyReplicas + out.AvailableReplicas = in.AvailableReplicas + out.UnavailableReplicas = in.UnavailableReplicas + out.FailureReason = (*errors.MachinePoolStatusFailure)(unsafe.Pointer(in.FailureReason)) + out.FailureMessage = (*string)(unsafe.Pointer(in.FailureMessage)) + out.Phase = in.Phase + out.BootstrapReady = in.BootstrapReady + out.InfrastructureReady = in.InfrastructureReady + out.ObservedGeneration = in.ObservedGeneration + out.Conditions = *(*v1beta1.Conditions)(unsafe.Pointer(&in.Conditions)) + return nil +} + +// Convert_v1alpha3_MachinePoolStatus_To_v1beta1_MachinePoolStatus is an autogenerated conversion function. +func Convert_v1alpha3_MachinePoolStatus_To_v1beta1_MachinePoolStatus(in *MachinePoolStatus, out *v1beta1.MachinePoolStatus, s conversion.Scope) error { + return autoConvert_v1alpha3_MachinePoolStatus_To_v1beta1_MachinePoolStatus(in, out, s) +} + +func autoConvert_v1beta1_MachinePoolStatus_To_v1alpha3_MachinePoolStatus(in *v1beta1.MachinePoolStatus, out *MachinePoolStatus, s conversion.Scope) error { + out.NodeRefs = *(*[]v1.ObjectReference)(unsafe.Pointer(&in.NodeRefs)) + out.Replicas = in.Replicas + out.ReadyReplicas = in.ReadyReplicas + out.AvailableReplicas = in.AvailableReplicas + out.UnavailableReplicas = in.UnavailableReplicas + out.FailureReason = (*errors.MachinePoolStatusFailure)(unsafe.Pointer(in.FailureReason)) + out.FailureMessage = (*string)(unsafe.Pointer(in.FailureMessage)) + out.Phase = in.Phase + out.BootstrapReady = in.BootstrapReady + out.InfrastructureReady = in.InfrastructureReady + out.ObservedGeneration = in.ObservedGeneration + out.Conditions = *(*Conditions)(unsafe.Pointer(&in.Conditions)) + return nil +} + +// Convert_v1beta1_MachinePoolStatus_To_v1alpha3_MachinePoolStatus is an autogenerated conversion function. +func Convert_v1beta1_MachinePoolStatus_To_v1alpha3_MachinePoolStatus(in *v1beta1.MachinePoolStatus, out *MachinePoolStatus, s conversion.Scope) error { + return autoConvert_v1beta1_MachinePoolStatus_To_v1alpha3_MachinePoolStatus(in, out, s) +} + func autoConvert_v1alpha3_MachineRollingUpdateDeployment_To_v1beta1_MachineRollingUpdateDeployment(in *MachineRollingUpdateDeployment, out *v1beta1.MachineRollingUpdateDeployment, s conversion.Scope) error { out.MaxUnavailable = (*intstr.IntOrString)(unsafe.Pointer(in.MaxUnavailable)) out.MaxSurge = (*intstr.IntOrString)(unsafe.Pointer(in.MaxSurge)) diff --git a/internal/apis/core/v1alpha3/zz_generated.deepcopy.go b/internal/apis/core/v1alpha3/zz_generated.deepcopy.go index cd302706b1d0..ac0ffaa9f4c5 100644 --- a/internal/apis/core/v1alpha3/zz_generated.deepcopy.go +++ b/internal/apis/core/v1alpha3/zz_generated.deepcopy.go @@ -23,7 +23,7 @@ package v1alpha3 import ( "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" + runtime "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/intstr" "sigs.k8s.io/cluster-api/errors" ) @@ -663,6 +663,143 @@ func (in *MachineList) DeepCopyObject() runtime.Object { return nil } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MachinePool) DeepCopyInto(out *MachinePool) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachinePool. +func (in *MachinePool) DeepCopy() *MachinePool { + if in == nil { + return nil + } + out := new(MachinePool) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *MachinePool) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MachinePoolList) DeepCopyInto(out *MachinePoolList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]MachinePool, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachinePoolList. +func (in *MachinePoolList) DeepCopy() *MachinePoolList { + if in == nil { + return nil + } + out := new(MachinePoolList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *MachinePoolList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MachinePoolSpec) DeepCopyInto(out *MachinePoolSpec) { + *out = *in + if in.Replicas != nil { + in, out := &in.Replicas, &out.Replicas + *out = new(int32) + **out = **in + } + in.Template.DeepCopyInto(&out.Template) + if in.Strategy != nil { + in, out := &in.Strategy, &out.Strategy + *out = new(MachineDeploymentStrategy) + (*in).DeepCopyInto(*out) + } + if in.MinReadySeconds != nil { + in, out := &in.MinReadySeconds, &out.MinReadySeconds + *out = new(int32) + **out = **in + } + if in.ProviderIDList != nil { + in, out := &in.ProviderIDList, &out.ProviderIDList + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.FailureDomains != nil { + in, out := &in.FailureDomains, &out.FailureDomains + *out = make([]string, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachinePoolSpec. +func (in *MachinePoolSpec) DeepCopy() *MachinePoolSpec { + if in == nil { + return nil + } + out := new(MachinePoolSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MachinePoolStatus) DeepCopyInto(out *MachinePoolStatus) { + *out = *in + if in.NodeRefs != nil { + in, out := &in.NodeRefs, &out.NodeRefs + *out = make([]v1.ObjectReference, len(*in)) + copy(*out, *in) + } + if in.FailureReason != nil { + in, out := &in.FailureReason, &out.FailureReason + *out = new(errors.MachinePoolStatusFailure) + **out = **in + } + if in.FailureMessage != nil { + in, out := &in.FailureMessage, &out.FailureMessage + *out = new(string) + **out = **in + } + if in.Conditions != nil { + in, out := &in.Conditions, &out.Conditions + *out = make(Conditions, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachinePoolStatus. +func (in *MachinePoolStatus) DeepCopy() *MachinePoolStatus { + if in == nil { + return nil + } + out := new(MachinePoolStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *MachineRollingUpdateDeployment) DeepCopyInto(out *MachineRollingUpdateDeployment) { *out = *in diff --git a/internal/apis/core/v1alpha4/condition_consts.go b/internal/apis/core/v1alpha4/condition_consts.go index d3c84b66d035..3da9a3b52f4e 100644 --- a/internal/apis/core/v1alpha4/condition_consts.go +++ b/internal/apis/core/v1alpha4/condition_consts.go @@ -251,3 +251,14 @@ const ( // ScalingDownReason (Severity=Info) documents a MachineSet is decreasing the number of replicas. ScalingDownReason = "ScalingDown" ) + +// Conditions and condition Reasons for the MachinePool object. + +const ( + // ReplicasReadyCondition reports an aggregate of current status of the replicas controlled by the MachinePool. + ReplicasReadyCondition ConditionType = "ReplicasReady" + + // WaitingForReplicasReadyReason (Severity=Info) documents a machinepool waiting for the required replicas + // to be ready. + WaitingForReplicasReadyReason = "WaitingForReplicasReady" +) diff --git a/internal/apis/core/v1alpha4/conversion.go b/internal/apis/core/v1alpha4/conversion.go index ba4469e52445..2ab6c311f707 100644 --- a/internal/apis/core/v1alpha4/conversion.go +++ b/internal/apis/core/v1alpha4/conversion.go @@ -334,6 +334,44 @@ func (dst *MachineHealthCheckList) ConvertFrom(srcRaw conversion.Hub) error { return Convert_v1beta1_MachineHealthCheckList_To_v1alpha4_MachineHealthCheckList(src, dst, nil) } +func (src *MachinePool) ConvertTo(dstRaw conversion.Hub) error { + dst := dstRaw.(*clusterv1.MachinePool) + + if err := Convert_v1alpha4_MachinePool_To_v1beta1_MachinePool(src, dst, nil); err != nil { + return err + } + + // Manually restore data. + restored := &clusterv1.MachinePool{} + if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok { + return err + } + dst.Spec.Template.Spec.NodeDeletionTimeout = restored.Spec.Template.Spec.NodeDeletionTimeout + dst.Spec.Template.Spec.NodeVolumeDetachTimeout = restored.Spec.Template.Spec.NodeVolumeDetachTimeout + return nil +} + +func (dst *MachinePool) ConvertFrom(srcRaw conversion.Hub) error { + src := srcRaw.(*clusterv1.MachinePool) + + if err := Convert_v1beta1_MachinePool_To_v1alpha4_MachinePool(src, dst, nil); err != nil { + return err + } + return utilconversion.MarshalData(src, dst) +} + +func (src *MachinePoolList) ConvertTo(dstRaw conversion.Hub) error { + dst := dstRaw.(*clusterv1.MachinePoolList) + + return Convert_v1alpha4_MachinePoolList_To_v1beta1_MachinePoolList(src, dst, nil) +} + +func (dst *MachinePoolList) ConvertFrom(srcRaw conversion.Hub) error { + src := srcRaw.(*clusterv1.MachinePoolList) + + return Convert_v1beta1_MachinePoolList_To_v1alpha4_MachinePoolList(src, dst, nil) +} + func Convert_v1alpha4_MachineStatus_To_v1beta1_MachineStatus(in *MachineStatus, out *clusterv1.MachineStatus, s apiconversion.Scope) error { // Status.version has been removed in v1beta1, thus requiring custom conversion function. the information will be dropped. return autoConvert_v1alpha4_MachineStatus_To_v1beta1_MachineStatus(in, out, s) @@ -406,3 +444,11 @@ func Convert_v1beta1_MachineDeploymentStrategy_To_v1alpha4_MachineDeploymentStra func Convert_v1beta1_MachineSetSpec_To_v1alpha4_MachineSetSpec(in *clusterv1.MachineSetSpec, out *MachineSetSpec, s apiconversion.Scope) error { return autoConvert_v1beta1_MachineSetSpec_To_v1alpha4_MachineSetSpec(in, out, s) } + +func Convert_v1alpha4_MachineTemplateSpec_To_v1beta1_MachineTemplateSpec(in *MachineTemplateSpec, out *clusterv1.MachineTemplateSpec, s apiconversion.Scope) error { + return autoConvert_v1alpha4_MachineTemplateSpec_To_v1beta1_MachineTemplateSpec(in, out, s) +} + +func Convert_v1beta1_MachineTemplateSpec_To_v1alpha4_MachineTemplateSpec(in *clusterv1.MachineTemplateSpec, out *MachineTemplateSpec, s apiconversion.Scope) error { + return autoConvert_v1beta1_MachineTemplateSpec_To_v1alpha4_MachineTemplateSpec(in, out, s) +} diff --git a/internal/apis/core/v1alpha4/conversion_test.go b/internal/apis/core/v1alpha4/conversion_test.go index ce34632007d9..add955159b50 100644 --- a/internal/apis/core/v1alpha4/conversion_test.go +++ b/internal/apis/core/v1alpha4/conversion_test.go @@ -62,6 +62,12 @@ func TestFuzzyConversion(t *testing.T) { Hub: &clusterv1.MachineHealthCheck{}, Spoke: &MachineHealthCheck{}, })) + + t.Run("for MachinePool", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ + Hub: &clusterv1.MachinePool{}, + Spoke: &MachinePool{}, + FuzzerFuncs: []fuzzer.FuzzerFuncs{}, + })) } func MachineStatusFuzzFunc(_ runtimeserializer.CodecFactory) []interface{} { diff --git a/internal/apis/core/exp/v1alpha4/machinepool_types.go b/internal/apis/core/v1alpha4/machinepool_types.go similarity index 96% rename from internal/apis/core/exp/v1alpha4/machinepool_types.go rename to internal/apis/core/v1alpha4/machinepool_types.go index 06f6d5876fc2..abbd03cd18b7 100644 --- a/internal/apis/core/exp/v1alpha4/machinepool_types.go +++ b/internal/apis/core/v1alpha4/machinepool_types.go @@ -21,7 +21,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" capierrors "sigs.k8s.io/cluster-api/errors" - clusterv1alpha4 "sigs.k8s.io/cluster-api/internal/apis/core/v1alpha4" ) const ( @@ -42,7 +41,7 @@ type MachinePoolSpec struct { Replicas *int32 `json:"replicas,omitempty"` // Template describes the machines that will be created. - Template clusterv1alpha4.MachineTemplateSpec `json:"template"` + Template MachineTemplateSpec `json:"template"` // Minimum number of seconds for which a newly created machine instances should // be ready. @@ -119,7 +118,7 @@ type MachinePoolStatus struct { // Conditions define the current service state of the MachinePool. // +optional - Conditions clusterv1alpha4.Conditions `json:"conditions,omitempty"` + Conditions Conditions `json:"conditions,omitempty"` } // ANCHOR_END: MachinePoolStatus @@ -222,12 +221,12 @@ type MachinePool struct { } // GetConditions returns the set of conditions for this object. -func (m *MachinePool) GetConditions() clusterv1alpha4.Conditions { +func (m *MachinePool) GetConditions() Conditions { return m.Status.Conditions } // SetConditions sets the conditions on this object. -func (m *MachinePool) SetConditions(conditions clusterv1alpha4.Conditions) { +func (m *MachinePool) SetConditions(conditions Conditions) { m.Status.Conditions = conditions } diff --git a/internal/apis/core/v1alpha4/zz_generated.conversion.go b/internal/apis/core/v1alpha4/zz_generated.conversion.go index e8f640274d79..2b773bb8dfb9 100644 --- a/internal/apis/core/v1alpha4/zz_generated.conversion.go +++ b/internal/apis/core/v1alpha4/zz_generated.conversion.go @@ -300,6 +300,46 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddGeneratedConversionFunc((*MachinePool)(nil), (*v1beta1.MachinePool)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha4_MachinePool_To_v1beta1_MachinePool(a.(*MachinePool), b.(*v1beta1.MachinePool), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*v1beta1.MachinePool)(nil), (*MachinePool)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_MachinePool_To_v1alpha4_MachinePool(a.(*v1beta1.MachinePool), b.(*MachinePool), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*MachinePoolList)(nil), (*v1beta1.MachinePoolList)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha4_MachinePoolList_To_v1beta1_MachinePoolList(a.(*MachinePoolList), b.(*v1beta1.MachinePoolList), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*v1beta1.MachinePoolList)(nil), (*MachinePoolList)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_MachinePoolList_To_v1alpha4_MachinePoolList(a.(*v1beta1.MachinePoolList), b.(*MachinePoolList), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*MachinePoolSpec)(nil), (*v1beta1.MachinePoolSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha4_MachinePoolSpec_To_v1beta1_MachinePoolSpec(a.(*MachinePoolSpec), b.(*v1beta1.MachinePoolSpec), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*v1beta1.MachinePoolSpec)(nil), (*MachinePoolSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_MachinePoolSpec_To_v1alpha4_MachinePoolSpec(a.(*v1beta1.MachinePoolSpec), b.(*MachinePoolSpec), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*MachinePoolStatus)(nil), (*v1beta1.MachinePoolStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha4_MachinePoolStatus_To_v1beta1_MachinePoolStatus(a.(*MachinePoolStatus), b.(*v1beta1.MachinePoolStatus), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*v1beta1.MachinePoolStatus)(nil), (*MachinePoolStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_MachinePoolStatus_To_v1alpha4_MachinePoolStatus(a.(*v1beta1.MachinePoolStatus), b.(*MachinePoolStatus), scope) + }); err != nil { + return err + } if err := s.AddGeneratedConversionFunc((*MachineRollingUpdateDeployment)(nil), (*v1beta1.MachineRollingUpdateDeployment)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha4_MachineRollingUpdateDeployment_To_v1beta1_MachineRollingUpdateDeployment(a.(*MachineRollingUpdateDeployment), b.(*v1beta1.MachineRollingUpdateDeployment), scope) }); err != nil { @@ -350,16 +390,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*MachineTemplateSpec)(nil), (*v1beta1.MachineTemplateSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha4_MachineTemplateSpec_To_v1beta1_MachineTemplateSpec(a.(*MachineTemplateSpec), b.(*v1beta1.MachineTemplateSpec), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*v1beta1.MachineTemplateSpec)(nil), (*MachineTemplateSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta1_MachineTemplateSpec_To_v1alpha4_MachineTemplateSpec(a.(*v1beta1.MachineTemplateSpec), b.(*MachineTemplateSpec), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*NetworkRanges)(nil), (*v1beta1.NetworkRanges)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha4_NetworkRanges_To_v1beta1_NetworkRanges(a.(*NetworkRanges), b.(*v1beta1.NetworkRanges), scope) }); err != nil { @@ -410,6 +440,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*MachineTemplateSpec)(nil), (*v1beta1.MachineTemplateSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha4_MachineTemplateSpec_To_v1beta1_MachineTemplateSpec(a.(*MachineTemplateSpec), b.(*v1beta1.MachineTemplateSpec), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*v1beta1.ClusterClassSpec)(nil), (*ClusterClassSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1beta1_ClusterClassSpec_To_v1alpha4_ClusterClassSpec(a.(*v1beta1.ClusterClassSpec), b.(*ClusterClassSpec), scope) }); err != nil { @@ -465,6 +500,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*v1beta1.MachineTemplateSpec)(nil), (*MachineTemplateSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_MachineTemplateSpec_To_v1alpha4_MachineTemplateSpec(a.(*v1beta1.MachineTemplateSpec), b.(*MachineTemplateSpec), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*v1beta1.Topology)(nil), (*Topology)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1beta1_Topology_To_v1alpha4_Topology(a.(*v1beta1.Topology), b.(*Topology), scope) }); err != nil { @@ -1428,6 +1468,156 @@ func Convert_v1beta1_MachineList_To_v1alpha4_MachineList(in *v1beta1.MachineList return autoConvert_v1beta1_MachineList_To_v1alpha4_MachineList(in, out, s) } +func autoConvert_v1alpha4_MachinePool_To_v1beta1_MachinePool(in *MachinePool, out *v1beta1.MachinePool, s conversion.Scope) error { + out.ObjectMeta = in.ObjectMeta + if err := Convert_v1alpha4_MachinePoolSpec_To_v1beta1_MachinePoolSpec(&in.Spec, &out.Spec, s); err != nil { + return err + } + if err := Convert_v1alpha4_MachinePoolStatus_To_v1beta1_MachinePoolStatus(&in.Status, &out.Status, s); err != nil { + return err + } + return nil +} + +// Convert_v1alpha4_MachinePool_To_v1beta1_MachinePool is an autogenerated conversion function. +func Convert_v1alpha4_MachinePool_To_v1beta1_MachinePool(in *MachinePool, out *v1beta1.MachinePool, s conversion.Scope) error { + return autoConvert_v1alpha4_MachinePool_To_v1beta1_MachinePool(in, out, s) +} + +func autoConvert_v1beta1_MachinePool_To_v1alpha4_MachinePool(in *v1beta1.MachinePool, out *MachinePool, s conversion.Scope) error { + out.ObjectMeta = in.ObjectMeta + if err := Convert_v1beta1_MachinePoolSpec_To_v1alpha4_MachinePoolSpec(&in.Spec, &out.Spec, s); err != nil { + return err + } + if err := Convert_v1beta1_MachinePoolStatus_To_v1alpha4_MachinePoolStatus(&in.Status, &out.Status, s); err != nil { + return err + } + return nil +} + +// Convert_v1beta1_MachinePool_To_v1alpha4_MachinePool is an autogenerated conversion function. +func Convert_v1beta1_MachinePool_To_v1alpha4_MachinePool(in *v1beta1.MachinePool, out *MachinePool, s conversion.Scope) error { + return autoConvert_v1beta1_MachinePool_To_v1alpha4_MachinePool(in, out, s) +} + +func autoConvert_v1alpha4_MachinePoolList_To_v1beta1_MachinePoolList(in *MachinePoolList, out *v1beta1.MachinePoolList, s conversion.Scope) error { + out.ListMeta = in.ListMeta + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]v1beta1.MachinePool, len(*in)) + for i := range *in { + if err := Convert_v1alpha4_MachinePool_To_v1beta1_MachinePool(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } + return nil +} + +// Convert_v1alpha4_MachinePoolList_To_v1beta1_MachinePoolList is an autogenerated conversion function. +func Convert_v1alpha4_MachinePoolList_To_v1beta1_MachinePoolList(in *MachinePoolList, out *v1beta1.MachinePoolList, s conversion.Scope) error { + return autoConvert_v1alpha4_MachinePoolList_To_v1beta1_MachinePoolList(in, out, s) +} + +func autoConvert_v1beta1_MachinePoolList_To_v1alpha4_MachinePoolList(in *v1beta1.MachinePoolList, out *MachinePoolList, s conversion.Scope) error { + out.ListMeta = in.ListMeta + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]MachinePool, len(*in)) + for i := range *in { + if err := Convert_v1beta1_MachinePool_To_v1alpha4_MachinePool(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } + return nil +} + +// Convert_v1beta1_MachinePoolList_To_v1alpha4_MachinePoolList is an autogenerated conversion function. +func Convert_v1beta1_MachinePoolList_To_v1alpha4_MachinePoolList(in *v1beta1.MachinePoolList, out *MachinePoolList, s conversion.Scope) error { + return autoConvert_v1beta1_MachinePoolList_To_v1alpha4_MachinePoolList(in, out, s) +} + +func autoConvert_v1alpha4_MachinePoolSpec_To_v1beta1_MachinePoolSpec(in *MachinePoolSpec, out *v1beta1.MachinePoolSpec, s conversion.Scope) error { + out.ClusterName = in.ClusterName + out.Replicas = (*int32)(unsafe.Pointer(in.Replicas)) + if err := Convert_v1alpha4_MachineTemplateSpec_To_v1beta1_MachineTemplateSpec(&in.Template, &out.Template, s); err != nil { + return err + } + out.MinReadySeconds = (*int32)(unsafe.Pointer(in.MinReadySeconds)) + out.ProviderIDList = *(*[]string)(unsafe.Pointer(&in.ProviderIDList)) + out.FailureDomains = *(*[]string)(unsafe.Pointer(&in.FailureDomains)) + return nil +} + +// Convert_v1alpha4_MachinePoolSpec_To_v1beta1_MachinePoolSpec is an autogenerated conversion function. +func Convert_v1alpha4_MachinePoolSpec_To_v1beta1_MachinePoolSpec(in *MachinePoolSpec, out *v1beta1.MachinePoolSpec, s conversion.Scope) error { + return autoConvert_v1alpha4_MachinePoolSpec_To_v1beta1_MachinePoolSpec(in, out, s) +} + +func autoConvert_v1beta1_MachinePoolSpec_To_v1alpha4_MachinePoolSpec(in *v1beta1.MachinePoolSpec, out *MachinePoolSpec, s conversion.Scope) error { + out.ClusterName = in.ClusterName + out.Replicas = (*int32)(unsafe.Pointer(in.Replicas)) + if err := Convert_v1beta1_MachineTemplateSpec_To_v1alpha4_MachineTemplateSpec(&in.Template, &out.Template, s); err != nil { + return err + } + out.MinReadySeconds = (*int32)(unsafe.Pointer(in.MinReadySeconds)) + out.ProviderIDList = *(*[]string)(unsafe.Pointer(&in.ProviderIDList)) + out.FailureDomains = *(*[]string)(unsafe.Pointer(&in.FailureDomains)) + return nil +} + +// Convert_v1beta1_MachinePoolSpec_To_v1alpha4_MachinePoolSpec is an autogenerated conversion function. +func Convert_v1beta1_MachinePoolSpec_To_v1alpha4_MachinePoolSpec(in *v1beta1.MachinePoolSpec, out *MachinePoolSpec, s conversion.Scope) error { + return autoConvert_v1beta1_MachinePoolSpec_To_v1alpha4_MachinePoolSpec(in, out, s) +} + +func autoConvert_v1alpha4_MachinePoolStatus_To_v1beta1_MachinePoolStatus(in *MachinePoolStatus, out *v1beta1.MachinePoolStatus, s conversion.Scope) error { + out.NodeRefs = *(*[]v1.ObjectReference)(unsafe.Pointer(&in.NodeRefs)) + out.Replicas = in.Replicas + out.ReadyReplicas = in.ReadyReplicas + out.AvailableReplicas = in.AvailableReplicas + out.UnavailableReplicas = in.UnavailableReplicas + out.FailureReason = (*errors.MachinePoolStatusFailure)(unsafe.Pointer(in.FailureReason)) + out.FailureMessage = (*string)(unsafe.Pointer(in.FailureMessage)) + out.Phase = in.Phase + out.BootstrapReady = in.BootstrapReady + out.InfrastructureReady = in.InfrastructureReady + out.ObservedGeneration = in.ObservedGeneration + out.Conditions = *(*v1beta1.Conditions)(unsafe.Pointer(&in.Conditions)) + return nil +} + +// Convert_v1alpha4_MachinePoolStatus_To_v1beta1_MachinePoolStatus is an autogenerated conversion function. +func Convert_v1alpha4_MachinePoolStatus_To_v1beta1_MachinePoolStatus(in *MachinePoolStatus, out *v1beta1.MachinePoolStatus, s conversion.Scope) error { + return autoConvert_v1alpha4_MachinePoolStatus_To_v1beta1_MachinePoolStatus(in, out, s) +} + +func autoConvert_v1beta1_MachinePoolStatus_To_v1alpha4_MachinePoolStatus(in *v1beta1.MachinePoolStatus, out *MachinePoolStatus, s conversion.Scope) error { + out.NodeRefs = *(*[]v1.ObjectReference)(unsafe.Pointer(&in.NodeRefs)) + out.Replicas = in.Replicas + out.ReadyReplicas = in.ReadyReplicas + out.AvailableReplicas = in.AvailableReplicas + out.UnavailableReplicas = in.UnavailableReplicas + out.FailureReason = (*errors.MachinePoolStatusFailure)(unsafe.Pointer(in.FailureReason)) + out.FailureMessage = (*string)(unsafe.Pointer(in.FailureMessage)) + out.Phase = in.Phase + out.BootstrapReady = in.BootstrapReady + out.InfrastructureReady = in.InfrastructureReady + out.ObservedGeneration = in.ObservedGeneration + out.Conditions = *(*Conditions)(unsafe.Pointer(&in.Conditions)) + return nil +} + +// Convert_v1beta1_MachinePoolStatus_To_v1alpha4_MachinePoolStatus is an autogenerated conversion function. +func Convert_v1beta1_MachinePoolStatus_To_v1alpha4_MachinePoolStatus(in *v1beta1.MachinePoolStatus, out *MachinePoolStatus, s conversion.Scope) error { + return autoConvert_v1beta1_MachinePoolStatus_To_v1alpha4_MachinePoolStatus(in, out, s) +} + func autoConvert_v1alpha4_MachineRollingUpdateDeployment_To_v1beta1_MachineRollingUpdateDeployment(in *MachineRollingUpdateDeployment, out *v1beta1.MachineRollingUpdateDeployment, s conversion.Scope) error { out.MaxUnavailable = (*intstr.IntOrString)(unsafe.Pointer(in.MaxUnavailable)) out.MaxSurge = (*intstr.IntOrString)(unsafe.Pointer(in.MaxSurge)) @@ -1666,11 +1856,6 @@ func autoConvert_v1alpha4_MachineTemplateSpec_To_v1beta1_MachineTemplateSpec(in return nil } -// Convert_v1alpha4_MachineTemplateSpec_To_v1beta1_MachineTemplateSpec is an autogenerated conversion function. -func Convert_v1alpha4_MachineTemplateSpec_To_v1beta1_MachineTemplateSpec(in *MachineTemplateSpec, out *v1beta1.MachineTemplateSpec, s conversion.Scope) error { - return autoConvert_v1alpha4_MachineTemplateSpec_To_v1beta1_MachineTemplateSpec(in, out, s) -} - func autoConvert_v1beta1_MachineTemplateSpec_To_v1alpha4_MachineTemplateSpec(in *v1beta1.MachineTemplateSpec, out *MachineTemplateSpec, s conversion.Scope) error { if err := Convert_v1beta1_ObjectMeta_To_v1alpha4_ObjectMeta(&in.ObjectMeta, &out.ObjectMeta, s); err != nil { return err @@ -1681,11 +1866,6 @@ func autoConvert_v1beta1_MachineTemplateSpec_To_v1alpha4_MachineTemplateSpec(in return nil } -// Convert_v1beta1_MachineTemplateSpec_To_v1alpha4_MachineTemplateSpec is an autogenerated conversion function. -func Convert_v1beta1_MachineTemplateSpec_To_v1alpha4_MachineTemplateSpec(in *v1beta1.MachineTemplateSpec, out *MachineTemplateSpec, s conversion.Scope) error { - return autoConvert_v1beta1_MachineTemplateSpec_To_v1alpha4_MachineTemplateSpec(in, out, s) -} - func autoConvert_v1alpha4_NetworkRanges_To_v1beta1_NetworkRanges(in *NetworkRanges, out *v1beta1.NetworkRanges, s conversion.Scope) error { out.CIDRBlocks = *(*[]string)(unsafe.Pointer(&in.CIDRBlocks)) return nil diff --git a/internal/apis/core/v1alpha4/zz_generated.deepcopy.go b/internal/apis/core/v1alpha4/zz_generated.deepcopy.go index ac1ae21e3332..827211bb8e95 100644 --- a/internal/apis/core/v1alpha4/zz_generated.deepcopy.go +++ b/internal/apis/core/v1alpha4/zz_generated.deepcopy.go @@ -869,6 +869,138 @@ func (in *MachineList) DeepCopyObject() runtime.Object { return nil } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MachinePool) DeepCopyInto(out *MachinePool) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachinePool. +func (in *MachinePool) DeepCopy() *MachinePool { + if in == nil { + return nil + } + out := new(MachinePool) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *MachinePool) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MachinePoolList) DeepCopyInto(out *MachinePoolList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]MachinePool, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachinePoolList. +func (in *MachinePoolList) DeepCopy() *MachinePoolList { + if in == nil { + return nil + } + out := new(MachinePoolList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *MachinePoolList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MachinePoolSpec) DeepCopyInto(out *MachinePoolSpec) { + *out = *in + if in.Replicas != nil { + in, out := &in.Replicas, &out.Replicas + *out = new(int32) + **out = **in + } + in.Template.DeepCopyInto(&out.Template) + if in.MinReadySeconds != nil { + in, out := &in.MinReadySeconds, &out.MinReadySeconds + *out = new(int32) + **out = **in + } + if in.ProviderIDList != nil { + in, out := &in.ProviderIDList, &out.ProviderIDList + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.FailureDomains != nil { + in, out := &in.FailureDomains, &out.FailureDomains + *out = make([]string, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachinePoolSpec. +func (in *MachinePoolSpec) DeepCopy() *MachinePoolSpec { + if in == nil { + return nil + } + out := new(MachinePoolSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MachinePoolStatus) DeepCopyInto(out *MachinePoolStatus) { + *out = *in + if in.NodeRefs != nil { + in, out := &in.NodeRefs, &out.NodeRefs + *out = make([]v1.ObjectReference, len(*in)) + copy(*out, *in) + } + if in.FailureReason != nil { + in, out := &in.FailureReason, &out.FailureReason + *out = new(errors.MachinePoolStatusFailure) + **out = **in + } + if in.FailureMessage != nil { + in, out := &in.FailureMessage, &out.FailureMessage + *out = new(string) + **out = **in + } + if in.Conditions != nil { + in, out := &in.Conditions, &out.Conditions + *out = make(Conditions, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachinePoolStatus. +func (in *MachinePoolStatus) DeepCopy() *MachinePoolStatus { + if in == nil { + return nil + } + out := new(MachinePoolStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *MachineRollingUpdateDeployment) DeepCopyInto(out *MachineRollingUpdateDeployment) { *out = *in diff --git a/internal/controllers/cluster/cluster_controller.go b/internal/controllers/cluster/cluster_controller.go index 452cfe9c0521..c9fcd2b45e2b 100644 --- a/internal/controllers/cluster/cluster_controller.go +++ b/internal/controllers/cluster/cluster_controller.go @@ -41,7 +41,6 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/controllers/external" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/feature" "sigs.k8s.io/cluster-api/internal/hooks" "sigs.k8s.io/cluster-api/util" @@ -349,7 +348,7 @@ type clusterDescendants struct { machineSets clusterv1.MachineSetList controlPlaneMachines clusterv1.MachineList workerMachines clusterv1.MachineList - machinePools expv1.MachinePoolList + machinePools clusterv1.MachinePoolList } // length returns the number of descendants. diff --git a/internal/controllers/cluster/cluster_controller_test.go b/internal/controllers/cluster/cluster_controller_test.go index b2f7fc47377c..3f6bc43ff471 100644 --- a/internal/controllers/cluster/cluster_controller_test.go +++ b/internal/controllers/cluster/cluster_controller_test.go @@ -30,7 +30,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client/fake" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" runtimev1 "sigs.k8s.io/cluster-api/exp/runtime/api/v1alpha1" "sigs.k8s.io/cluster-api/feature" "sigs.k8s.io/cluster-api/internal/test/builder" @@ -619,7 +618,7 @@ func (b *machineBuilder) build() clusterv1.Machine { } type machinePoolBuilder struct { - mp expv1.MachinePool + mp clusterv1.MachinePool } func newMachinePoolBuilder() *machinePoolBuilder { @@ -640,7 +639,7 @@ func (b *machinePoolBuilder) ownedBy(c *clusterv1.Cluster) *machinePoolBuilder { return b } -func (b *machinePoolBuilder) build() expv1.MachinePool { +func (b *machinePoolBuilder) build() clusterv1.MachinePool { return b.mp } @@ -711,8 +710,8 @@ func TestFilterOwnedDescendants(t *testing.T) { m5OwnedByCluster, }, }, - machinePools: expv1.MachinePoolList{ - Items: []expv1.MachinePool{ + machinePools: clusterv1.MachinePoolList{ + Items: []clusterv1.MachinePool{ mp1NotOwnedByCluster, mp2OwnedByCluster, mp3NotOwnedByCluster, @@ -770,8 +769,8 @@ func TestDescendantsLength(t *testing.T) { newMachineBuilder().named("m6").build(), }, }, - machinePools: expv1.MachinePoolList{ - Items: []expv1.MachinePool{ + machinePools: clusterv1.MachinePoolList{ + Items: []clusterv1.MachinePool{ newMachinePoolBuilder().named("mp1").build(), newMachinePoolBuilder().named("mp2").build(), newMachinePoolBuilder().named("mp3").build(), diff --git a/internal/controllers/machinepool/doc.go b/internal/controllers/machinepool/doc.go new file mode 100644 index 000000000000..a519e3679444 --- /dev/null +++ b/internal/controllers/machinepool/doc.go @@ -0,0 +1,18 @@ +/* +Copyright 2024 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 machinepool implements the machinepool controller. +package machinepool diff --git a/exp/internal/controllers/machinepool_controller.go b/internal/controllers/machinepool/machinepool_controller.go similarity index 87% rename from exp/internal/controllers/machinepool_controller.go rename to internal/controllers/machinepool/machinepool_controller.go index 5ade870c39d1..750b2b059745 100644 --- a/exp/internal/controllers/machinepool_controller.go +++ b/internal/controllers/machinepool/machinepool_controller.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package controllers +package machinepool import ( "context" @@ -41,7 +41,6 @@ import ( "sigs.k8s.io/cluster-api/api/v1beta1/index" "sigs.k8s.io/cluster-api/controllers/external" "sigs.k8s.io/cluster-api/controllers/remote" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/internal/util/ssa" "sigs.k8s.io/cluster-api/util" "sigs.k8s.io/cluster-api/util/annotations" @@ -65,8 +64,8 @@ const ( MachinePoolControllerName = "machinepool-controller" ) -// MachinePoolReconciler reconciles a MachinePool object. -type MachinePoolReconciler struct { +// Reconciler reconciles a MachinePool object. +type Reconciler struct { Client client.Client APIReader client.Reader Tracker *remote.ClusterCacheTracker @@ -80,14 +79,14 @@ type MachinePoolReconciler struct { externalTracker external.ObjectTracker } -func (r *MachinePoolReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error { - clusterToMachinePools, err := util.ClusterToTypedObjectsMapper(mgr.GetClient(), &expv1.MachinePoolList{}, mgr.GetScheme()) +func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error { + clusterToMachinePools, err := util.ClusterToTypedObjectsMapper(mgr.GetClient(), &clusterv1.MachinePoolList{}, mgr.GetScheme()) if err != nil { return err } c, err := ctrl.NewControllerManagedBy(mgr). - For(&expv1.MachinePool{}). + For(&clusterv1.MachinePool{}). WithOptions(options). WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)). Watches( @@ -117,10 +116,10 @@ func (r *MachinePoolReconciler) SetupWithManager(ctx context.Context, mgr ctrl.M return nil } -func (r *MachinePoolReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Result, reterr error) { +func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Result, reterr error) { log := ctrl.LoggerFrom(ctx) - mp := &expv1.MachinePool{} + mp := &clusterv1.MachinePool{} if err := r.Client.Get(ctx, req.NamespacedName, mp); err != nil { if apierrors.IsNotFound(err) { // Object not found, return. Created objects are automatically garbage collected. @@ -162,7 +161,7 @@ func (r *MachinePoolReconciler) Reconcile(ctx context.Context, req ctrl.Request) conditions.WithConditions( clusterv1.BootstrapReadyCondition, clusterv1.InfrastructureReadyCondition, - expv1.ReplicasReadyCondition, + clusterv1.ReplicasReadyCondition, ), ) @@ -173,7 +172,7 @@ func (r *MachinePoolReconciler) Reconcile(ctx context.Context, req ctrl.Request) clusterv1.ReadyCondition, clusterv1.BootstrapReadyCondition, clusterv1.InfrastructureReadyCondition, - expv1.ReplicasReadyCondition, + clusterv1.ReplicasReadyCondition, }}, } if reterr == nil { @@ -204,8 +203,8 @@ func (r *MachinePoolReconciler) Reconcile(ctx context.Context, req ctrl.Request) // Add finalizer first if not set to avoid the race condition between init and delete. // Note: Finalizers in general can only be added when the deletionTimestamp is not set. - if !controllerutil.ContainsFinalizer(mp, expv1.MachinePoolFinalizer) { - controllerutil.AddFinalizer(mp, expv1.MachinePoolFinalizer) + if !controllerutil.ContainsFinalizer(mp, clusterv1.MachinePoolFinalizer) { + controllerutil.AddFinalizer(mp, clusterv1.MachinePoolFinalizer) return ctrl.Result{}, nil } @@ -220,7 +219,7 @@ func (r *MachinePoolReconciler) Reconcile(ctx context.Context, req ctrl.Request) return res, err } -func (r *MachinePoolReconciler) reconcile(ctx context.Context, cluster *clusterv1.Cluster, mp *expv1.MachinePool) (ctrl.Result, error) { +func (r *Reconciler) reconcile(ctx context.Context, cluster *clusterv1.Cluster, mp *clusterv1.MachinePool) (ctrl.Result, error) { // Ensure the MachinePool is owned by the Cluster it belongs to. mp.SetOwnerReferences(util.EnsureOwnerRef(mp.GetOwnerReferences(), metav1.OwnerReference{ APIVersion: clusterv1.GroupVersion.String(), @@ -229,7 +228,7 @@ func (r *MachinePoolReconciler) reconcile(ctx context.Context, cluster *clusterv UID: cluster.UID, })) - phases := []func(context.Context, *clusterv1.Cluster, *expv1.MachinePool) (ctrl.Result, error){ + phases := []func(context.Context, *clusterv1.Cluster, *clusterv1.MachinePool) (ctrl.Result, error){ r.reconcileBootstrap, r.reconcileInfrastructure, r.reconcileNodeRefs, @@ -252,7 +251,7 @@ func (r *MachinePoolReconciler) reconcile(ctx context.Context, cluster *clusterv return res, kerrors.NewAggregate(errs) } -func (r *MachinePoolReconciler) reconcileDelete(ctx context.Context, cluster *clusterv1.Cluster, mp *expv1.MachinePool) error { +func (r *Reconciler) reconcileDelete(ctx context.Context, cluster *clusterv1.Cluster, mp *clusterv1.MachinePool) error { if ok, err := r.reconcileDeleteExternal(ctx, mp); !ok || err != nil { // Return early and don't remove the finalizer if we got an error or // the external reconciliation deletion isn't ready. @@ -264,11 +263,11 @@ func (r *MachinePoolReconciler) reconcileDelete(ctx context.Context, cluster *cl return err } - controllerutil.RemoveFinalizer(mp, expv1.MachinePoolFinalizer) + controllerutil.RemoveFinalizer(mp, clusterv1.MachinePoolFinalizer) return nil } -func (r *MachinePoolReconciler) reconcileDeleteNodes(ctx context.Context, cluster *clusterv1.Cluster, machinepool *expv1.MachinePool) error { +func (r *Reconciler) reconcileDeleteNodes(ctx context.Context, cluster *clusterv1.Cluster, machinepool *clusterv1.MachinePool) error { if len(machinepool.Status.NodeRefs) == 0 { return nil } @@ -282,7 +281,7 @@ func (r *MachinePoolReconciler) reconcileDeleteNodes(ctx context.Context, cluste } // reconcileDeleteExternal tries to delete external references, returning true if it cannot find any. -func (r *MachinePoolReconciler) reconcileDeleteExternal(ctx context.Context, m *expv1.MachinePool) (bool, error) { +func (r *Reconciler) reconcileDeleteExternal(ctx context.Context, m *clusterv1.MachinePool) (bool, error) { objects := []*unstructured.Unstructured{} references := []*corev1.ObjectReference{ m.Spec.Template.Spec.Bootstrap.ConfigRef, @@ -318,7 +317,7 @@ func (r *MachinePoolReconciler) reconcileDeleteExternal(ctx context.Context, m * return len(objects) == 0, nil } -func (r *MachinePoolReconciler) watchClusterNodes(ctx context.Context, cluster *clusterv1.Cluster) error { +func (r *Reconciler) watchClusterNodes(ctx context.Context, cluster *clusterv1.Cluster) error { log := ctrl.LoggerFrom(ctx) if !conditions.IsTrue(cluster, clusterv1.ControlPlaneInitializedCondition) { @@ -340,7 +339,7 @@ func (r *MachinePoolReconciler) watchClusterNodes(ctx context.Context, cluster * }) } -func (r *MachinePoolReconciler) nodeToMachinePool(ctx context.Context, o client.Object) []reconcile.Request { +func (r *Reconciler) nodeToMachinePool(ctx context.Context, o client.Object) []reconcile.Request { node, ok := o.(*corev1.Node) if !ok { panic(fmt.Sprintf("Expected a Node but got a %T", o)) @@ -360,7 +359,7 @@ func (r *MachinePoolReconciler) nodeToMachinePool(ctx context.Context, o client. } // Match by nodeName and status.nodeRef.name. - machinePoolList := &expv1.MachinePoolList{} + machinePoolList := &clusterv1.MachinePoolList{} if err := r.Client.List( ctx, machinePoolList, @@ -378,7 +377,7 @@ func (r *MachinePoolReconciler) nodeToMachinePool(ctx context.Context, o client. if node.Spec.ProviderID == "" { return nil } - machinePoolList = &expv1.MachinePoolList{} + machinePoolList = &clusterv1.MachinePoolList{} if err := r.Client.List( ctx, machinePoolList, diff --git a/exp/internal/controllers/machinepool_controller_noderef.go b/internal/controllers/machinepool/machinepool_controller_noderef.go similarity index 89% rename from exp/internal/controllers/machinepool_controller_noderef.go rename to internal/controllers/machinepool/machinepool_controller_noderef.go index a2afac9557ba..922e4ace1834 100644 --- a/exp/internal/controllers/machinepool_controller_noderef.go +++ b/internal/controllers/machinepool/machinepool_controller_noderef.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package controllers +package machinepool import ( "context" @@ -30,7 +30,6 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/controllers/noderefutil" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/internal/util/taints" "sigs.k8s.io/cluster-api/util" "sigs.k8s.io/cluster-api/util/annotations" @@ -46,7 +45,7 @@ type getNodeReferencesResult struct { ready int } -func (r *MachinePoolReconciler) reconcileNodeRefs(ctx context.Context, cluster *clusterv1.Cluster, mp *expv1.MachinePool) (ctrl.Result, error) { +func (r *Reconciler) reconcileNodeRefs(ctx context.Context, cluster *clusterv1.Cluster, mp *clusterv1.MachinePool) (ctrl.Result, error) { log := ctrl.LoggerFrom(ctx) // Create a watch on the nodes in the Cluster. @@ -62,7 +61,7 @@ func (r *MachinePoolReconciler) reconcileNodeRefs(ctx context.Context, cluster * // Check that the Machine doesn't already have a NodeRefs. // Return early if there is no work to do. if mp.Status.Replicas == mp.Status.ReadyReplicas && len(mp.Status.NodeRefs) == int(mp.Status.ReadyReplicas) { - conditions.MarkTrue(mp, expv1.ReplicasReadyCondition) + conditions.MarkTrue(mp, clusterv1.ReplicasReadyCondition) return ctrl.Result{}, nil } @@ -109,19 +108,19 @@ func (r *MachinePoolReconciler) reconcileNodeRefs(ctx context.Context, cluster * if mp.Status.Replicas != mp.Status.ReadyReplicas || len(nodeRefsResult.references) != int(mp.Status.ReadyReplicas) { log.Info("NodeRefs != ReadyReplicas", "nodeRefs", len(nodeRefsResult.references), "readyReplicas", mp.Status.ReadyReplicas) - conditions.MarkFalse(mp, expv1.ReplicasReadyCondition, expv1.WaitingForReplicasReadyReason, clusterv1.ConditionSeverityInfo, "") + conditions.MarkFalse(mp, clusterv1.ReplicasReadyCondition, clusterv1.WaitingForReplicasReadyReason, clusterv1.ConditionSeverityInfo, "") return ctrl.Result{RequeueAfter: 30 * time.Second}, nil } // At this point, the required number of replicas are ready - conditions.MarkTrue(mp, expv1.ReplicasReadyCondition) + conditions.MarkTrue(mp, clusterv1.ReplicasReadyCondition) return ctrl.Result{}, nil } // deleteRetiredNodes deletes nodes that don't have a corresponding ProviderID in Spec.ProviderIDList. // A MachinePool infrastructure provider indicates an instance in the set has been deleted by // removing its ProviderID from the slice. -func (r *MachinePoolReconciler) deleteRetiredNodes(ctx context.Context, c client.Client, nodeRefs []corev1.ObjectReference, providerIDList []string) error { +func (r *Reconciler) deleteRetiredNodes(ctx context.Context, c client.Client, nodeRefs []corev1.ObjectReference, providerIDList []string) error { log := ctrl.LoggerFrom(ctx, "providerIDList", len(providerIDList)) nodeRefsMap := make(map[string]*corev1.Node, len(nodeRefs)) for _, nodeRef := range nodeRefs { @@ -153,7 +152,7 @@ func (r *MachinePoolReconciler) deleteRetiredNodes(ctx context.Context, c client return nil } -func (r *MachinePoolReconciler) getNodeReferences(ctx context.Context, c client.Client, providerIDList []string, minReadySeconds *int32) (getNodeReferencesResult, error) { +func (r *Reconciler) getNodeReferences(ctx context.Context, c client.Client, providerIDList []string, minReadySeconds *int32) (getNodeReferencesResult, error) { log := ctrl.LoggerFrom(ctx, "providerIDList", len(providerIDList)) var ready, available int @@ -207,7 +206,7 @@ func (r *MachinePoolReconciler) getNodeReferences(ctx context.Context, c client. } // patchNodes patches the nodes with the cluster name and cluster namespace annotations. -func (r *MachinePoolReconciler) patchNodes(ctx context.Context, c client.Client, references []corev1.ObjectReference, mp *expv1.MachinePool) error { +func (r *Reconciler) patchNodes(ctx context.Context, c client.Client, references []corev1.ObjectReference, mp *clusterv1.MachinePool) error { log := ctrl.LoggerFrom(ctx) for _, nodeRef := range references { node := &corev1.Node{} diff --git a/exp/internal/controllers/machinepool_controller_noderef_test.go b/internal/controllers/machinepool/machinepool_controller_noderef_test.go similarity index 97% rename from exp/internal/controllers/machinepool_controller_noderef_test.go rename to internal/controllers/machinepool/machinepool_controller_noderef_test.go index b573cb47ba38..835e4027c8eb 100644 --- a/exp/internal/controllers/machinepool_controller_noderef_test.go +++ b/internal/controllers/machinepool/machinepool_controller_noderef_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package controllers +package machinepool import ( "testing" @@ -28,11 +28,10 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client/fake" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" ) func TestMachinePoolGetNodeReference(t *testing.T) { - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fake.NewClientBuilder().Build(), recorder: record.NewFakeRecorder(32), } @@ -310,7 +309,7 @@ func TestMachinePoolGetNodeReference(t *testing.T) { } func TestMachinePoolPatchNodes(t *testing.T) { - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fake.NewClientBuilder().Build(), recorder: record.NewFakeRecorder(32), } @@ -388,14 +387,14 @@ func TestMachinePoolPatchNodes(t *testing.T) { testCases := []struct { name string - machinePool *expv1.MachinePool + machinePool *clusterv1.MachinePool nodeRefs []corev1.ObjectReference expectedNodes []corev1.Node err error }{ { name: "Node with uninitialized taint should be patched", - machinePool: &expv1.MachinePool{ + machinePool: &clusterv1.MachinePool{ TypeMeta: metav1.TypeMeta{ Kind: "MachinePool", }, @@ -403,7 +402,7 @@ func TestMachinePoolPatchNodes(t *testing.T) { Name: "machinepool-1", Namespace: "my-namespace", }, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ ClusterName: "cluster-1", ProviderIDList: []string{"aws://us-east-1/id-node-1"}, }, @@ -430,7 +429,7 @@ func TestMachinePoolPatchNodes(t *testing.T) { }, { name: "Node with existing annotations and taints should be patched", - machinePool: &expv1.MachinePool{ + machinePool: &clusterv1.MachinePool{ TypeMeta: metav1.TypeMeta{ Kind: "MachinePool", }, @@ -438,7 +437,7 @@ func TestMachinePoolPatchNodes(t *testing.T) { Name: "machinepool-2", Namespace: "my-namespace", }, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ ClusterName: "cluster-1", ProviderIDList: []string{"aws://us-west-2/id-node-2"}, }, diff --git a/exp/internal/controllers/machinepool_controller_phases.go b/internal/controllers/machinepool/machinepool_controller_phases.go similarity index 91% rename from exp/internal/controllers/machinepool_controller_phases.go rename to internal/controllers/machinepool/machinepool_controller_phases.go index 956627036a09..a15512da39ab 100644 --- a/exp/internal/controllers/machinepool_controller_phases.go +++ b/internal/controllers/machinepool/machinepool_controller_phases.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package controllers +package machinepool import ( "context" @@ -39,7 +39,6 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/controllers/external" capierrors "sigs.k8s.io/cluster-api/errors" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" utilexp "sigs.k8s.io/cluster-api/exp/util" "sigs.k8s.io/cluster-api/internal/util/ssa" "sigs.k8s.io/cluster-api/util" @@ -51,35 +50,35 @@ import ( "sigs.k8s.io/cluster-api/util/patch" ) -func (r *MachinePoolReconciler) reconcilePhase(mp *expv1.MachinePool) { +func (r *Reconciler) reconcilePhase(mp *clusterv1.MachinePool) { // Set the phase to "pending" if nil. if mp.Status.Phase == "" { - mp.Status.SetTypedPhase(expv1.MachinePoolPhasePending) + mp.Status.SetTypedPhase(clusterv1.MachinePoolPhasePending) } // Set the phase to "provisioning" if bootstrap is ready and the infrastructure isn't. if mp.Status.BootstrapReady && !mp.Status.InfrastructureReady { - mp.Status.SetTypedPhase(expv1.MachinePoolPhaseProvisioning) + mp.Status.SetTypedPhase(clusterv1.MachinePoolPhaseProvisioning) } // Set the phase to "provisioned" if the infrastructure is ready. if len(mp.Status.NodeRefs) != 0 { - mp.Status.SetTypedPhase(expv1.MachinePoolPhaseProvisioned) + mp.Status.SetTypedPhase(clusterv1.MachinePoolPhaseProvisioned) } // Set the phase to "running" if the number of ready replicas is equal to desired replicas. if mp.Status.InfrastructureReady && mp.Spec.Replicas != nil && *mp.Spec.Replicas == mp.Status.ReadyReplicas { - mp.Status.SetTypedPhase(expv1.MachinePoolPhaseRunning) + mp.Status.SetTypedPhase(clusterv1.MachinePoolPhaseRunning) } // Set the appropriate phase in response to the MachinePool replica count being greater than the observed infrastructure replicas. if mp.Status.InfrastructureReady && mp.Spec.Replicas != nil && *mp.Spec.Replicas > mp.Status.ReadyReplicas { // If we are being managed by an external autoscaler and can't predict scaling direction, set to "Scaling". if annotations.ReplicasManagedByExternalAutoscaler(mp) { - mp.Status.SetTypedPhase(expv1.MachinePoolPhaseScaling) + mp.Status.SetTypedPhase(clusterv1.MachinePoolPhaseScaling) } else { // Set the phase to "ScalingUp" if we are actively scaling the infrastructure out. - mp.Status.SetTypedPhase(expv1.MachinePoolPhaseScalingUp) + mp.Status.SetTypedPhase(clusterv1.MachinePoolPhaseScalingUp) } } @@ -87,26 +86,26 @@ func (r *MachinePoolReconciler) reconcilePhase(mp *expv1.MachinePool) { if mp.Status.InfrastructureReady && mp.Spec.Replicas != nil && *mp.Spec.Replicas < mp.Status.ReadyReplicas { // If we are being managed by an external autoscaler and can't predict scaling direction, set to "Scaling". if annotations.ReplicasManagedByExternalAutoscaler(mp) { - mp.Status.SetTypedPhase(expv1.MachinePoolPhaseScaling) + mp.Status.SetTypedPhase(clusterv1.MachinePoolPhaseScaling) } else { // Set the phase to "ScalingDown" if we are actively scaling the infrastructure in. - mp.Status.SetTypedPhase(expv1.MachinePoolPhaseScalingDown) + mp.Status.SetTypedPhase(clusterv1.MachinePoolPhaseScalingDown) } } // Set the phase to "failed" if any of Status.FailureReason or Status.FailureMessage is not-nil. if mp.Status.FailureReason != nil || mp.Status.FailureMessage != nil { - mp.Status.SetTypedPhase(expv1.MachinePoolPhaseFailed) + mp.Status.SetTypedPhase(clusterv1.MachinePoolPhaseFailed) } // Set the phase to "deleting" if the deletion timestamp is set. if !mp.DeletionTimestamp.IsZero() { - mp.Status.SetTypedPhase(expv1.MachinePoolPhaseDeleting) + mp.Status.SetTypedPhase(clusterv1.MachinePoolPhaseDeleting) } } // reconcileExternal handles generic unstructured objects referenced by a MachinePool. -func (r *MachinePoolReconciler) reconcileExternal(ctx context.Context, cluster *clusterv1.Cluster, m *expv1.MachinePool, ref *corev1.ObjectReference) (external.ReconcileOutput, error) { +func (r *Reconciler) reconcileExternal(ctx context.Context, cluster *clusterv1.Cluster, m *clusterv1.MachinePool, ref *corev1.ObjectReference) (external.ReconcileOutput, error) { log := ctrl.LoggerFrom(ctx) if err := utilconversion.UpdateReferenceAPIContract(ctx, r.Client, ref); err != nil { @@ -123,7 +122,7 @@ func (r *MachinePoolReconciler) reconcileExternal(ctx context.Context, cluster * } // Ensure we add a watch to the external object, if there isn't one already. - if err := r.externalTracker.Watch(log, obj, handler.EnqueueRequestForOwner(r.Client.Scheme(), r.Client.RESTMapper(), &expv1.MachinePool{})); err != nil { + if err := r.externalTracker.Watch(log, obj, handler.EnqueueRequestForOwner(r.Client.Scheme(), r.Client.RESTMapper(), &clusterv1.MachinePool{})); err != nil { return external.ReconcileOutput{}, err } @@ -177,7 +176,7 @@ func (r *MachinePoolReconciler) reconcileExternal(ctx context.Context, cluster * } // reconcileBootstrap reconciles the Spec.Bootstrap.ConfigRef object on a MachinePool. -func (r *MachinePoolReconciler) reconcileBootstrap(ctx context.Context, cluster *clusterv1.Cluster, m *expv1.MachinePool) (ctrl.Result, error) { +func (r *Reconciler) reconcileBootstrap(ctx context.Context, cluster *clusterv1.Cluster, m *clusterv1.MachinePool) (ctrl.Result, error) { log := ctrl.LoggerFrom(ctx) // Call generic external reconciler if we have an external reference. @@ -241,7 +240,7 @@ func (r *MachinePoolReconciler) reconcileBootstrap(ctx context.Context, cluster } // reconcileInfrastructure reconciles the Spec.InfrastructureRef object on a MachinePool. -func (r *MachinePoolReconciler) reconcileInfrastructure(ctx context.Context, cluster *clusterv1.Cluster, mp *expv1.MachinePool) (ctrl.Result, error) { +func (r *Reconciler) reconcileInfrastructure(ctx context.Context, cluster *clusterv1.Cluster, mp *clusterv1.MachinePool) (ctrl.Result, error) { log := ctrl.LoggerFrom(ctx) // Call generic external reconciler. @@ -328,7 +327,7 @@ func (r *MachinePoolReconciler) reconcileInfrastructure(ctx context.Context, clu // infrastructure is created accordingly. // Note: When supported by the cloud provider implementation of the MachinePool, machines will provide a means to interact // with the corresponding infrastructure (e.g. delete a specific machine in case MachineHealthCheck detects it is unhealthy). -func (r *MachinePoolReconciler) reconcileMachines(ctx context.Context, mp *expv1.MachinePool, infraMachinePool *unstructured.Unstructured) error { +func (r *Reconciler) reconcileMachines(ctx context.Context, mp *clusterv1.MachinePool, infraMachinePool *unstructured.Unstructured) error { log := ctrl.LoggerFrom(ctx) var infraMachineKind string @@ -384,7 +383,7 @@ func (r *MachinePoolReconciler) reconcileMachines(ctx context.Context, mp *expv1 } // createOrUpdateMachines creates a MachinePool Machine for each infraMachine if it doesn't already exist and sets the owner reference and infraRef. -func (r *MachinePoolReconciler) createOrUpdateMachines(ctx context.Context, mp *expv1.MachinePool, machines []clusterv1.Machine, infraMachines []unstructured.Unstructured) error { +func (r *Reconciler) createOrUpdateMachines(ctx context.Context, mp *clusterv1.MachinePool, machines []clusterv1.Machine, infraMachines []unstructured.Unstructured) error { log := ctrl.LoggerFrom(ctx) // Construct a set of names of infraMachines that already have a Machine. @@ -432,7 +431,7 @@ func (r *MachinePoolReconciler) createOrUpdateMachines(ctx context.Context, mp * // computeDesiredMachine constructs the desired Machine for an infraMachine. // If the Machine exists, it ensures the Machine always owned by the MachinePool. -func computeDesiredMachine(mp *expv1.MachinePool, infraMachine *unstructured.Unstructured, existingMachine *clusterv1.Machine) *clusterv1.Machine { +func computeDesiredMachine(mp *clusterv1.MachinePool, infraMachine *unstructured.Unstructured, existingMachine *clusterv1.Machine) *clusterv1.Machine { infraRef := corev1.ObjectReference{ APIVersion: infraMachine.GetAPIVersion(), Kind: infraMachine.GetKind(), @@ -482,7 +481,7 @@ func computeDesiredMachine(mp *expv1.MachinePool, infraMachine *unstructured.Uns // infraMachineToMachinePoolMapper is a mapper function that maps an InfraMachine to the MachinePool that owns it. // This is used to trigger an update of the MachinePool when a InfraMachine is changed. -func (r *MachinePoolReconciler) infraMachineToMachinePoolMapper(ctx context.Context, o client.Object) []ctrl.Request { +func (r *Reconciler) infraMachineToMachinePoolMapper(ctx context.Context, o client.Object) []ctrl.Request { log := ctrl.LoggerFrom(ctx) if labels.IsMachinePoolOwned(o) { @@ -506,7 +505,7 @@ func (r *MachinePoolReconciler) infraMachineToMachinePoolMapper(ctx context.Cont return nil } -func (r *MachinePoolReconciler) waitForMachineCreation(ctx context.Context, machineList []clusterv1.Machine) error { +func (r *Reconciler) waitForMachineCreation(ctx context.Context, machineList []clusterv1.Machine) error { _ = ctrl.LoggerFrom(ctx) // waitForCacheUpdateTimeout is the amount of time allowed to wait for desired state. diff --git a/exp/internal/controllers/machinepool_controller_phases_test.go b/internal/controllers/machinepool/machinepool_controller_phases_test.go similarity index 93% rename from exp/internal/controllers/machinepool_controller_phases_test.go rename to internal/controllers/machinepool/machinepool_controller_phases_test.go index b416c818c874..cdd7605e1ab0 100644 --- a/exp/internal/controllers/machinepool_controller_phases_test.go +++ b/internal/controllers/machinepool/machinepool_controller_phases_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package controllers +package machinepool import ( "fmt" @@ -38,7 +38,6 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/controllers/external" "sigs.k8s.io/cluster-api/controllers/remote" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/internal/test/builder" "sigs.k8s.io/cluster-api/internal/util/ssa" "sigs.k8s.io/cluster-api/util/kubeconfig" @@ -61,12 +60,12 @@ func TestReconcileMachinePoolPhases(t *testing.T) { }, } - defaultMachinePool := expv1.MachinePool{ + defaultMachinePool := clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: "machinepool-test", Namespace: metav1.NamespaceDefault, }, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ ClusterName: defaultCluster.Name, Replicas: ptr.To[int32](1), Template: clusterv1.MachineTemplateSpec{ @@ -126,7 +125,7 @@ func TestReconcileMachinePoolPhases(t *testing.T) { bootstrapConfig := defaultBootstrap.DeepCopy() infraConfig := defaultInfra.DeepCopy() - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fake.NewClientBuilder().WithObjects(defaultCluster, defaultKubeconfigSecret, machinepool, bootstrapConfig, infraConfig, builder.TestBootstrapConfigCRD, builder.TestInfrastructureMachineTemplateCRD).Build(), } @@ -155,7 +154,7 @@ func TestReconcileMachinePoolPhases(t *testing.T) { bootstrapConfig := defaultBootstrap.DeepCopy() infraConfig := defaultInfra.DeepCopy() - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fake.NewClientBuilder().WithObjects(defaultCluster, defaultKubeconfigSecret, machinepool, bootstrapConfig, infraConfig, builder.TestBootstrapConfigCRD, builder.TestInfrastructureMachineTemplateCRD).Build(), } @@ -164,7 +163,7 @@ func TestReconcileMachinePoolPhases(t *testing.T) { g.Expect(res.Requeue).To(BeFalse()) r.reconcilePhase(machinepool) - g.Expect(machinepool.Status.GetTypedPhase()).To(Equal(expv1.MachinePoolPhasePending)) + g.Expect(machinepool.Status.GetTypedPhase()).To(Equal(clusterv1.MachinePoolPhasePending)) }) t.Run("Should set `Provisioning` when bootstrap is ready", func(t *testing.T) { @@ -182,7 +181,7 @@ func TestReconcileMachinePoolPhases(t *testing.T) { err = unstructured.SetNestedField(bootstrapConfig.Object, "secret-data", "status", "dataSecretName") g.Expect(err).ToNot(HaveOccurred()) - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fake.NewClientBuilder().WithObjects(defaultCluster, defaultKubeconfigSecret, machinepool, bootstrapConfig, infraConfig, builder.TestBootstrapConfigCRD, builder.TestInfrastructureMachineTemplateCRD).Build(), } @@ -191,7 +190,7 @@ func TestReconcileMachinePoolPhases(t *testing.T) { g.Expect(res.Requeue).To(BeFalse()) r.reconcilePhase(machinepool) - g.Expect(machinepool.Status.GetTypedPhase()).To(Equal(expv1.MachinePoolPhaseProvisioning)) + g.Expect(machinepool.Status.GetTypedPhase()).To(Equal(clusterv1.MachinePoolPhaseProvisioning)) }) t.Run("Should set `Running` when bootstrap and infra is ready", func(t *testing.T) { @@ -226,7 +225,7 @@ func TestReconcileMachinePoolPhases(t *testing.T) { machinepool.Status.NodeRefs = []corev1.ObjectReference{{Kind: "Node", Name: "machinepool-test-node"}} fakeClient := fake.NewClientBuilder().WithObjects(defaultCluster, defaultKubeconfigSecret, machinepool, bootstrapConfig, infraConfig, builder.TestBootstrapConfigCRD, builder.TestInfrastructureMachineTemplateCRD).Build() - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fakeClient, Tracker: remote.NewTestClusterCacheTracker(logr.New(log.NullLogSink{}), fakeClient, fakeClient, fakeClient.Scheme(), client.ObjectKey{Name: defaultCluster.Name, Namespace: defaultCluster.Namespace}), } @@ -239,7 +238,7 @@ func TestReconcileMachinePoolPhases(t *testing.T) { machinepool.Status.ReadyReplicas = 1 r.reconcilePhase(machinepool) - g.Expect(machinepool.Status.GetTypedPhase()).To(Equal(expv1.MachinePoolPhaseRunning)) + g.Expect(machinepool.Status.GetTypedPhase()).To(Equal(clusterv1.MachinePoolPhaseRunning)) }) t.Run("Should set `Running` when bootstrap, infra, and ready replicas equals spec replicas", func(t *testing.T) { @@ -283,7 +282,7 @@ func TestReconcileMachinePoolPhases(t *testing.T) { machinepool.Status.NodeRefs = []corev1.ObjectReference{{Kind: "Node", Name: "machinepool-test-node"}} fakeClient := fake.NewClientBuilder().WithObjects(defaultCluster, defaultKubeconfigSecret, machinepool, bootstrapConfig, infraConfig, builder.TestBootstrapConfigCRD, builder.TestInfrastructureMachineTemplateCRD).Build() - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fakeClient, Tracker: remote.NewTestClusterCacheTracker(logr.New(log.NullLogSink{}), fakeClient, fakeClient, fakeClient.Scheme(), client.ObjectKey{Name: defaultCluster.Name, Namespace: defaultCluster.Namespace}), } @@ -296,7 +295,7 @@ func TestReconcileMachinePoolPhases(t *testing.T) { machinepool.Status.ReadyReplicas = 1 r.reconcilePhase(machinepool) - g.Expect(machinepool.Status.GetTypedPhase()).To(Equal(expv1.MachinePoolPhaseRunning)) + g.Expect(machinepool.Status.GetTypedPhase()).To(Equal(clusterv1.MachinePoolPhaseRunning)) }) t.Run("Should set `Provisioned` when there is a NodeRef but infra is not ready ", func(t *testing.T) { @@ -317,7 +316,7 @@ func TestReconcileMachinePoolPhases(t *testing.T) { // Set NodeRef. machinepool.Status.NodeRefs = []corev1.ObjectReference{{Kind: "Node", Name: "machinepool-test-node"}} - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fake.NewClientBuilder().WithObjects(defaultCluster, defaultKubeconfigSecret, machinepool, bootstrapConfig, infraConfig, builder.TestBootstrapConfigCRD, builder.TestInfrastructureMachineTemplateCRD).Build(), } @@ -326,7 +325,7 @@ func TestReconcileMachinePoolPhases(t *testing.T) { g.Expect(res.Requeue).To(BeFalse()) r.reconcilePhase(machinepool) - g.Expect(machinepool.Status.GetTypedPhase()).To(Equal(expv1.MachinePoolPhaseProvisioned)) + g.Expect(machinepool.Status.GetTypedPhase()).To(Equal(clusterv1.MachinePoolPhaseProvisioned)) }) t.Run("Should set `ScalingUp` when infra is scaling up", func(t *testing.T) { @@ -358,7 +357,7 @@ func TestReconcileMachinePoolPhases(t *testing.T) { machinepool.Status.NodeRefs = []corev1.ObjectReference{{Kind: "Node", Name: "machinepool-test-node"}} fakeClient := fake.NewClientBuilder().WithObjects(defaultCluster, defaultKubeconfigSecret, machinepool, bootstrapConfig, infraConfig, builder.TestBootstrapConfigCRD, builder.TestInfrastructureMachineTemplateCRD).Build() - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fakeClient, Tracker: remote.NewTestClusterCacheTracker(logr.New(log.NullLogSink{}), fakeClient, fakeClient, fakeClient.Scheme(), client.ObjectKey{Name: defaultCluster.Name, Namespace: defaultCluster.Namespace}), } @@ -374,7 +373,7 @@ func TestReconcileMachinePoolPhases(t *testing.T) { machinepool.Spec.Replicas = ptr.To[int32](5) r.reconcilePhase(machinepool) - g.Expect(machinepool.Status.GetTypedPhase()).To(Equal(expv1.MachinePoolPhaseScalingUp)) + g.Expect(machinepool.Status.GetTypedPhase()).To(Equal(clusterv1.MachinePoolPhaseScalingUp)) }) t.Run("Should set `ScalingDown` when infra is scaling down", func(t *testing.T) { @@ -413,7 +412,7 @@ func TestReconcileMachinePoolPhases(t *testing.T) { } fakeClient := fake.NewClientBuilder().WithObjects(defaultCluster, defaultKubeconfigSecret, machinepool, bootstrapConfig, infraConfig, builder.TestBootstrapConfigCRD, builder.TestInfrastructureMachineTemplateCRD).Build() - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fakeClient, Tracker: remote.NewTestClusterCacheTracker(logr.New(log.NullLogSink{}), fakeClient, fakeClient, fakeClient.Scheme(), client.ObjectKey{Name: defaultCluster.Name, Namespace: defaultCluster.Namespace}), } @@ -429,7 +428,7 @@ func TestReconcileMachinePoolPhases(t *testing.T) { machinepool.Spec.Replicas = ptr.To[int32](1) r.reconcilePhase(machinepool) - g.Expect(machinepool.Status.GetTypedPhase()).To(Equal(expv1.MachinePoolPhaseScalingDown)) + g.Expect(machinepool.Status.GetTypedPhase()).To(Equal(clusterv1.MachinePoolPhaseScalingDown)) }) t.Run("Should set `Deleting` when MachinePool is being deleted", func(t *testing.T) { @@ -471,9 +470,9 @@ func TestReconcileMachinePoolPhases(t *testing.T) { // Set Deletion Timestamp. machinepool.SetDeletionTimestamp(&deletionTimestamp) - machinepool.Finalizers = []string{expv1.MachinePoolFinalizer} + machinepool.Finalizers = []string{clusterv1.MachinePoolFinalizer} - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fake.NewClientBuilder().WithObjects(defaultCluster, defaultKubeconfigSecret, machinepool, bootstrapConfig, infraConfig, builder.TestBootstrapConfigCRD, builder.TestInfrastructureMachineTemplateCRD).Build(), } @@ -482,7 +481,7 @@ func TestReconcileMachinePoolPhases(t *testing.T) { g.Expect(res.Requeue).To(BeFalse()) r.reconcilePhase(machinepool) - g.Expect(machinepool.Status.GetTypedPhase()).To(Equal(expv1.MachinePoolPhaseDeleting)) + g.Expect(machinepool.Status.GetTypedPhase()).To(Equal(clusterv1.MachinePoolPhaseDeleting)) }) t.Run("Should keep `Running` when MachinePool bootstrap config is changed to another ready one", func(t *testing.T) { @@ -530,7 +529,7 @@ func TestReconcileMachinePoolPhases(t *testing.T) { machinePool.Status.ReadyReplicas = 1 machinePool.Status.Replicas = 1 - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fake.NewClientBuilder().WithObjects(defaultCluster, defaultKubeconfigSecret, machinePool, bootstrapConfig, infraConfig, builder.TestBootstrapConfigCRD, builder.TestInfrastructureMachineTemplateCRD).Build(), } @@ -539,7 +538,7 @@ func TestReconcileMachinePoolPhases(t *testing.T) { g.Expect(res.Requeue).To(BeFalse()) r.reconcilePhase(machinePool) - g.Expect(machinePool.Status.GetTypedPhase()).To(Equal(expv1.MachinePoolPhaseRunning)) + g.Expect(machinePool.Status.GetTypedPhase()).To(Equal(clusterv1.MachinePoolPhaseRunning)) g.Expect(*machinePool.Spec.Template.Spec.Bootstrap.DataSecretName).To(Equal("secret-data")) // Change bootstrap reference. @@ -561,7 +560,7 @@ func TestReconcileMachinePoolPhases(t *testing.T) { r.reconcilePhase(machinePool) g.Expect(*machinePool.Spec.Template.Spec.Bootstrap.DataSecretName).To(Equal("secret-data-new")) g.Expect(machinePool.Status.BootstrapReady).To(BeTrue()) - g.Expect(machinePool.Status.GetTypedPhase()).To(Equal(expv1.MachinePoolPhaseRunning)) + g.Expect(machinePool.Status.GetTypedPhase()).To(Equal(clusterv1.MachinePoolPhaseRunning)) }) t.Run("Should keep `Running` when MachinePool bootstrap config is changed to a non-ready one", func(t *testing.T) { @@ -609,7 +608,7 @@ func TestReconcileMachinePoolPhases(t *testing.T) { machinePool.Status.ReadyReplicas = 1 machinePool.Status.Replicas = 1 - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fake.NewClientBuilder().WithObjects(defaultCluster, defaultKubeconfigSecret, machinePool, bootstrapConfig, infraConfig, builder.TestBootstrapConfigCRD, builder.TestInfrastructureMachineTemplateCRD).Build(), } @@ -618,7 +617,7 @@ func TestReconcileMachinePoolPhases(t *testing.T) { g.Expect(res.Requeue).To(BeFalse()) r.reconcilePhase(machinePool) - g.Expect(machinePool.Status.GetTypedPhase()).To(Equal(expv1.MachinePoolPhaseRunning)) + g.Expect(machinePool.Status.GetTypedPhase()).To(Equal(clusterv1.MachinePoolPhaseRunning)) g.Expect(*machinePool.Spec.Template.Spec.Bootstrap.DataSecretName).To(Equal("secret-data")) // Change bootstrap reference @@ -649,12 +648,12 @@ func TestReconcileMachinePoolPhases(t *testing.T) { // There is no phase defined for "changing to new bootstrap config", so it should still be `Running` the // old configuration - g.Expect(machinePool.Status.GetTypedPhase()).To(Equal(expv1.MachinePoolPhaseRunning)) + g.Expect(machinePool.Status.GetTypedPhase()).To(Equal(clusterv1.MachinePoolPhaseRunning)) }) } func TestReconcileMachinePoolBootstrap(t *testing.T) { - defaultMachinePool := expv1.MachinePool{ + defaultMachinePool := clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: "machinepool-test", Namespace: metav1.NamespaceDefault, @@ -662,7 +661,7 @@ func TestReconcileMachinePoolBootstrap(t *testing.T) { clusterv1.ClusterNameLabel: clusterName, }, }, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ Template: clusterv1.MachineTemplateSpec{ Spec: clusterv1.MachineSpec{ Bootstrap: clusterv1.Bootstrap{ @@ -687,10 +686,10 @@ func TestReconcileMachinePoolBootstrap(t *testing.T) { testCases := []struct { name string bootstrapConfig map[string]interface{} - machinepool *expv1.MachinePool + machinepool *clusterv1.MachinePool expectError bool expectResult ctrl.Result - expected func(g *WithT, m *expv1.MachinePool) + expected func(g *WithT, m *clusterv1.MachinePool) }{ { name: "new machinepool, bootstrap config ready with data", @@ -708,7 +707,7 @@ func TestReconcileMachinePoolBootstrap(t *testing.T) { }, }, expectError: false, - expected: func(g *WithT, m *expv1.MachinePool) { + expected: func(g *WithT, m *clusterv1.MachinePool) { g.Expect(m.Status.BootstrapReady).To(BeTrue()) g.Expect(m.Spec.Template.Spec.Bootstrap.DataSecretName).ToNot(BeNil()) g.Expect(*m.Spec.Template.Spec.Bootstrap.DataSecretName).To(ContainSubstring("secret-data")) @@ -729,7 +728,7 @@ func TestReconcileMachinePoolBootstrap(t *testing.T) { }, }, expectError: true, - expected: func(g *WithT, m *expv1.MachinePool) { + expected: func(g *WithT, m *clusterv1.MachinePool) { g.Expect(m.Status.BootstrapReady).To(BeFalse()) g.Expect(m.Spec.Template.Spec.Bootstrap.DataSecretName).To(BeNil()) }, @@ -748,7 +747,7 @@ func TestReconcileMachinePoolBootstrap(t *testing.T) { }, expectError: false, expectResult: ctrl.Result{}, - expected: func(g *WithT, m *expv1.MachinePool) { + expected: func(g *WithT, m *clusterv1.MachinePool) { g.Expect(m.Status.BootstrapReady).To(BeFalse()) }, }, @@ -765,7 +764,7 @@ func TestReconcileMachinePoolBootstrap(t *testing.T) { "status": map[string]interface{}{}, }, expectError: true, - expected: func(g *WithT, m *expv1.MachinePool) { + expected: func(g *WithT, m *clusterv1.MachinePool) { g.Expect(m.Status.BootstrapReady).To(BeFalse()) }, }, @@ -798,12 +797,12 @@ func TestReconcileMachinePoolBootstrap(t *testing.T) { "dataSecretName": "secret-data", }, }, - machinepool: &expv1.MachinePool{ + machinepool: &clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: "bootstrap-test-existing", Namespace: metav1.NamespaceDefault, }, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ Template: clusterv1.MachineTemplateSpec{ Spec: clusterv1.MachineSpec{ Bootstrap: clusterv1.Bootstrap{ @@ -817,12 +816,12 @@ func TestReconcileMachinePoolBootstrap(t *testing.T) { }, }, }, - Status: expv1.MachinePoolStatus{ + Status: clusterv1.MachinePoolStatus{ BootstrapReady: true, }, }, expectError: false, - expected: func(g *WithT, m *expv1.MachinePool) { + expected: func(g *WithT, m *clusterv1.MachinePool) { g.Expect(m.Status.BootstrapReady).To(BeTrue()) g.Expect(*m.Spec.Template.Spec.Bootstrap.DataSecretName).To(Equal("secret-data")) }, @@ -842,12 +841,12 @@ func TestReconcileMachinePoolBootstrap(t *testing.T) { "dataSecretName": "secret-data", }, }, - machinepool: &expv1.MachinePool{ + machinepool: &clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: "bootstrap-test-existing", Namespace: metav1.NamespaceDefault, }, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ Template: clusterv1.MachineTemplateSpec{ Spec: clusterv1.MachineSpec{ Bootstrap: clusterv1.Bootstrap{ @@ -856,12 +855,12 @@ func TestReconcileMachinePoolBootstrap(t *testing.T) { }, }, }, - Status: expv1.MachinePoolStatus{ + Status: clusterv1.MachinePoolStatus{ BootstrapReady: true, }, }, expectError: false, - expected: func(g *WithT, m *expv1.MachinePool) { + expected: func(g *WithT, m *clusterv1.MachinePool) { g.Expect(m.Status.BootstrapReady).To(BeTrue()) g.Expect(*m.Spec.Template.Spec.Bootstrap.DataSecretName).To(Equal("data")) }, @@ -881,12 +880,12 @@ func TestReconcileMachinePoolBootstrap(t *testing.T) { "data": "#!/bin/bash ... data", }, }, - machinepool: &expv1.MachinePool{ + machinepool: &clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: "bootstrap-test-existing", Namespace: metav1.NamespaceDefault, }, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ Template: clusterv1.MachineTemplateSpec{ Spec: clusterv1.MachineSpec{ Bootstrap: clusterv1.Bootstrap{ @@ -900,13 +899,13 @@ func TestReconcileMachinePoolBootstrap(t *testing.T) { }, }, }, - Status: expv1.MachinePoolStatus{ + Status: clusterv1.MachinePoolStatus{ BootstrapReady: false, }, }, expectError: false, expectResult: ctrl.Result{}, - expected: func(g *WithT, m *expv1.MachinePool) { + expected: func(g *WithT, m *clusterv1.MachinePool) { g.Expect(m.Status.BootstrapReady).To(BeFalse()) }, }, @@ -920,7 +919,7 @@ func TestReconcileMachinePoolBootstrap(t *testing.T) { } bootstrapConfig := &unstructured.Unstructured{Object: tc.bootstrapConfig} - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fake.NewClientBuilder().WithObjects(tc.machinepool, bootstrapConfig, builder.TestBootstrapConfigCRD, builder.TestInfrastructureMachineTemplateCRD).Build(), } @@ -940,7 +939,7 @@ func TestReconcileMachinePoolBootstrap(t *testing.T) { } func TestReconcileMachinePoolInfrastructure(t *testing.T) { - defaultMachinePool := expv1.MachinePool{ + defaultMachinePool := clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: "machinepool-test", Namespace: metav1.NamespaceDefault, @@ -948,7 +947,7 @@ func TestReconcileMachinePoolInfrastructure(t *testing.T) { clusterv1.ClusterNameLabel: clusterName, }, }, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ Replicas: ptr.To[int32](1), Template: clusterv1.MachineTemplateSpec{ Spec: clusterv1.MachineSpec{ @@ -980,11 +979,11 @@ func TestReconcileMachinePoolInfrastructure(t *testing.T) { name string bootstrapConfig map[string]interface{} infraConfig map[string]interface{} - machinepool *expv1.MachinePool + machinepool *clusterv1.MachinePool expectError bool expectChanged bool expectRequeueAfter bool - expected func(g *WithT, m *expv1.MachinePool) + expected func(g *WithT, m *clusterv1.MachinePool) }{ { name: "new machinepool, infrastructure config ready", @@ -1016,18 +1015,18 @@ func TestReconcileMachinePoolInfrastructure(t *testing.T) { }, expectError: false, expectChanged: true, - expected: func(g *WithT, m *expv1.MachinePool) { + expected: func(g *WithT, m *clusterv1.MachinePool) { g.Expect(m.Status.InfrastructureReady).To(BeTrue()) }, }, { name: "ready bootstrap, infra, and nodeRef, machinepool is running, infra object is deleted, expect failed", - machinepool: &expv1.MachinePool{ + machinepool: &clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: "machinepool-test", Namespace: metav1.NamespaceDefault, }, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ Replicas: ptr.To[int32](1), Template: clusterv1.MachineTemplateSpec{ Spec: clusterv1.MachineSpec{ @@ -1046,7 +1045,7 @@ func TestReconcileMachinePoolInfrastructure(t *testing.T) { }, }, }, - Status: expv1.MachinePoolStatus{ + Status: clusterv1.MachinePoolStatus{ BootstrapReady: true, InfrastructureReady: true, NodeRefs: []corev1.ObjectReference{{Kind: "Node", Name: "machinepool-test-node"}}, @@ -1072,11 +1071,11 @@ func TestReconcileMachinePoolInfrastructure(t *testing.T) { }, expectError: true, expectRequeueAfter: false, - expected: func(g *WithT, m *expv1.MachinePool) { + expected: func(g *WithT, m *clusterv1.MachinePool) { g.Expect(m.Status.InfrastructureReady).To(BeTrue()) g.Expect(m.Status.FailureMessage).ToNot(BeNil()) g.Expect(m.Status.FailureReason).ToNot(BeNil()) - g.Expect(m.Status.GetTypedPhase()).To(Equal(expv1.MachinePoolPhaseFailed)) + g.Expect(m.Status.GetTypedPhase()).To(Equal(clusterv1.MachinePoolPhaseFailed)) }, }, { @@ -1112,18 +1111,18 @@ func TestReconcileMachinePoolInfrastructure(t *testing.T) { }, expectError: false, expectChanged: false, - expected: func(g *WithT, m *expv1.MachinePool) { + expected: func(g *WithT, m *clusterv1.MachinePool) { g.Expect(m.Status.InfrastructureReady).To(BeFalse()) }, }, { name: "ready bootstrap, infra, and nodeRef, machinepool is running, replicas 0, providerIDList not set", - machinepool: &expv1.MachinePool{ + machinepool: &clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: "machinepool-test", Namespace: metav1.NamespaceDefault, }, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ Replicas: ptr.To[int32](0), Template: clusterv1.MachineTemplateSpec{ Spec: clusterv1.MachineSpec{ @@ -1142,7 +1141,7 @@ func TestReconcileMachinePoolInfrastructure(t *testing.T) { }, }, }, - Status: expv1.MachinePoolStatus{ + Status: clusterv1.MachinePoolStatus{ BootstrapReady: true, InfrastructureReady: true, NodeRefs: []corev1.ObjectReference{{Kind: "Node", Name: "machinepool-test-node"}}, @@ -1187,14 +1186,14 @@ func TestReconcileMachinePoolInfrastructure(t *testing.T) { }, expectError: false, expectRequeueAfter: false, - expected: func(g *WithT, m *expv1.MachinePool) { + expected: func(g *WithT, m *clusterv1.MachinePool) { g.Expect(m.Status.InfrastructureReady).To(BeTrue()) g.Expect(m.Status.ReadyReplicas).To(Equal(int32(0))) g.Expect(m.Status.AvailableReplicas).To(Equal(int32(0))) g.Expect(m.Status.UnavailableReplicas).To(Equal(int32(0))) g.Expect(m.Status.FailureMessage).To(BeNil()) g.Expect(m.Status.FailureReason).To(BeNil()) - g.Expect(m.Status.GetTypedPhase()).To(Equal(expv1.MachinePoolPhaseRunning)) + g.Expect(m.Status.GetTypedPhase()).To(Equal(clusterv1.MachinePoolPhaseRunning)) }, }, } @@ -1208,7 +1207,7 @@ func TestReconcileMachinePoolInfrastructure(t *testing.T) { } infraConfig := &unstructured.Unstructured{Object: tc.infraConfig} - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fake.NewClientBuilder().WithObjects(tc.machinepool, infraConfig, builder.TestBootstrapConfigCRD, builder.TestInfrastructureMachineTemplateCRD).Build(), } @@ -1285,7 +1284,7 @@ func TestReconcileMachinePoolMachines(t *testing.T) { } g.Expect(env.Create(ctx, &unstructured.Unstructured{Object: infraConfig})).To(Succeed()) - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: env, ssaCache: ssa.NewCache(), } @@ -1346,7 +1345,7 @@ func TestReconcileMachinePoolMachines(t *testing.T) { } g.Expect(env.Create(ctx, &unstructured.Unstructured{Object: infraConfig})).To(Succeed()) - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: env, ssaCache: ssa.NewCache(), } @@ -1401,7 +1400,7 @@ func TestReconcileMachinePoolMachines(t *testing.T) { } g.Expect(env.Create(ctx, &unstructured.Unstructured{Object: infraConfig})).To(Succeed()) - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: env, ssaCache: ssa.NewCache(), } @@ -1422,7 +1421,7 @@ func TestReconcileMachinePoolMachines(t *testing.T) { } func TestInfraMachineToMachinePoolMapper(t *testing.T) { - machinePool1 := expv1.MachinePool{ + machinePool1 := clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: "machinepool-1", Namespace: metav1.NamespaceDefault, @@ -1432,7 +1431,7 @@ func TestInfraMachineToMachinePoolMapper(t *testing.T) { }, } - machinePool2 := expv1.MachinePool{ + machinePool2 := clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: "machinepool-2", Namespace: "other-namespace", @@ -1442,7 +1441,7 @@ func TestInfraMachineToMachinePoolMapper(t *testing.T) { }, } - machinePool3 := expv1.MachinePool{ + machinePool3 := clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: "machinepool-3", Namespace: metav1.NamespaceDefault, @@ -1452,7 +1451,7 @@ func TestInfraMachineToMachinePoolMapper(t *testing.T) { }, } - machinePoolLongName := expv1.MachinePool{ + machinePoolLongName := clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: "machinepool-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long", // Use a name longer than 64 characters to trigger a hash Namespace: metav1.NamespaceDefault, @@ -1510,13 +1509,13 @@ func TestInfraMachineToMachinePoolMapper(t *testing.T) { testCases := []struct { name string infraMachine *unstructured.Unstructured - machinepools []expv1.MachinePool - expectedMachinePool *expv1.MachinePool + machinepools []clusterv1.MachinePool + expectedMachinePool *clusterv1.MachinePool }{ { name: "match machinePool name with label value", infraMachine: &infraMachine1, - machinepools: []expv1.MachinePool{ + machinepools: []clusterv1.MachinePool{ machinePool1, machinePool2, machinePool3, @@ -1527,7 +1526,7 @@ func TestInfraMachineToMachinePoolMapper(t *testing.T) { { name: "match hash of machinePool name with label hash", infraMachine: &infraMachine2, - machinepools: []expv1.MachinePool{ + machinepools: []clusterv1.MachinePool{ machinePool1, machinePool2, machinePool3, @@ -1538,7 +1537,7 @@ func TestInfraMachineToMachinePoolMapper(t *testing.T) { { name: "return nil if no machinePool matches", infraMachine: &infraMachine3, - machinepools: []expv1.MachinePool{ + machinepools: []clusterv1.MachinePool{ machinePool1, machinePool2, machinePool3, @@ -1558,7 +1557,7 @@ func TestInfraMachineToMachinePoolMapper(t *testing.T) { objs = append(objs, mp.DeepCopy()) } - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fake.NewClientBuilder().WithObjects(objs...).Build(), } @@ -1593,12 +1592,12 @@ func TestReconcileMachinePoolScaleToFromZero(t *testing.T) { g.Expect(env.CleanupAndWait(ctx, do...)).To(Succeed()) }(testCluster) - defaultMachinePool := expv1.MachinePool{ + defaultMachinePool := clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: "machinepool-test", Namespace: ns.Name, }, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ ClusterName: testCluster.Name, Template: clusterv1.MachineTemplateSpec{ Spec: clusterv1.MachineSpec{ @@ -1618,7 +1617,7 @@ func TestReconcileMachinePoolScaleToFromZero(t *testing.T) { }, MinReadySeconds: ptr.To[int32](0), }, - Status: expv1.MachinePoolStatus{}, + Status: clusterv1.MachinePoolStatus{}, } defaultBootstrap := &unstructured.Unstructured{ @@ -1695,7 +1694,7 @@ func TestReconcileMachinePoolScaleToFromZero(t *testing.T) { g.Expect(err).ToNot(HaveOccurred()) fakeClient := fake.NewClientBuilder().WithObjects(testCluster, kubeconfigSecret, machinepool, bootstrapConfig, infraConfig, builder.TestBootstrapConfigCRD, builder.TestInfrastructureMachineTemplateCRD).Build() - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fakeClient, Tracker: remote.NewTestClusterCacheTracker(logr.New(log.NullLogSink{}), env.GetClient(), env.GetClient(), env.GetClient().Scheme(), client.ObjectKey{Name: testCluster.Name, Namespace: testCluster.Namespace}), recorder: record.NewFakeRecorder(32), @@ -1707,7 +1706,7 @@ func TestReconcileMachinePoolScaleToFromZero(t *testing.T) { r.reconcilePhase(machinepool) - g.Expect(machinepool.Status.GetTypedPhase()).To(Equal(expv1.MachinePoolPhaseScalingDown)) + g.Expect(machinepool.Status.GetTypedPhase()).To(Equal(clusterv1.MachinePoolPhaseScalingDown)) delNode := &corev1.Node{} g.Expect(env.Get(ctx, client.ObjectKeyFromObject(node), delNode)).To(Succeed()) @@ -1752,7 +1751,7 @@ func TestReconcileMachinePoolScaleToFromZero(t *testing.T) { g.Expect(err).ToNot(HaveOccurred()) fakeClient := fake.NewClientBuilder().WithObjects(testCluster, kubeconfigSecret, machinepool, bootstrapConfig, infraConfig, builder.TestBootstrapConfigCRD, builder.TestInfrastructureMachineTemplateCRD).Build() - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fakeClient, Tracker: remote.NewTestClusterCacheTracker(logr.New(log.NullLogSink{}), env.GetClient(), env.GetClient(), env.GetClient().Scheme(), client.ObjectKey{Name: testCluster.Name, Namespace: testCluster.Namespace}), recorder: record.NewFakeRecorder(32), @@ -1763,7 +1762,7 @@ func TestReconcileMachinePoolScaleToFromZero(t *testing.T) { g.Expect(res.Requeue).To(BeFalse()) r.reconcilePhase(machinepool) - g.Expect(machinepool.Status.GetTypedPhase()).To(Equal(expv1.MachinePoolPhaseRunning)) + g.Expect(machinepool.Status.GetTypedPhase()).To(Equal(clusterv1.MachinePoolPhaseRunning)) delNode := &corev1.Node{} err = env.GetAPIReader().Get(ctx, client.ObjectKeyFromObject(node), delNode) @@ -1791,7 +1790,7 @@ func TestReconcileMachinePoolScaleToFromZero(t *testing.T) { err := unstructured.SetNestedField(infraConfig.Object, int64(0), "status", "replicas") g.Expect(err).ToNot(HaveOccurred()) - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fake.NewClientBuilder().WithObjects(testCluster, kubeconfigSecret, machinepool, bootstrapConfig, infraConfig, builder.TestBootstrapConfigCRD, builder.TestInfrastructureMachineTemplateCRD).Build(), recorder: record.NewFakeRecorder(32), } @@ -1802,7 +1801,7 @@ func TestReconcileMachinePoolScaleToFromZero(t *testing.T) { r.reconcilePhase(machinepool) - g.Expect(machinepool.Status.GetTypedPhase()).To(Equal(expv1.MachinePoolPhaseRunning)) + g.Expect(machinepool.Status.GetTypedPhase()).To(Equal(clusterv1.MachinePoolPhaseRunning)) }) t.Run("Should set `ScalingUp` when scaling from zero to one", func(t *testing.T) { @@ -1825,7 +1824,7 @@ func TestReconcileMachinePoolScaleToFromZero(t *testing.T) { err := unstructured.SetNestedField(infraConfig.Object, int64(0), "status", "replicas") g.Expect(err).ToNot(HaveOccurred()) - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fake.NewClientBuilder().WithObjects(testCluster, kubeconfigSecret, machinepool, bootstrapConfig, infraConfig, builder.TestBootstrapConfigCRD, builder.TestInfrastructureMachineTemplateCRD).Build(), recorder: record.NewFakeRecorder(32), } @@ -1836,7 +1835,7 @@ func TestReconcileMachinePoolScaleToFromZero(t *testing.T) { r.reconcilePhase(machinepool) - g.Expect(machinepool.Status.GetTypedPhase()).To(Equal(expv1.MachinePoolPhaseScalingUp)) + g.Expect(machinepool.Status.GetTypedPhase()).To(Equal(clusterv1.MachinePoolPhaseScalingUp)) }) t.Run("Should set `Running` when scaled from zero to one", func(t *testing.T) { @@ -1882,7 +1881,7 @@ func TestReconcileMachinePoolScaleToFromZero(t *testing.T) { g.Expect(err).ToNot(HaveOccurred()) fakeClient := fake.NewClientBuilder().WithObjects(testCluster, kubeconfigSecret, machinepool, bootstrapConfig, infraConfig, builder.TestBootstrapConfigCRD, builder.TestInfrastructureMachineTemplateCRD).Build() - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fakeClient, Tracker: remote.NewTestClusterCacheTracker(logr.New(log.NullLogSink{}), env.GetClient(), env.GetClient(), env.GetClient().Scheme(), client.ObjectKey{Name: testCluster.Name, Namespace: testCluster.Namespace}), recorder: record.NewFakeRecorder(32), @@ -1894,7 +1893,7 @@ func TestReconcileMachinePoolScaleToFromZero(t *testing.T) { r.reconcilePhase(machinepool) - g.Expect(machinepool.Status.GetTypedPhase()).To(Equal(expv1.MachinePoolPhaseRunning)) + g.Expect(machinepool.Status.GetTypedPhase()).To(Equal(clusterv1.MachinePoolPhaseRunning)) delNode := &corev1.Node{} g.Expect(env.Get(ctx, client.ObjectKeyFromObject(node), delNode)).To(Succeed()) @@ -1954,8 +1953,8 @@ func getMachines(replicas int, mpName, clusterName, nsName string) []clusterv1.M return machines } -func getMachinePool(replicas int, mpName, clusterName, nsName string) expv1.MachinePool { - return expv1.MachinePool{ +func getMachinePool(replicas int, mpName, clusterName, nsName string) clusterv1.MachinePool { + return clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: mpName, Namespace: nsName, @@ -1963,7 +1962,7 @@ func getMachinePool(replicas int, mpName, clusterName, nsName string) expv1.Mach clusterv1.ClusterNameLabel: clusterName, }, }, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ ClusterName: clusterName, Replicas: ptr.To[int32](int32(replicas)), Template: clusterv1.MachineTemplateSpec{ diff --git a/exp/internal/controllers/machinepool_controller_test.go b/internal/controllers/machinepool/machinepool_controller_test.go similarity index 90% rename from exp/internal/controllers/machinepool_controller_test.go rename to internal/controllers/machinepool/machinepool_controller_test.go index 731ad55b0200..096f886aff63 100644 --- a/exp/internal/controllers/machinepool_controller_test.go +++ b/internal/controllers/machinepool/machinepool_controller_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package controllers +package machinepool import ( "testing" @@ -31,7 +31,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/internal/test/builder" "sigs.k8s.io/cluster-api/util" "sigs.k8s.io/cluster-api/util/conditions" @@ -46,12 +45,12 @@ func TestMachinePoolFinalizer(t *testing.T) { }, } - machinePoolValidCluster := &expv1.MachinePool{ + machinePoolValidCluster := &clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: "machinePool1", Namespace: metav1.NamespaceDefault, }, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ Replicas: ptr.To[int32](1), Template: clusterv1.MachineTemplateSpec{ Spec: clusterv1.MachineSpec{ @@ -64,13 +63,13 @@ func TestMachinePoolFinalizer(t *testing.T) { }, } - machinePoolWithFinalizer := &expv1.MachinePool{ + machinePoolWithFinalizer := &clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: "machinePool2", Namespace: metav1.NamespaceDefault, Finalizers: []string{"some-other-finalizer"}, }, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ Replicas: ptr.To[int32](1), Template: clusterv1.MachineTemplateSpec{ Spec: clusterv1.MachineSpec{ @@ -86,7 +85,7 @@ func TestMachinePoolFinalizer(t *testing.T) { testCases := []struct { name string request reconcile.Request - m *expv1.MachinePool + m *clusterv1.MachinePool expectedFinalizers []string }{ { @@ -95,7 +94,7 @@ func TestMachinePoolFinalizer(t *testing.T) { NamespacedName: util.ObjectKey(machinePoolValidCluster), }, m: machinePoolValidCluster, - expectedFinalizers: []string{expv1.MachinePoolFinalizer}, + expectedFinalizers: []string{clusterv1.MachinePoolFinalizer}, }, { name: "should append the machinePool finalizer to the machinePool if it already has a finalizer", @@ -103,7 +102,7 @@ func TestMachinePoolFinalizer(t *testing.T) { NamespacedName: util.ObjectKey(machinePoolWithFinalizer), }, m: machinePoolWithFinalizer, - expectedFinalizers: []string{"some-other-finalizer", expv1.MachinePoolFinalizer}, + expectedFinalizers: []string{"some-other-finalizer", clusterv1.MachinePoolFinalizer}, }, } @@ -111,7 +110,7 @@ func TestMachinePoolFinalizer(t *testing.T) { t.Run(tc.name, func(t *testing.T) { g := NewWithT(t) - mr := &MachinePoolReconciler{ + mr := &Reconciler{ Client: fake.NewClientBuilder().WithObjects( clusterCorrectMeta, machinePoolValidCluster, @@ -122,7 +121,7 @@ func TestMachinePoolFinalizer(t *testing.T) { _, _ = mr.Reconcile(ctx, tc.request) key := client.ObjectKey{Namespace: tc.m.Namespace, Name: tc.m.Name} - var actual expv1.MachinePool + var actual clusterv1.MachinePool if len(tc.expectedFinalizers) > 0 { g.Expect(mr.Client.Get(ctx, key, &actual)).To(Succeed()) g.Expect(actual.Finalizers).ToNot(BeEmpty()) @@ -141,23 +140,23 @@ func TestMachinePoolOwnerReference(t *testing.T) { ObjectMeta: metav1.ObjectMeta{Namespace: metav1.NamespaceDefault, Name: "test-cluster"}, } - machinePoolInvalidCluster := &expv1.MachinePool{ + machinePoolInvalidCluster := &clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: "machinePool1", Namespace: metav1.NamespaceDefault, }, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ Replicas: ptr.To[int32](1), ClusterName: "invalid", }, } - machinePoolValidCluster := &expv1.MachinePool{ + machinePoolValidCluster := &clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: "machinePool2", Namespace: metav1.NamespaceDefault, }, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ Replicas: ptr.To[int32](1), Template: clusterv1.MachineTemplateSpec{ Spec: clusterv1.MachineSpec{ @@ -170,7 +169,7 @@ func TestMachinePoolOwnerReference(t *testing.T) { }, } - machinePoolValidMachinePool := &expv1.MachinePool{ + machinePoolValidMachinePool := &clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: "machinePool3", Namespace: metav1.NamespaceDefault, @@ -178,7 +177,7 @@ func TestMachinePoolOwnerReference(t *testing.T) { clusterv1.ClusterNameLabel: "valid-cluster", }, }, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ Replicas: ptr.To[int32](1), Template: clusterv1.MachineTemplateSpec{ Spec: clusterv1.MachineSpec{ @@ -194,7 +193,7 @@ func TestMachinePoolOwnerReference(t *testing.T) { testCases := []struct { name string request reconcile.Request - m *expv1.MachinePool + m *clusterv1.MachinePool expectedOR []metav1.OwnerReference }{ { @@ -223,21 +222,21 @@ func TestMachinePoolOwnerReference(t *testing.T) { machinePoolInvalidCluster, machinePoolValidCluster, machinePoolValidMachinePool, - ).WithStatusSubresource(&expv1.MachinePool{}).Build() - mr := &MachinePoolReconciler{ + ).WithStatusSubresource(&clusterv1.MachinePool{}).Build() + mr := &Reconciler{ Client: fakeClient, APIReader: fakeClient, } key := client.ObjectKey{Namespace: tc.m.Namespace, Name: tc.m.Name} - var actual expv1.MachinePool + var actual clusterv1.MachinePool // this first requeue is to add finalizer result, err := mr.Reconcile(ctx, tc.request) g.Expect(err).ToNot(HaveOccurred()) g.Expect(result).To(BeComparableTo(ctrl.Result{})) g.Expect(mr.Client.Get(ctx, key, &actual)).To(Succeed()) - g.Expect(actual.Finalizers).To(ContainElement(expv1.MachinePoolFinalizer)) + g.Expect(actual.Finalizers).To(ContainElement(clusterv1.MachinePoolFinalizer)) _, _ = mr.Reconcile(ctx, tc.request) @@ -300,17 +299,17 @@ func TestReconcileMachinePoolRequest(t *testing.T) { err bool } testCases := []struct { - machinePool expv1.MachinePool + machinePool clusterv1.MachinePool expected expected }{ { - machinePool: expv1.MachinePool{ + machinePool: clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: "created", Namespace: metav1.NamespaceDefault, - Finalizers: []string{expv1.MachinePoolFinalizer}, + Finalizers: []string{clusterv1.MachinePoolFinalizer}, }, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ ClusterName: "test-cluster", ProviderIDList: []string{"test://id-1"}, Replicas: ptr.To[int32](1), @@ -326,7 +325,7 @@ func TestReconcileMachinePoolRequest(t *testing.T) { }, }, }, - Status: expv1.MachinePoolStatus{ + Status: clusterv1.MachinePoolStatus{ Replicas: 1, ReadyReplicas: 1, NodeRefs: []corev1.ObjectReference{ @@ -341,13 +340,13 @@ func TestReconcileMachinePoolRequest(t *testing.T) { }, }, { - machinePool: expv1.MachinePool{ + machinePool: clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: "updated", Namespace: metav1.NamespaceDefault, - Finalizers: []string{expv1.MachinePoolFinalizer}, + Finalizers: []string{clusterv1.MachinePoolFinalizer}, }, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ ClusterName: "test-cluster", ProviderIDList: []string{"test://id-1"}, Replicas: ptr.To[int32](1), @@ -362,7 +361,7 @@ func TestReconcileMachinePoolRequest(t *testing.T) { }, }, }, - Status: expv1.MachinePoolStatus{ + Status: clusterv1.MachinePoolStatus{ Replicas: 1, ReadyReplicas: 1, NodeRefs: []corev1.ObjectReference{ @@ -377,17 +376,17 @@ func TestReconcileMachinePoolRequest(t *testing.T) { }, }, { - machinePool: expv1.MachinePool{ + machinePool: clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: "deleted", Namespace: metav1.NamespaceDefault, Labels: map[string]string{ clusterv1.MachineControlPlaneLabel: "", }, - Finalizers: []string{expv1.MachinePoolFinalizer}, + Finalizers: []string{clusterv1.MachinePoolFinalizer}, DeletionTimestamp: &time, }, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ ClusterName: "test-cluster", Replicas: ptr.To[int32](1), Template: clusterv1.MachineTemplateSpec{ @@ -421,9 +420,9 @@ func TestReconcileMachinePoolRequest(t *testing.T) { bootstrapConfig, builder.TestBootstrapConfigCRD, builder.TestInfrastructureMachineTemplateCRD, - ).WithStatusSubresource(&expv1.MachinePool{}).Build() + ).WithStatusSubresource(&clusterv1.MachinePool{}).Build() - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: clientFake, APIReader: clientFake, } @@ -467,12 +466,12 @@ func TestReconcileMachinePoolDeleteExternal(t *testing.T) { }, } - machinePool := &expv1.MachinePool{ + machinePool := &clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: "delete", Namespace: metav1.NamespaceDefault, }, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ ClusterName: "test-cluster", Replicas: ptr.To[int32](1), Template: clusterv1.MachineTemplateSpec{ @@ -544,7 +543,7 @@ func TestReconcileMachinePoolDeleteExternal(t *testing.T) { objs = append(objs, infraConfig) } - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fake.NewClientBuilder().WithObjects(objs...).Build(), } @@ -568,14 +567,14 @@ func TestRemoveMachinePoolFinalizerAfterDeleteReconcile(t *testing.T) { ObjectMeta: metav1.ObjectMeta{Namespace: metav1.NamespaceDefault, Name: "test-cluster"}, } - m := &expv1.MachinePool{ + m := &clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: "delete123", Namespace: metav1.NamespaceDefault, - Finalizers: []string{expv1.MachinePoolFinalizer, "test"}, + Finalizers: []string{clusterv1.MachinePoolFinalizer, "test"}, DeletionTimestamp: &dt, }, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ ClusterName: "test-cluster", Replicas: ptr.To[int32](1), Template: clusterv1.MachineTemplateSpec{ @@ -591,13 +590,13 @@ func TestRemoveMachinePoolFinalizerAfterDeleteReconcile(t *testing.T) { }, } key := client.ObjectKey{Namespace: m.Namespace, Name: m.Name} - mr := &MachinePoolReconciler{ - Client: fake.NewClientBuilder().WithObjects(testCluster, m).WithStatusSubresource(&expv1.MachinePool{}).Build(), + mr := &Reconciler{ + Client: fake.NewClientBuilder().WithObjects(testCluster, m).WithStatusSubresource(&clusterv1.MachinePool{}).Build(), } _, err := mr.Reconcile(ctx, reconcile.Request{NamespacedName: key}) g.Expect(err).ToNot(HaveOccurred()) - var actual expv1.MachinePool + var actual clusterv1.MachinePool g.Expect(mr.Client.Get(ctx, key, &actual)).To(Succeed()) g.Expect(actual.ObjectMeta.Finalizers).To(Equal([]string{"test"})) } @@ -646,13 +645,13 @@ func TestMachinePoolConditions(t *testing.T) { } } - machinePool := &expv1.MachinePool{ + machinePool := &clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Name: "blah", Namespace: metav1.NamespaceDefault, - Finalizers: []string{expv1.MachinePoolFinalizer}, + Finalizers: []string{clusterv1.MachinePoolFinalizer}, }, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ ClusterName: "test-cluster", Replicas: ptr.To[int32](2), Template: clusterv1.MachineTemplateSpec{ @@ -702,16 +701,16 @@ func TestMachinePoolConditions(t *testing.T) { bootstrapReady bool infrastructureReady bool expectError bool - beforeFunc func(bootstrap, infra *unstructured.Unstructured, mp *expv1.MachinePool, nodeList *corev1.NodeList) + beforeFunc func(bootstrap, infra *unstructured.Unstructured, mp *clusterv1.MachinePool, nodeList *corev1.NodeList) conditionAssertFunc func(t *testing.T, getter conditions.Getter) }{ { name: "all conditions true", bootstrapReady: true, infrastructureReady: true, - beforeFunc: func(_, _ *unstructured.Unstructured, mp *expv1.MachinePool, _ *corev1.NodeList) { + beforeFunc: func(_, _ *unstructured.Unstructured, mp *clusterv1.MachinePool, _ *corev1.NodeList) { mp.Spec.ProviderIDList = []string{"azure://westus2/id-node-4", "aws://us-east-1/id-node-1"} - mp.Status = expv1.MachinePoolStatus{ + mp.Status = clusterv1.MachinePoolStatus{ NodeRefs: []corev1.ObjectReference{ {Name: "node-1"}, {Name: "azure-node-4"}, @@ -734,7 +733,7 @@ func TestMachinePoolConditions(t *testing.T) { name: "boostrap not ready", bootstrapReady: false, infrastructureReady: true, - beforeFunc: func(bootstrap, _ *unstructured.Unstructured, _ *expv1.MachinePool, _ *corev1.NodeList) { + beforeFunc: func(bootstrap, _ *unstructured.Unstructured, _ *clusterv1.MachinePool, _ *corev1.NodeList) { addConditionsToExternal(bootstrap, clusterv1.Conditions{ { Type: clusterv1.ReadyCondition, @@ -775,7 +774,7 @@ func TestMachinePoolConditions(t *testing.T) { name: "infrastructure not ready", bootstrapReady: true, infrastructureReady: false, - beforeFunc: func(_, infra *unstructured.Unstructured, _ *expv1.MachinePool, _ *corev1.NodeList) { + beforeFunc: func(_, infra *unstructured.Unstructured, _ *clusterv1.MachinePool, _ *corev1.NodeList) { addConditionsToExternal(infra, clusterv1.Conditions{ { Type: clusterv1.ReadyCondition, @@ -817,7 +816,7 @@ func TestMachinePoolConditions(t *testing.T) { name: "incorrect infrastructure reference", bootstrapReady: true, expectError: true, - beforeFunc: func(_, _ *unstructured.Unstructured, mp *expv1.MachinePool, _ *corev1.NodeList) { + beforeFunc: func(_, _ *unstructured.Unstructured, mp *clusterv1.MachinePool, _ *corev1.NodeList) { mp.Spec.Template.Spec.InfrastructureRef = corev1.ObjectReference{ APIVersion: builder.InfrastructureGroupVersion.String(), Kind: builder.TestInfrastructureMachineTemplateKind, @@ -859,9 +858,9 @@ func TestMachinePoolConditions(t *testing.T) { &nodes.Items[1], builder.TestBootstrapConfigCRD, builder.TestInfrastructureMachineTemplateCRD, - ).WithStatusSubresource(&expv1.MachinePool{}).Build() + ).WithStatusSubresource(&clusterv1.MachinePool{}).Build() - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: clientFake, APIReader: clientFake, } @@ -871,7 +870,7 @@ func TestMachinePoolConditions(t *testing.T) { g.Expect(err).ToNot(HaveOccurred()) } - m := &expv1.MachinePool{} + m := &clusterv1.MachinePool{} machinePoolKey := client.ObjectKeyFromObject(machinePool) g.Expect(r.Client.Get(ctx, machinePoolKey, m)).ToNot(HaveOccurred()) diff --git a/exp/internal/controllers/suite_test.go b/internal/controllers/machinepool/suite_test.go similarity index 95% rename from exp/internal/controllers/suite_test.go rename to internal/controllers/machinepool/suite_test.go index 93194d2f8361..21139166c232 100644 --- a/exp/internal/controllers/suite_test.go +++ b/internal/controllers/machinepool/suite_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package controllers +package machinepool import ( "context" @@ -42,7 +42,7 @@ func TestMain(m *testing.M) { } setupReconcilers := func(ctx context.Context, mgr ctrl.Manager) { - machinePoolReconciler := MachinePoolReconciler{ + machinePoolReconciler := Reconciler{ Client: mgr.GetClient(), recorder: mgr.GetEventRecorderFor("machinepool-controller"), } diff --git a/internal/controllers/topology/cluster/cluster_controller.go b/internal/controllers/topology/cluster/cluster_controller.go index c3415c4b8426..1f82794a14f0 100644 --- a/internal/controllers/topology/cluster/cluster_controller.go +++ b/internal/controllers/topology/cluster/cluster_controller.go @@ -37,7 +37,6 @@ import ( "sigs.k8s.io/cluster-api/api/v1beta1/index" "sigs.k8s.io/cluster-api/controllers/external" "sigs.k8s.io/cluster-api/controllers/remote" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" runtimecatalog "sigs.k8s.io/cluster-api/exp/runtime/catalog" runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1" "sigs.k8s.io/cluster-api/exp/topology/desiredstate" @@ -104,7 +103,7 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt builder.WithPredicates(predicates.ResourceIsTopologyOwned(ctrl.LoggerFrom(ctx))), ). Watches( - &expv1.MachinePool{}, + &clusterv1.MachinePool{}, handler.EnqueueRequestsFromMapFunc(r.machinePoolToCluster), // Only trigger Cluster reconciliation if the MachinePool is topology owned. builder.WithPredicates(predicates.ResourceIsTopologyOwned(ctrl.LoggerFrom(ctx))), @@ -378,7 +377,7 @@ func (r *Reconciler) machineDeploymentToCluster(_ context.Context, o client.Obje // machinePoolToCluster is a handler.ToRequestsFunc to be used to enqueue requests for reconciliation // for Cluster to update when one of its own MachinePools gets updated. func (r *Reconciler) machinePoolToCluster(_ context.Context, o client.Object) []ctrl.Request { - mp, ok := o.(*expv1.MachinePool) + mp, ok := o.(*clusterv1.MachinePool) if !ok { panic(fmt.Sprintf("Expected a MachinePool but got a %T", o)) } diff --git a/internal/controllers/topology/cluster/cluster_controller_test.go b/internal/controllers/topology/cluster/cluster_controller_test.go index 972f3b42120a..94200ce166ae 100644 --- a/internal/controllers/topology/cluster/cluster_controller_test.go +++ b/internal/controllers/topology/cluster/cluster_controller_test.go @@ -34,7 +34,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" runtimev1 "sigs.k8s.io/cluster-api/exp/runtime/api/v1alpha1" runtimecatalog "sigs.k8s.io/cluster-api/exp/runtime/catalog" runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1" @@ -1082,13 +1081,13 @@ func assertMachineDeploymentsReconcile(cluster *clusterv1.Cluster) error { // 4) Have the correct Kind/APIVersion and Labels/Annotations for BoostrapRef and InfrastructureRef templates. func assertMachinePoolsReconcile(cluster *clusterv1.Cluster) error { // List all created machine pools to assert the expected numbers are created. - machinePools := &expv1.MachinePoolList{} + machinePools := &clusterv1.MachinePoolList{} if err := env.List(ctx, machinePools, client.InNamespace(cluster.Namespace)); err != nil { return err } // clusterMPs will hold the MachinePools that have labels associating them with the cluster. - clusterMPs := []expv1.MachinePool{} + clusterMPs := []clusterv1.MachinePool{} // Run through all machine pools and add only those with the TopologyOwnedLabel and the correct // ClusterNameLabel to the items for further testing. diff --git a/internal/controllers/topology/cluster/conditions_test.go b/internal/controllers/topology/cluster/conditions_test.go index d19f84e75275..b0603a24cd15 100644 --- a/internal/controllers/topology/cluster/conditions_test.go +++ b/internal/controllers/topology/cluster/conditions_test.go @@ -265,7 +265,7 @@ func TestReconcileTopologyReconciledCondition(t *testing.T) { "mp0": &scope.MachinePoolState{ Object: builder.MachinePool("ns1", "mp0-abc123"). WithReplicas(2). - WithStatus(expv1.MachinePoolStatus{ + WithStatus(clusterv1.MachinePoolStatus{ Replicas: int32(1), ReadyReplicas: int32(1), AvailableReplicas: int32(1), @@ -355,7 +355,7 @@ func TestReconcileTopologyReconciledCondition(t *testing.T) { "mp0": &scope.MachinePoolState{ Object: builder.MachinePool("ns1", "mp0-abc123"). WithReplicas(2). - WithStatus(expv1.MachinePoolStatus{ + WithStatus(clusterv1.MachinePoolStatus{ Replicas: int32(2), ReadyReplicas: int32(2), AvailableReplicas: int32(2), @@ -446,7 +446,7 @@ func TestReconcileTopologyReconciledCondition(t *testing.T) { "mp0": &scope.MachinePoolState{ Object: builder.MachinePool("ns1", "mp0-abc123"). WithReplicas(2). - WithStatus(expv1.MachinePoolStatus{ + WithStatus(clusterv1.MachinePoolStatus{ Replicas: int32(2), ReadyReplicas: int32(2), AvailableReplicas: int32(2), @@ -695,7 +695,7 @@ func TestReconcileTopologyReconciledCondition(t *testing.T) { Object: builder.MachinePool("ns1", "mp0-abc123"). WithReplicas(2). WithVersion("v1.22.0"). - WithStatus(expv1.MachinePoolStatus{ + WithStatus(clusterv1.MachinePoolStatus{ // mp is not ready because we don't have 2 updated, ready and available replicas. Replicas: int32(2), ReadyReplicas: int32(1), @@ -708,7 +708,7 @@ func TestReconcileTopologyReconciledCondition(t *testing.T) { Object: builder.MachinePool("ns1", "mp1-abc123"). WithReplicas(2). WithVersion("v1.21.2"). - WithStatus(expv1.MachinePoolStatus{ + WithStatus(clusterv1.MachinePoolStatus{ Replicas: int32(2), ReadyReplicas: int32(2), AvailableReplicas: int32(2), @@ -823,7 +823,7 @@ func TestReconcileTopologyReconciledCondition(t *testing.T) { Object: builder.MachinePool("ns1", "mp0-abc123"). WithReplicas(2). WithVersion("v1.22.0"). - WithStatus(expv1.MachinePoolStatus{ + WithStatus(clusterv1.MachinePoolStatus{ Replicas: int32(2), ReadyReplicas: int32(2), AvailableReplicas: int32(2), @@ -835,7 +835,7 @@ func TestReconcileTopologyReconciledCondition(t *testing.T) { Object: builder.MachinePool("ns1", "mp1-abc123"). WithReplicas(2). WithVersion("v1.21.2"). - WithStatus(expv1.MachinePoolStatus{ + WithStatus(clusterv1.MachinePoolStatus{ Replicas: int32(2), ReadyReplicas: int32(2), AvailableReplicas: int32(2), @@ -908,7 +908,7 @@ func TestReconcileTopologyReconciledCondition(t *testing.T) { Object: builder.MachinePool("ns1", "mp0-abc123"). WithReplicas(2). WithVersion("v1.22.0"). - WithStatus(expv1.MachinePoolStatus{ + WithStatus(clusterv1.MachinePoolStatus{ Replicas: int32(1), ReadyReplicas: int32(1), AvailableReplicas: int32(1), @@ -920,7 +920,7 @@ func TestReconcileTopologyReconciledCondition(t *testing.T) { Object: builder.MachinePool("ns1", "mp1-abc123"). WithReplicas(2). WithVersion("v1.22.0"). - WithStatus(expv1.MachinePoolStatus{ + WithStatus(clusterv1.MachinePoolStatus{ Replicas: int32(2), ReadyReplicas: int32(2), AvailableReplicas: int32(2), diff --git a/internal/controllers/topology/cluster/current_state.go b/internal/controllers/topology/cluster/current_state.go index fb359b9af917..fb51e74ee9e9 100644 --- a/internal/controllers/topology/cluster/current_state.go +++ b/internal/controllers/topology/cluster/current_state.go @@ -28,7 +28,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/exp/topology/scope" "sigs.k8s.io/cluster-api/internal/contract" tlog "sigs.k8s.io/cluster-api/internal/log" @@ -292,7 +291,7 @@ func (r *Reconciler) getCurrentMachinePoolState(ctx context.Context, blueprintMa // Note: This is a cached list call. We ensure in reconcile_state that the cache is up-to-date // after we create/update a MachinePool and we double-check if an MP already exists before // we create it. - mp := &expv1.MachinePoolList{} + mp := &clusterv1.MachinePoolList{} err := r.Client.List(ctx, mp, client.MatchingLabels{ clusterv1.ClusterNameLabel: cluster.Name, diff --git a/internal/controllers/topology/cluster/patches/engine.go b/internal/controllers/topology/cluster/patches/engine.go index 963b220cc8d9..339383e5351e 100644 --- a/internal/controllers/topology/cluster/patches/engine.go +++ b/internal/controllers/topology/cluster/patches/engine.go @@ -29,7 +29,6 @@ import ( "k8s.io/klog/v2" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1" "sigs.k8s.io/cluster-api/exp/topology/scope" "sigs.k8s.io/cluster-api/feature" @@ -240,7 +239,7 @@ func getMDTopologyFromMD(blueprint *scope.ClusterBlueprint, md *clusterv1.Machin return mdTopology, nil } -func getMPTopologyFromMP(blueprint *scope.ClusterBlueprint, mp *expv1.MachinePool) (*clusterv1.MachinePoolTopology, error) { +func getMPTopologyFromMP(blueprint *scope.ClusterBlueprint, mp *clusterv1.MachinePool) (*clusterv1.MachinePoolTopology, error) { topologyName, ok := mp.Labels[clusterv1.ClusterTopologyMachinePoolNameLabel] if !ok { return nil, errors.Errorf("failed to get topology name for %s", klog.KObj(mp)) @@ -355,7 +354,7 @@ func createRequest(blueprint *scope.ClusterBlueprint, desired *scope.ClusterStat // Add the BootstrapTemplate. t, err := newRequestItemBuilder(mpClass.BootstrapTemplate). - WithHolder(mp.Object, expv1.GroupVersion.WithKind("MachinePool"), "spec.template.spec.bootstrap.configRef"). + WithHolder(mp.Object, clusterv1.GroupVersion.WithKind("MachinePool"), "spec.template.spec.bootstrap.configRef"). Build() if err != nil { return nil, errors.Wrapf(err, "failed to prepare BootstrapConfig template %s for MachinePool topology %s for patching", @@ -365,7 +364,7 @@ func createRequest(blueprint *scope.ClusterBlueprint, desired *scope.ClusterStat // Add the InfrastructureMachineTemplate. t, err = newRequestItemBuilder(mpClass.InfrastructureMachinePoolTemplate). - WithHolder(mp.Object, expv1.GroupVersion.WithKind("MachinePool"), "spec.template.spec.infrastructureRef"). + WithHolder(mp.Object, clusterv1.GroupVersion.WithKind("MachinePool"), "spec.template.spec.infrastructureRef"). Build() if err != nil { return nil, errors.Wrapf(err, "failed to prepare InfrastructureMachinePoolTemplate %s for MachinePool topology %s for patching", diff --git a/internal/controllers/topology/cluster/patches/variables/variables.go b/internal/controllers/topology/cluster/patches/variables/variables.go index 9d3cd1ac7a68..37b82cc2fada 100644 --- a/internal/controllers/topology/cluster/patches/variables/variables.go +++ b/internal/controllers/topology/cluster/patches/variables/variables.go @@ -26,7 +26,6 @@ import ( "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1" "sigs.k8s.io/cluster-api/internal/contract" ) @@ -206,7 +205,7 @@ func MachineDeployment(mdTopology *clusterv1.MachineDeploymentTopology, md *clus } // MachinePool returns variables that apply to templates belonging to a MachinePool. -func MachinePool(mpTopology *clusterv1.MachinePoolTopology, mp *expv1.MachinePool, mpBootstrapObject, mpInfrastructureMachinePool *unstructured.Unstructured, definitionFrom string, patchVariableDefinitions map[string]bool) ([]runtimehooksv1.Variable, error) { +func MachinePool(mpTopology *clusterv1.MachinePoolTopology, mp *clusterv1.MachinePool, mpBootstrapObject, mpInfrastructureMachinePool *unstructured.Unstructured, definitionFrom string, patchVariableDefinitions map[string]bool) ([]runtimehooksv1.Variable, error) { variables := []runtimehooksv1.Variable{} // Add variables overrides for the MachinePool. diff --git a/internal/controllers/topology/cluster/patches/variables/variables_test.go b/internal/controllers/topology/cluster/patches/variables/variables_test.go index f564df166393..3bf26b4e6712 100644 --- a/internal/controllers/topology/cluster/patches/variables/variables_test.go +++ b/internal/controllers/topology/cluster/patches/variables/variables_test.go @@ -28,7 +28,6 @@ import ( "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1" "sigs.k8s.io/cluster-api/internal/test/builder" ) @@ -1010,7 +1009,7 @@ func TestMachinePool(t *testing.T) { mpTopology *clusterv1.MachinePoolTopology forPatch string variableDefinitionsForPatch map[string]bool - mp *expv1.MachinePool + mp *clusterv1.MachinePool mpBootstrapConfig *unstructured.Unstructured mpInfrastructureMachinePool *unstructured.Unstructured want []runtimehooksv1.Variable diff --git a/internal/controllers/topology/cluster/reconcile_state.go b/internal/controllers/topology/cluster/reconcile_state.go index cd6de9a44299..c2314ebdb6a4 100644 --- a/internal/controllers/topology/cluster/reconcile_state.go +++ b/internal/controllers/topology/cluster/reconcile_state.go @@ -36,7 +36,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1" "sigs.k8s.io/cluster-api/exp/topology/scope" "sigs.k8s.io/cluster-api/feature" @@ -875,7 +874,7 @@ func (r *Reconciler) reconcileMachinePools(ctx context.Context, s *scope.Scope) func (r *Reconciler) getCurrentMachinePools(ctx context.Context, s *scope.Scope) (sets.Set[string], error) { // TODO: We should consider using PartialObjectMetadataList here. Currently this doesn't work as our // implementation for topology dryrun doesn't support PartialObjectMetadataList. - mpList := &expv1.MachinePoolList{} + mpList := &clusterv1.MachinePoolList{} err := r.APIReader.List(ctx, mpList, client.MatchingLabels{ clusterv1.ClusterNameLabel: s.Current.Cluster.Name, @@ -983,7 +982,7 @@ func (r *Reconciler) createMachinePool(ctx context.Context, s *scope.Scope, mp * // miss a newly created MachinePool (because the cache might be stale). err = wait.PollUntilContextTimeout(ctx, 5*time.Millisecond, 5*time.Second, true, func(ctx context.Context) (bool, error) { key := client.ObjectKey{Namespace: mp.Object.Namespace, Name: mp.Object.Name} - if err := r.Client.Get(ctx, key, &expv1.MachinePool{}); err != nil { + if err := r.Client.Get(ctx, key, &clusterv1.MachinePool{}); err != nil { if apierrors.IsNotFound(err) { return false, nil } @@ -1058,7 +1057,7 @@ func (r *Reconciler) updateMachinePool(ctx context.Context, s *scope.Scope, curr // version here guarantees that we see the changes of our own update. err = wait.PollUntilContextTimeout(ctx, 5*time.Millisecond, 5*time.Second, true, func(ctx context.Context) (bool, error) { key := client.ObjectKey{Namespace: currentMP.Object.GetNamespace(), Name: currentMP.Object.GetName()} - cachedMP := &expv1.MachinePool{} + cachedMP := &clusterv1.MachinePool{} if err := r.Client.Get(ctx, key, cachedMP); err != nil { return false, err } @@ -1072,7 +1071,7 @@ func (r *Reconciler) updateMachinePool(ctx context.Context, s *scope.Scope, curr return nil } -func logMachinePoolVersionChange(current, desired *expv1.MachinePool) string { +func logMachinePoolVersionChange(current, desired *clusterv1.MachinePool) string { if current.Spec.Template.Spec.Version == nil || desired.Spec.Template.Spec.Version == nil { return "" } diff --git a/internal/controllers/topology/cluster/reconcile_state_test.go b/internal/controllers/topology/cluster/reconcile_state_test.go index bdd250f2c97b..b1df3070438c 100644 --- a/internal/controllers/topology/cluster/reconcile_state_test.go +++ b/internal/controllers/topology/cluster/reconcile_state_test.go @@ -40,7 +40,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/webhook/admission" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" runtimev1 "sigs.k8s.io/cluster-api/exp/runtime/api/v1alpha1" runtimecatalog "sigs.k8s.io/cluster-api/exp/runtime/catalog" runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1" @@ -2639,7 +2638,7 @@ func TestReconcileMachinePools(t *testing.T) { } g.Expect(err).ToNot(HaveOccurred()) - var gotMachinePoolList expv1.MachinePoolList + var gotMachinePoolList clusterv1.MachinePoolList g.Expect(env.GetAPIReader().List(ctx, &gotMachinePoolList, &client.ListOptions{Namespace: namespace.GetName()})).To(Succeed()) g.Expect(gotMachinePoolList.Items).To(HaveLen(len(tt.want))) diff --git a/internal/log/log.go b/internal/log/log.go index ca349e6e4b36..bc540618e2b2 100644 --- a/internal/log/log.go +++ b/internal/log/log.go @@ -28,7 +28,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" ) // LoggerFrom returns a logger with predefined values from a context.Context. @@ -62,7 +61,7 @@ type Logger interface { WithMachineDeployment(md *clusterv1.MachineDeployment) Logger // WithMachinePool adds to the logger information about the MachinePool object being processed. - WithMachinePool(mp *expv1.MachinePool) Logger + WithMachinePool(mp *clusterv1.MachinePool) Logger // WithValues adds key-value pairs of context to a logger. WithValues(keysAndValues ...interface{}) Logger @@ -128,7 +127,7 @@ func (l *topologyReconcileLogger) WithMachineDeployment(md *clusterv1.MachineDep } // WithMachinePool adds to the logger information about the MachinePool object being processed. -func (l *topologyReconcileLogger) WithMachinePool(mp *expv1.MachinePool) Logger { +func (l *topologyReconcileLogger) WithMachinePool(mp *clusterv1.MachinePool) Logger { topologyName := mp.Labels[clusterv1.ClusterTopologyMachinePoolNameLabel] return &topologyReconcileLogger{ Logger: l.Logger.WithValues( diff --git a/internal/test/builder/builders.go b/internal/test/builder/builders.go index 01a131f053f7..6b40f00b9e02 100644 --- a/internal/test/builder/builders.go +++ b/internal/test/builder/builders.go @@ -26,7 +26,6 @@ import ( "k8s.io/apimachinery/pkg/util/intstr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" ) // ClusterBuilder holds the variables and objects required to build a clusterv1.Cluster. @@ -1532,7 +1531,7 @@ type MachinePoolBuilder struct { clusterName string replicas *int32 labels map[string]string - status *expv1.MachinePoolStatus + status *clusterv1.MachinePoolStatus minReadySeconds *int32 } @@ -1581,7 +1580,7 @@ func (m *MachinePoolBuilder) WithReplicas(replicas int32) *MachinePoolBuilder { } // WithStatus sets the passed status object as the status of the MachinePool object. -func (m *MachinePoolBuilder) WithStatus(status expv1.MachinePoolStatus) *MachinePoolBuilder { +func (m *MachinePoolBuilder) WithStatus(status clusterv1.MachinePoolStatus) *MachinePoolBuilder { m.status = &status return m } @@ -1593,18 +1592,18 @@ func (m *MachinePoolBuilder) WithMinReadySeconds(minReadySeconds int32) *Machine } // Build creates a new MachinePool with the variables and objects passed to the MachinePoolBuilder. -func (m *MachinePoolBuilder) Build() *expv1.MachinePool { - obj := &expv1.MachinePool{ +func (m *MachinePoolBuilder) Build() *clusterv1.MachinePool { + obj := &clusterv1.MachinePool{ TypeMeta: metav1.TypeMeta{ Kind: "MachinePool", - APIVersion: expv1.GroupVersion.String(), + APIVersion: clusterv1.GroupVersion.String(), }, ObjectMeta: metav1.ObjectMeta{ Name: m.name, Namespace: m.namespace, Labels: m.labels, }, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ ClusterName: m.clusterName, Replicas: m.replicas, MinReadySeconds: m.minReadySeconds, diff --git a/internal/test/builder/zz_generated.deepcopy.go b/internal/test/builder/zz_generated.deepcopy.go index 8f597138b106..fb7bedf465ba 100644 --- a/internal/test/builder/zz_generated.deepcopy.go +++ b/internal/test/builder/zz_generated.deepcopy.go @@ -24,7 +24,6 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" "sigs.k8s.io/cluster-api/api/v1beta1" - apiv1beta1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -646,7 +645,7 @@ func (in *MachinePoolBuilder) DeepCopyInto(out *MachinePoolBuilder) { } if in.status != nil { in, out := &in.status, &out.status - *out = new(apiv1beta1.MachinePoolStatus) + *out = new(v1beta1.MachinePoolStatus) (*in).DeepCopyInto(*out) } if in.minReadySeconds != nil { diff --git a/internal/test/envtest/environment.go b/internal/test/envtest/environment.go index 6e33d91f76ff..28fc7f68446d 100644 --- a/internal/test/envtest/environment.go +++ b/internal/test/envtest/environment.go @@ -61,7 +61,6 @@ import ( ipamv1 "sigs.k8s.io/cluster-api/exp/ipam/api/v1beta1" expipamwebhooks "sigs.k8s.io/cluster-api/exp/ipam/webhooks" runtimev1 "sigs.k8s.io/cluster-api/exp/runtime/api/v1alpha1" - expapiwebhooks "sigs.k8s.io/cluster-api/exp/webhooks" "sigs.k8s.io/cluster-api/internal/test/builder" internalwebhooks "sigs.k8s.io/cluster-api/internal/webhooks" runtimewebhooks "sigs.k8s.io/cluster-api/internal/webhooks/runtime" @@ -317,7 +316,7 @@ func newEnvironment(uncachedObjs ...client.Object) *Environment { if err := (&addonswebhooks.ClusterResourceSetBinding{}).SetupWebhookWithManager(mgr); err != nil { klog.Fatalf("unable to create webhook for ClusterResourceSetBinding: %+v", err) } - if err := (&expapiwebhooks.MachinePool{}).SetupWebhookWithManager(mgr); err != nil { + if err := (&webhooks.MachinePool{}).SetupWebhookWithManager(mgr); err != nil { klog.Fatalf("unable to create webhook for machinepool: %+v", err) } if err := (&runtimewebhooks.ExtensionConfig{}).SetupWebhookWithManager(mgr); err != nil { diff --git a/internal/topology/check/upgrade.go b/internal/topology/check/upgrade.go index affb359cbf11..e4a1d56d8799 100644 --- a/internal/topology/check/upgrade.go +++ b/internal/topology/check/upgrade.go @@ -26,7 +26,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" ) // IsMachineDeploymentUpgrading determines if the MachineDeployment is upgrading. @@ -63,7 +62,7 @@ func IsMachineDeploymentUpgrading(ctx context.Context, c client.Reader, md *clus // IsMachinePoolUpgrading determines if the MachinePool is upgrading. // A machine pool is considered upgrading if at least one of the Machines of this // MachinePool has a different version. -func IsMachinePoolUpgrading(ctx context.Context, c client.Reader, mp *expv1.MachinePool) (bool, error) { +func IsMachinePoolUpgrading(ctx context.Context, c client.Reader, mp *clusterv1.MachinePool) (bool, error) { // If the MachinePool has no version there is no definitive way to check if it is upgrading. Therefore, return false. // Note: This case should not happen. if mp.Spec.Template.Spec.Version == nil { diff --git a/internal/topology/check/upgrade_test.go b/internal/topology/check/upgrade_test.go index 601343ef9c07..cc6254523eb9 100644 --- a/internal/topology/check/upgrade_test.go +++ b/internal/topology/check/upgrade_test.go @@ -28,7 +28,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client/fake" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/internal/test/builder" ) @@ -124,7 +123,7 @@ func TestIsMachinePoolUpgrading(t *testing.T) { tests := []struct { name string - mp *expv1.MachinePool + mp *clusterv1.MachinePool nodes []*corev1.Node want bool wantErr bool @@ -134,7 +133,7 @@ func TestIsMachinePoolUpgrading(t *testing.T) { mp: builder.MachinePool("ns", "mp1"). WithClusterName("cluster1"). WithVersion("v1.2.3"). - WithStatus(expv1.MachinePoolStatus{ + WithStatus(clusterv1.MachinePoolStatus{ NodeRefs: []corev1.ObjectReference{ {Name: "node1"}, {Name: "node2"}, @@ -162,7 +161,7 @@ func TestIsMachinePoolUpgrading(t *testing.T) { mp: builder.MachinePool("ns", "mp1"). WithClusterName("cluster1"). WithVersion("v1.2.3"). - WithStatus(expv1.MachinePoolStatus{ + WithStatus(clusterv1.MachinePoolStatus{ NodeRefs: []corev1.ObjectReference{ {Name: "node1"}, {Name: "node2"}, @@ -190,7 +189,7 @@ func TestIsMachinePoolUpgrading(t *testing.T) { mp: builder.MachinePool("ns", "mp1"). WithClusterName("cluster1"). WithVersion("v1.2.3"). - WithStatus(expv1.MachinePoolStatus{ + WithStatus(clusterv1.MachinePoolStatus{ NodeRefs: []corev1.ObjectReference{}}). Build(), nodes: []*corev1.Node{}, diff --git a/internal/webhooks/cluster.go b/internal/webhooks/cluster.go index 0f066af8c68b..204505f794cd 100644 --- a/internal/webhooks/cluster.go +++ b/internal/webhooks/cluster.go @@ -40,7 +40,6 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/controllers/external" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/feature" "sigs.k8s.io/cluster-api/internal/contract" "sigs.k8s.io/cluster-api/internal/topology/check" @@ -566,7 +565,7 @@ func validateTopologyMachineDeploymentVersions(ctx context.Context, ctrlClient c func validateTopologyMachinePoolVersions(ctx context.Context, ctrlClient client.Reader, tracker ClusterCacheTrackerReader, oldCluster *clusterv1.Cluster, oldVersion semver.Version) error { // List all the machine pools in the current cluster and in a managed topology. // FROM: current_state.go getCurrentMachinePoolState - mps := &expv1.MachinePoolList{} + mps := &clusterv1.MachinePoolList{} err := ctrlClient.List(ctx, mps, client.MatchingLabels{ clusterv1.ClusterNameLabel: oldCluster.Name, diff --git a/internal/webhooks/cluster_test.go b/internal/webhooks/cluster_test.go index ede22d3f79c8..8b61e6e95d62 100644 --- a/internal/webhooks/cluster_test.go +++ b/internal/webhooks/cluster_test.go @@ -36,7 +36,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client/interceptor" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/feature" "sigs.k8s.io/cluster-api/internal/test/builder" "sigs.k8s.io/cluster-api/internal/webhooks/util" @@ -3148,7 +3147,7 @@ func Test_validateTopologyMachinePoolVersions(t *testing.T) { clusterv1.ClusterNameLabel: "cluster1", clusterv1.ClusterTopologyOwnedLabel: "", clusterv1.ClusterTopologyMachinePoolNameLabel: "pool1", - }).WithVersion("v1.19.1").WithStatus(expv1.MachinePoolStatus{NodeRefs: []corev1.ObjectReference{{Name: "mp-node-1"}}}).Build(), + }).WithVersion("v1.19.1").WithStatus(clusterv1.MachinePoolStatus{NodeRefs: []corev1.ObjectReference{{Name: "mp-node-1"}}}).Build(), }, workloadObjects: []client.Object{ &corev1.Node{ @@ -3175,7 +3174,7 @@ func Test_validateTopologyMachinePoolVersions(t *testing.T) { clusterv1.ClusterNameLabel: "cluster1", clusterv1.ClusterTopologyOwnedLabel: "", clusterv1.ClusterTopologyMachinePoolNameLabel: "pool1", - }).WithVersion("v1.19.1").WithStatus(expv1.MachinePoolStatus{NodeRefs: []corev1.ObjectReference{{Name: "mp-node-1"}}}).Build(), + }).WithVersion("v1.19.1").WithStatus(clusterv1.MachinePoolStatus{NodeRefs: []corev1.ObjectReference{{Name: "mp-node-1"}}}).Build(), }, workloadObjects: []client.Object{}, }, diff --git a/exp/internal/webhooks/machinepool.go b/internal/webhooks/machinepool.go similarity index 95% rename from exp/internal/webhooks/machinepool.go rename to internal/webhooks/machinepool.go index 5f52e091a1ee..f61829ea65f8 100644 --- a/exp/internal/webhooks/machinepool.go +++ b/internal/webhooks/machinepool.go @@ -33,7 +33,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/webhook/admission" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/feature" "sigs.k8s.io/cluster-api/util/version" ) @@ -44,7 +43,7 @@ func (webhook *MachinePool) SetupWebhookWithManager(mgr ctrl.Manager) error { } return ctrl.NewWebhookManagedBy(mgr). - For(&expv1.MachinePool{}). + For(&clusterv1.MachinePool{}). WithDefaulter(webhook). WithValidator(webhook). Complete() @@ -63,7 +62,7 @@ var _ webhook.CustomDefaulter = &MachinePool{} // Default implements webhook.Defaulter so a webhook will be registered for the type. func (webhook *MachinePool) Default(ctx context.Context, obj runtime.Object) error { - m, ok := obj.(*expv1.MachinePool) + m, ok := obj.(*clusterv1.MachinePool) if !ok { return apierrors.NewBadRequest(fmt.Sprintf("expected a MachinePool but got a %T", obj)) } @@ -76,9 +75,9 @@ func (webhook *MachinePool) Default(ctx context.Context, obj runtime.Object) err if req.DryRun != nil { dryRun = *req.DryRun } - var oldMP *expv1.MachinePool + var oldMP *clusterv1.MachinePool if req.Operation == v1.Update { - oldMP = &expv1.MachinePool{} + oldMP = &clusterv1.MachinePool{} if err := webhook.decoder.DecodeRaw(req.OldObject, oldMP); err != nil { return errors.Wrapf(err, "failed to decode oldObject to MachinePool") } @@ -118,7 +117,7 @@ func (webhook *MachinePool) Default(ctx context.Context, obj runtime.Object) err // ValidateCreate implements webhook.Validator so a webhook will be registered for the type. func (webhook *MachinePool) ValidateCreate(_ context.Context, obj runtime.Object) (admission.Warnings, error) { - mp, ok := obj.(*expv1.MachinePool) + mp, ok := obj.(*clusterv1.MachinePool) if !ok { return nil, apierrors.NewBadRequest(fmt.Sprintf("expected a MachinePool but got a %T", obj)) } @@ -128,11 +127,11 @@ func (webhook *MachinePool) ValidateCreate(_ context.Context, obj runtime.Object // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type. func (webhook *MachinePool) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) { - oldMP, ok := oldObj.(*expv1.MachinePool) + oldMP, ok := oldObj.(*clusterv1.MachinePool) if !ok { return nil, apierrors.NewBadRequest(fmt.Sprintf("expected a MachinePool but got a %T", oldObj)) } - newMP, ok := newObj.(*expv1.MachinePool) + newMP, ok := newObj.(*clusterv1.MachinePool) if !ok { return nil, apierrors.NewBadRequest(fmt.Sprintf("expected a MachinePool but got a %T", newObj)) } @@ -141,7 +140,7 @@ func (webhook *MachinePool) ValidateUpdate(_ context.Context, oldObj, newObj run // ValidateDelete implements webhook.Validator so a webhook will be registered for the type. func (webhook *MachinePool) ValidateDelete(_ context.Context, obj runtime.Object) (admission.Warnings, error) { - mp, ok := obj.(*expv1.MachinePool) + mp, ok := obj.(*clusterv1.MachinePool) if !ok { return nil, apierrors.NewBadRequest(fmt.Sprintf("expected a MachinePool but got a %T", obj)) } @@ -149,7 +148,7 @@ func (webhook *MachinePool) ValidateDelete(_ context.Context, obj runtime.Object return nil, webhook.validate(nil, mp) } -func (webhook *MachinePool) validate(oldObj, newObj *expv1.MachinePool) error { +func (webhook *MachinePool) validate(oldObj, newObj *clusterv1.MachinePool) error { // NOTE: MachinePool is behind MachinePool feature gate flag; the web hook // must prevent creating newObj objects when the feature flag is disabled. specPath := field.NewPath("spec") @@ -216,7 +215,7 @@ func (webhook *MachinePool) validate(oldObj, newObj *expv1.MachinePool) error { return apierrors.NewInvalid(clusterv1.GroupVersion.WithKind("MachinePool").GroupKind(), newObj.Name, allErrs) } -func calculateMachinePoolReplicas(ctx context.Context, oldMP *expv1.MachinePool, newMP *expv1.MachinePool, dryRun bool) (int32, error) { +func calculateMachinePoolReplicas(ctx context.Context, oldMP *clusterv1.MachinePool, newMP *clusterv1.MachinePool, dryRun bool) (int32, error) { // If replicas is already set => Keep the current value. if newMP.Spec.Replicas != nil { return *newMP.Spec.Replicas, nil diff --git a/exp/internal/webhooks/machinepool_test.go b/internal/webhooks/machinepool_test.go similarity index 91% rename from exp/internal/webhooks/machinepool_test.go rename to internal/webhooks/machinepool_test.go index 61fbc53b75ed..7a4f01a540f0 100644 --- a/exp/internal/webhooks/machinepool_test.go +++ b/internal/webhooks/machinepool_test.go @@ -25,24 +25,20 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/utils/ptr" - ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/webhook/admission" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/internal/webhooks/util" ) -var ctx = ctrl.SetupSignalHandler() - func TestMachinePoolDefault(t *testing.T) { g := NewWithT(t) - mp := &expv1.MachinePool{ + mp := &clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Namespace: "foobar", }, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ Template: clusterv1.MachineTemplateSpec{ Spec: clusterv1.MachineSpec{ Bootstrap: clusterv1.Bootstrap{ConfigRef: &corev1.ObjectReference{}}, @@ -67,15 +63,15 @@ func TestMachinePoolDefault(t *testing.T) { func TestCalculateMachinePoolReplicas(t *testing.T) { tests := []struct { name string - newMP *expv1.MachinePool - oldMP *expv1.MachinePool + newMP *clusterv1.MachinePool + oldMP *clusterv1.MachinePool expectedReplicas int32 expectErr bool }{ { name: "if new MP has replicas set, keep that value", - newMP: &expv1.MachinePool{ - Spec: expv1.MachinePoolSpec{ + newMP: &clusterv1.MachinePool{ + Spec: clusterv1.MachinePoolSpec{ Replicas: ptr.To[int32](5), }, }, @@ -83,12 +79,12 @@ func TestCalculateMachinePoolReplicas(t *testing.T) { }, { name: "if new MP does not have replicas set and no annotations, use 1", - newMP: &expv1.MachinePool{}, + newMP: &clusterv1.MachinePool{}, expectedReplicas: 1, }, { name: "if new MP only has min size annotation, fallback to 1", - newMP: &expv1.MachinePool{ + newMP: &clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ clusterv1.AutoscalerMinSizeAnnotation: "3", @@ -99,7 +95,7 @@ func TestCalculateMachinePoolReplicas(t *testing.T) { }, { name: "if new MP only has max size annotation, fallback to 1", - newMP: &expv1.MachinePool{ + newMP: &clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ clusterv1.AutoscalerMaxSizeAnnotation: "7", @@ -110,7 +106,7 @@ func TestCalculateMachinePoolReplicas(t *testing.T) { }, { name: "if new MP has min and max size annotation and min size is invalid, fail", - newMP: &expv1.MachinePool{ + newMP: &clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ clusterv1.AutoscalerMinSizeAnnotation: "abc", @@ -122,7 +118,7 @@ func TestCalculateMachinePoolReplicas(t *testing.T) { }, { name: "if new MP has min and max size annotation and max size is invalid, fail", - newMP: &expv1.MachinePool{ + newMP: &clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ clusterv1.AutoscalerMinSizeAnnotation: "3", @@ -134,7 +130,7 @@ func TestCalculateMachinePoolReplicas(t *testing.T) { }, { name: "if new MP has min and max size annotation and new MP is a new MP, use min size", - newMP: &expv1.MachinePool{ + newMP: &clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ clusterv1.AutoscalerMinSizeAnnotation: "3", @@ -146,7 +142,7 @@ func TestCalculateMachinePoolReplicas(t *testing.T) { }, { name: "if new MP has min and max size annotation and old MP doesn't have replicas set, use min size", - newMP: &expv1.MachinePool{ + newMP: &clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ clusterv1.AutoscalerMinSizeAnnotation: "3", @@ -154,12 +150,12 @@ func TestCalculateMachinePoolReplicas(t *testing.T) { }, }, }, - oldMP: &expv1.MachinePool{}, + oldMP: &clusterv1.MachinePool{}, expectedReplicas: 3, }, { name: "if new MP has min and max size annotation and old MP replicas is below min size, use min size", - newMP: &expv1.MachinePool{ + newMP: &clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ clusterv1.AutoscalerMinSizeAnnotation: "3", @@ -167,8 +163,8 @@ func TestCalculateMachinePoolReplicas(t *testing.T) { }, }, }, - oldMP: &expv1.MachinePool{ - Spec: expv1.MachinePoolSpec{ + oldMP: &clusterv1.MachinePool{ + Spec: clusterv1.MachinePoolSpec{ Replicas: ptr.To[int32](1), }, }, @@ -176,7 +172,7 @@ func TestCalculateMachinePoolReplicas(t *testing.T) { }, { name: "if new MP has min and max size annotation and old MP replicas is above max size, use max size", - newMP: &expv1.MachinePool{ + newMP: &clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ clusterv1.AutoscalerMinSizeAnnotation: "3", @@ -184,8 +180,8 @@ func TestCalculateMachinePoolReplicas(t *testing.T) { }, }, }, - oldMP: &expv1.MachinePool{ - Spec: expv1.MachinePoolSpec{ + oldMP: &clusterv1.MachinePool{ + Spec: clusterv1.MachinePoolSpec{ Replicas: ptr.To[int32](15), }, }, @@ -193,7 +189,7 @@ func TestCalculateMachinePoolReplicas(t *testing.T) { }, { name: "if new MP has min and max size annotation and old MP replicas is between min and max size, use old MP replicas", - newMP: &expv1.MachinePool{ + newMP: &clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ clusterv1.AutoscalerMinSizeAnnotation: "3", @@ -201,8 +197,8 @@ func TestCalculateMachinePoolReplicas(t *testing.T) { }, }, }, - oldMP: &expv1.MachinePool{ - Spec: expv1.MachinePoolSpec{ + oldMP: &clusterv1.MachinePool{ + Spec: clusterv1.MachinePoolSpec{ Replicas: ptr.To[int32](4), }, }, @@ -254,8 +250,8 @@ func TestMachinePoolBootstrapValidation(t *testing.T) { t.Run(tt.name, func(t *testing.T) { g := NewWithT(t) webhook := &MachinePool{} - mp := &expv1.MachinePool{ - Spec: expv1.MachinePoolSpec{ + mp := &clusterv1.MachinePool{ + Spec: clusterv1.MachinePoolSpec{ Template: clusterv1.MachineTemplateSpec{ Spec: clusterv1.MachineSpec{ Bootstrap: tt.bootstrap, @@ -326,9 +322,9 @@ func TestMachinePoolNamespaceValidation(t *testing.T) { g := NewWithT(t) webhook := &MachinePool{} - mp := &expv1.MachinePool{ + mp := &clusterv1.MachinePool{ ObjectMeta: metav1.ObjectMeta{Namespace: tt.namespace}, - Spec: expv1.MachinePoolSpec{ + Spec: clusterv1.MachinePoolSpec{ Template: clusterv1.MachineTemplateSpec{ Spec: clusterv1.MachineSpec{ Bootstrap: tt.bootstrap, @@ -382,8 +378,8 @@ func TestMachinePoolClusterNameImmutable(t *testing.T) { t.Run(tt.name, func(t *testing.T) { g := NewWithT(t) - newMP := &expv1.MachinePool{ - Spec: expv1.MachinePoolSpec{ + newMP := &clusterv1.MachinePool{ + Spec: clusterv1.MachinePoolSpec{ ClusterName: tt.newClusterName, Template: clusterv1.MachineTemplateSpec{ Spec: clusterv1.MachineSpec{ @@ -393,8 +389,8 @@ func TestMachinePoolClusterNameImmutable(t *testing.T) { }, } - oldMP := &expv1.MachinePool{ - Spec: expv1.MachinePoolSpec{ + oldMP := &clusterv1.MachinePool{ + Spec: clusterv1.MachinePoolSpec{ ClusterName: tt.oldClusterName, Template: clusterv1.MachineTemplateSpec{ Spec: clusterv1.MachineSpec{ @@ -449,8 +445,8 @@ func TestMachinePoolVersionValidation(t *testing.T) { t.Run(tt.name, func(t *testing.T) { g := NewWithT(t) - mp := &expv1.MachinePool{ - Spec: expv1.MachinePoolSpec{ + mp := &clusterv1.MachinePool{ + Spec: clusterv1.MachinePoolSpec{ Template: clusterv1.MachineTemplateSpec{ Spec: clusterv1.MachineSpec{ Bootstrap: clusterv1.Bootstrap{ConfigRef: &corev1.ObjectReference{}}, @@ -504,8 +500,8 @@ func TestMachinePoolMetadataValidation(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { g := NewWithT(t) - mp := &expv1.MachinePool{ - Spec: expv1.MachinePoolSpec{ + mp := &clusterv1.MachinePool{ + Spec: clusterv1.MachinePoolSpec{ Template: clusterv1.MachineTemplateSpec{ ObjectMeta: clusterv1.ObjectMeta{ Labels: tt.labels, diff --git a/main.go b/main.go index affbcba5bf57..36987408c65c 100644 --- a/main.go +++ b/main.go @@ -53,14 +53,12 @@ import ( addonscontrollers "sigs.k8s.io/cluster-api/exp/addons/controllers" addonswebhooks "sigs.k8s.io/cluster-api/exp/addons/webhooks" expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" - expcontrollers "sigs.k8s.io/cluster-api/exp/controllers" ipamv1 "sigs.k8s.io/cluster-api/exp/ipam/api/v1beta1" expipamwebhooks "sigs.k8s.io/cluster-api/exp/ipam/webhooks" runtimev1 "sigs.k8s.io/cluster-api/exp/runtime/api/v1alpha1" runtimecatalog "sigs.k8s.io/cluster-api/exp/runtime/catalog" runtimecontrollers "sigs.k8s.io/cluster-api/exp/runtime/controllers" runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1" - expwebhooks "sigs.k8s.io/cluster-api/exp/webhooks" "sigs.k8s.io/cluster-api/feature" addonsv1alpha3 "sigs.k8s.io/cluster-api/internal/apis/core/exp/addons/v1alpha3" addonsv1alpha4 "sigs.k8s.io/cluster-api/internal/apis/core/exp/addons/v1alpha4" @@ -526,7 +524,7 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) webhooks.ClusterCac } if feature.Gates.Enabled(feature.MachinePool) { - if err := (&expcontrollers.MachinePoolReconciler{ + if err := (&controllers.MachinePoolReconciler{ Client: mgr.GetClient(), APIReader: mgr.GetAPIReader(), Tracker: tracker, @@ -599,7 +597,7 @@ func setupWebhooks(mgr ctrl.Manager, tracker webhooks.ClusterCacheTrackerReader) // NOTE: MachinePool is behind MachinePool feature gate flag; the webhook // is going to prevent creating or updating new objects in case the feature flag is disabled - if err := (&expwebhooks.MachinePool{}).SetupWebhookWithManager(mgr); err != nil { + if err := (&webhooks.MachinePool{}).SetupWebhookWithManager(mgr); err != nil { setupLog.Error(err, "unable to create webhook", "webhook", "MachinePool") os.Exit(1) } diff --git a/test/e2e/clusterclass_changes.go b/test/e2e/clusterclass_changes.go index f919a701ec92..fdf3f0470f99 100644 --- a/test/e2e/clusterclass_changes.go +++ b/test/e2e/clusterclass_changes.go @@ -34,7 +34,6 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/controllers/external" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/internal/contract" "sigs.k8s.io/cluster-api/test/e2e/internal/log" "sigs.k8s.io/cluster-api/test/framework" @@ -539,7 +538,7 @@ func modifyMachinePoolViaClusterClassAndWait(ctx context.Context, input modifyMa log.Logf("Waiting for MachinePool rollout for MachinePoolTopology %q (class %q) to complete.", mpTopology.Name, mpTopology.Class) Eventually(func(g Gomega) error { // Get MachinePool for the current MachinePoolTopology. - mpList := &expv1.MachinePoolList{} + mpList := &clusterv1.MachinePoolList{} g.Expect(mgmtClient.List(ctx, mpList, client.InNamespace(input.Cluster.Namespace), client.MatchingLabels{ clusterv1.ClusterTopologyMachinePoolNameLabel: mpTopology.Name, })).To(Succeed()) @@ -626,7 +625,7 @@ func assertMachineDeploymentTopologyFields(g Gomega, md clusterv1.MachineDeploym // assertMachinePoolTopologyFields asserts that all fields set in the MachinePoolTopology have been set on the MachinePool. // Note: We intentionally focus on the fields set in the MachinePoolTopology and ignore the ones set through ClusterClass // as we want to validate that the fields of the MachinePoolTopology have been propagated correctly. -func assertMachinePoolTopologyFields(g Gomega, mp expv1.MachinePool, mpTopology clusterv1.MachinePoolTopology) { +func assertMachinePoolTopologyFields(g Gomega, mp clusterv1.MachinePool, mpTopology clusterv1.MachinePoolTopology) { // Note: We only verify that all labels and annotations from the Cluster topology exist to keep it simple here. // This is fully covered by the ClusterClass rollout test. for k, v := range mpTopology.Metadata.Labels { diff --git a/test/e2e/clusterclass_rollout.go b/test/e2e/clusterclass_rollout.go index e9ca19ea4581..7e2851192ca8 100644 --- a/test/e2e/clusterclass_rollout.go +++ b/test/e2e/clusterclass_rollout.go @@ -40,7 +40,6 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/controllers/external" controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/internal/contract" "sigs.k8s.io/cluster-api/internal/controllers/topology/machineset" "sigs.k8s.io/cluster-api/test/e2e/internal/log" @@ -934,7 +933,7 @@ func getMDTopology(cluster *clusterv1.Cluster, md *clusterv1.MachineDeployment) } // getMPClass looks up the MachinePoolClass for a MachinePool in the ClusterClass. -func getMPClass(cluster *clusterv1.Cluster, clusterClass *clusterv1.ClusterClass, mp *expv1.MachinePool) *clusterv1.MachinePoolClass { +func getMPClass(cluster *clusterv1.Cluster, clusterClass *clusterv1.ClusterClass, mp *clusterv1.MachinePool) *clusterv1.MachinePoolClass { mpTopology := getMPTopology(cluster, mp) for _, mdClass := range clusterClass.Spec.Workers.MachinePools { @@ -947,7 +946,7 @@ func getMPClass(cluster *clusterv1.Cluster, clusterClass *clusterv1.ClusterClass } // getMPTopology looks up the MachinePoolTopology for a mp in the Cluster. -func getMPTopology(cluster *clusterv1.Cluster, mp *expv1.MachinePool) *clusterv1.MachinePoolTopology { +func getMPTopology(cluster *clusterv1.Cluster, mp *clusterv1.MachinePool) *clusterv1.MachinePoolTopology { for _, mpTopology := range cluster.Spec.Topology.Workers.MachinePools { if mpTopology.Name == mp.Labels[clusterv1.ClusterTopologyMachinePoolNameLabel] { return &mpTopology @@ -1087,7 +1086,7 @@ type clusterObjects struct { MachinesByMachineSet map[string][]*clusterv1.Machine NodesByMachine map[string]*corev1.Node - MachinePools []*expv1.MachinePool + MachinePools []*clusterv1.MachinePool InfrastructureMachineTemplateByMachineDeployment map[string]*unstructured.Unstructured BootstrapConfigTemplateByMachineDeployment map[string]*unstructured.Unstructured @@ -1183,7 +1182,7 @@ func getClusterObjects(ctx context.Context, g Gomega, clusterProxy framework.Clu // MachinePools. for _, mpTopology := range cluster.Spec.Topology.Workers.MachinePools { // Get MachinePool for the current MachinePoolTopology. - mpList := &expv1.MachinePoolList{} + mpList := &clusterv1.MachinePoolList{} g.Expect(mgmtClient.List(ctx, mpList, client.InNamespace(cluster.Namespace), client.MatchingLabels{ clusterv1.ClusterTopologyMachinePoolNameLabel: mpTopology.Name, })).To(Succeed()) @@ -1337,7 +1336,7 @@ func modifyMachinePoolViaClusterAndWait(ctx context.Context, input modifyMachine log.Logf("Waiting for MachinePool rollout for MachinePoolTopology %q to complete.", mpTopology.Name) Eventually(func(g Gomega) { // Get MachinePool for the current MachinePoolTopology. - mpList := &expv1.MachinePoolList{} + mpList := &clusterv1.MachinePoolList{} g.Expect(mgmtClient.List(ctx, mpList, client.InNamespace(input.Cluster.Namespace), client.MatchingLabels{ clusterv1.ClusterTopologyMachinePoolNameLabel: mpTopology.Name, })).To(Succeed()) diff --git a/test/e2e/clusterctl_upgrade.go b/test/e2e/clusterctl_upgrade.go index e5e32ae7aa12..59d94e3306a1 100644 --- a/test/e2e/clusterctl_upgrade.go +++ b/test/e2e/clusterctl_upgrade.go @@ -47,7 +47,6 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/cmd/clusterctl/client/config" "sigs.k8s.io/cluster-api/controllers/external" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/test/e2e/internal/log" "sigs.k8s.io/cluster-api/test/framework" "sigs.k8s.io/cluster-api/test/framework/bootstrap" @@ -497,7 +496,7 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg By("Waiting for MachinePool to be ready with correct number of replicas") Eventually(func() (int64, error) { var n int64 - machinePoolList := &expv1.MachinePoolList{} + machinePoolList := &clusterv1.MachinePoolList{} if err := managementClusterProxy.GetClient().List( ctx, machinePoolList, @@ -505,7 +504,7 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg client.MatchingLabels{clusterv1.ClusterNameLabel: workloadClusterName}, ); err == nil { for _, mp := range machinePoolList.Items { - if mp.Status.Phase == string(expv1.MachinePoolPhaseRunning) { + if mp.Status.Phase == string(clusterv1.MachinePoolPhaseRunning) { n += int64(mp.Status.ReadyReplicas) } } @@ -883,7 +882,7 @@ func calculateExpectedMachineDeploymentMachineCount(ctx context.Context, c clien func calculateExpectedMachinePoolMachineCount(ctx context.Context, c client.Client, workloadClusterNamespace, workloadClusterName string) (int64, error) { expectedMachinePoolMachineCount := int64(0) - machinePoolList := &expv1.MachinePoolList{} + machinePoolList := &clusterv1.MachinePoolList{} if err := c.List( ctx, machinePoolList, diff --git a/test/framework/cluster_proxy.go b/test/framework/cluster_proxy.go index f1b58b425fe4..f5c6824b2be5 100644 --- a/test/framework/cluster_proxy.go +++ b/test/framework/cluster_proxy.go @@ -43,7 +43,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" testexec "sigs.k8s.io/cluster-api/test/framework/exec" "sigs.k8s.io/cluster-api/test/framework/internal/log" "sigs.k8s.io/cluster-api/test/infrastructure/container" @@ -108,7 +107,7 @@ type ClusterLogCollector interface { // CollectMachineLog collects log from a machine. // TODO: describe output folder struct CollectMachineLog(ctx context.Context, managementClusterClient client.Client, m *clusterv1.Machine, outputPath string) error - CollectMachinePoolLog(ctx context.Context, managementClusterClient client.Client, m *expv1.MachinePool, outputPath string) error + CollectMachinePoolLog(ctx context.Context, managementClusterClient client.Client, m *clusterv1.MachinePool, outputPath string) error // CollectInfrastructureLogs collects log from the infrastructure. CollectInfrastructureLogs(ctx context.Context, managementClusterClient client.Client, c *clusterv1.Cluster, outputPath string) error } @@ -319,7 +318,7 @@ func (p *clusterProxy) CollectWorkloadClusterLogs(ctx context.Context, namespace } } - var machinePools *expv1.MachinePoolList + var machinePools *clusterv1.MachinePoolList Eventually(func() error { var err error machinePools, err = getMachinePoolsInCluster(ctx, p.GetClient(), namespace, name) @@ -367,12 +366,12 @@ func getMachinesInCluster(ctx context.Context, c client.Client, namespace, name return machineList, nil } -func getMachinePoolsInCluster(ctx context.Context, c client.Client, namespace, name string) (*expv1.MachinePoolList, error) { +func getMachinePoolsInCluster(ctx context.Context, c client.Client, namespace, name string) (*clusterv1.MachinePoolList, error) { if name == "" { return nil, errors.New("cluster name should not be empty") } - machinePoolList := &expv1.MachinePoolList{} + machinePoolList := &clusterv1.MachinePoolList{} labels := map[string]string{clusterv1.ClusterNameLabel: name} if err := c.List(ctx, machinePoolList, client.InNamespace(namespace), client.MatchingLabels(labels)); err != nil { return nil, err diff --git a/test/framework/cluster_topology_helpers.go b/test/framework/cluster_topology_helpers.go index 2c83da78d80c..57f1fd683d2c 100644 --- a/test/framework/cluster_topology_helpers.go +++ b/test/framework/cluster_topology_helpers.go @@ -28,7 +28,6 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/test/framework/internal/log" "sigs.k8s.io/cluster-api/util/patch" ) @@ -66,7 +65,7 @@ type UpgradeClusterTopologyAndWaitForUpgradeInput struct { EtcdImageTag string DNSImageTag string MachineDeployments []*clusterv1.MachineDeployment - MachinePools []*expv1.MachinePool + MachinePools []*clusterv1.MachinePool KubernetesUpgradeVersion string WaitForMachinesToBeUpgraded []interface{} WaitForMachinePoolToBeUpgraded []interface{} diff --git a/test/framework/clusterctl/clusterctl_helpers.go b/test/framework/clusterctl/clusterctl_helpers.go index 38788af2aab4..ecaaad194ce3 100644 --- a/test/framework/clusterctl/clusterctl_helpers.go +++ b/test/framework/clusterctl/clusterctl_helpers.go @@ -31,7 +31,6 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/cmd/clusterctl/client/config" controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/test/framework" "sigs.k8s.io/cluster-api/test/framework/internal/log" ) @@ -267,7 +266,7 @@ type ApplyClusterTemplateAndWaitResult struct { Cluster *clusterv1.Cluster ControlPlane *controlplanev1.KubeadmControlPlane MachineDeployments []*clusterv1.MachineDeployment - MachinePools []*expv1.MachinePool + MachinePools []*clusterv1.MachinePool } // ExpectedWorkerNodes returns the expected number of worker nodes that will @@ -388,7 +387,7 @@ type ApplyCustomClusterTemplateAndWaitResult struct { Cluster *clusterv1.Cluster ControlPlane *controlplanev1.KubeadmControlPlane MachineDeployments []*clusterv1.MachineDeployment - MachinePools []*expv1.MachinePool + MachinePools []*clusterv1.MachinePool } func ApplyCustomClusterTemplateAndWait(ctx context.Context, input ApplyCustomClusterTemplateAndWaitInput, result *ApplyCustomClusterTemplateAndWaitResult) { diff --git a/test/framework/docker_logcollector.go b/test/framework/docker_logcollector.go index 6655685cb2a2..58afc4a9a50b 100644 --- a/test/framework/docker_logcollector.go +++ b/test/framework/docker_logcollector.go @@ -30,7 +30,6 @@ import ( "sigs.k8s.io/kind/pkg/errors" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/test/infrastructure/container" ) @@ -57,7 +56,7 @@ func (k DockerLogCollector) CollectMachineLog(ctx context.Context, _ client.Clie return k.collectLogsFromNode(ctx, outputPath, containerName) } -func (k DockerLogCollector) CollectMachinePoolLog(ctx context.Context, _ client.Client, m *expv1.MachinePool, outputPath string) error { +func (k DockerLogCollector) CollectMachinePoolLog(ctx context.Context, _ client.Client, m *clusterv1.MachinePool, outputPath string) error { containerRuntime, err := container.NewDockerClient() if err != nil { return err diff --git a/test/framework/finalizers_helpers.go b/test/framework/finalizers_helpers.go index 946ec36ea3b3..226da8fa2068 100644 --- a/test/framework/finalizers_helpers.go +++ b/test/framework/finalizers_helpers.go @@ -34,7 +34,6 @@ import ( clusterctlcluster "sigs.k8s.io/cluster-api/cmd/clusterctl/client/cluster" controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1" addonsv1 "sigs.k8s.io/cluster-api/exp/addons/api/v1beta1" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" infrav1 "sigs.k8s.io/cluster-api/test/infrastructure/docker/api/v1beta1" infraexpv1 "sigs.k8s.io/cluster-api/test/infrastructure/docker/exp/api/v1beta1" "sigs.k8s.io/cluster-api/util/patch" @@ -60,7 +59,7 @@ var CoreFinalizersAssertionWithClassyClusters = func() map[string]func(types.Nam // ExpFinalizersAssertion maps experimental resource types to their expected finalizers. var ExpFinalizersAssertion = map[string]func(types.NamespacedName) []string{ clusterResourceSetKind: func(_ types.NamespacedName) []string { return []string{addonsv1.ClusterResourceSetFinalizer} }, - machinePoolKind: func(_ types.NamespacedName) []string { return []string{expv1.MachinePoolFinalizer} }, + machinePoolKind: func(_ types.NamespacedName) []string { return []string{clusterv1.MachinePoolFinalizer} }, } // DockerInfraFinalizersAssertion maps docker infrastructure resource types to their expected finalizers. diff --git a/test/framework/machinepool_helpers.go b/test/framework/machinepool_helpers.go index 7aaf40fcefd5..30317c8dc97a 100644 --- a/test/framework/machinepool_helpers.go +++ b/test/framework/machinepool_helpers.go @@ -31,7 +31,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/test/framework/internal/log" "sigs.k8s.io/cluster-api/util/patch" ) @@ -46,18 +45,18 @@ type GetMachinePoolsByClusterInput struct { // GetMachinePoolsByCluster returns the MachinePools objects for a cluster. // Important! this method relies on labels that are created by the CAPI controllers during the first reconciliation, so // it is necessary to ensure this is already happened before calling it. -func GetMachinePoolsByCluster(ctx context.Context, input GetMachinePoolsByClusterInput) []*expv1.MachinePool { +func GetMachinePoolsByCluster(ctx context.Context, input GetMachinePoolsByClusterInput) []*clusterv1.MachinePool { Expect(ctx).NotTo(BeNil(), "ctx is required for GetMachinePoolsByCluster") Expect(input.Lister).ToNot(BeNil(), "Invalid argument. input.Lister can't be nil when calling GetMachinePoolsByCluster") Expect(input.Namespace).ToNot(BeEmpty(), "Invalid argument. input.Namespace can't be empty when calling GetMachinePoolsByCluster") Expect(input.ClusterName).ToNot(BeEmpty(), "Invalid argument. input.ClusterName can't be empty when calling GetMachinePoolsByCluster") - mpList := &expv1.MachinePoolList{} + mpList := &clusterv1.MachinePoolList{} Eventually(func() error { return input.Lister.List(ctx, mpList, byClusterOptions(input.ClusterName, input.Namespace)...) }, retryableOperationTimeout, retryableOperationInterval).Should(Succeed(), "Failed to list MachinePools object for Cluster %s", klog.KRef(input.Namespace, input.ClusterName)) - mps := make([]*expv1.MachinePool, len(mpList.Items)) + mps := make([]*clusterv1.MachinePool, len(mpList.Items)) for i := range mpList.Items { mps[i] = &mpList.Items[i] } @@ -67,7 +66,7 @@ func GetMachinePoolsByCluster(ctx context.Context, input GetMachinePoolsByCluste // WaitForMachinePoolNodesToExistInput is the input for WaitForMachinePoolNodesToExist. type WaitForMachinePoolNodesToExistInput struct { Getter Getter - MachinePool *expv1.MachinePool + MachinePool *clusterv1.MachinePool } // WaitForMachinePoolNodesToExist waits until all nodes associated with a machine pool exist. @@ -99,7 +98,7 @@ type DiscoveryAndWaitForMachinePoolsInput struct { } // DiscoveryAndWaitForMachinePools discovers the MachinePools existing in a cluster and waits for them to be ready (all the machines provisioned). -func DiscoveryAndWaitForMachinePools(ctx context.Context, input DiscoveryAndWaitForMachinePoolsInput, intervals ...interface{}) []*expv1.MachinePool { +func DiscoveryAndWaitForMachinePools(ctx context.Context, input DiscoveryAndWaitForMachinePoolsInput, intervals ...interface{}) []*clusterv1.MachinePool { Expect(ctx).NotTo(BeNil(), "ctx is required for DiscoveryAndWaitForMachinePools") Expect(input.Lister).ToNot(BeNil(), "Invalid argument. input.Lister can't be nil when calling DiscoveryAndWaitForMachinePools") Expect(input.Cluster).ToNot(BeNil(), "Invalid argument. input.Cluster can't be nil when calling DiscoveryAndWaitForMachinePools") @@ -125,7 +124,7 @@ type UpgradeMachinePoolAndWaitInput struct { ClusterProxy ClusterProxy Cluster *clusterv1.Cluster UpgradeVersion string - MachinePools []*expv1.MachinePool + MachinePools []*clusterv1.MachinePool WaitForMachinePoolToBeUpgraded []interface{} } @@ -171,7 +170,7 @@ type ScaleMachinePoolAndWaitInput struct { ClusterProxy ClusterProxy Cluster *clusterv1.Cluster Replicas int32 - MachinePools []*expv1.MachinePool + MachinePools []*clusterv1.MachinePool WaitForMachinePoolToScale []interface{} } @@ -233,7 +232,7 @@ func ScaleMachinePoolTopologyAndWait(ctx context.Context, input ScaleMachinePool }, retryableOperationTimeout, retryableOperationInterval).Should(Succeed(), "Failed to scale machine pool topology %s", mpTopology.Name) log.Logf("Waiting for correct number of replicas to exist") - mpList := &expv1.MachinePoolList{} + mpList := &clusterv1.MachinePoolList{} Eventually(func() error { return input.ClusterProxy.GetClient().List(ctx, mpList, client.InNamespace(input.Cluster.Namespace), @@ -259,7 +258,7 @@ type WaitForMachinePoolInstancesToBeUpgradedInput struct { Cluster *clusterv1.Cluster KubernetesUpgradeVersion string MachineCount int - MachinePool *expv1.MachinePool + MachinePool *clusterv1.MachinePool } // WaitForMachinePoolInstancesToBeUpgraded waits until all instances belonging to a MachinePool are upgraded to the correct kubernetes version. @@ -305,7 +304,7 @@ func WaitForMachinePoolInstancesToBeUpgraded(ctx context.Context, input WaitForM type GetMachinesPoolInstancesInput struct { WorkloadClusterGetter Getter Namespace string - MachinePool *expv1.MachinePool + MachinePool *clusterv1.MachinePool } // getMachinePoolInstanceVersions returns the Kubernetes versions of the machine pool instances. @@ -343,7 +342,7 @@ func getMachinePoolInstanceVersions(ctx context.Context, input GetMachinesPoolIn type AssertMachinePoolReplicasInput struct { Getter Getter - MachinePool *expv1.MachinePool + MachinePool *clusterv1.MachinePool Replicas int32 WaitForMachinePool []interface{} } @@ -355,7 +354,7 @@ func AssertMachinePoolReplicas(ctx context.Context, input AssertMachinePoolRepli Eventually(func(g Gomega) { // Get the MachinePool - mp := &expv1.MachinePool{} + mp := &clusterv1.MachinePool{} key := client.ObjectKey{ Namespace: input.MachinePool.Namespace, Name: input.MachinePool.Name, diff --git a/test/infrastructure/docker/exp/internal/controllers/dockermachinepool_controller.go b/test/infrastructure/docker/exp/internal/controllers/dockermachinepool_controller.go index f9b91e042513..f4ad126bc2c1 100644 --- a/test/infrastructure/docker/exp/internal/controllers/dockermachinepool_controller.go +++ b/test/infrastructure/docker/exp/internal/controllers/dockermachinepool_controller.go @@ -41,7 +41,6 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/controllers/external" "sigs.k8s.io/cluster-api/controllers/remote" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" utilexp "sigs.k8s.io/cluster-api/exp/util" "sigs.k8s.io/cluster-api/internal/util/ssa" "sigs.k8s.io/cluster-api/test/infrastructure/container" @@ -176,7 +175,7 @@ func (r *DockerMachinePoolReconciler) SetupWithManager(ctx context.Context, mgr WithOptions(options). WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)). Watches( - &expv1.MachinePool{}, + &clusterv1.MachinePool{}, handler.EnqueueRequestsFromMapFunc(utilexp.MachinePoolToInfrastructureMapFunc(ctx, infraexpv1.GroupVersion.WithKind("DockerMachinePool"))), ). @@ -205,7 +204,7 @@ func (r *DockerMachinePoolReconciler) SetupWithManager(ctx context.Context, mgr return nil } -func (r *DockerMachinePoolReconciler) reconcileDelete(ctx context.Context, cluster *clusterv1.Cluster, machinePool *expv1.MachinePool, dockerMachinePool *infraexpv1.DockerMachinePool) error { +func (r *DockerMachinePoolReconciler) reconcileDelete(ctx context.Context, cluster *clusterv1.Cluster, machinePool *clusterv1.MachinePool, dockerMachinePool *infraexpv1.DockerMachinePool) error { log := ctrl.LoggerFrom(ctx) dockerMachineList, err := getDockerMachines(ctx, r.Client, *cluster, *machinePool, *dockerMachinePool) @@ -261,7 +260,7 @@ func (r *DockerMachinePoolReconciler) reconcileDelete(ctx context.Context, clust return nil } -func (r *DockerMachinePoolReconciler) reconcileNormal(ctx context.Context, cluster *clusterv1.Cluster, machinePool *expv1.MachinePool, dockerMachinePool *infraexpv1.DockerMachinePool) (ctrl.Result, error) { +func (r *DockerMachinePoolReconciler) reconcileNormal(ctx context.Context, cluster *clusterv1.Cluster, machinePool *clusterv1.MachinePool, dockerMachinePool *infraexpv1.DockerMachinePool) (ctrl.Result, error) { log := ctrl.LoggerFrom(ctx) // Make sure bootstrap data is available and populated. @@ -314,7 +313,7 @@ func (r *DockerMachinePoolReconciler) reconcileNormal(ctx context.Context, clust if len(dockerMachinePool.Spec.ProviderIDList) == int(*machinePool.Spec.Replicas) && len(dockerMachineList.Items) == int(*machinePool.Spec.Replicas) { dockerMachinePool.Status.Ready = true - conditions.MarkTrue(dockerMachinePool, expv1.ReplicasReadyCondition) + conditions.MarkTrue(dockerMachinePool, clusterv1.ReplicasReadyCondition) return ctrl.Result{}, nil } @@ -322,7 +321,7 @@ func (r *DockerMachinePoolReconciler) reconcileNormal(ctx context.Context, clust return r.updateStatus(ctx, cluster, machinePool, dockerMachinePool, dockerMachineList.Items) } -func getDockerMachines(ctx context.Context, c client.Client, cluster clusterv1.Cluster, machinePool expv1.MachinePool, dockerMachinePool infraexpv1.DockerMachinePool) (*infrav1.DockerMachineList, error) { +func getDockerMachines(ctx context.Context, c client.Client, cluster clusterv1.Cluster, machinePool clusterv1.MachinePool, dockerMachinePool infraexpv1.DockerMachinePool) (*infrav1.DockerMachineList, error) { dockerMachineList := &infrav1.DockerMachineList{} labels := map[string]string{ clusterv1.ClusterNameLabel: cluster.Name, @@ -379,7 +378,7 @@ func dockerMachineToDockerMachinePool(_ context.Context, o client.Object) []ctrl // updateStatus updates the Status field for the MachinePool object. // It checks for the current state of the replicas and updates the Status of the MachineSet. -func (r *DockerMachinePoolReconciler) updateStatus(ctx context.Context, cluster *clusterv1.Cluster, machinePool *expv1.MachinePool, dockerMachinePool *infraexpv1.DockerMachinePool, dockerMachines []infrav1.DockerMachine) (ctrl.Result, error) { +func (r *DockerMachinePoolReconciler) updateStatus(ctx context.Context, cluster *clusterv1.Cluster, machinePool *clusterv1.MachinePool, dockerMachinePool *infraexpv1.DockerMachinePool, dockerMachines []infrav1.DockerMachine) (ctrl.Result, error) { log := ctrl.LoggerFrom(ctx) // List the Docker containers. This corresponds to an InfraMachinePool instance for providers. @@ -430,7 +429,7 @@ func (r *DockerMachinePoolReconciler) updateStatus(ctx context.Context, cluster // Aggregate the operational state of all the machines; while aggregating we are adding the // source ref (reason@machine/name) so the problem can be easily tracked down to its source machine. - conditions.SetAggregate(dockerMachinePool, expv1.ReplicasReadyCondition, getters, conditions.AddSourceRef()) + conditions.SetAggregate(dockerMachinePool, clusterv1.ReplicasReadyCondition, getters, conditions.AddSourceRef()) return ctrl.Result{}, nil } @@ -438,7 +437,7 @@ func (r *DockerMachinePoolReconciler) updateStatus(ctx context.Context, cluster func patchDockerMachinePool(ctx context.Context, patchHelper *patch.Helper, dockerMachinePool *infraexpv1.DockerMachinePool) error { conditions.SetSummary(dockerMachinePool, conditions.WithConditions( - expv1.ReplicasReadyCondition, + clusterv1.ReplicasReadyCondition, ), ) @@ -448,7 +447,7 @@ func patchDockerMachinePool(ctx context.Context, patchHelper *patch.Helper, dock dockerMachinePool, patch.WithOwnedConditions{Conditions: []clusterv1.ConditionType{ clusterv1.ReadyCondition, - expv1.ReplicasReadyCondition, + clusterv1.ReplicasReadyCondition, }}, ) } diff --git a/test/infrastructure/docker/exp/internal/controllers/dockermachinepool_controller_phases.go b/test/infrastructure/docker/exp/internal/controllers/dockermachinepool_controller_phases.go index 2afae7393738..63c5426a2eba 100644 --- a/test/infrastructure/docker/exp/internal/controllers/dockermachinepool_controller_phases.go +++ b/test/infrastructure/docker/exp/internal/controllers/dockermachinepool_controller_phases.go @@ -32,7 +32,6 @@ import ( "sigs.k8s.io/kind/pkg/cluster/constants" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/internal/util/ssa" infrav1 "sigs.k8s.io/cluster-api/test/infrastructure/docker/api/v1beta1" infraexpv1 "sigs.k8s.io/cluster-api/test/infrastructure/docker/exp/api/v1beta1" @@ -48,7 +47,7 @@ import ( // - Does not delete any containers as that must be triggered in reconcileDockerMachines to ensure node cordon/drain. // // Providers should similarly create their infrastructure instances and reconcile any additional logic. -func (r *DockerMachinePoolReconciler) reconcileDockerContainers(ctx context.Context, cluster *clusterv1.Cluster, machinePool *expv1.MachinePool, dockerMachinePool *infraexpv1.DockerMachinePool) error { +func (r *DockerMachinePoolReconciler) reconcileDockerContainers(ctx context.Context, cluster *clusterv1.Cluster, machinePool *clusterv1.MachinePool, dockerMachinePool *infraexpv1.DockerMachinePool) error { log := ctrl.LoggerFrom(ctx) log.V(2).Info("Reconciling Docker containers", "DockerMachinePool", klog.KObj(dockerMachinePool)) @@ -74,7 +73,7 @@ func (r *DockerMachinePoolReconciler) reconcileDockerContainers(ctx context.Cont } // createDockerContainer creates a Docker container to serve as a replica for the MachinePool. -func createDockerContainer(ctx context.Context, name string, cluster *clusterv1.Cluster, machinePool *expv1.MachinePool, dockerMachinePool *infraexpv1.DockerMachinePool) error { +func createDockerContainer(ctx context.Context, name string, cluster *clusterv1.Cluster, machinePool *clusterv1.MachinePool, dockerMachinePool *infraexpv1.DockerMachinePool) error { log := ctrl.LoggerFrom(ctx) labelFilters := map[string]string{dockerMachinePoolLabel: dockerMachinePool.Name} externalMachine, err := docker.NewMachine(ctx, cluster, name, labelFilters) @@ -112,7 +111,7 @@ func createDockerContainer(ctx context.Context, name string, cluster *clusterv1. // - Deleting DockerMachines referencing a container whose Kubernetes version or custom image no longer matches the spec. // - Deleting DockerMachines that correspond to a deleted/non-existent Docker container. // - Deleting DockerMachines when scaling down such that DockerMachines whose owner Machine has the clusterv1.DeleteMachineAnnotation is given priority. -func (r *DockerMachinePoolReconciler) reconcileDockerMachines(ctx context.Context, cluster *clusterv1.Cluster, machinePool *expv1.MachinePool, dockerMachinePool *infraexpv1.DockerMachinePool) error { +func (r *DockerMachinePoolReconciler) reconcileDockerMachines(ctx context.Context, cluster *clusterv1.Cluster, machinePool *clusterv1.MachinePool, dockerMachinePool *infraexpv1.DockerMachinePool) error { log := ctrl.LoggerFrom(ctx) log.V(2).Info("Reconciling DockerMachines", "DockerMachinePool", klog.KObj(dockerMachinePool)) @@ -245,7 +244,7 @@ func (r *DockerMachinePoolReconciler) reconcileDockerMachines(ctx context.Contex // computeDesiredDockerMachine creates a DockerMachine to represent a Docker container in a DockerMachinePool. // These DockerMachines have the clusterv1.ClusterNameLabel and clusterv1.MachinePoolNameLabel to support MachinePool Machines. -func computeDesiredDockerMachine(name string, cluster *clusterv1.Cluster, machinePool *expv1.MachinePool, dockerMachinePool *infraexpv1.DockerMachinePool, existingDockerMachine *infrav1.DockerMachine) *infrav1.DockerMachine { +func computeDesiredDockerMachine(name string, cluster *clusterv1.Cluster, machinePool *clusterv1.MachinePool, dockerMachinePool *infraexpv1.DockerMachinePool, existingDockerMachine *infrav1.DockerMachine) *infrav1.DockerMachine { dockerMachine := &infrav1.DockerMachine{ ObjectMeta: metav1.ObjectMeta{ Namespace: dockerMachinePool.Namespace, @@ -346,7 +345,7 @@ func orderByDeleteMachineAnnotation(machines []infrav1.DockerMachine) []infrav1. } // isMachineMatchingInfrastructureSpec returns true if the Docker container image matches the custom image in the DockerMachinePool spec. -func isMachineMatchingInfrastructureSpec(_ context.Context, machine *docker.Machine, machinePool *expv1.MachinePool, dockerMachinePool *infraexpv1.DockerMachinePool) bool { +func isMachineMatchingInfrastructureSpec(_ context.Context, machine *docker.Machine, machinePool *clusterv1.MachinePool, dockerMachinePool *infraexpv1.DockerMachinePool) bool { // NOTE: With the current implementation we are checking if the machine is using a kindest/node image for the expected version, // but not checking if the machine has the expected extra.mounts or pre.loaded images. @@ -362,7 +361,7 @@ func isMachineMatchingInfrastructureSpec(_ context.Context, machine *docker.Mach } // machinesMatchingInfrastructureSpec returns the Docker containers matching the custom image in the DockerMachinePool spec. -func machinesMatchingInfrastructureSpec(ctx context.Context, machines []*docker.Machine, machinePool *expv1.MachinePool, dockerMachinePool *infraexpv1.DockerMachinePool) []*docker.Machine { +func machinesMatchingInfrastructureSpec(ctx context.Context, machines []*docker.Machine, machinePool *clusterv1.MachinePool, dockerMachinePool *infraexpv1.DockerMachinePool) []*docker.Machine { var matchingMachines []*docker.Machine for _, machine := range machines { if isMachineMatchingInfrastructureSpec(ctx, machine, machinePool, dockerMachinePool) { @@ -374,7 +373,7 @@ func machinesMatchingInfrastructureSpec(ctx context.Context, machines []*docker. } // getDeletionCandidates returns the DockerMachines for a MachinePool that do not match the infrastructure spec followed by any DockerMachines that are ready and up to date, i.e. matching the infrastructure spec. -func (r *DockerMachinePoolReconciler) getDeletionCandidates(ctx context.Context, dockerMachines []infrav1.DockerMachine, externalMachineSet map[string]*docker.Machine, machinePool *expv1.MachinePool, dockerMachinePool *infraexpv1.DockerMachinePool) (outdatedMachines []infrav1.DockerMachine, readyMatchingMachines []infrav1.DockerMachine, err error) { +func (r *DockerMachinePoolReconciler) getDeletionCandidates(ctx context.Context, dockerMachines []infrav1.DockerMachine, externalMachineSet map[string]*docker.Machine, machinePool *clusterv1.MachinePool, dockerMachinePool *infraexpv1.DockerMachinePool) (outdatedMachines []infrav1.DockerMachine, readyMatchingMachines []infrav1.DockerMachine, err error) { for i := range dockerMachines { dockerMachine := dockerMachines[i] externalMachine, ok := externalMachineSet[dockerMachine.Name] diff --git a/webhooks/alias.go b/webhooks/alias.go index 1d1271bb1530..51e9653125eb 100644 --- a/webhooks/alias.go +++ b/webhooks/alias.go @@ -92,6 +92,14 @@ func (webhook *MachineSet) SetupWebhookWithManager(mgr ctrl.Manager) error { return (&webhooks.MachineSet{}).SetupWebhookWithManager(mgr) } +// MachinePool implements a validating and defaulting webhook for MachinePool. +type MachinePool struct{} + +// SetupWebhookWithManager sets up MachinePool webhooks. +func (webhook *MachinePool) SetupWebhookWithManager(mgr ctrl.Manager) error { + return (&webhooks.MachinePool{}).SetupWebhookWithManager(mgr) +} + // MachineHealthCheck implements a validating and defaulting webhook for MachineHealthCheck. type MachineHealthCheck struct{}