diff --git a/OWNERS_ALIASES b/OWNERS_ALIASES index 27c242bab119..967d2e75c37e 100644 --- a/OWNERS_ALIASES +++ b/OWNERS_ALIASES @@ -125,3 +125,11 @@ aliases: - mboersma - shecodesmagic - tsuzu + + # ----------------------------------------------------------- + # OWNER_ALIASES for release-team + # ----------------------------------------------------------- + + cluster-api-machinepool-reviewers: + - mboersma + - richardcase diff --git a/exp/controllers/alias.go b/exp/controllers/alias.go index 920ef26da2de..ee55fffd18b8 100644 --- a/exp/controllers/alias.go +++ b/exp/controllers/alias.go @@ -24,7 +24,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/cluster-api/controllers/clustercache" - machinepool "sigs.k8s.io/cluster-api/exp/internal/controllers" + "sigs.k8s.io/cluster-api/exp/internal/controllers/machinepool" ) // MachinePoolReconciler reconciles a MachinePool object. @@ -38,7 +38,7 @@ type MachinePoolReconciler struct { } func (r *MachinePoolReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error { - return (&machinepool.MachinePoolReconciler{ + return (&machinepool.Reconciler{ Client: r.Client, APIReader: r.APIReader, ClusterCache: r.ClusterCache, diff --git a/exp/internal/controllers/machinepool/OWNERS b/exp/internal/controllers/machinepool/OWNERS new file mode 100644 index 000000000000..c7ff5c37ae80 --- /dev/null +++ b/exp/internal/controllers/machinepool/OWNERS @@ -0,0 +1,8 @@ +# See the OWNERS docs at https://go.k8s.io/owners + +approvers: + - cluster-api-maintainers + +reviewers: + - cluster-api-reviewers + - cluster-api-machinepool-reviewers diff --git a/exp/internal/controllers/machinepool/doc.go b/exp/internal/controllers/machinepool/doc.go new file mode 100644 index 000000000000..79662d306acd --- /dev/null +++ b/exp/internal/controllers/machinepool/doc.go @@ -0,0 +1,18 @@ +/* +Copyright 2021 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 machinepool controllers. +package machinepool diff --git a/exp/internal/controllers/machinepool_controller.go b/exp/internal/controllers/machinepool/machinepool_controller.go similarity index 92% rename from exp/internal/controllers/machinepool_controller.go rename to exp/internal/controllers/machinepool/machinepool_controller.go index 9fe8b9c44fd0..28b039ac8295 100644 --- a/exp/internal/controllers/machinepool_controller.go +++ b/exp/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" @@ -73,8 +73,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 ClusterCache clustercache.ClusterCache @@ -105,7 +105,7 @@ type scope struct { nodeRefMap map[string]*corev1.Node } -func (r *MachinePoolReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error { +func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error { if r.Client == nil || r.APIReader == nil || r.ClusterCache == nil { return errors.New("Client, APIReader and ClusterCache must not be nil") } @@ -151,7 +151,7 @@ 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{} @@ -243,7 +243,7 @@ func (r *MachinePoolReconciler) Reconcile(ctx context.Context, req ctrl.Request) return r.reconcile(ctx, scope) } -func (r *MachinePoolReconciler) reconcile(ctx context.Context, s *scope) (ctrl.Result, error) { +func (r *Reconciler) reconcile(ctx context.Context, s *scope) (ctrl.Result, error) { // Ensure the MachinePool is owned by the Cluster it belongs to. cluster := s.cluster mp := s.machinePool @@ -278,7 +278,7 @@ func (r *MachinePoolReconciler) reconcile(ctx context.Context, s *scope) (ctrl.R } // reconcileDelete delete machinePool related resources. -func (r *MachinePoolReconciler) reconcileDelete(ctx context.Context, cluster *clusterv1.Cluster, machinePool *expv1.MachinePool) error { +func (r *Reconciler) reconcileDelete(ctx context.Context, cluster *clusterv1.Cluster, machinePool *expv1.MachinePool) error { if ok, err := r.reconcileDeleteExternal(ctx, machinePool); !ok || err != nil { // Return early and don't remove the finalizer if we got an error or // the external reconciliation deletion isn't ready. @@ -300,7 +300,7 @@ func (r *MachinePoolReconciler) reconcileDelete(ctx context.Context, cluster *cl } // reconcileDeleteNodes delete the cluster nodes. -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 *expv1.MachinePool) error { if len(machinePool.Status.NodeRefs) == 0 { return nil } @@ -314,7 +314,7 @@ func (r *MachinePoolReconciler) reconcileDeleteNodes(ctx context.Context, cluste } // isMachinePoolDeleteTimeoutPassed check the machinePool node delete time out. -func (r *MachinePoolReconciler) isMachinePoolNodeDeleteTimeoutPassed(machinePool *expv1.MachinePool) bool { +func (r *Reconciler) isMachinePoolNodeDeleteTimeoutPassed(machinePool *expv1.MachinePool) bool { if !machinePool.DeletionTimestamp.IsZero() && machinePool.Spec.Template.Spec.NodeDeletionTimeout != nil { if machinePool.Spec.Template.Spec.NodeDeletionTimeout.Nanoseconds() != 0 { deleteTimePlusDuration := machinePool.DeletionTimestamp.Add(machinePool.Spec.Template.Spec.NodeDeletionTimeout.Duration) @@ -325,7 +325,7 @@ func (r *MachinePoolReconciler) isMachinePoolNodeDeleteTimeoutPassed(machinePool } // reconcileDeleteExternal tries to delete external references, returning true if it cannot find any. -func (r *MachinePoolReconciler) reconcileDeleteExternal(ctx context.Context, machinePool *expv1.MachinePool) (bool, error) { +func (r *Reconciler) reconcileDeleteExternal(ctx context.Context, machinePool *expv1.MachinePool) (bool, error) { objects := []*unstructured.Unstructured{} references := []*corev1.ObjectReference{ machinePool.Spec.Template.Spec.Bootstrap.ConfigRef, @@ -361,7 +361,7 @@ func (r *MachinePoolReconciler) reconcileDeleteExternal(ctx context.Context, mac 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.ClusterControlPlaneInitializedCondition) { @@ -378,7 +378,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)) diff --git a/exp/internal/controllers/machinepool_controller_noderef.go b/exp/internal/controllers/machinepool/machinepool_controller_noderef.go similarity index 93% rename from exp/internal/controllers/machinepool_controller_noderef.go rename to exp/internal/controllers/machinepool/machinepool_controller_noderef.go index a9ce42d8fe9c..a18664c88b29 100644 --- a/exp/internal/controllers/machinepool_controller_noderef.go +++ b/exp/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" @@ -48,7 +48,7 @@ type getNodeReferencesResult struct { ready int } -func (r *MachinePoolReconciler) reconcileNodeRefs(ctx context.Context, s *scope) (ctrl.Result, error) { +func (r *Reconciler) reconcileNodeRefs(ctx context.Context, s *scope) (ctrl.Result, error) { log := ctrl.LoggerFrom(ctx) cluster := s.cluster mp := s.machinePool @@ -140,7 +140,7 @@ func (r *MachinePoolReconciler) reconcileNodeRefs(ctx context.Context, s *scope) // 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 { @@ -172,7 +172,7 @@ func (r *MachinePoolReconciler) deleteRetiredNodes(ctx context.Context, c client return nil } -func (r *MachinePoolReconciler) getNodeReferences(ctx context.Context, providerIDList []string, minReadySeconds int32, nodeRefsMap map[string]*corev1.Node) (getNodeReferencesResult, error) { +func (r *Reconciler) getNodeReferences(ctx context.Context, providerIDList []string, minReadySeconds int32, nodeRefsMap map[string]*corev1.Node) (getNodeReferencesResult, error) { log := ctrl.LoggerFrom(ctx, "providerIDList", len(providerIDList)) var ready, available int @@ -206,7 +206,7 @@ func (r *MachinePoolReconciler) getNodeReferences(ctx context.Context, providerI } // 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 *expv1.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/exp/internal/controllers/machinepool/machinepool_controller_noderef_test.go similarity index 99% rename from exp/internal/controllers/machinepool_controller_noderef_test.go rename to exp/internal/controllers/machinepool/machinepool_controller_noderef_test.go index 9452d1344aa5..b9102d098a7d 100644 --- a/exp/internal/controllers/machinepool_controller_noderef_test.go +++ b/exp/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" @@ -31,7 +31,7 @@ import ( ) func TestMachinePoolGetNodeReference(t *testing.T) { - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fake.NewClientBuilder().Build(), recorder: record.NewFakeRecorder(32), } @@ -306,7 +306,7 @@ func TestMachinePoolGetNodeReference(t *testing.T) { } func TestMachinePoolPatchNodes(t *testing.T) { - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fake.NewClientBuilder().Build(), recorder: record.NewFakeRecorder(32), } diff --git a/exp/internal/controllers/machinepool_controller_phases.go b/exp/internal/controllers/machinepool/machinepool_controller_phases.go similarity index 95% rename from exp/internal/controllers/machinepool_controller_phases.go rename to exp/internal/controllers/machinepool/machinepool_controller_phases.go index 5d4275bf93fd..7a10fd045059 100644 --- a/exp/internal/controllers/machinepool_controller_phases.go +++ b/exp/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" @@ -53,7 +53,7 @@ import ( "sigs.k8s.io/cluster-api/util/predicates" ) -func (r *MachinePoolReconciler) reconcilePhase(mp *expv1.MachinePool) { +func (r *Reconciler) reconcilePhase(mp *expv1.MachinePool) { // Set the phase to "pending" if nil. if mp.Status.Phase == "" { mp.Status.SetTypedPhase(expv1.MachinePoolPhasePending) @@ -108,7 +108,7 @@ func (r *MachinePoolReconciler) reconcilePhase(mp *expv1.MachinePool) { } // reconcileExternal handles generic unstructured objects referenced by a MachinePool. -func (r *MachinePoolReconciler) reconcileExternal(ctx context.Context, m *expv1.MachinePool, ref *corev1.ObjectReference) (external.ReconcileOutput, error) { +func (r *Reconciler) reconcileExternal(ctx context.Context, m *expv1.MachinePool, ref *corev1.ObjectReference) (external.ReconcileOutput, error) { log := ctrl.LoggerFrom(ctx) if err := utilconversion.UpdateReferenceAPIContract(ctx, r.Client, ref); err != nil { @@ -185,7 +185,7 @@ func (r *MachinePoolReconciler) reconcileExternal(ctx context.Context, m *expv1. } // reconcileBootstrap reconciles the Spec.Bootstrap.ConfigRef object on a MachinePool. -func (r *MachinePoolReconciler) reconcileBootstrap(ctx context.Context, s *scope) (ctrl.Result, error) { +func (r *Reconciler) reconcileBootstrap(ctx context.Context, s *scope) (ctrl.Result, error) { log := ctrl.LoggerFrom(ctx) m := s.machinePool // Call generic external reconciler if we have an external reference. @@ -264,7 +264,7 @@ func (r *MachinePoolReconciler) reconcileBootstrap(ctx context.Context, s *scope } // reconcileInfrastructure reconciles the Spec.InfrastructureRef object on a MachinePool. -func (r *MachinePoolReconciler) reconcileInfrastructure(ctx context.Context, s *scope) (ctrl.Result, error) { +func (r *Reconciler) reconcileInfrastructure(ctx context.Context, s *scope) (ctrl.Result, error) { log := ctrl.LoggerFrom(ctx) cluster := s.cluster mp := s.machinePool @@ -374,7 +374,7 @@ func (r *MachinePoolReconciler) reconcileInfrastructure(ctx context.Context, s * // 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, s *scope, infraMachinePool *unstructured.Unstructured) error { +func (r *Reconciler) reconcileMachines(ctx context.Context, s *scope, infraMachinePool *unstructured.Unstructured) error { log := ctrl.LoggerFrom(ctx) mp := s.machinePool @@ -431,7 +431,7 @@ func (r *MachinePoolReconciler) reconcileMachines(ctx context.Context, s *scope, } // 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, s *scope, machines []clusterv1.Machine, infraMachines []unstructured.Unstructured) error { +func (r *Reconciler) createOrUpdateMachines(ctx context.Context, s *scope, machines []clusterv1.Machine, infraMachines []unstructured.Unstructured) error { log := ctrl.LoggerFrom(ctx) // Construct a set of names of infraMachines that already have a Machine. @@ -490,7 +490,7 @@ func (r *MachinePoolReconciler) createOrUpdateMachines(ctx context.Context, s *s // computeDesiredMachine constructs the desired Machine for an infraMachine. // If the Machine exists, it ensures the Machine always owned by the MachinePool. -func (r *MachinePoolReconciler) computeDesiredMachine(mp *expv1.MachinePool, infraMachine *unstructured.Unstructured, existingMachine *clusterv1.Machine, existingNode *corev1.Node) *clusterv1.Machine { +func (r *Reconciler) computeDesiredMachine(mp *expv1.MachinePool, infraMachine *unstructured.Unstructured, existingMachine *clusterv1.Machine, existingNode *corev1.Node) *clusterv1.Machine { infraRef := corev1.ObjectReference{ APIVersion: infraMachine.GetAPIVersion(), Kind: infraMachine.GetKind(), @@ -546,7 +546,7 @@ func (r *MachinePoolReconciler) computeDesiredMachine(mp *expv1.MachinePool, inf // 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) { @@ -570,7 +570,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. @@ -602,7 +602,7 @@ func (r *MachinePoolReconciler) waitForMachineCreation(ctx context.Context, mach return nil } -func (r *MachinePoolReconciler) getNodeRefMap(ctx context.Context, c client.Client) (map[string]*corev1.Node, error) { +func (r *Reconciler) getNodeRefMap(ctx context.Context, c client.Client) (map[string]*corev1.Node, error) { log := ctrl.LoggerFrom(ctx) nodeRefsMap := make(map[string]*corev1.Node) nodeList := corev1.NodeList{} diff --git a/exp/internal/controllers/machinepool_controller_phases_test.go b/exp/internal/controllers/machinepool/machinepool_controller_phases_test.go similarity index 99% rename from exp/internal/controllers/machinepool_controller_phases_test.go rename to exp/internal/controllers/machinepool/machinepool_controller_phases_test.go index d14cb69dd13e..b920ae8362f6 100644 --- a/exp/internal/controllers/machinepool_controller_phases_test.go +++ b/exp/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" @@ -132,7 +132,7 @@ func TestReconcileMachinePoolPhases(t *testing.T) { infraConfig := defaultInfra.DeepCopy() fakeClient := fake.NewClientBuilder().WithObjects(defaultCluster, defaultKubeconfigSecret, machinepool, bootstrapConfig, infraConfig, builder.TestBootstrapConfigCRD, builder.TestInfrastructureMachineTemplateCRD).Build() - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fakeClient, ClusterCache: clustercache.NewFakeClusterCache(fakeClient, client.ObjectKey{Name: defaultCluster.Name, Namespace: defaultCluster.Namespace}), externalTracker: external.ObjectTracker{ @@ -175,7 +175,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, ClusterCache: clustercache.NewFakeClusterCache(fakeClient, client.ObjectKey{Name: defaultCluster.Name, Namespace: defaultCluster.Namespace}), externalTracker: external.ObjectTracker{ @@ -215,7 +215,7 @@ func TestReconcileMachinePoolPhases(t *testing.T) { g.Expect(err).ToNot(HaveOccurred()) fakeClient := fake.NewClientBuilder().WithObjects(defaultCluster, defaultKubeconfigSecret, machinepool, bootstrapConfig, infraConfig, builder.TestBootstrapConfigCRD, builder.TestInfrastructureMachineTemplateCRD).Build() - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fakeClient, ClusterCache: clustercache.NewFakeClusterCache(fakeClient, client.ObjectKey{Name: defaultCluster.Name, Namespace: defaultCluster.Namespace}), externalTracker: external.ObjectTracker{ @@ -271,7 +271,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, ClusterCache: clustercache.NewFakeClusterCache(fakeClient, client.ObjectKey{Name: defaultCluster.Name, Namespace: defaultCluster.Namespace}), externalTracker: external.ObjectTracker{ @@ -343,7 +343,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, ClusterCache: clustercache.NewFakeClusterCache(fakeClient, client.ObjectKey{Name: defaultCluster.Name, Namespace: defaultCluster.Namespace}), externalTracker: external.ObjectTracker{ @@ -393,7 +393,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, ClusterCache: clustercache.NewFakeClusterCache(fakeClient, client.ObjectKey{Name: defaultCluster.Name, Namespace: defaultCluster.Namespace}), externalTracker: external.ObjectTracker{ @@ -446,7 +446,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, ClusterCache: clustercache.NewFakeClusterCache(fakeClient, client.ObjectKey{Name: defaultCluster.Name, Namespace: defaultCluster.Namespace}), externalTracker: external.ObjectTracker{ @@ -516,7 +516,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, ClusterCache: clustercache.NewFakeClusterCache(fakeClient, client.ObjectKey{Name: defaultCluster.Name, Namespace: defaultCluster.Namespace}), externalTracker: external.ObjectTracker{ @@ -592,7 +592,7 @@ func TestReconcileMachinePoolPhases(t *testing.T) { machinepool.Finalizers = []string{expv1.MachinePoolFinalizer} fakeClient := fake.NewClientBuilder().WithObjects(defaultCluster, defaultKubeconfigSecret, machinepool, bootstrapConfig, infraConfig, builder.TestBootstrapConfigCRD, builder.TestInfrastructureMachineTemplateCRD).Build() - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fakeClient, ClusterCache: clustercache.NewFakeClusterCache(fakeClient, client.ObjectKey{Name: defaultCluster.Name, Namespace: defaultCluster.Namespace}), externalTracker: external.ObjectTracker{ @@ -666,7 +666,7 @@ func TestReconcileMachinePoolPhases(t *testing.T) { machinePool.Status.Replicas = ptr.To(int32(1)) fakeClient := fake.NewClientBuilder().WithObjects(defaultCluster, defaultKubeconfigSecret, machinePool, bootstrapConfig, infraConfig, builder.TestBootstrapConfigCRD, builder.TestInfrastructureMachineTemplateCRD).Build() - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fakeClient, ClusterCache: clustercache.NewFakeClusterCache(fakeClient, client.ObjectKey{Name: defaultCluster.Name, Namespace: defaultCluster.Namespace}), externalTracker: external.ObjectTracker{ @@ -762,7 +762,7 @@ func TestReconcileMachinePoolPhases(t *testing.T) { machinePool.Status.Replicas = ptr.To(int32(1)) fakeClient := fake.NewClientBuilder().WithObjects(defaultCluster, defaultKubeconfigSecret, machinePool, bootstrapConfig, infraConfig, builder.TestBootstrapConfigCRD, builder.TestInfrastructureMachineTemplateCRD).Build() - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fakeClient, ClusterCache: clustercache.NewFakeClusterCache(fakeClient, client.ObjectKey{Name: defaultCluster.Name, Namespace: defaultCluster.Namespace}), externalTracker: external.ObjectTracker{ @@ -1105,7 +1105,7 @@ func TestReconcileMachinePoolBootstrap(t *testing.T) { bootstrapConfig := &unstructured.Unstructured{Object: tc.bootstrapConfig} fakeClient := fake.NewClientBuilder().WithObjects(tc.machinepool, bootstrapConfig, builder.TestBootstrapConfigCRD, builder.TestInfrastructureMachineTemplateCRD).Build() - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fakeClient, externalTracker: external.ObjectTracker{ Controller: externalfake.Controller{}, @@ -1317,7 +1317,7 @@ func TestReconcileMachinePoolInfrastructure(t *testing.T) { infraConfig := &unstructured.Unstructured{Object: tc.infraConfig} fakeClient := fake.NewClientBuilder().WithObjects(tc.machinepool, infraConfig, builder.TestBootstrapConfigCRD, builder.TestInfrastructureMachineTemplateCRD).Build() - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fakeClient, ClusterCache: clustercache.NewFakeClusterCache(fakeClient, client.ObjectKey{Name: defaultCluster.Name, Namespace: defaultCluster.Namespace}), externalTracker: external.ObjectTracker{ @@ -1406,7 +1406,7 @@ func TestReconcileMachinePoolMachines(t *testing.T) { } g.Expect(env.CreateAndWait(ctx, &unstructured.Unstructured{Object: infraConfig})).To(Succeed()) - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: env, ssaCache: ssa.NewCache(testController), externalTracker: external.ObjectTracker{ @@ -1475,7 +1475,7 @@ func TestReconcileMachinePoolMachines(t *testing.T) { } g.Expect(env.CreateAndWait(ctx, &unstructured.Unstructured{Object: infraConfig})).To(Succeed()) - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: env, ssaCache: ssa.NewCache(testController), externalTracker: external.ObjectTracker{ @@ -1540,7 +1540,7 @@ func TestReconcileMachinePoolMachines(t *testing.T) { } g.Expect(env.CreateAndWait(ctx, &unstructured.Unstructured{Object: infraConfig})).To(Succeed()) - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: env, ssaCache: ssa.NewCache(testController), } @@ -1701,7 +1701,7 @@ func TestInfraMachineToMachinePoolMapper(t *testing.T) { objs = append(objs, mp.DeepCopy()) } - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fake.NewClientBuilder().WithObjects(objs...).Build(), } @@ -1841,7 +1841,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, ClusterCache: clustercache.NewFakeClusterCache(env.GetClient(), client.ObjectKey{Name: testCluster.Name, Namespace: testCluster.Namespace}), recorder: record.NewFakeRecorder(32), @@ -1909,7 +1909,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, ClusterCache: clustercache.NewFakeClusterCache(env.GetClient(), client.ObjectKey{Name: testCluster.Name, Namespace: testCluster.Namespace}), recorder: record.NewFakeRecorder(32), @@ -1960,7 +1960,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, recorder: record.NewFakeRecorder(32), ClusterCache: clustercache.NewFakeClusterCache(fakeClient, client.ObjectKey{Name: testCluster.Name, Namespace: testCluster.Namespace}), @@ -2007,7 +2007,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, recorder: record.NewFakeRecorder(32), ClusterCache: clustercache.NewFakeClusterCache(fakeClient, client.ObjectKey{Name: testCluster.Name, Namespace: testCluster.Namespace}), @@ -2076,7 +2076,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, ClusterCache: clustercache.NewFakeClusterCache(env.GetClient(), client.ObjectKey{Name: testCluster.Name, Namespace: testCluster.Namespace}), recorder: record.NewFakeRecorder(32), @@ -2308,7 +2308,7 @@ func TestMachinePoolReconciler_getNodeRefMap(t *testing.T) { for _, tt := range testCases { t.Run(tt.name, func(t *testing.T) { g := NewWithT(t) - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fake.NewClientBuilder().Build(), recorder: record.NewFakeRecorder(32), } diff --git a/exp/internal/controllers/machinepool_controller_test.go b/exp/internal/controllers/machinepool/machinepool_controller_test.go similarity index 99% rename from exp/internal/controllers/machinepool_controller_test.go rename to exp/internal/controllers/machinepool/machinepool_controller_test.go index effd5adb99ea..1b8178cba0ca 100644 --- a/exp/internal/controllers/machinepool_controller_test.go +++ b/exp/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 ( "context" @@ -124,7 +124,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, @@ -258,7 +258,7 @@ func TestMachinePoolOwnerReference(t *testing.T) { machinePoolValidCluster, machinePoolValidMachinePool, ).WithStatusSubresource(&expv1.MachinePool{}).Build() - mr := &MachinePoolReconciler{ + mr := &Reconciler{ Client: fakeClient, APIReader: fakeClient, } @@ -606,7 +606,7 @@ func TestReconcileMachinePoolRequest(t *testing.T) { }, }).WithObjects(trackerObjects...).Build() - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: clientFake, APIReader: clientFake, ClusterCache: clustercache.NewFakeClusterCache(trackerClientFake, client.ObjectKey{Name: testCluster.Name, Namespace: testCluster.Namespace}), @@ -725,7 +725,7 @@ func TestMachinePoolNodeDeleteTimeoutPassed(t *testing.T) { t.Run(tc.name, func(t *testing.T) { g := NewWithT(t) - timeoutPassed := (&MachinePoolReconciler{}).isMachinePoolNodeDeleteTimeoutPassed(tc.machinePool) + timeoutPassed := (&Reconciler{}).isMachinePoolNodeDeleteTimeoutPassed(tc.machinePool) g.Expect(timeoutPassed).To(Equal(tc.want)) }) } @@ -837,7 +837,7 @@ func TestReconcileMachinePoolDeleteExternal(t *testing.T) { objs = append(objs, infraConfig) } - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: fake.NewClientBuilder().WithObjects(objs...).Build(), } @@ -893,7 +893,7 @@ func TestRemoveMachinePoolFinalizerAfterDeleteReconcile(t *testing.T) { } key := client.ObjectKey{Namespace: m.Namespace, Name: m.Name} clientFake := fake.NewClientBuilder().WithObjects(testCluster, m).WithStatusSubresource(&expv1.MachinePool{}).Build() - mr := &MachinePoolReconciler{ + mr := &Reconciler{ Client: clientFake, ClusterCache: clustercache.NewFakeClusterCache(clientFake, client.ObjectKey{Name: testCluster.Name, Namespace: testCluster.Namespace}), } @@ -1184,7 +1184,7 @@ func TestMachinePoolConditions(t *testing.T) { builder.TestInfrastructureMachineTemplateCRD, ).WithStatusSubresource(&expv1.MachinePool{}).Build() - r := &MachinePoolReconciler{ + r := &Reconciler{ Client: clientFake, APIReader: clientFake, ClusterCache: clustercache.NewFakeClusterCache(clientFake, client.ObjectKey{Name: testCluster.Name, Namespace: testCluster.Namespace}), diff --git a/exp/internal/controllers/suite_test.go b/exp/internal/controllers/machinepool/suite_test.go similarity index 98% rename from exp/internal/controllers/suite_test.go rename to exp/internal/controllers/machinepool/suite_test.go index 6bd0c63fbe71..08f51fb8ad0a 100644 --- a/exp/internal/controllers/suite_test.go +++ b/exp/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" @@ -74,7 +74,7 @@ func TestMain(m *testing.M) { clusterCache.(interface{ Shutdown() }).Shutdown() }() - if err := (&MachinePoolReconciler{ + if err := (&Reconciler{ Client: mgr.GetClient(), APIReader: mgr.GetAPIReader(), ClusterCache: clusterCache, diff --git a/test/infrastructure/docker/exp/controllers/alias.go b/test/infrastructure/docker/exp/controllers/alias.go index adf1beac6676..2b14f725348b 100644 --- a/test/infrastructure/docker/exp/controllers/alias.go +++ b/test/infrastructure/docker/exp/controllers/alias.go @@ -25,7 +25,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/cluster-api/test/infrastructure/container" - dockermachinepoolcontrollers "sigs.k8s.io/cluster-api/test/infrastructure/docker/exp/internal/controllers" + dockermachinepoolcontrollers "sigs.k8s.io/cluster-api/test/infrastructure/docker/exp/internal/controllers/machinepool" ) // DockerMachinePoolReconciler reconciles a DockerMachinePool object. diff --git a/test/infrastructure/docker/exp/internal/controllers/machinepool/OWNERS b/test/infrastructure/docker/exp/internal/controllers/machinepool/OWNERS new file mode 100644 index 000000000000..c7ff5c37ae80 --- /dev/null +++ b/test/infrastructure/docker/exp/internal/controllers/machinepool/OWNERS @@ -0,0 +1,8 @@ +# See the OWNERS docs at https://go.k8s.io/owners + +approvers: + - cluster-api-maintainers + +reviewers: + - cluster-api-reviewers + - cluster-api-machinepool-reviewers diff --git a/test/infrastructure/docker/exp/internal/controllers/dockermachinepool_controller.go b/test/infrastructure/docker/exp/internal/controllers/machinepool/dockermachinepool_controller.go similarity index 99% rename from test/infrastructure/docker/exp/internal/controllers/dockermachinepool_controller.go rename to test/infrastructure/docker/exp/internal/controllers/machinepool/dockermachinepool_controller.go index 2dff5f74a7e3..13fbd424e7bb 100644 --- a/test/infrastructure/docker/exp/internal/controllers/dockermachinepool_controller.go +++ b/test/infrastructure/docker/exp/internal/controllers/machinepool/dockermachinepool_controller.go @@ -14,8 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Package controllers implements controller functionality. -package controllers +// Package machinepool implements machinepool controller functionality. +package machinepool import ( "context" diff --git a/test/infrastructure/docker/exp/internal/controllers/dockermachinepool_controller_phases.go b/test/infrastructure/docker/exp/internal/controllers/machinepool/dockermachinepool_controller_phases.go similarity index 99% rename from test/infrastructure/docker/exp/internal/controllers/dockermachinepool_controller_phases.go rename to test/infrastructure/docker/exp/internal/controllers/machinepool/dockermachinepool_controller_phases.go index 02fe0d941859..1964ca8913f6 100644 --- a/test/infrastructure/docker/exp/internal/controllers/dockermachinepool_controller_phases.go +++ b/test/infrastructure/docker/exp/internal/controllers/machinepool/dockermachinepool_controller_phases.go @@ -14,8 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Package controllers implements controller functionality. -package controllers +// Package machinepool implements controller functionality. +package machinepool import ( "context"