Skip to content

Commit

Permalink
Register aso secret controller
Browse files Browse the repository at this point in the history
  • Loading branch information
adriananeci committed Jul 28, 2023
1 parent dbffce9 commit 30c9a8b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
30 changes: 7 additions & 23 deletions controllers/asosecret_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,6 @@ func (asos *ASOSecretReconciler) Reconcile(ctx context.Context, req ctrl.Request

azureClient = clusterScope.AzureClients

azureClusterName := types.NamespacedName{
Namespace: req.Namespace,
Name: req.Name,
}
// fetch the azure cluster
if err := asos.Get(ctx, azureClusterName, azureCluster); err != nil {
log.Error(err, "failed to fetch AzureCluster")
return reconcile.Result{}, err
}

case *infrav1.AzureManagedControlPlane:
clusterIdentity = ownerType.Spec.IdentityRef

Expand Down Expand Up @@ -222,17 +212,16 @@ func (asos *ASOSecretReconciler) Reconcile(ctx context.Context, req ctrl.Request

// Construct ASO secret for this AzureCluster
newASOSecret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: aso.GetASOSecretName(asoSecretOwner.GetName()),
Namespace: asoSecretOwner.GetNamespace(),
},
Data: map[string][]byte{
"AZURE_SUBSCRIPTION_ID": []byte(azureClient.SubscriptionID()),
},
}

if clusterIdentity != nil {
newASOSecret.ObjectMeta = metav1.ObjectMeta{
Name: aso.GetASOSecretName(clusterIdentity.Name),
Namespace: azureCluster.GetNamespace(),
}

identity := &infrav1.AzureClusterIdentity{}
key := client.ObjectKey{
Name: clusterIdentity.Name,
Expand Down Expand Up @@ -264,11 +253,6 @@ func (asos *ASOSecretReconciler) Reconcile(ctx context.Context, req ctrl.Request
newASOSecret.Data["AZURE_CLIENT_CERTIFICATE_PASSWORD"] = identitySecret.Data["password"]
}
} else {
newASOSecret.ObjectMeta = metav1.ObjectMeta{
Name: aso.GetASOSecretName(asoSecretOwner.GetName()),
Namespace: azureCluster.GetNamespace(),
}

newASOSecret.Data["AZURE_TENANT_ID"] = []byte(azureClient.TenantID())
newASOSecret.Data["AZURE_CLIENT_ID"] = []byte(azureClient.ClientID())

Expand All @@ -293,12 +277,12 @@ func (asos *ASOSecretReconciler) Reconcile(ctx context.Context, req ctrl.Request
owner := metav1.OwnerReference{
APIVersion: gvk.GroupVersion().String(),
Kind: gvk.Kind,
Name: azureCluster.GetName(),
UID: azureCluster.GetUID(),
Name: asoSecretOwner.GetName(),
UID: asoSecretOwner.GetUID(),
}

if err := reconcileAzureSecret(ctx, asos.Client, owner, newASOSecret, asoSecretOwner.GetName()); err != nil {
asos.Recorder.Eventf(azureCluster, corev1.EventTypeWarning, "Error reconciling ASO secret for AzureCluster", err.Error())
asos.Recorder.Eventf(asoSecretOwner, corev1.EventTypeWarning, "Error reconciling ASO secret", err.Error())
return ctrl.Result{}, errors.Wrap(err, "failed to reconcile ASO secret")
}

Expand Down
10 changes: 10 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,16 @@ func registerControllers(ctx context.Context, mgr manager.Manager) {
os.Exit(1)
}

if err := (&controllers.ASOSecretReconciler{
Client: mgr.GetClient(),
Recorder: mgr.GetEventRecorderFor("asosecret-reconciler"),
ReconcileTimeout: reconcileTimeout,
WatchFilterValue: watchFilterValue,
}).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: azureClusterConcurrency}); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "ASOSecret")
os.Exit(1)
}

// just use CAPI MachinePool feature flag rather than create a new one
setupLog.V(1).Info(fmt.Sprintf("%+v\n", feature.Gates))
if feature.Gates.Enabled(capifeature.MachinePool) {
Expand Down

0 comments on commit 30c9a8b

Please sign in to comment.