Skip to content

Commit 9183a3d

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 octavia-api-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: octavia-api-internal.openstack.svc TLS: true public: Override: false SSLCertificateFile: /etc/pki/tls/certs/public.crt SSLCertificateKeyFile: /etc/pki/tls/private/public.key ServerName: octavia-api-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 7099ef6 commit 9183a3d

17 files changed

+295
-21
lines changed

api/bases/octavia.openstack.org_octaviaapis.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@ spec:
8989
But can also be used to add additional files. Those get added to the service config dir in /etc/<service> .
9090
TODO: -> implement
9191
type: object
92+
httpdCustomization:
93+
description: HttpdCustomization - customize the httpd service
94+
properties:
95+
customConfigSecret:
96+
description: |-
97+
CustomConfigSecret - customize the httpd vhost config using this parameter to specify
98+
a secret that contains service config data. The content of each provided snippet gets
99+
rendered as a go template and placed into /etc/httpd/conf/httpd_custom_<key> .
100+
In the default httpd template at the end of the vhost those custom configs get
101+
included using `Include conf/httpd_custom_<endpoint>_*`.
102+
For information on how sections in httpd configuration get merged, check section
103+
"How the sections are merged" in https://httpd.apache.org/docs/current/sections.html#merging
104+
type: string
105+
type: object
92106
networkAttachments:
93107
description: NetworkAttachments is a list of NetworkAttachment resource
94108
names to expose the services to the given network

api/bases/octavia.openstack.org_octavias.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,20 @@ spec:
196196
But can also be used to add additional files. Those get added to the service config dir in /etc/<service> .
197197
TODO: -> implement
198198
type: object
199+
httpdCustomization:
200+
description: HttpdCustomization - customize the httpd service
201+
properties:
202+
customConfigSecret:
203+
description: |-
204+
CustomConfigSecret - customize the httpd vhost config using this parameter to specify
205+
a secret that contains service config data. The content of each provided snippet gets
206+
rendered as a go template and placed into /etc/httpd/conf/httpd_custom_<key> .
207+
In the default httpd template at the end of the vhost those custom configs get
208+
included using `Include conf/httpd_custom_<endpoint>_*`.
209+
For information on how sections in httpd configuration get merged, check section
210+
"How the sections are merged" in https://httpd.apache.org/docs/current/sections.html#merging
211+
type: string
212+
type: object
199213
networkAttachments:
200214
description: NetworkAttachments is a list of NetworkAttachment
201215
resource names to expose the services to the given network

api/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.21
55
require (
66
github.com/onsi/ginkgo/v2 v2.20.1
77
github.com/onsi/gomega v1.34.1
8-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241216113837-d172b3ac0f4e
8+
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250116145727-01a8948d5dd7
99
k8s.io/api v0.29.13
1010
k8s.io/apimachinery v0.29.13
1111
k8s.io/client-go v0.29.13

api/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ github.com/onsi/ginkgo/v2 v2.20.1 h1:YlVIbqct+ZmnEph770q9Q7NVAz4wwIiVNahee6JyUzo
7272
github.com/onsi/ginkgo/v2 v2.20.1/go.mod h1:lG9ey2Z29hR41WMVthyJBGUBcBhGOtoPF2VFMvBXFCI=
7373
github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k=
7474
github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY=
75-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241216113837-d172b3ac0f4e h1:hf4kVQBkyG79WcHBxdQ25QrDBbGFdarebS1Tc0Xclq4=
76-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241216113837-d172b3ac0f4e/go.mod h1:YpNTuJhDWhbXM50O3qBkhO7M+OOyRmWkNVmJ4y3cyFs=
75+
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250116145727-01a8948d5dd7 h1:vXHpH93PjbAgg5ZN6n5WmxkybVQOs0nhXvVw62o7aZs=
76+
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250116145727-01a8948d5dd7/go.mod h1:YpNTuJhDWhbXM50O3qBkhO7M+OOyRmWkNVmJ4y3cyFs=
7777
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
7878
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
7979
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

api/v1beta1/octaviaapi_types.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ type OctaviaAPISpecCore struct {
150150
// +kubebuilder:validation:Optional
151151
// APITimeout for HAProxy and Apache defaults to OctaviaSpecCore APITimeout (seconds)
152152
APITimeout int `json:"apiTimeout"`
153+
154+
// +kubebuilder:validation:Optional
155+
// HttpdCustomization - customize the httpd service
156+
HttpdCustomization HttpdCustomization `json:"httpdCustomization,omitempty"`
153157
}
154158

155159
type OctaviaApiTLS struct {
@@ -174,6 +178,19 @@ type APIOverrideSpec struct {
174178
Service map[service.Endpoint]service.RoutedOverrideSpec `json:"service,omitempty"`
175179
}
176180

181+
// HttpdCustomization - customize the httpd service
182+
type HttpdCustomization struct {
183+
// +kubebuilder:validation:Optional
184+
// CustomConfigSecret - customize the httpd vhost config using this parameter to specify
185+
// a secret that contains service config data. The content of each provided snippet gets
186+
// rendered as a go template and placed into /etc/httpd/conf/httpd_custom_<key> .
187+
// In the default httpd template at the end of the vhost those custom configs get
188+
// included using `Include conf/httpd_custom_<endpoint>_*`.
189+
// For information on how sections in httpd configuration get merged, check section
190+
// "How the sections are merged" in https://httpd.apache.org/docs/current/sections.html#merging
191+
CustomConfigSecret *string `json:"customConfigSecret,omitempty"`
192+
}
193+
177194
// OctaviaAPIStatus defines the observed state of OctaviaAPI
178195
type OctaviaAPIStatus struct {
179196
// ReadyCount of octavia API instances

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/octavia.openstack.org_octaviaapis.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@ spec:
8989
But can also be used to add additional files. Those get added to the service config dir in /etc/<service> .
9090
TODO: -> implement
9191
type: object
92+
httpdCustomization:
93+
description: HttpdCustomization - customize the httpd service
94+
properties:
95+
customConfigSecret:
96+
description: |-
97+
CustomConfigSecret - customize the httpd vhost config using this parameter to specify
98+
a secret that contains service config data. The content of each provided snippet gets
99+
rendered as a go template and placed into /etc/httpd/conf/httpd_custom_<key> .
100+
In the default httpd template at the end of the vhost those custom configs get
101+
included using `Include conf/httpd_custom_<endpoint>_*`.
102+
For information on how sections in httpd configuration get merged, check section
103+
"How the sections are merged" in https://httpd.apache.org/docs/current/sections.html#merging
104+
type: string
105+
type: object
92106
networkAttachments:
93107
description: NetworkAttachments is a list of NetworkAttachment resource
94108
names to expose the services to the given network

config/crd/bases/octavia.openstack.org_octavias.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,20 @@ spec:
196196
But can also be used to add additional files. Those get added to the service config dir in /etc/<service> .
197197
TODO: -> implement
198198
type: object
199+
httpdCustomization:
200+
description: HttpdCustomization - customize the httpd service
201+
properties:
202+
customConfigSecret:
203+
description: |-
204+
CustomConfigSecret - customize the httpd vhost config using this parameter to specify
205+
a secret that contains service config data. The content of each provided snippet gets
206+
rendered as a go template and placed into /etc/httpd/conf/httpd_custom_<key> .
207+
In the default httpd template at the end of the vhost those custom configs get
208+
included using `Include conf/httpd_custom_<endpoint>_*`.
209+
For information on how sections in httpd configuration get merged, check section
210+
"How the sections are merged" in https://httpd.apache.org/docs/current/sections.html#merging
211+
type: string
212+
type: object
199213
networkAttachments:
200214
description: NetworkAttachments is a list of NetworkAttachment
201215
resource names to expose the services to the given network

controllers/amphoracontroller_controller.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"
3636
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
3737
mariadbv1 "github.com/openstack-k8s-operators/mariadb-operator/api/v1beta1"
38+
"gopkg.in/yaml.v2"
3839

3940
networkv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
4041
keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1"
@@ -643,6 +644,13 @@ func (r *OctaviaAmphoraControllerReconciler) generateServiceSecrets(
643644
}
644645
templateParameters["HeartbeatKey"] = string(ospSecret.Data["OctaviaHeartbeatKey"])
645646

647+
// Marshal the templateParameters map to YAML
648+
yamlData, err := yaml.Marshal(templateParameters)
649+
if err != nil {
650+
return fmt.Errorf("Error marshalling to YAML: %w", err)
651+
}
652+
customData[common.TemplateParameters] = string(yamlData)
653+
646654
// TODO(beagles): populate the template parameters
647655
cms := []util.Template{
648656
{

controllers/octavia_controller.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import (
4343
mariadbv1 "github.com/openstack-k8s-operators/mariadb-operator/api/v1beta1"
4444
octaviav1 "github.com/openstack-k8s-operators/octavia-operator/api/v1beta1"
4545
"github.com/openstack-k8s-operators/octavia-operator/pkg/octavia"
46+
"gopkg.in/yaml.v2"
4647
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4748
"k8s.io/apimachinery/pkg/types"
4849
"k8s.io/apimachinery/pkg/util/intstr"
@@ -223,11 +224,12 @@ func (r *OctaviaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
223224

224225
// fields to index to reconcile when change
225226
const (
226-
passwordSecretField = ".spec.secret"
227-
caBundleSecretNameField = ".spec.tls.caBundleSecretName"
228-
tlsAPIInternalField = ".spec.tls.api.internal.secretName"
229-
tlsAPIPublicField = ".spec.tls.api.public.secretName"
230-
tlsOvnField = ".spec.tls.ovn.secretName"
227+
passwordSecretField = ".spec.secret"
228+
caBundleSecretNameField = ".spec.tls.caBundleSecretName"
229+
tlsAPIInternalField = ".spec.tls.api.internal.secretName"
230+
tlsAPIPublicField = ".spec.tls.api.public.secretName"
231+
tlsOvnField = ".spec.tls.ovn.secretName"
232+
httpdCustomServiceConfigSecretField = ".spec.httpdCustomization.customServiceConfigSecret"
231233
)
232234

233235
var (
@@ -237,6 +239,7 @@ var (
237239
tlsAPIInternalField,
238240
tlsAPIPublicField,
239241
tlsOvnField,
242+
httpdCustomServiceConfigSecretField,
240243
}
241244
)
242245

@@ -1423,6 +1426,13 @@ func (r *OctaviaReconciler) generateServiceSecrets(
14231426
templateParameters["ServiceUser"] = instance.Spec.ServiceUser
14241427
templateParameters["TenantName"] = instance.Spec.TenantName
14251428

1429+
// Marshal the templateParameters map to YAML
1430+
yamlData, err := yaml.Marshal(templateParameters)
1431+
if err != nil {
1432+
return fmt.Errorf("Error marshalling to YAML: %w", err)
1433+
}
1434+
customData[common.TemplateParameters] = string(yamlData)
1435+
14261436
cms := []util.Template{
14271437
{
14281438
Name: fmt.Sprintf("%s-scripts", instance.Name),
@@ -1442,7 +1452,7 @@ func (r *OctaviaReconciler) generateServiceSecrets(
14421452
Labels: cmLabels,
14431453
},
14441454
}
1445-
err := oko_secret.EnsureSecrets(ctx, h, instance, cms, envVars)
1455+
err = oko_secret.EnsureSecrets(ctx, h, instance, cms, envVars)
14461456
if err != nil {
14471457
return err
14481458
}

0 commit comments

Comments
 (0)