Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func main() {
majorVersion = 4
}
defaultMutableGate := feature.DefaultMutableFeatureGate
gateOpts, err := features.NewFeatureGateOptions(defaultMutableGate, majorVersion, apifeatures.SelfManaged, apifeatures.FeatureGateAzureWorkloadIdentity, apifeatures.FeatureGateMachineAPIMigration)
gateOpts, err := features.NewFeatureGateOptions(defaultMutableGate, majorVersion, apifeatures.SelfManaged, apifeatures.FeatureGateMachineAPIMigration)
if err != nil {
klog.Fatalf("Error setting up feature gates: %v", err)
}
Expand Down Expand Up @@ -152,8 +152,6 @@ func main() {
}

klog.Infof("FeatureGateMachineAPIMigration initialised: %t", defaultMutableGate.Enabled(featuregate.Feature(apifeatures.FeatureGateMachineAPIMigration)))
klog.Infof("FeatureGateAzureWorkloadIdentity initialised: %t", defaultMutableGate.Enabled(featuregate.Feature(apifeatures.FeatureGateAzureWorkloadIdentity)))
azureWorkloadIdentityEnabled := defaultMutableGate.Enabled(featuregate.Feature(apifeatures.FeatureGateAzureWorkloadIdentity))

// Setup a Manager
mgr, err := manager.New(cfg, opts)
Expand All @@ -167,10 +165,9 @@ func main() {

// Initialize machine actuator.
machineActuator := actuator.NewActuator(actuator.ActuatorParams{
CoreClient: mgr.GetClient(),
ReconcilerBuilder: actuator.NewReconciler,
EventRecorder: mgr.GetEventRecorderFor("azure-controller"),
AzureWorkloadIdentityEnabled: azureWorkloadIdentityEnabled,
CoreClient: mgr.GetClient(),
ReconcilerBuilder: actuator.NewReconciler,
EventRecorder: mgr.GetEventRecorderFor("azure-controller"),
})

if err := machinev1.AddToScheme(mgr.GetScheme()); err != nil {
Expand All @@ -193,8 +190,6 @@ func main() {
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("MachineSet"),
ResourceSkusServiceBuilder: resourceskus.NewService,

AzureWorkloadIdentityEnabled: azureWorkloadIdentityEnabled,
}).SetupWithManager(mgr, controller.Options{}); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "MachineSet")
os.Exit(1)
Expand Down
36 changes: 14 additions & 22 deletions pkg/cloud/azure/actuators/machine/actuator.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,21 @@ type Actuator struct {
eventRecorder record.EventRecorder

reconcilerBuilder func(scope *actuators.MachineScope) *Reconciler

azureWorkloadIdentityEnabled bool
}

// ActuatorParams holds parameter information for Actuator.
type ActuatorParams struct {
CoreClient controllerclient.Client
EventRecorder record.EventRecorder
ReconcilerBuilder func(scope *actuators.MachineScope) *Reconciler
AzureWorkloadIdentityEnabled bool
CoreClient controllerclient.Client
EventRecorder record.EventRecorder
ReconcilerBuilder func(scope *actuators.MachineScope) *Reconciler
}

// NewActuator returns an actuator.
func NewActuator(params ActuatorParams) *Actuator {
return &Actuator{
coreClient: params.CoreClient,
eventRecorder: params.EventRecorder,
reconcilerBuilder: params.ReconcilerBuilder,
azureWorkloadIdentityEnabled: params.AzureWorkloadIdentityEnabled,
coreClient: params.CoreClient,
eventRecorder: params.EventRecorder,
reconcilerBuilder: params.ReconcilerBuilder,
}
}

Expand All @@ -90,9 +86,8 @@ func (a *Actuator) Create(ctx context.Context, machine *machinev1.Machine) error
klog.Infof("Creating machine %v", machine.Name)

scope, err := actuators.NewMachineScope(actuators.MachineScopeParams{
Machine: machine,
CoreClient: a.coreClient,
AzureWorkloadIdentityEnabled: a.azureWorkloadIdentityEnabled,
Machine: machine,
CoreClient: a.coreClient,
})
if err != nil {
return a.handleMachineError(machine, machineapierrors.InvalidMachineConfiguration("failed to create machine %q scope: %v", machine.Name, err), createEventAction)
Expand Down Expand Up @@ -142,9 +137,8 @@ func (a *Actuator) Delete(ctx context.Context, machine *machinev1.Machine) error
klog.Infof("Deleting machine %v", machine.Name)

scope, err := actuators.NewMachineScope(actuators.MachineScopeParams{
Machine: machine,
CoreClient: a.coreClient,
AzureWorkloadIdentityEnabled: a.azureWorkloadIdentityEnabled,
Machine: machine,
CoreClient: a.coreClient,
})
if err != nil {
return a.handleMachineError(machine, machineapierrors.DeleteMachine("failed to create machine %q scope: %v", machine.Name, err), deleteEventAction)
Expand Down Expand Up @@ -178,9 +172,8 @@ func (a *Actuator) Update(ctx context.Context, machine *machinev1.Machine) error
klog.Infof("Updating machine %v", machine.Name)

scope, err := actuators.NewMachineScope(actuators.MachineScopeParams{
Machine: machine,
CoreClient: a.coreClient,
AzureWorkloadIdentityEnabled: a.azureWorkloadIdentityEnabled,
Machine: machine,
CoreClient: a.coreClient,
})
if err != nil {
return a.handleMachineError(machine, machineapierrors.UpdateMachine("failed to create machine %q scope: %v", machine.Name, err), updateEventAction)
Expand Down Expand Up @@ -247,9 +240,8 @@ func (a *Actuator) Exists(ctx context.Context, machine *machinev1.Machine) (bool
klog.Infof("%s: actuator checking if machine exists", machine.GetName())

scope, err := actuators.NewMachineScope(actuators.MachineScopeParams{
Machine: machine,
CoreClient: a.coreClient,
AzureWorkloadIdentityEnabled: a.azureWorkloadIdentityEnabled,
Machine: machine,
CoreClient: a.coreClient,
})
if err != nil {
return false, fmt.Errorf("failed to create scope: %+v", err)
Expand Down
12 changes: 3 additions & 9 deletions pkg/cloud/azure/actuators/machine_scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ const (
// MachineScopeParams defines the input parameters used to create a new MachineScope.
type MachineScopeParams struct {
AzureClients
Machine *machinev1.Machine
CoreClient controllerclient.Client
AzureWorkloadIdentityEnabled bool
Machine *machinev1.Machine
CoreClient controllerclient.Client
}

// NewMachineScope creates a new MachineScope from the supplied parameters.
Expand Down Expand Up @@ -139,8 +138,6 @@ func NewMachineScope(params MachineScopeParams) (*MachineScope, error) {
armEndpoint: armEndpoint,
Tags: tags,
azureResourceGroup: resourceGroup,

azureWorkloadIdentityEnabled: params.AzureWorkloadIdentityEnabled,
}

if err = updateFromSecret(params.CoreClient, machineScope); err != nil {
Expand Down Expand Up @@ -182,9 +179,6 @@ type MachineScope struct {

// azureResourceGroup is the resource group pulled from the cluster infrastructure object
azureResourceGroup string

// azureWorkloadIdentityEnabled for if the cluster has opted in to azure workload identity
azureWorkloadIdentityEnabled bool
}

// Name returns the machine name.
Expand Down Expand Up @@ -401,7 +395,7 @@ func updateFromSecret(coreClient controllerclient.Client, scope *MachineScope) e
var cred azcore.TokenCredential
cloudConfig := getCloudConfig(env)

if scope.azureWorkloadIdentityEnabled && strings.TrimSpace(clientSecret) == "" {
if strings.TrimSpace(clientSecret) == "" {
options := azidentity.WorkloadIdentityCredentialOptions{
ClientOptions: azcore.ClientOptions{
Cloud: cloudConfig,
Expand Down
4 changes: 0 additions & 4 deletions pkg/cloud/azure/actuators/machineset/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ type Reconciler struct {
Log logr.Logger
ResourceSkusServiceBuilder resourceskus.ResourceSkusServiceBuilderFuncType

AzureWorkloadIdentityEnabled bool

recorder record.EventRecorder
scheme *runtime.Scheme
}
Expand Down Expand Up @@ -202,8 +200,6 @@ func createMachineScope(r *Reconciler, machineSet *machinev1.MachineSet) (*actua
Spec: machineSet.Spec.Template.Spec,
},
CoreClient: r.Client,

AzureWorkloadIdentityEnabled: r.AzureWorkloadIdentityEnabled,
}

machineScope, err := actuators.NewMachineScope(params)
Expand Down