From b504b64188bf5604ccb64f2fb78281b93a39c182 Mon Sep 17 00:00:00 2001 From: Abhinav Pandey Date: Wed, 15 Nov 2023 16:51:53 -0800 Subject: [PATCH] Add in-place controllers to EKS-A manager (#7056) --- config/manifest/eksa-components.yaml | 26 +++++++ config/rbac/role.yaml | 26 +++++++ controllers/controlplaneupgrade_controller.go | 11 ++- controllers/factory.go | 68 +++++++++++++++++-- .../machinedeploymentupgrade_controller.go | 15 +++- controllers/nodeupgrade_controller.go | 11 ++- manager/main.go | 23 ++++++- pkg/api/v1alpha1/controlplaneupgrade_types.go | 3 +- .../machinedeploymentupgrade_types.go | 3 +- pkg/api/v1alpha1/nodeupgrade_types.go | 3 + 10 files changed, 170 insertions(+), 19 deletions(-) diff --git a/config/manifest/eksa-components.yaml b/config/manifest/eksa-components.yaml index 52b8d11b32f0..829028d09aca 100644 --- a/config/manifest/eksa-components.yaml +++ b/config/manifest/eksa-components.yaml @@ -6784,6 +6784,32 @@ rules: - get - list - watch +- apiGroups: + - anywhere.eks.amazonaws.com + resources: + - machinedeploymentupgrades + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - anywhere.eks.amazonaws.com + resources: + - machinedeploymentupgrades/finalizers + verbs: + - update +- apiGroups: + - anywhere.eks.amazonaws.com + resources: + - machinedeploymentupgrades/status + verbs: + - get + - patch + - update - apiGroups: - anywhere.eks.amazonaws.com resources: diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index d8c32a1b3ff7..310d5a313ec4 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -152,6 +152,32 @@ rules: - get - list - watch +- apiGroups: + - anywhere.eks.amazonaws.com + resources: + - machinedeploymentupgrades + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - anywhere.eks.amazonaws.com + resources: + - machinedeploymentupgrades/finalizers + verbs: + - update +- apiGroups: + - anywhere.eks.amazonaws.com + resources: + - machinedeploymentupgrades/status + verbs: + - get + - patch + - update - apiGroups: - anywhere.eks.amazonaws.com resources: diff --git a/controllers/controlplaneupgrade_controller.go b/controllers/controlplaneupgrade_controller.go index d7665ee4d406..2f5407d46a44 100644 --- a/controllers/controlplaneupgrade_controller.go +++ b/controllers/controlplaneupgrade_controller.go @@ -19,7 +19,6 @@ package controllers import ( "context" - "k8s.io/apimachinery/pkg/runtime" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" @@ -29,8 +28,14 @@ import ( // ControlPlaneUpgradeReconciler reconciles a ControlPlaneUpgradeReconciler object. type ControlPlaneUpgradeReconciler struct { - client.Client - Scheme *runtime.Scheme + client client.Client +} + +// NewControlPlaneUpgradeReconciler returns a new instance of ControlPlaneUpgradeReconciler. +func NewControlPlaneUpgradeReconciler(client client.Client) *ControlPlaneUpgradeReconciler { + return &ControlPlaneUpgradeReconciler{ + client: client, + } } //+kubebuilder:rbac:groups=anywhere.eks.amazonaws.com,resources=controlplaneupgrades,verbs=get;list;watch;create;update;patch;delete diff --git a/controllers/factory.go b/controllers/factory.go index e45b74433469..ccef722b2483 100644 --- a/controllers/factory.go +++ b/controllers/factory.go @@ -59,13 +59,16 @@ type Factory struct { } type Reconcilers struct { - ClusterReconciler *ClusterReconciler - DockerDatacenterReconciler *DockerDatacenterReconciler - VSphereDatacenterReconciler *VSphereDatacenterReconciler - SnowMachineConfigReconciler *SnowMachineConfigReconciler - TinkerbellDatacenterReconciler *TinkerbellDatacenterReconciler - CloudStackDatacenterReconciler *CloudStackDatacenterReconciler - NutanixDatacenterReconciler *NutanixDatacenterReconciler + ClusterReconciler *ClusterReconciler + DockerDatacenterReconciler *DockerDatacenterReconciler + VSphereDatacenterReconciler *VSphereDatacenterReconciler + SnowMachineConfigReconciler *SnowMachineConfigReconciler + TinkerbellDatacenterReconciler *TinkerbellDatacenterReconciler + CloudStackDatacenterReconciler *CloudStackDatacenterReconciler + NutanixDatacenterReconciler *NutanixDatacenterReconciler + ControlPlaneUpgradeReconciler *ControlPlaneUpgradeReconciler + MachineDeploymentUpgradeReconciler *MachineDeploymentUpgradeReconciler + NodeUpgradeReconciler *NodeUpgradeReconciler } type buildStep func(ctx context.Context) error @@ -550,3 +553,54 @@ func (f *Factory) withMachineHealthCheckReconciler() *Factory { return f } + +// WithControlPlaneUpgradeReconciler builds the ControlPlaneUpgrade reconciler. +func (f *Factory) WithControlPlaneUpgradeReconciler() *Factory { + f.buildSteps = append(f.buildSteps, func(ctx context.Context) error { + if f.reconcilers.ControlPlaneUpgradeReconciler != nil { + return nil + } + + f.reconcilers.ControlPlaneUpgradeReconciler = NewControlPlaneUpgradeReconciler( + f.manager.GetClient(), + ) + + return nil + }) + + return f +} + +// WithMachineDeploymentUpgradeReconciler builds the WithMachineDeploymentUpgrade reconciler. +func (f *Factory) WithMachineDeploymentUpgradeReconciler() *Factory { + f.buildSteps = append(f.buildSteps, func(ctx context.Context) error { + if f.reconcilers.MachineDeploymentUpgradeReconciler != nil { + return nil + } + + f.reconcilers.MachineDeploymentUpgradeReconciler = NewMachineDeploymentUpgradeReconciler( + f.manager.GetClient(), + ) + + return nil + }) + + return f +} + +// WithNodeUpgradeReconciler builds the WithNodeUpgrade reconciler. +func (f *Factory) WithNodeUpgradeReconciler() *Factory { + f.buildSteps = append(f.buildSteps, func(ctx context.Context) error { + if f.reconcilers.NodeUpgradeReconciler != nil { + return nil + } + + f.reconcilers.NodeUpgradeReconciler = NewNodeUpgradeReconciler( + f.manager.GetClient(), + ) + + return nil + }) + + return f +} diff --git a/controllers/machinedeploymentupgrade_controller.go b/controllers/machinedeploymentupgrade_controller.go index bf17af907234..a2b0bed303e8 100644 --- a/controllers/machinedeploymentupgrade_controller.go +++ b/controllers/machinedeploymentupgrade_controller.go @@ -19,7 +19,6 @@ package controllers import ( "context" - "k8s.io/apimachinery/pkg/runtime" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" @@ -29,10 +28,20 @@ import ( // MachineDeploymentUpgradeReconciler reconciles a MachineDeploymentUpgrade object. type MachineDeploymentUpgradeReconciler struct { - client.Client - Scheme *runtime.Scheme + client client.Client } +// NewMachineDeploymentUpgradeReconciler returns a new instance of MachineDeploymentUpgradeReconciler. +func NewMachineDeploymentUpgradeReconciler(client client.Client) *MachineDeploymentUpgradeReconciler { + return &MachineDeploymentUpgradeReconciler{ + client: client, + } +} + +//+kubebuilder:rbac:groups=anywhere.eks.amazonaws.com,resources=machinedeploymentupgrades,verbs=get;list;watch;create;update;patch;delete +//+kubebuilder:rbac:groups=anywhere.eks.amazonaws.com,resources=machinedeploymentupgrades/status,verbs=get;update;patch +//+kubebuilder:rbac:groups=anywhere.eks.amazonaws.com,resources=machinedeploymentupgrades/finalizers,verbs=update + // Reconcile reconciles a MachineDeploymentUpgrade object. func (r *MachineDeploymentUpgradeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { _ = log.FromContext(ctx) diff --git a/controllers/nodeupgrade_controller.go b/controllers/nodeupgrade_controller.go index e44325cb2a97..2ca871cc19e2 100644 --- a/controllers/nodeupgrade_controller.go +++ b/controllers/nodeupgrade_controller.go @@ -3,7 +3,6 @@ package controllers import ( "context" - "k8s.io/apimachinery/pkg/runtime" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" @@ -13,8 +12,14 @@ import ( // NodeUpgradeReconciler reconciles a NodeUpgrade object. type NodeUpgradeReconciler struct { - client.Client - Scheme *runtime.Scheme + client client.Client +} + +// NewNodeUpgradeReconciler returns a new instance of NodeUpgradeReconciler. +func NewNodeUpgradeReconciler(client client.Client) *NodeUpgradeReconciler { + return &NodeUpgradeReconciler{ + client: client, + } } //+kubebuilder:rbac:groups=anywhere.eks.amazonaws.com,resources=nodeupgrades,verbs=get;list;watch;create;update;patch;delete diff --git a/manager/main.go b/manager/main.go index 9f998d0ebad1..8cf7ab52849a 100644 --- a/manager/main.go +++ b/manager/main.go @@ -175,7 +175,10 @@ func setupReconcilers(ctx context.Context, setupLog logr.Logger, mgr ctrl.Manage WithVSphereDatacenterReconciler(). WithSnowMachineConfigReconciler(). WithNutanixDatacenterReconciler(). - WithCloudStackDatacenterReconciler() + WithCloudStackDatacenterReconciler(). + WithControlPlaneUpgradeReconciler(). + WithMachineDeploymentUpgradeReconciler(). + WithNodeUpgradeReconciler() reconcilers, err := factory.Build(ctx) if err != nil { @@ -214,6 +217,24 @@ func setupReconcilers(ctx context.Context, setupLog logr.Logger, mgr ctrl.Manage failed = true } + setupLog.Info("Setting up controlplaneupgrade controller") + if err := (reconcilers.ControlPlaneUpgradeReconciler).SetupWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create controller", "controller", anywherev1.ControlPlaneUpgradeKind) + failed = true + } + + setupLog.Info("Setting up machinedeploymentupgrade controller") + if err := (reconcilers.MachineDeploymentUpgradeReconciler).SetupWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create controller", "controller", anywherev1.MachineDeploymentUpgradeKind) + failed = true + } + + setupLog.Info("Setting up nodeupgrade controller") + if err := (reconcilers.NodeUpgradeReconciler).SetupWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create controller", "controller", anywherev1.NodeUpgradeKind) + failed = true + } + if failed { if err := factory.Close(ctx); err != nil { setupLog.Error(err, "Failed closing controller factory") diff --git a/pkg/api/v1alpha1/controlplaneupgrade_types.go b/pkg/api/v1alpha1/controlplaneupgrade_types.go index c366fdc62965..5e3aea0253cf 100644 --- a/pkg/api/v1alpha1/controlplaneupgrade_types.go +++ b/pkg/api/v1alpha1/controlplaneupgrade_types.go @@ -4,7 +4,8 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. +// ControlPlaneUpgradeKind stores the kind for ControlPlaneUpgrade. +const ControlPlaneUpgradeKind = "ControlPlaneUpgrade" // ControlPlaneUpgradeSpec defines the desired state of ControlPlaneUpgrade. type ControlPlaneUpgradeSpec struct { diff --git a/pkg/api/v1alpha1/machinedeploymentupgrade_types.go b/pkg/api/v1alpha1/machinedeploymentupgrade_types.go index d2908fcbea79..1ef08a885c84 100644 --- a/pkg/api/v1alpha1/machinedeploymentupgrade_types.go +++ b/pkg/api/v1alpha1/machinedeploymentupgrade_types.go @@ -4,7 +4,8 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. +// MachineDeploymentUpgradeKind stores the Kind for MachineDeploymentUpgrade. +const MachineDeploymentUpgradeKind = "MachineDeploymentUpgrade" // MachineDeploymentUpgradeSpec defines the desired state of MachineDeploymentUpgrade. type MachineDeploymentUpgradeSpec struct { diff --git a/pkg/api/v1alpha1/nodeupgrade_types.go b/pkg/api/v1alpha1/nodeupgrade_types.go index 4fb34cdda799..f6730a5d306d 100644 --- a/pkg/api/v1alpha1/nodeupgrade_types.go +++ b/pkg/api/v1alpha1/nodeupgrade_types.go @@ -5,6 +5,9 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" ) +// NodeUpgradeKind stores the Kind for NodeUpgrade. +const NodeUpgradeKind = "NodeUpgrade" + // NodeUpgradeSpec defines the desired state of NodeUpgrade. type NodeUpgradeSpec struct { Machine Ref `json:"machine"`