Skip to content

Commit 0536f52

Browse files
Deydra71claude
andcommitted
Fix defaultConfigOverwrite mounting to /etc/barbican/
The defaultConfigOverwrite field is documented to place files in /etc/<service>/, but barbican-operator was only mounting them into /etc/barbican/barbican.conf.d/ This prevented overriding files that upstream barbican hardcodes to /etc/barbican/ (e.g. barbican-api-paste.ini) and was inconsistent with how other operators (nova, keystone, etc.) handle this field. Fix the bug by adding per-file SubPath volume mounts from the existing config-data-custom Secret into /etc/barbican/<key>. SubPath mounts are used instead of a directory mount to avoid shadowing existing files in /etc/barbican/. For backwards compatibility, each defaultConfigOverwrite key is mounted at BOTH locations: 1. /etc/barbican/<key> (correct path per CRD) 2. /etc/barbican/barbican.conf.d/<key> (old path) The dual mount preserves existing customer workarounds where e.g. policy.yaml was referenced via customServiceConfig as: [oslo_policy] policy_file = /etc/barbican/barbican.conf.d/policy.yaml Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Veronika Fisarova <vfisarov@redhat.com>
1 parent 0a225c8 commit 0536f52

15 files changed

Lines changed: 355 additions & 59 deletions

File tree

api/v1beta1/barbican_types.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
2021
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
2122
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
2223
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23-
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
24-
2524
)
2625

2726
const (
@@ -103,7 +102,6 @@ type BarbicanSpecBase struct {
103102
// +kubebuilder:validation:Optional
104103
// ConfigOverwrite - interface to overwrite default config files like e.g. logging.conf or policy.json.
105104
// But can also be used to add additional files. Those get added to the service config dir in /etc/<service> .
106-
// TODO(dmendiza): -> implement
107105
DefaultConfigOverwrite map[string]string `json:"defaultConfigOverwrite,omitempty"`
108106

109107
// +kubebuilder:validation:Required

api/v1beta1/common_types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ type BarbicanComponentTemplate struct {
100100
// +kubebuilder:validation:Optional
101101
// ConfigOverwrite - interface to overwrite default config files like e.g. policy.json.
102102
// But can also be used to add additional files. Those get added to the service config dir in /etc/<service> .
103-
// TODO: -> implement
104103
DefaultConfigOverwrite map[string]string `json:"defaultConfigOverwrite,omitempty"`
105104

106105
// +kubebuilder:validation:Optional

internal/barbican/const.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ const (
5858
CustomConfigVolume = "config-data-custom"
5959
// CustomConfigMountPoint is the mount point for custom service config
6060
CustomConfigMountPoint = "/etc/barbican/barbican.conf.d"
61+
// ConfigOverwriteBasePath is the base directory where defaultConfigOverwrite
62+
// files are placed via SubPath mounts (e.g. /etc/barbican/policy.yaml and /etc/barbican/api-paste.ini).
63+
ConfigOverwriteBasePath = "/etc/barbican"
6164
// ScriptVolume is the default volume name used to mount scripts
6265
ScriptVolume = "scripts"
6366
// ScriptMountPoint is the mount point for scripts

internal/barbican/volumes.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package barbican
22

33
import (
4+
"fmt"
5+
"slices"
6+
47
barbicanv1beta1 "github.com/openstack-k8s-operators/barbican-operator/api/v1beta1"
58
corev1 "k8s.io/api/core/v1"
69
)
@@ -145,6 +148,44 @@ func GetCustomConfigVolumeMount() corev1.VolumeMount {
145148
}
146149
}
147150

151+
// GetConfigOverwriteVolumeMounts returns SubPath volume mounts that place
152+
// each defaultConfigOverwrite key as an individual file under /etc/barbican/.
153+
// SubPath mounts are used instead of a directory mount so that existing files
154+
// in /etc/barbican/ (barbican.conf, api-paste.ini, etc.) are not shadowed.
155+
// The overwrite data lives in the same config-data-custom Secret (merged via
156+
// CustomData).
157+
//
158+
// Each key is mounted at the following locations:
159+
// 1. /etc/barbican/<key> (correct location per CRD)
160+
// 2. /etc/barbican/barbican.conf.d/<key> (backwards-compatible location)
161+
//
162+
// The dual mount preserves backwards-compatible customer workarounds where
163+
// policy.yaml was placed in .conf.d/ (due to the original bug) and referenced
164+
// via a customServiceConfig override.
165+
func GetConfigOverwriteVolumeMounts(overwriteKeys []string) []corev1.VolumeMount {
166+
mounts := make([]corev1.VolumeMount, 0, len(overwriteKeys)*2)
167+
sorted := make([]string, len(overwriteKeys))
168+
copy(sorted, overwriteKeys)
169+
slices.Sort(sorted)
170+
for _, key := range sorted {
171+
mounts = append(mounts,
172+
corev1.VolumeMount{
173+
Name: CustomConfigVolume,
174+
MountPath: fmt.Sprintf("%s/%s", ConfigOverwriteBasePath, key),
175+
SubPath: key,
176+
ReadOnly: true,
177+
},
178+
corev1.VolumeMount{
179+
Name: CustomConfigVolume,
180+
MountPath: fmt.Sprintf("%s/%s", CustomConfigMountPoint, key),
181+
SubPath: key,
182+
ReadOnly: true,
183+
},
184+
)
185+
}
186+
return mounts
187+
}
188+
148189
// GetDBSyncVolumes - dbsync volumes
149190
// Unlike the individual Barbican services, the DbSyncJob doesn't need a
150191
// secret that contains all of the config snippets required by every

internal/barbicanapi/deployment.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func Deployment(
2626
labels map[string]string,
2727
annotations map[string]string,
2828
topology *topologyv1.Topology,
29+
overwriteKeys []string,
2930
) (*appsv1.Deployment, error) {
3031
envVars := map[string]env.Setter{}
3132
envVars["KOLLA_CONFIG_STRATEGY"] = env.SetValue("COPY_ALWAYS")
@@ -58,7 +59,7 @@ func Deployment(
5859
}
5960
readinessProbe.HTTPGet = livenessProbe.HTTPGet
6061

61-
apiVolumes, apiVolumeMounts, err := GetAPIVolumesAndMounts(instance)
62+
apiVolumes, apiVolumeMounts, err := GetAPIVolumesAndMounts(instance, overwriteKeys)
6263
if err != nil {
6364
return nil, err
6465
}

internal/barbicanapi/volumes.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import (
1111
corev1 "k8s.io/api/core/v1"
1212
)
1313

14-
// GetAPIVolumesAndMounts returns the volumes and mounts for a BarbicanAPI deployment
15-
func GetAPIVolumesAndMounts(instance *barbicanv1beta1.BarbicanAPI) ([]corev1.Volume, []corev1.VolumeMount, error) {
14+
// GetAPIVolumesAndMounts returns the volumes and mounts for a BarbicanAPI deployment.
15+
// overwriteKeys lists the defaultConfigOverwrite filenames that need SubPath
16+
// mounts into /etc/barbican/ (e.g. policy.yaml).
17+
func GetAPIVolumesAndMounts(instance *barbicanv1beta1.BarbicanAPI, overwriteKeys []string) ([]corev1.Volume, []corev1.VolumeMount, error) {
1618
apiVolumes := []corev1.Volume{
1719
barbican.GetCustomConfigVolume(instance.Name),
1820
barbican.GetLogVolume(),
@@ -23,6 +25,7 @@ func GetAPIVolumesAndMounts(instance *barbicanv1beta1.BarbicanAPI) ([]corev1.Vol
2325
barbican.GetKollaConfigVolumeMount(instance.Name),
2426
barbican.GetLogVolumeMount(),
2527
}
28+
apiVolumeMounts = append(apiVolumeMounts, barbican.GetConfigOverwriteVolumeMounts(overwriteKeys)...)
2629

2730
// prepend general config volumes and mounts
2831
apiVolumes = append(barbican.GetVolumes("barbican"), apiVolumes...)

internal/barbicankeystonelistener/deployment.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ func Deployment(
2424
labels map[string]string,
2525
annotations map[string]string,
2626
topology *topologyv1.Topology,
27+
overwriteKeys []string,
2728
) *appsv1.Deployment {
2829
envVars := map[string]env.Setter{}
2930
envVars["KOLLA_CONFIG_STRATEGY"] = env.SetValue("COPY_ALWAYS")
3031
envVars["CONFIG_HASH"] = env.SetValue(configHash)
3132
args := []string{"-c", ServiceCommand}
3233

33-
keystoneListenerVolumes, keystoneListenerVolumeMounts := GetListenerVolumesAndMounts(instance)
34+
keystoneListenerVolumes, keystoneListenerVolumeMounts := GetListenerVolumesAndMounts(instance, overwriteKeys)
3435

3536
deployment := &appsv1.Deployment{
3637
ObjectMeta: metav1.ObjectMeta{

internal/barbicankeystonelistener/volumes.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import (
66
corev1 "k8s.io/api/core/v1"
77
)
88

9-
// GetListenerVolumesAndMounts returns the volumes and mounts for a BarbicanKeystoneListener deployment
10-
func GetListenerVolumesAndMounts(instance *barbicanv1beta1.BarbicanKeystoneListener) ([]corev1.Volume, []corev1.VolumeMount) {
9+
// GetListenerVolumesAndMounts returns the volumes and mounts for a BarbicanKeystoneListener deployment.
10+
// overwriteKeys lists the defaultConfigOverwrite filenames that need SubPath
11+
// mounts into /etc/barbican/ (e.g. policy.yaml).
12+
func GetListenerVolumesAndMounts(instance *barbicanv1beta1.BarbicanKeystoneListener, overwriteKeys []string) ([]corev1.Volume, []corev1.VolumeMount) {
1113
listenerVolumes := []corev1.Volume{
1214
barbican.GetCustomConfigVolume(instance.Name),
1315
barbican.GetLogVolume(),
@@ -18,6 +20,7 @@ func GetListenerVolumesAndMounts(instance *barbicanv1beta1.BarbicanKeystoneListe
1820
barbican.GetKollaConfigVolumeMount(instance.Name),
1921
barbican.GetLogVolumeMount(),
2022
}
23+
listenerVolumeMounts = append(listenerVolumeMounts, barbican.GetConfigOverwriteVolumeMounts(overwriteKeys)...)
2124

2225
// prepend general config volumes and mounts
2326
listenerVolumes = append(barbican.GetVolumes("barbican"), listenerVolumes...)

internal/barbicanworker/deployment.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func Deployment(
2626
labels map[string]string,
2727
annotations map[string]string,
2828
topology *topologyv1.Topology,
29+
overwriteKeys []string,
2930
) *appsv1.Deployment {
3031
envVars := map[string]env.Setter{}
3132
envVars["KOLLA_CONFIG_STRATEGY"] = env.SetValue("COPY_ALWAYS")
@@ -54,7 +55,7 @@ func Deployment(
5455
//}
5556
//readinessProbe.HTTPGet = livenessProbe.HTTPGet
5657

57-
workerVolumes, workerVolumeMounts := GetWorkerVolumesAndMounts(instance)
58+
workerVolumes, workerVolumeMounts := GetWorkerVolumesAndMounts(instance, overwriteKeys)
5859

5960
deployment := &appsv1.Deployment{
6061
ObjectMeta: metav1.ObjectMeta{

internal/barbicanworker/volumes.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import (
88
corev1 "k8s.io/api/core/v1"
99
)
1010

11-
// GetWorkerVolumesAndMounts returns the volumes and mounts for a BarbicanWorker deployment
12-
func GetWorkerVolumesAndMounts(instance *barbicanv1beta1.BarbicanWorker) ([]corev1.Volume, []corev1.VolumeMount) {
11+
// GetWorkerVolumesAndMounts returns the volumes and mounts for a BarbicanWorker deployment.
12+
// overwriteKeys lists the defaultConfigOverwrite filenames that need SubPath
13+
// mounts into /etc/barbican/ (e.g. policy.yaml).
14+
func GetWorkerVolumesAndMounts(instance *barbicanv1beta1.BarbicanWorker, overwriteKeys []string) ([]corev1.Volume, []corev1.VolumeMount) {
1315
workerVolumes := []corev1.Volume{
1416
barbican.GetCustomConfigVolume(instance.Name),
1517
barbican.GetLogVolume(),
@@ -20,6 +22,7 @@ func GetWorkerVolumesAndMounts(instance *barbicanv1beta1.BarbicanWorker) ([]core
2022
barbican.GetKollaConfigVolumeMount(instance.Name),
2123
barbican.GetLogVolumeMount(),
2224
}
25+
workerVolumeMounts = append(workerVolumeMounts, barbican.GetConfigOverwriteVolumeMounts(overwriteKeys)...)
2326

2427
// prepend general config volumes and mounts
2528
workerVolumes = append(barbican.GetVolumes("barbican"), workerVolumes...)

0 commit comments

Comments
 (0)