Skip to content

Commit 63f5573

Browse files
committed
Adding passwordSelectors and secret to CR generation
Signed-off-by: Veronika Fisarova <[email protected]>
1 parent c1d4085 commit 63f5573

File tree

6 files changed

+69
-58
lines changed

6 files changed

+69
-58
lines changed

apis/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,4 @@ replace github.com/openshift/api => github.com/openshift/api v0.0.0-202408300231
116116
// custom RabbitmqClusterSpecCore for OpenStackControlplane (v2.9.0_patches_tag)
117117
replace github.com/rabbitmq/cluster-operator/v2 => github.com/openstack-k8s-operators/rabbitmq-cluster-operator/v2 v2.6.1-0.20241017142550-a3524acedd49 //allow-merging
118118

119-
replace github.com/openstack-k8s-operators/keystone-operator/api => github.com/Deydra71/keystone-operator/api v0.0.0-20250507073641-38cb51217a45
119+
replace github.com/openstack-k8s-operators/keystone-operator/api => github.com/Deydra71/keystone-operator/api v0.0.0-20250514070500-15fcdb912b2c

apis/go.sum

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
github.com/Deydra71/keystone-operator/api v0.0.0-20250507073641-38cb51217a45 h1:c13rfNoKIXAd5R/k1D5wCBWtsR31xylSaiXKmfaAI4w=
2-
github.com/Deydra71/keystone-operator/api v0.0.0-20250507073641-38cb51217a45/go.mod h1:VPkYswnrCtlSMTeYjgxTOpfNN7zvxqa+kZ8EWDJaFrg=
1+
github.com/Deydra71/keystone-operator/api v0.0.0-20250514070500-15fcdb912b2c h1:DXnHQg/+AjMsoJqvQEusjkyjOsOPGbKJ8uRVLyTkseQ=
2+
github.com/Deydra71/keystone-operator/api v0.0.0-20250514070500-15fcdb912b2c/go.mod h1:VPkYswnrCtlSMTeYjgxTOpfNN7zvxqa+kZ8EWDJaFrg=
33
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
44
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
55
github.com/cert-manager/cert-manager v1.14.7 h1:C2L59sMGMdSpd8SPx5qfPAL7ejZaNxJBRd24S7Ws5Ek=
@@ -118,30 +118,30 @@ github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.2025050814
118118
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250508141203-be026d3164f7/go.mod h1:UwHXRIrMSPJD3lFqrA4oKmRXVLFQCRkLAj9x6KLEHiQ=
119119
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.6.1-0.20250423055245-3cb2ae8df6f0 h1:FAHrScvlj6w17wvcDhJ0ZnmraMrrOX1CxzvqZK595hA=
120120
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.6.1-0.20250423055245-3cb2ae8df6f0/go.mod h1:fesgTbs2j30Fhw2hebXkPgbeAIqG0Yk2oaeOklAInZg=
121-
github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20250419062702-0acec6a591c8 h1:oLY6iMNPe3/L5S8EvNcjvfWd1tbCNgfQ+iSnv3UCB0U=
122-
github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20250419062702-0acec6a591c8/go.mod h1:5+v92XC/PRATIiBrhNLEpJ+T4R9JpxBCgRP6QvbfwgE=
123-
github.com/openstack-k8s-operators/manila-operator/api v0.6.1-0.20250401095833-93bc034c64a9 h1:xQI2xgWLETETgm3bC9d5hrJygNTnDI6sGL+lgL2ucR8=
124-
github.com/openstack-k8s-operators/manila-operator/api v0.6.1-0.20250401095833-93bc034c64a9/go.mod h1:P4xWHFGuDyLtxW+EIvDS3A37uydYxG6ggVggA9/a5LA=
125-
github.com/openstack-k8s-operators/mariadb-operator/api v0.6.1-0.20250328081634-08026fd530d9 h1:BjuLQisbx6maIP+7pHheci+iW5lQiRMJOKE+1r4Ug6E=
126-
github.com/openstack-k8s-operators/mariadb-operator/api v0.6.1-0.20250328081634-08026fd530d9/go.mod h1:oOyOnJHMTEqy4Idzzm1E9HFl45Y1hVQ+V+AHEhMLzwk=
127-
github.com/openstack-k8s-operators/neutron-operator/api v0.6.1-0.20250401073502-1e282b4746cd h1:YUrPl8cBWGlEVeGVFh1nGhf+FnjKnX4K6g+1nOe5e98=
128-
github.com/openstack-k8s-operators/neutron-operator/api v0.6.1-0.20250401073502-1e282b4746cd/go.mod h1:iqNMhLVQY3W9y6qoRPd9orJMCogw8KgD3GjAvCVLO1Q=
129-
github.com/openstack-k8s-operators/nova-operator/api v0.6.1-0.20250402053313-b88da4dd7a62 h1:xZkgup6a3svAwNxDQ6tGBpD6EMKZE/JUA6eM6yGlHxk=
130-
github.com/openstack-k8s-operators/nova-operator/api v0.6.1-0.20250402053313-b88da4dd7a62/go.mod h1:AufhARPECqf9N0jfzIswTvv89jd7f3YChXsE17rVgio=
131-
github.com/openstack-k8s-operators/octavia-operator/api v0.6.1-0.20250406092807-8386f9655c0b h1:YnKepfaft8wY/wpOkgGgM56qruzMP2wDj07xWpddxro=
132-
github.com/openstack-k8s-operators/octavia-operator/api v0.6.1-0.20250406092807-8386f9655c0b/go.mod h1:0z/P1Yhk7h5nnx8bLMz3gSSoqo+dFRwJG1O14qVtsuQ=
133-
github.com/openstack-k8s-operators/openstack-baremetal-operator/api v0.6.1-0.20250402113637-b66aeb654907 h1:pNUuydkvSeUFhCinCLC8KKxr/RBPcu8VqXlBDK81mDc=
134-
github.com/openstack-k8s-operators/openstack-baremetal-operator/api v0.6.1-0.20250402113637-b66aeb654907/go.mod h1:RZj8UXrq5Sg6a8SP3R4kzpQbHxM1bBCYPc3ecDfuQPQ=
135-
github.com/openstack-k8s-operators/ovn-operator/api v0.6.1-0.20250418131034-8c1e46e5dd08 h1:bqyBhXpZ77a1daC9mCYuP8uwqTLcVcS8xZcbIhCzzMQ=
136-
github.com/openstack-k8s-operators/ovn-operator/api v0.6.1-0.20250418131034-8c1e46e5dd08/go.mod h1:wlRoylGCfu6weUrvRARU1yAKl8hza9X6LAENB7XVIkw=
137-
github.com/openstack-k8s-operators/placement-operator/api v0.6.1-0.20250420191048-db23ac9a6ff9 h1:zdb3m91+JLLgQMxO/aEL7Tqrtx49uQm05IPS662IVHI=
138-
github.com/openstack-k8s-operators/placement-operator/api v0.6.1-0.20250420191048-db23ac9a6ff9/go.mod h1:r2KGHWjHqpF4e3R3JiQTICgHqjcTUbzL7c3Uv/ZEndg=
121+
github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20250508141203-be026d3164f7 h1:N7HNoUrjqrWZWWcQdtaZubrQ1pFeWai1Cbls0RoCjK8=
122+
github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20250508141203-be026d3164f7/go.mod h1:5+v92XC/PRATIiBrhNLEpJ+T4R9JpxBCgRP6QvbfwgE=
123+
github.com/openstack-k8s-operators/manila-operator/api v0.6.1-0.20250429110312-bdf0391aca8b h1:uNdpmQF3mORCgZ4D78Dy0FjT8p0YGfsjTW0nPtYNMnU=
124+
github.com/openstack-k8s-operators/manila-operator/api v0.6.1-0.20250429110312-bdf0391aca8b/go.mod h1:hoGpPnwLpUBj+xYJIVkXMsk5CKs3rMO3XDkc/z9MplI=
125+
github.com/openstack-k8s-operators/mariadb-operator/api v0.6.1-0.20250429105455-119a21fd879a h1:IHGE1rUzvonx1Vsfk4QgetGfOr6z0CB5idbu3NBUUSA=
126+
github.com/openstack-k8s-operators/mariadb-operator/api v0.6.1-0.20250429105455-119a21fd879a/go.mod h1:ZgHSxZSgpgHg1FhKPnBm/cqxAJbVFbKiBkqQoRohn3Q=
127+
github.com/openstack-k8s-operators/neutron-operator/api v0.6.1-0.20250508051221-25c4196e4eb6 h1:POLDrWP4IZG6a0VM8gdOp47vwbU/SSB9XWO3ajOJK2E=
128+
github.com/openstack-k8s-operators/neutron-operator/api v0.6.1-0.20250508051221-25c4196e4eb6/go.mod h1:OWHUfGoYVAEIQ7paLAl4Cz5CrQfMZt8O+YKqbi4Xp4Q=
129+
github.com/openstack-k8s-operators/nova-operator/api v0.6.1-0.20250505091323-48288280c311 h1:+7Eb3lvH0dS6LqIL0lgGbXG1MpeRws8qxBjWFz7gcEs=
130+
github.com/openstack-k8s-operators/nova-operator/api v0.6.1-0.20250505091323-48288280c311/go.mod h1:NNhtdwoGV4PW+Ca4KwoNM1EaEWFc9Rf4N7T1gz0bNQo=
131+
github.com/openstack-k8s-operators/octavia-operator/api v0.6.1-0.20250507174955-d28d78d74950 h1:ARB9OsmhoC6Ix6gbLaaYUH80YuHrh0Cc53jwgrsawnE=
132+
github.com/openstack-k8s-operators/octavia-operator/api v0.6.1-0.20250507174955-d28d78d74950/go.mod h1:w7rPsKhoPDf/l9G+d2BhOrEGAl11+/ZCzn3UX6/+qEQ=
133+
github.com/openstack-k8s-operators/openstack-baremetal-operator/api v0.6.1-0.20250429095646-8b102b4956dd h1:1GZyxBISQ7QkDmbrluLNebkATdVoaP7u9ODln5h1jrQ=
134+
github.com/openstack-k8s-operators/openstack-baremetal-operator/api v0.6.1-0.20250429095646-8b102b4956dd/go.mod h1:X/4IL9CBeWJWxMsqz9RVHEbDvpNNuHq43mqg2jVaKZg=
135+
github.com/openstack-k8s-operators/ovn-operator/api v0.6.1-0.20250509053924-33a097e86b88 h1:ssCpLmyH680EEJEIsaMIa5XCTMV+MXt7urhy1k32Ar4=
136+
github.com/openstack-k8s-operators/ovn-operator/api v0.6.1-0.20250509053924-33a097e86b88/go.mod h1:iLeHkckueEEBrkgOmmbKC8tP8ezIzJngd8buO2gQF40=
137+
github.com/openstack-k8s-operators/placement-operator/api v0.6.1-0.20250507105601-d9bf51effcc2 h1:bOudfZtQYSPjUMCBeauMcF+L7p6nc3apZwTd51fBmEo=
138+
github.com/openstack-k8s-operators/placement-operator/api v0.6.1-0.20250507105601-d9bf51effcc2/go.mod h1:BPX8qRwZyFVkyS1ttgzQrKFL+p3iXeh6Br+Q5ljL+YE=
139139
github.com/openstack-k8s-operators/rabbitmq-cluster-operator/v2 v2.6.1-0.20241017142550-a3524acedd49 h1:/7SnnHfGCH/dwuZFNUx54zw4cnwv2w6hjONq16aoowM=
140140
github.com/openstack-k8s-operators/rabbitmq-cluster-operator/v2 v2.6.1-0.20241017142550-a3524acedd49/go.mod h1:6Mq2N/KtNFW20L+PQC5qkeK8R8UGadmGBXL8HDY6lcg=
141-
github.com/openstack-k8s-operators/swift-operator/api v0.6.1-0.20250415061104-ec26f3967b8e h1:W4xVCUt0GL5vjIeodLyHwJnFO/z7ZO/Qr5tzSNcgnao=
142-
github.com/openstack-k8s-operators/swift-operator/api v0.6.1-0.20250415061104-ec26f3967b8e/go.mod h1:F6yh/lGjYlSDPVMUKGuKRiSSPq/+se54ciobRz4+nlg=
143-
github.com/openstack-k8s-operators/telemetry-operator/api v0.6.1-0.20250420191048-a2d55f55d5da h1:/Tjdeb1Y3MuLQy6p5ezNvWLNlmyUG+2i8fOCVfRfQkg=
144-
github.com/openstack-k8s-operators/telemetry-operator/api v0.6.1-0.20250420191048-a2d55f55d5da/go.mod h1:meN7CoBND2usExOU7D02sSyplgxS0r2NAGh1IyDPWA4=
141+
github.com/openstack-k8s-operators/swift-operator/api v0.6.1-0.20250429071246-b912d22ca9aa h1:F1LC6mmIfCWGcJPwVOFLl1/pUjiVPjupzr1tgp8JGJ4=
142+
github.com/openstack-k8s-operators/swift-operator/api v0.6.1-0.20250429071246-b912d22ca9aa/go.mod h1:wwAjceRRL7sWtYgQeN6r0qiCI197q7DsLsdWIoLu3iA=
143+
github.com/openstack-k8s-operators/telemetry-operator/api v0.6.1-0.20250509120424-5d61299fe6f5 h1:K6Oo4fwrkjJfL9NSaeTDUgFCVfeEnKWXW83zWp0qqa0=
144+
github.com/openstack-k8s-operators/telemetry-operator/api v0.6.1-0.20250509120424-5d61299fe6f5/go.mod h1:h5/tGFgA8vjotBagBWoOISTvOSOSuBjLZdJqVmnxNfU=
145145
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
146146
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
147147
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=

bindata/crds/keystone.openstack.org_applicationcredentials.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ spec:
7070
the AC should be rotated
7171
minimum: 1
7272
type: integer
73+
passwordSelector:
74+
description: PasswordSelector for extracting the service password
75+
type: string
76+
secret:
77+
default: osp-secret
78+
description: Secret containing service user password
79+
type: string
7380
userName:
7481
description: UserName - the Keystone user under which this AC is created
7582
type: string

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,4 @@ replace github.com/openshift/api => github.com/openshift/api v0.0.0-202408300231
128128
// custom RabbitmqClusterSpecCore for OpenStackControlplane (v2.9.0_patches_tag)
129129
replace github.com/rabbitmq/cluster-operator/v2 => github.com/openstack-k8s-operators/rabbitmq-cluster-operator/v2 v2.6.1-0.20241017142550-a3524acedd49 //allow-merging
130130

131-
replace github.com/openstack-k8s-operators/keystone-operator/api => github.com/Deydra71/keystone-operator/api v0.0.0-20250507073641-38cb51217a45
131+
replace github.com/openstack-k8s-operators/keystone-operator/api => github.com/Deydra71/keystone-operator/api v0.0.0-20250514070500-15fcdb912b2c

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
github.com/Deydra71/keystone-operator/api v0.0.0-20250507073641-38cb51217a45 h1:c13rfNoKIXAd5R/k1D5wCBWtsR31xylSaiXKmfaAI4w=
2-
github.com/Deydra71/keystone-operator/api v0.0.0-20250507073641-38cb51217a45/go.mod h1:VPkYswnrCtlSMTeYjgxTOpfNN7zvxqa+kZ8EWDJaFrg=
1+
github.com/Deydra71/keystone-operator/api v0.0.0-20250514070500-15fcdb912b2c h1:DXnHQg/+AjMsoJqvQEusjkyjOsOPGbKJ8uRVLyTkseQ=
2+
github.com/Deydra71/keystone-operator/api v0.0.0-20250514070500-15fcdb912b2c/go.mod h1:VPkYswnrCtlSMTeYjgxTOpfNN7zvxqa+kZ8EWDJaFrg=
33
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
44
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
55
github.com/cert-manager/cert-manager v1.14.7 h1:C2L59sMGMdSpd8SPx5qfPAL7ejZaNxJBRd24S7Ws5Ek=
@@ -116,8 +116,6 @@ github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250512104855-4
116116
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250512104855-47f817ef8ff8/go.mod h1:47iJk3vedZWnBkZyNyYij4ma2HjG4l2VCqKz3f+XDkQ=
117117
github.com/openstack-k8s-operators/ironic-operator/api v0.6.1-0.20250505201920-2f6d0b9f6aed h1:Osy/pq1qQ0nxwcATpUOo8bz00MngiBYjHv/9Ov5iuxw=
118118
github.com/openstack-k8s-operators/ironic-operator/api v0.6.1-0.20250505201920-2f6d0b9f6aed/go.mod h1:n8mWh/qZZSieuDEnkTZyhDc5UeVyUHC3YSYMzdVbbVo=
119-
github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20250506083817-ce591b464a0f h1:FR9Wuamrt2h5Dnn3Q1ySXcEZ9OaKDgpSJSA7QBh2jP4=
120-
github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20250506083817-ce591b464a0f/go.mod h1:xmEVdGGDz4pqPyzgR6oAZbeomz00Co68OyvsYNoT3Z0=
121119
github.com/openstack-k8s-operators/lib-common/modules/ansible v0.6.1-0.20250508141203-be026d3164f7 h1:RBYAybZcCzbSeR3XwqahBYRe9u9HeWkwidJcBDVv4bg=
122120
github.com/openstack-k8s-operators/lib-common/modules/ansible v0.6.1-0.20250508141203-be026d3164f7/go.mod h1:0bajRHochTUT6Ecfriw27l3vL0yezVrnUmt3bcIpu4w=
123121
github.com/openstack-k8s-operators/lib-common/modules/certmanager v0.6.1-0.20250508141203-be026d3164f7 h1:0tpgz3x6REAZGwOqnGFVwlTt4Hf5mm/EAdleW2NJbxU=

pkg/openstack/applicationcredential.go

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,20 @@ import (
77
keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1"
88
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
99
corev1beta1 "github.com/openstack-k8s-operators/openstack-operator/apis/core/v1beta1"
10-
1110
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1211
ctrl "sigs.k8s.io/controller-runtime"
1312
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
1413
)
1514

16-
// mergeAppCred returns a new ApplicationCredentialSection
17-
// by starting from the global defaults, then overriding
18-
// only the fields the service user has explicitly set
15+
// mergeAppCred returns a new ApplicationCredentialSection by overlaying
16+
// service-specific values on top of the global defaults.
1917
func mergeAppCred(
2018
global corev1beta1.ApplicationCredentialSection,
2119
svc *corev1beta1.ServiceAppCredSection,
2220
) corev1beta1.ApplicationCredentialSection {
2321
out := global
24-
2522
if svc != nil {
26-
// always override Enabled, even if false
2723
out.Enabled = svc.Enabled
28-
2924
// only override expiry/grace if the user actually set them
3025
if svc.ExpirationDays != nil {
3126
out.ExpirationDays = svc.ExpirationDays
@@ -34,30 +29,23 @@ func mergeAppCred(
3429
out.GracePeriodDays = svc.GracePeriodDays
3530
}
3631
}
37-
3832
return out
3933
}
4034

41-
// ReconcileApplicationCredentials ensures that every OpenStack service which
42-
// has AC enabled (both globally and per-service) has a corresponding
43-
// keystone.openstack.org/v1beta1 ApplicationCredential CR, with proper
44-
// ExpirationDays and GracePeriodDays inherited or overridden
35+
// ReconcileApplicationCredentials ensures an AC CR per enabled service,
36+
// propagating its secret name, passwordSelector, and serviceUser fields.
4537
func ReconcileApplicationCredentials(
4638
ctx context.Context,
4739
instance *corev1beta1.OpenStackControlPlane,
4840
_ *corev1beta1.OpenStackVersion,
4941
helper *helper.Helper,
5042
) (ctrl.Result, error) {
51-
5243
log := GetLogger(ctx)
5344

54-
// If global AC is turned off, delete service AC CRs
45+
// If global disabled, delete all ACs:
5546
if !instance.Spec.ApplicationCredential.Enabled {
56-
log.Info("Global .spec.applicationCredential.enabled is false – deleting all per-service AC CRs")
57-
for _, svc := range []string{
58-
"glance", "nova", "swift", "ceilometer",
59-
"barbican", "cinder", "placement", "neutron",
60-
} {
47+
log.Info("Global AC disabled; deleting per-service AC CRs")
48+
for _, svc := range []string{"glance", "nova", "swift", "ceilometer", "barbican", "cinder", "placement", "neutron"} {
6149
ac := &keystonev1.ApplicationCredential{
6250
ObjectMeta: metav1.ObjectMeta{
6351
Name: fmt.Sprintf("ac-%s", svc),
@@ -71,9 +59,25 @@ func ReconcileApplicationCredentials(
7159
return ctrl.Result{}, nil
7260
}
7361

74-
// Build list of services to reconcile
62+
// Build a lookup with each service’s secret, selector, and service user name field:
63+
services := map[string]struct {
64+
SecretName string
65+
PasswordSelector string
66+
ServiceUser string
67+
}{
68+
"glance": {instance.Spec.Glance.Template.Secret, instance.Spec.Glance.Template.PasswordSelectors.Service, instance.Spec.Glance.Template.ServiceUser},
69+
"nova": {instance.Spec.Nova.Template.Secret, instance.Spec.Nova.Template.PasswordSelectors.Service, instance.Spec.Nova.Template.ServiceUser},
70+
"swift": {instance.Spec.Swift.Template.SwiftProxy.Secret, instance.Spec.Swift.Template.SwiftProxy.PasswordSelectors.Service, instance.Spec.Swift.Template.SwiftProxy.ServiceUser},
71+
"ceilometer": {instance.Spec.Telemetry.Template.Ceilometer.Secret, instance.Spec.Telemetry.Template.Ceilometer.PasswordSelectors.CeilometerService, instance.Spec.Telemetry.Template.Ceilometer.ServiceUser},
72+
"barbican": {instance.Spec.Barbican.Template.Secret, instance.Spec.Barbican.Template.PasswordSelectors.Service, instance.Spec.Barbican.Template.ServiceUser},
73+
"cinder": {instance.Spec.Cinder.Template.Secret, instance.Spec.Cinder.Template.PasswordSelectors.Service, instance.Spec.Cinder.Template.ServiceUser},
74+
"placement": {instance.Spec.Placement.Template.Secret, instance.Spec.Placement.Template.PasswordSelectors.Service, instance.Spec.Placement.Template.ServiceUser},
75+
"neutron": {instance.Spec.Neutron.Template.Secret, instance.Spec.Neutron.Template.PasswordSelectors.Service, instance.Spec.Neutron.Template.ServiceUser},
76+
}
77+
78+
// Collect each service’s enabled flag and AC section:
7579
type svcAC struct {
76-
Name string
80+
Key string
7781
Enabled bool
7882
ACSection *corev1beta1.ServiceAppCredSection
7983
}
@@ -87,33 +91,35 @@ func ReconcileApplicationCredentials(
8791
{"placement", instance.Spec.Placement.Enabled, instance.Spec.Placement.ApplicationCredential},
8892
{"neutron", instance.Spec.Neutron.Enabled, instance.Spec.Neutron.ApplicationCredential},
8993
}
90-
9194
global := instance.Spec.ApplicationCredential
9295

96+
// Loop, CreateOrPatch or delete each AC CR:
9397
for _, svc := range svcs {
94-
acName := fmt.Sprintf("ac-%s", svc.Name)
98+
acName := fmt.Sprintf("ac-%s", svc.Key)
9599
acObj := &keystonev1.ApplicationCredential{
96100
ObjectMeta: metav1.ObjectMeta{
97101
Name: acName,
98102
Namespace: instance.Namespace,
99103
},
100104
}
101105

106+
// merge flags
102107
effective := mergeAppCred(global, svc.ACSection)
103-
// if either the service itself is disabled, or the merged AC.Enabled is false,
104-
// then ensure that CR is deleted
105108
if !(svc.Enabled && effective.Enabled) {
106109
if res, err := EnsureDeleted(ctx, helper, acObj); err != nil {
107110
return res, err
108111
}
109112
continue
110113
}
111114

112-
// otherwise create or patch it to have exactly the merged values
115+
// create/patch
113116
op, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), acObj, func() error {
114-
acObj.Spec.UserName = svc.Name
117+
acObj.Spec.UserName = services[svc.Key].ServiceUser
115118
acObj.Spec.ExpirationDays = *effective.ExpirationDays
116119
acObj.Spec.GracePeriodDays = *effective.GracePeriodDays
120+
acObj.Spec.Secret = services[svc.Key].SecretName
121+
acObj.Spec.PasswordSelector = services[svc.Key].PasswordSelector
122+
117123
return controllerutil.SetControllerReference(
118124
helper.GetBeforeObject(), acObj, helper.GetScheme(),
119125
)
@@ -122,7 +128,7 @@ func ReconcileApplicationCredentials(
122128
return ctrl.Result{}, err
123129
}
124130
if op != controllerutil.OperationResultNone {
125-
log.Info("Reconciled ApplicationCredential", "service", svc.Name, "operation", op)
131+
log.Info("Reconciled ApplicationCredential", "service", svc.Key, "operation", op)
126132
}
127133
}
128134

0 commit comments

Comments
 (0)