Skip to content

Commit 0249ba1

Browse files
committed
Allow customize http vhost config using HttpdCustomization.CustomConfigSecret
This change allows to customize the httpd vhost config using this parameter to specify a secret that contains service config data. The content of each provided snippet gets rendered as a go template and placed into /etc/httpd/conf/httpd_custom_<endpoint>_<key> . At the end of the vhost config in the default httpd template these custom configs get included using `Include conf/httpd_custom_<endpoint>_*`. For information on how sections in httpd configuration get merged, check section "How the sections are merged" in https://httpd.apache.org/docs/current/sections.html#merging All possible parameters which can be use in a template can be looked up in the <service>-config-data secret of the service like: $ oc get secret -n openstack glance-config-data -o json | jq -r .data.TemplateParameters | base64 -d or in the running pod of the service in the file: $ cat /var/lib/config-data/default/TemplateParameters The content is a versioned dump of the parameters of the service operator, like: ~~~ DatabaseConnection: mysql+pymysql://user:[email protected]/keystone?read_default_file=/etc/my.cnf KeystoneEndpointInternal: https://keystone-internal.openstack.svc:5000 KeystoneEndpointPublic: https://keystone-public-openstack.apps-crc.testing TransportURL: rabbit://user:[email protected]:5671/?ssl=1 VHosts: internal: Override: false SSLCertificateFile: /etc/pki/tls/certs/internal.crt SSLCertificateKeyFile: /etc/pki/tls/private/internal.key ServerName: glance-internal.openstack.svc TLS: true public: Override: false SSLCertificateFile: /etc/pki/tls/certs/public.crt SSLCertificateKeyFile: /etc/pki/tls/private/public.key ServerName: glance-public.openstack.svc TLS: true ... ~~~ Depends-On: openstack-k8s-operators/lib-common#591 Depends-On: openstack-k8s-operators/lib-common#593 Jira: https://issues.redhat.com/browse/OSPRH-13100 Signed-off-by: Martin Schuppert <[email protected]>
1 parent 72c189b commit 0249ba1

19 files changed

+354
-21
lines changed

api/bases/glance.openstack.org_glanceapis.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,11 @@ spec:
546546
- extraVol
547547
type: object
548548
type: array
549+
httpdCustomization:
550+
properties:
551+
customConfigSecret:
552+
type: string
553+
type: object
549554
imageCache:
550555
properties:
551556
cleanerScheduler:

api/bases/glance.openstack.org_glances.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,11 @@ spec:
559559
items:
560560
type: string
561561
type: array
562+
httpdCustomization:
563+
properties:
564+
customConfigSecret:
565+
type: string
566+
type: object
562567
imageCache:
563568
properties:
564569
cleanerScheduler:
@@ -708,6 +713,11 @@ spec:
708713
type: object
709714
default: {}
710715
type: object
716+
httpdCustomization:
717+
properties:
718+
customConfigSecret:
719+
type: string
720+
type: object
711721
imageCache:
712722
properties:
713723
cleanerScheduler:

api/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.21
44

55
require (
66
github.com/google/go-cmp v0.6.0
7-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241216113837-d172b3ac0f4e
7+
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250116145727-01a8948d5dd7
88
github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.20241216113837-d172b3ac0f4e
99
k8s.io/api v0.29.12
1010
k8s.io/apimachinery v0.29.12

api/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k=
7575
github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY=
7676
github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094 h1:J1wuGhVxpsHykZBa6Beb1gQ96Ptej9AE/BvwCBiRj1E=
7777
github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094/go.mod h1:CxgbWAlvu2iQB0UmKTtRu1YfepRg1/vJ64n2DlIEVz4=
78-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241216113837-d172b3ac0f4e h1:hf4kVQBkyG79WcHBxdQ25QrDBbGFdarebS1Tc0Xclq4=
79-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241216113837-d172b3ac0f4e/go.mod h1:YpNTuJhDWhbXM50O3qBkhO7M+OOyRmWkNVmJ4y3cyFs=
78+
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250116145727-01a8948d5dd7 h1:vXHpH93PjbAgg5ZN6n5WmxkybVQOs0nhXvVw62o7aZs=
79+
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250116145727-01a8948d5dd7/go.mod h1:YpNTuJhDWhbXM50O3qBkhO7M+OOyRmWkNVmJ4y3cyFs=
8080
github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.20241216113837-d172b3ac0f4e h1:Qz0JFEoRDUyjEWorNY3LggwxTsmpMtQkcpmZDQulGHQ=
8181
github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.20241216113837-d172b3ac0f4e/go.mod h1:tfgBeLRqmlH/NQkLPe7396rj+t0whv2wPuMb8Ttvh8w=
8282
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=

api/v1beta1/common_types.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ type GlanceAPITemplate struct {
106106
// +kubebuilder:validation:Minimum=1
107107
// APITimeout for HAProxy and Apache defaults to GlanceSpecCore APITimeout
108108
APITimeout int `json:"apiTimeout,omitempty"`
109+
110+
// +kubebuilder:validation:Optional
111+
// HttpdCustomization - customize the httpd service
112+
HttpdCustomization HttpdCustomization `json:"httpdCustomization,omitempty"`
109113
}
110114

111115
// Storage -
@@ -144,6 +148,19 @@ type APIOverrideSpec struct {
144148
Service map[service.Endpoint]service.RoutedOverrideSpec `json:"service,omitempty"`
145149
}
146150

151+
// HttpdCustomization - customize the httpd service
152+
type HttpdCustomization struct {
153+
// +kubebuilder:validation:Optional
154+
// CustomConfigSecret - customize the httpd vhost config using this parameter to specify
155+
// a secret that contains service config data. The content of each provided snippet gets
156+
// rendered as a go template and placed into /etc/httpd/conf/httpd_custom_<key> .
157+
// In the default httpd template at the end of the vhost those custom configs get
158+
// included using `Include conf/httpd_custom_<endpoint>_*`.
159+
// For information on how sections in httpd configuration get merged, check section
160+
// "How the sections are merged" in https://httpd.apache.org/docs/current/sections.html#merging
161+
CustomConfigSecret *string `json:"customConfigSecret,omitempty"`
162+
}
163+
147164
// SetupDefaults - initializes any CRD field defaults based on environment variables (the defaulting mechanism itself is implemented via webhooks)
148165
func SetupDefaults() {
149166
// Acquire environmental defaults and initialize Glance defaults with them

api/v1beta1/glance_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ type GlanceSpecCore struct {
125125
// +kubebuilder:validation:Minimum=1
126126
// Default APITimeout for HAProxy and Apache, defaults to 60 seconds
127127
APITimeout int `json:"apiTimeout"`
128+
129+
// +kubebuilder:validation:Optional
130+
// HttpdCustomization - customize the httpd service of all GlanceAPIs
131+
HttpdCustomization HttpdCustomization `json:"httpdCustomization,omitempty"`
128132
}
129133

130134
// GlanceSpec defines the desired state of Glance

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/glance.openstack.org_glanceapis.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,11 @@ spec:
546546
- extraVol
547547
type: object
548548
type: array
549+
httpdCustomization:
550+
properties:
551+
customConfigSecret:
552+
type: string
553+
type: object
549554
imageCache:
550555
properties:
551556
cleanerScheduler:

config/crd/bases/glance.openstack.org_glances.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,11 @@ spec:
559559
items:
560560
type: string
561561
type: array
562+
httpdCustomization:
563+
properties:
564+
customConfigSecret:
565+
type: string
566+
type: object
562567
imageCache:
563568
properties:
564569
cleanerScheduler:
@@ -708,6 +713,11 @@ spec:
708713
type: object
709714
default: {}
710715
type: object
716+
httpdCustomization:
717+
properties:
718+
customConfigSecret:
719+
type: string
720+
type: object
711721
imageCache:
712722
properties:
713723
cleanerScheduler:

controllers/glance_common.go

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
networkv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
2525
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
26+
"gopkg.in/yaml.v2"
2627
"k8s.io/apimachinery/pkg/types"
2728

2829
glancev1 "github.com/openstack-k8s-operators/glance-operator/api/v1beta1"
@@ -45,10 +46,11 @@ import (
4546

4647
// fields to index to reconcile when change
4748
const (
48-
passwordSecretField = ".spec.secret"
49-
caBundleSecretNameField = ".spec.tls.caBundleSecretName"
50-
tlsAPIInternalField = ".spec.tls.api.internal.secretName"
51-
tlsAPIPublicField = ".spec.tls.api.public.secretName"
49+
passwordSecretField = ".spec.secret"
50+
caBundleSecretNameField = ".spec.tls.caBundleSecretName"
51+
tlsAPIInternalField = ".spec.tls.api.internal.secretName"
52+
tlsAPIPublicField = ".spec.tls.api.public.secretName"
53+
httpdCustomServiceConfigSecretField = ".spec.httpdCustomization.customServiceConfigSecret"
5254
)
5355

5456
var (
@@ -60,6 +62,7 @@ var (
6062
caBundleSecretNameField,
6163
tlsAPIInternalField,
6264
tlsAPIPublicField,
65+
httpdCustomServiceConfigSecretField,
6366
}
6467
)
6568

@@ -162,18 +165,27 @@ func GenerateConfigsGeneric(
162165
customData map[string]string,
163166
cmLabels map[string]string,
164167
scripts bool,
168+
customTemplates map[string]string,
165169
) error {
166170

171+
// Marshal the templateParameters map to YAML
172+
yamlData, err := yaml.Marshal(templateParameters)
173+
if err != nil {
174+
return fmt.Errorf("Error marshalling to YAML: %w", err)
175+
}
176+
customData[common.TemplateParameters] = string(yamlData)
177+
167178
cms := []util.Template{
168179
// Templates where the GlanceAPI config is stored
169180
{
170-
Name: fmt.Sprintf("%s-config-data", instance.GetName()),
171-
Namespace: instance.GetNamespace(),
172-
Type: util.TemplateTypeConfig,
173-
InstanceType: instance.GetObjectKind().GroupVersionKind().Kind,
174-
ConfigOptions: templateParameters,
175-
CustomData: customData,
176-
Labels: cmLabels,
181+
Name: fmt.Sprintf("%s-config-data", instance.GetName()),
182+
Namespace: instance.GetNamespace(),
183+
Type: util.TemplateTypeConfig,
184+
InstanceType: instance.GetObjectKind().GroupVersionKind().Kind,
185+
ConfigOptions: templateParameters,
186+
CustomData: customData,
187+
StringTemplate: customTemplates,
188+
Labels: cmLabels,
177189
},
178190
}
179191
// TODO: Scripts have no reason to be secrets, should move to configmap

0 commit comments

Comments
 (0)