Skip to content

Commit f6ee71a

Browse files
committed
Add application credential finalizer management
Signed-off-by: Veronika Fisarova <vfisarov@redhat.com>
1 parent 886e4f9 commit f6ee71a

6 files changed

Lines changed: 370 additions & 0 deletions

File tree

api/bases/placement.openstack.org_placementapis.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,13 @@ spec:
412412
status:
413413
description: PlacementAPIStatus defines the observed state of PlacementAPI
414414
properties:
415+
applicationCredentialSecret:
416+
description: |-
417+
ApplicationCredentialSecret - the AC secret placement is currently
418+
consuming and protecting with the openstack.org/placementapi-ac-consumer
419+
finalizer. Tracked so the controller can remove its finalizer from the
420+
old secret when the openstack-operator rotates the reference.
421+
type: string
415422
conditions:
416423
description: Conditions
417424
items:

api/placement/v1beta1/api_types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ type PlacementAPIStatus struct {
182182

183183
// LastAppliedTopology - the last applied Topology
184184
LastAppliedTopology *topologyv1.TopoRef `json:"lastAppliedTopology,omitempty"`
185+
186+
// ApplicationCredentialSecret - the AC secret placement is currently
187+
// consuming and protecting with the openstack.org/placementapi-ac-consumer
188+
// finalizer. Tracked so the controller can remove its finalizer from the
189+
// old secret when the openstack-operator rotates the reference.
190+
ApplicationCredentialSecret string `json:"applicationCredentialSecret,omitempty"`
185191
}
186192

187193
// PlacementAPI is the Schema for the placementapis API

config/crd/bases/placement.openstack.org_placementapis.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,13 @@ spec:
412412
status:
413413
description: PlacementAPIStatus defines the observed state of PlacementAPI
414414
properties:
415+
applicationCredentialSecret:
416+
description: |-
417+
ApplicationCredentialSecret - the AC secret placement is currently
418+
consuming and protecting with the openstack.org/placementapi-ac-consumer
419+
finalizer. Tracked so the controller can remove its finalizer from the
420+
old secret when the openstack-operator rotates the reference.
421+
type: string
415422
conditions:
416423
description: Conditions
417424
items:

internal/controller/placement/api_controller.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,21 @@ func (r *PlacementAPIReconciler) Reconcile(ctx context.Context, req ctrl.Request
455455
return ctrl.Result{}, nil
456456
}
457457

458+
if instance.Spec.Auth.ApplicationCredentialSecret != "" {
459+
if err := keystonev1.ManageACSecretFinalizer(ctx, h, instance.Namespace,
460+
instance.Spec.Auth.ApplicationCredentialSecret,
461+
"",
462+
placement.ACConsumerFinalizer); err != nil {
463+
instance.Status.Conditions.Set(condition.FalseCondition(
464+
condition.ServiceConfigReadyCondition,
465+
condition.ErrorReason,
466+
condition.SeverityWarning,
467+
condition.ServiceConfigReadyErrorMessage,
468+
err.Error()))
469+
return ctrl.Result{}, err
470+
}
471+
}
472+
458473
instance.Status.Conditions.MarkTrue(condition.ServiceConfigReadyCondition, condition.ServiceConfigReadyMessage)
459474

460475
serviceAnnotations, result, err := r.ensureNetworkAttachments(ctx, h, instance)
@@ -502,6 +517,26 @@ func (r *PlacementAPIReconciler) Reconcile(ctx context.Context, req ctrl.Request
502517
return ctrl.Result{}, err
503518
}
504519

520+
// Manage the old AC secret's finalizer and status tracking.
521+
// On rotation (old != new), only remove the old secret's finalizer after
522+
// all sub-services are ready with the new credentials. This prevents
523+
// premature revocation during rapid rotations.
524+
isRotation := instance.Status.ApplicationCredentialSecret != "" &&
525+
instance.Status.ApplicationCredentialSecret != instance.Spec.Auth.ApplicationCredentialSecret
526+
527+
if isRotation {
528+
allServicesReady := instance.Status.Conditions.AllSubConditionIsTrue()
529+
if allServicesReady {
530+
if err := keystonev1.RemoveACSecretConsumerFinalizer(ctx, h, instance.Namespace,
531+
instance.Status.ApplicationCredentialSecret, placement.ACConsumerFinalizer); err != nil {
532+
return ctrl.Result{}, err
533+
}
534+
instance.Status.ApplicationCredentialSecret = instance.Spec.Auth.ApplicationCredentialSecret
535+
}
536+
} else {
537+
instance.Status.ApplicationCredentialSecret = instance.Spec.Auth.ApplicationCredentialSecret
538+
}
539+
505540
return ctrl.Result{}, nil
506541
}
507542

@@ -1094,6 +1129,17 @@ func (r *PlacementAPIReconciler) reconcileDelete(ctx context.Context, instance *
10941129
}
10951130
}
10961131

1132+
// Remove consumer finalizer from AC secrets placement was consuming.
1133+
for _, secretName := range []string{
1134+
instance.Status.ApplicationCredentialSecret,
1135+
instance.Spec.Auth.ApplicationCredentialSecret,
1136+
} {
1137+
if err := keystonev1.RemoveACSecretConsumerFinalizer(ctx, helper, instance.Namespace,
1138+
secretName, placement.ACConsumerFinalizer); err != nil {
1139+
return ctrl.Result{}, err
1140+
}
1141+
}
1142+
10971143
// We did all the cleanup on the objects we created so we can remove the
10981144
// finalizer from ourselves to allow the deletion
10991145
controllerutil.RemoveFinalizer(instance, helper.GetFinalizer())
@@ -1332,6 +1378,25 @@ func (r *PlacementAPIReconciler) ensureDeployment(
13321378
}
13331379
// create Deployment - end
13341380

1381+
// Manage the old AC secret's finalizer and status tracking.
1382+
// On rotation (old != new), only remove the old secret's finalizer after
1383+
// all sub-services are ready with the new credentials. This prevents
1384+
// premature revocation during rapid rotations.
1385+
isRotation := instance.Status.ApplicationCredentialSecret != "" && instance.Status.ApplicationCredentialSecret != instance.Spec.Auth.ApplicationCredentialSecret
1386+
1387+
if isRotation {
1388+
allServicesReady := instance.Status.Conditions.AllSubConditionIsTrue()
1389+
if allServicesReady {
1390+
if err := keystonev1.RemoveACSecretConsumerFinalizer(ctx, h, instance.Namespace,
1391+
instance.Status.ApplicationCredentialSecret, placement.ACConsumerFinalizer); err != nil {
1392+
return ctrl.Result{}, err
1393+
}
1394+
instance.Status.ApplicationCredentialSecret = instance.Spec.Auth.ApplicationCredentialSecret
1395+
}
1396+
} else {
1397+
instance.Status.ApplicationCredentialSecret = instance.Spec.Auth.ApplicationCredentialSecret
1398+
}
1399+
13351400
Log.Info("Reconciled Service successfully")
13361401
return ctrl.Result{}, nil
13371402
}

internal/placement/const.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,7 @@ const (
3636
// PlacementUserID is the linux user ID used by Kolla for the placement
3737
// user in the service containers
3838
PlacementUserID int64 = 42482
39+
40+
// ACConsumerFinalizer is added to AC secrets that placement is actively consuming
41+
ACConsumerFinalizer = "openstack.org/placementapi-ac-consumer"
3942
)

0 commit comments

Comments
 (0)