Skip to content

Commit

Permalink
Add in-place controllers to EKS-A manager (#7056)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinavmpandey08 authored Nov 16, 2023
1 parent 25bf901 commit b504b64
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 19 deletions.
26 changes: 26 additions & 0 deletions config/manifest/eksa-components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
26 changes: 26 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 8 additions & 3 deletions controllers/controlplaneupgrade_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
68 changes: 61 additions & 7 deletions controllers/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
15 changes: 12 additions & 3 deletions controllers/machinedeploymentupgrade_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down
11 changes: 8 additions & 3 deletions controllers/nodeupgrade_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
23 changes: 22 additions & 1 deletion manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion pkg/api/v1alpha1/controlplaneupgrade_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion pkg/api/v1alpha1/machinedeploymentupgrade_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions pkg/api/v1alpha1/nodeupgrade_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit b504b64

Please sign in to comment.