@@ -59,6 +59,34 @@ func isACEnabled(globalAC corev1beta1.ApplicationCredentialSection, serviceAC *c
5959 return serviceAC != nil && serviceAC .Enabled
6060}
6161
62+ // CleanupApplicationCredentialForService deletes the AC CR for a service if it exists.
63+ // Used when a service or its AC is disabled - deletes the AC CR if it exists regardless
64+ // of the AC enabled flag.
65+ func CleanupApplicationCredentialForService (
66+ ctx context.Context ,
67+ helper * helper.Helper ,
68+ instance * corev1beta1.OpenStackControlPlane ,
69+ serviceName string ,
70+ ) error {
71+ acName := keystonev1 .GetACCRName (serviceName )
72+ acCR := & keystonev1.KeystoneApplicationCredential {
73+ ObjectMeta : metav1.ObjectMeta {
74+ Name : acName ,
75+ Namespace : instance .Namespace ,
76+ },
77+ }
78+ Log := GetLogger (ctx )
79+ err := helper .GetClient ().Delete (ctx , acCR )
80+ if k8s_errors .IsNotFound (err ) {
81+ return nil
82+ }
83+ if err != nil {
84+ return err
85+ }
86+ Log .Info ("Service disabled, deleted existing KeystoneApplicationCredential CR" , "service" , serviceName , "acName" , acName )
87+ return nil
88+ }
89+
6290// EnsureApplicationCredentialForService handles AC creation for a single service.
6391// If service is not ready, AC creation is deferred
6492// If AC already exists and is ready, it's used immediately
@@ -125,6 +153,11 @@ func EnsureApplicationCredentialForService(
125153
126154 // Check if AC CR exists and is ready
127155 if acExists {
156+ // We want to run reconcileApplicationCredential to update the AC CR if it exists and is ready and AC config fields changed
157+ err = reconcileApplicationCredential (ctx , helper , instance , acName , serviceUser , secretName , passwordSelector , merged )
158+ if err != nil {
159+ return "" , ctrl.Result {}, err
160+ }
128161 if acCR .IsReady () {
129162 Log .Info ("Application Credential is ready" , "service" , serviceName , "acName" , acName , "secretName" , acCR .Status .SecretName )
130163 return acCR .Status .SecretName , ctrl.Result {}, nil
0 commit comments