Skip to content

Commit 024ce48

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_<key> . At the end of the vhost config in the default httpd template these custom configs get included using `Include conf/httpd_custom_*`. 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 rendered config-data secret of the service like: $ oc get cm -n openstack horizon-config-data -o json | jq -r .data.templatingParameters | base64 -d or in the running pod of the service in the file: $ cat /var/lib/config-data/default/templatingParameters The content is a versioned dump of the parameters of the service operator, like: ~~~ KeystoneEndpointInternal: https://keystone-internal.openstack.svc:5000 Override: false SSLCertificateFile: /etc/pki/tls/certs/horizon.crt SSLCertificateKeyFile: /etc/pki/tls/private/horizon.key ServerName: horizon.openstack.svc TLS: true MemcachedServers: memcached-0.memcached.openstack.svc:11212 ... ~~~ 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 <mschuppert@redhat.com>
1 parent 8f2f2c4 commit 024ce48

File tree

13 files changed

+210
-34
lines changed

13 files changed

+210
-34
lines changed

api/bases/horizon.openstack.org_horizons.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,20 @@ spec:
11341134
- extraVol
11351135
type: object
11361136
type: array
1137+
httpdCustomization:
1138+
description: HttpdCustomization - customize the httpd service
1139+
properties:
1140+
customConfigSecret:
1141+
description: |-
1142+
CustomConfigSecret - customize the httpd vhost config using this parameter to specify
1143+
a secret that contains service config data. The content of each provided snippet gets
1144+
rendered as a go template and placed into /etc/httpd/conf/httpd_custom_<key> .
1145+
In the default httpd template at the end of the vhost those custom configs get
1146+
included using `Include conf/httpd_custom_<endpoint>_*`.
1147+
For information on how sections in httpd configuration get merged, check section
1148+
"How the sections are merged" in https://httpd.apache.org/docs/current/sections.html#merging
1149+
type: string
1150+
type: object
11371151
memcachedInstance:
11381152
default: memcached
11391153
description: Memcached instance name.

api/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/openstack-k8s-operators/horizon-operator/api
33
go 1.21
44

55
require (
6-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241216113837-d172b3ac0f4e
6+
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250116145727-01a8948d5dd7
77
github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.20241216113837-d172b3ac0f4e
88
k8s.io/api v0.29.12
99
k8s.io/apimachinery v0.29.12

api/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ github.com/onsi/ginkgo/v2 v2.20.1 h1:YlVIbqct+ZmnEph770q9Q7NVAz4wwIiVNahee6JyUzo
7373
github.com/onsi/ginkgo/v2 v2.20.1/go.mod h1:lG9ey2Z29hR41WMVthyJBGUBcBhGOtoPF2VFMvBXFCI=
7474
github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k=
7575
github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY=
76-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241216113837-d172b3ac0f4e h1:hf4kVQBkyG79WcHBxdQ25QrDBbGFdarebS1Tc0Xclq4=
77-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241216113837-d172b3ac0f4e/go.mod h1:YpNTuJhDWhbXM50O3qBkhO7M+OOyRmWkNVmJ4y3cyFs=
76+
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250116145727-01a8948d5dd7 h1:vXHpH93PjbAgg5ZN6n5WmxkybVQOs0nhXvVw62o7aZs=
77+
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250116145727-01a8948d5dd7/go.mod h1:YpNTuJhDWhbXM50O3qBkhO7M+OOyRmWkNVmJ4y3cyFs=
7878
github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.20241216113837-d172b3ac0f4e h1:Qz0JFEoRDUyjEWorNY3LggwxTsmpMtQkcpmZDQulGHQ=
7979
github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.20241216113837-d172b3ac0f4e/go.mod h1:tfgBeLRqmlH/NQkLPe7396rj+t0whv2wPuMb8Ttvh8w=
8080
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=

api/v1beta1/horizon_types.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ type HorizonSpecCore struct {
104104
// +kubebuilder:validation:Optional
105105
// NetworkAttachments is a list of NetworkAttachment resource names to expose the services to the given network
106106
NetworkAttachments []string `json:"networkAttachments,omitempty"`
107+
108+
// +kubebuilder:validation:Optional
109+
// HttpdCustomization - customize the httpd service
110+
HttpdCustomization HttpdCustomization `json:"httpdCustomization,omitempty"`
107111
}
108112

109113
// HorizionOverrideSpec to override the generated manifest of several child resources.
@@ -112,6 +116,19 @@ type HorizionOverrideSpec struct {
112116
Service *service.RoutedOverrideSpec `json:"service,omitempty"`
113117
}
114118

119+
// HttpdCustomization - customize the httpd service
120+
type HttpdCustomization struct {
121+
// +kubebuilder:validation:Optional
122+
// CustomConfigSecret - customize the httpd vhost config using this parameter to specify
123+
// a secret that contains service config data. The content of each provided snippet gets
124+
// rendered as a go template and placed into /etc/httpd/conf/httpd_custom_<key> .
125+
// In the default httpd template at the end of the vhost those custom configs get
126+
// included using `Include conf/httpd_custom_<endpoint>_*`.
127+
// For information on how sections in httpd configuration get merged, check section
128+
// "How the sections are merged" in https://httpd.apache.org/docs/current/sections.html#merging
129+
CustomConfigSecret *string `json:"customConfigSecret,omitempty"`
130+
}
131+
115132
// HorizonStatus defines the observed state of Horizon
116133
type HorizonStatus struct {
117134
// Map of hashes to track e.g. job status

api/v1beta1/zz_generated.deepcopy.go

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

config/crd/bases/horizon.openstack.org_horizons.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,20 @@ spec:
11341134
- extraVol
11351135
type: object
11361136
type: array
1137+
httpdCustomization:
1138+
description: HttpdCustomization - customize the httpd service
1139+
properties:
1140+
customConfigSecret:
1141+
description: |-
1142+
CustomConfigSecret - customize the httpd vhost config using this parameter to specify
1143+
a secret that contains service config data. The content of each provided snippet gets
1144+
rendered as a go template and placed into /etc/httpd/conf/httpd_custom_<key> .
1145+
In the default httpd template at the end of the vhost those custom configs get
1146+
included using `Include conf/httpd_custom_<endpoint>_*`.
1147+
For information on how sections in httpd configuration get merged, check section
1148+
"How the sections are merged" in https://httpd.apache.org/docs/current/sections.html#merging
1149+
type: string
1150+
type: object
11371151
memcachedInstance:
11381152
default: memcached
11391153
description: Memcached instance name.

controllers/horizon_controller.go

Lines changed: 62 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import (
4242
"github.com/openstack-k8s-operators/lib-common/modules/common/service"
4343
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"
4444
util "github.com/openstack-k8s-operators/lib-common/modules/common/util"
45+
"gopkg.in/yaml.v2"
4546
appsv1 "k8s.io/api/apps/v1"
4647
corev1 "k8s.io/api/core/v1"
4748
rbacv1 "k8s.io/api/rbac/v1"
@@ -203,15 +204,17 @@ func (r *HorizonReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
203204

204205
// fields to index to reconcile when change
205206
const (
206-
passwordSecretField = ".spec.secret"
207-
tlsField = ".spec.tls.secretName"
208-
caBundleSecretNameField = ".spec.tls.caBundleSecretName"
207+
passwordSecretField = ".spec.secret"
208+
tlsField = ".spec.tls.secretName"
209+
caBundleSecretNameField = ".spec.tls.caBundleSecretName"
210+
httpdCustomServiceConfigSecretField = ".spec.httpdCustomization.customServiceConfigSecret"
209211
)
210212

211213
var allWatchFields = []string{
212214
passwordSecretField,
213215
caBundleSecretNameField,
214216
tlsField,
217+
httpdCustomServiceConfigSecretField,
215218
}
216219

217220
// SetupWithManager -
@@ -254,6 +257,18 @@ func (r *HorizonReconciler) SetupWithManager(mgr ctrl.Manager) error {
254257
return err
255258
}
256259

260+
// index httpdOverrideSecretField
261+
if err := mgr.GetFieldIndexer().IndexField(context.Background(), &horizonv1beta1.Horizon{}, httpdCustomServiceConfigSecretField, func(rawObj client.Object) []string {
262+
// Extract the secret name from the spec, if one is provided
263+
cr := rawObj.(*horizonv1beta1.Horizon)
264+
if cr.Spec.HttpdCustomization.CustomConfigSecret == nil {
265+
return nil
266+
}
267+
return []string{*cr.Spec.HttpdCustomization.CustomConfigSecret}
268+
}); err != nil {
269+
return err
270+
}
271+
257272
memcachedFn := func(_ context.Context, o client.Object) []reconcile.Request {
258273
result := []reconcile.Request{}
259274

@@ -887,16 +902,24 @@ func (r *HorizonReconciler) generateServiceConfigMaps(
887902
return err
888903
}
889904

905+
httpdOverrideSecret := &corev1.Secret{}
906+
if instance.Spec.HttpdCustomization.CustomConfigSecret != nil && *instance.Spec.HttpdCustomization.CustomConfigSecret != "" {
907+
httpdOverrideSecret, _, err = oko_secret.GetSecret(ctx, h, *instance.Spec.HttpdCustomization.CustomConfigSecret, instance.Namespace)
908+
if err != nil {
909+
return err
910+
}
911+
}
912+
890913
templateParameters := map[string]interface{}{
891-
"keystoneURL": authURL,
892-
"horizonEndpoint": instance.Status.Endpoint,
893-
"horizonEndpointHost": url.Host,
894-
"memcachedServers": mc.GetMemcachedServerListQuotedString(),
895-
"memcachedTLS": mc.GetMemcachedTLSSupport(),
896-
"ServerName": fmt.Sprintf("%s.%s.svc", horizon.ServiceName, instance.Namespace),
897-
"Port": horizon.HorizonPort,
898-
"TLS": false,
899-
"isPublicHTTPS": url.Scheme == "https",
914+
"KeystoneEndpointInternal": authURL,
915+
"HorizonEndpoint": instance.Status.Endpoint,
916+
"HorizonEndpointHost": url.Host,
917+
"MemcachedServers": mc.GetMemcachedServerListQuotedString(),
918+
"MemcachedTLS": mc.GetMemcachedTLSSupport(),
919+
"ServerName": fmt.Sprintf("%s.%s.svc", horizon.ServiceName, instance.Namespace),
920+
"Port": horizon.HorizonPort,
921+
"TLS": false,
922+
"IsPublicHTTPS": url.Scheme == "https",
900923
}
901924

902925
// create httpd tls template parameters
@@ -907,16 +930,36 @@ func (r *HorizonReconciler) generateServiceConfigMaps(
907930
templateParameters["SSLCertificateKeyFile"] = fmt.Sprintf("/etc/pki/tls/private/%s.key", horizon.ServiceName)
908931
}
909932

933+
// httpd overrides
934+
customTemplates := map[string]string{}
935+
templateParameters["Override"] = false
936+
if len(httpdOverrideSecret.Data) > 0 {
937+
templateParameters["Override"] = true
938+
for key, data := range httpdOverrideSecret.Data {
939+
if len(data) > 0 {
940+
customTemplates["httpd_custom_"+key] = string(data)
941+
}
942+
}
943+
}
944+
945+
// Marshal the templateParameters map to YAML
946+
yamlData, err := yaml.Marshal(templateParameters)
947+
if err != nil {
948+
return fmt.Errorf("Error marshalling to YAML: %w", err)
949+
}
950+
customData[common.TemplateParameters] = string(yamlData)
951+
910952
cms := []util.Template{
911953
// ConfigMap
912954
{
913-
Name: fmt.Sprintf("%s-config-data", instance.Name),
914-
Namespace: instance.Namespace,
915-
Type: util.TemplateTypeConfig,
916-
InstanceType: instance.Kind,
917-
CustomData: customData,
918-
ConfigOptions: templateParameters,
919-
Labels: cmLabels,
955+
Name: fmt.Sprintf("%s-config-data", instance.Name),
956+
Namespace: instance.Namespace,
957+
Type: util.TemplateTypeConfig,
958+
InstanceType: instance.Kind,
959+
CustomData: customData,
960+
ConfigOptions: templateParameters,
961+
StringTemplate: customTemplates,
962+
Labels: cmLabels,
920963
},
921964
}
922965
return configmap.EnsureConfigMaps(ctx, h, instance, cms, envVars)

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ require (
1313
github.com/openstack-k8s-operators/horizon-operator/api v0.3.1-0.20240214134444-c675e5f69043
1414
github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20241217184302-c302f3d72ada
1515
github.com/openstack-k8s-operators/keystone-operator/api v0.5.1-0.20241217165019-8e243bd36596
16-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241216113837-d172b3ac0f4e
16+
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250116145727-01a8948d5dd7
1717
github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.20241216113837-d172b3ac0f4e
1818
github.com/openstack-k8s-operators/lib-common/modules/test v0.5.1-0.20241216113837-d172b3ac0f4e
19+
gopkg.in/yaml.v2 v2.4.0
1920
k8s.io/api v0.29.12
2021
k8s.io/apimachinery v0.29.12
2122
k8s.io/client-go v0.29.12
@@ -73,7 +74,6 @@ require (
7374
google.golang.org/appengine v1.6.8 // indirect
7475
google.golang.org/protobuf v1.34.1 // indirect
7576
gopkg.in/inf.v0 v0.9.1 // indirect
76-
gopkg.in/yaml.v2 v2.4.0 // indirect
7777
gopkg.in/yaml.v3 v3.0.1 // indirect
7878
k8s.io/apiextensions-apiserver v0.29.12 // indirect
7979
k8s.io/component-base v0.29.12 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20241217184302-c
8282
github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20241217184302-c302f3d72ada/go.mod h1:gznNWtIOdZLwyv3/LmWbDqtwRgtyzCw616Rwrn51DT0=
8383
github.com/openstack-k8s-operators/keystone-operator/api v0.5.1-0.20241217165019-8e243bd36596 h1:JKeShCY9BQj6cYDk44bgEIm8jPcvggodGxrW4ECzsv4=
8484
github.com/openstack-k8s-operators/keystone-operator/api v0.5.1-0.20241217165019-8e243bd36596/go.mod h1:CyuEOM1TpXKNUR1n8cudNtRzTEwkzv90JFkpDPPId8E=
85-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241216113837-d172b3ac0f4e h1:hf4kVQBkyG79WcHBxdQ25QrDBbGFdarebS1Tc0Xclq4=
86-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241216113837-d172b3ac0f4e/go.mod h1:YpNTuJhDWhbXM50O3qBkhO7M+OOyRmWkNVmJ4y3cyFs=
85+
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250116145727-01a8948d5dd7 h1:vXHpH93PjbAgg5ZN6n5WmxkybVQOs0nhXvVw62o7aZs=
86+
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250116145727-01a8948d5dd7/go.mod h1:YpNTuJhDWhbXM50O3qBkhO7M+OOyRmWkNVmJ4y3cyFs=
8787
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.5.1-0.20241216113837-d172b3ac0f4e h1:HFo4OqPY0x4ZQeaWI2YGonTXAGTQFt+rOEJlfZVhS7s=
8888
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.5.1-0.20241216113837-d172b3ac0f4e/go.mod h1:IASoGvp5QM/tBJUd/8i8uIjj4DBnI+64Ydh4r7pmnvA=
8989
github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.20241216113837-d172b3ac0f4e h1:Qz0JFEoRDUyjEWorNY3LggwxTsmpMtQkcpmZDQulGHQ=

templates/horizon/config/horizon.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@
4949
"perm": "0600",
5050
"optional": true,
5151
"merge": true
52+
},
53+
{
54+
"source": "/var/lib/config-data/default/httpd_custom_*",
55+
"dest": "/etc/httpd/conf/",
56+
"owner": "apache",
57+
"perm": "0444",
58+
"optional": true
5259
}
5360
],
5461
"permissions": [

0 commit comments

Comments
 (0)