Skip to content

Commit 6c82ece

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 cinder-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: ~~~ DatabaseConnection: mysql+pymysql://user:pwd@openstack.openstack.svc/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:pwd@rabbitmq.openstack.svc:5671/?ssl=1 VHosts: internal: Override: false SSLCertificateFile: /etc/pki/tls/certs/internal.crt SSLCertificateKeyFile: /etc/pki/tls/private/internal.key ServerName: cinder-internal.openstack.svc TLS: true public: Override: false SSLCertificateFile: /etc/pki/tls/certs/public.crt SSLCertificateKeyFile: /etc/pki/tls/private/public.key ServerName: cinder-public.openstack.svc TLS: true MemcachedServersWithInet: inet:[memcached-0.memcached.openstack.svc]:11211 ... ~~~ 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> Signed-off-by: Martin Schuppert <mschuppert@redhat.com>
1 parent cbc7eaf commit 6c82ece

14 files changed

Lines changed: 176 additions & 15 deletions

api/bases/cinder.openstack.org_cinderapis.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,11 @@ spec:
535535
- extraVol
536536
type: object
537537
type: array
538+
httpdCustomization:
539+
properties:
540+
customConfigSecret:
541+
type: string
542+
type: object
538543
networkAttachments:
539544
items:
540545
type: string

api/bases/cinder.openstack.org_cinders.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ spec:
4949
items:
5050
type: string
5151
type: array
52+
httpdCustomization:
53+
properties:
54+
customConfigSecret:
55+
type: string
56+
type: object
5257
networkAttachments:
5358
items:
5459
type: string

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/cinder-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
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
99
k8s.io/api v0.29.10

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/cinderapi_types.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ type CinderAPITemplateCore struct {
4242
// +operator-sdk:csv:customresourcedefinitions:type=spec
4343
// TLS - Parameters related to the TLS
4444
TLS tls.API `json:"tls,omitempty"`
45+
46+
// +kubebuilder:validation:Optional
47+
// HttpdCustomization - customize the httpd service
48+
HttpdCustomization HttpdCustomization `json:"httpdCustomization,omitempty"`
4549
}
4650

4751
// CinderAPITemplate defines the input parameters for the Cinder API service
@@ -60,6 +64,19 @@ type APIOverrideSpec struct {
6064
Service map[service.Endpoint]service.RoutedOverrideSpec `json:"service,omitempty"`
6165
}
6266

67+
// HttpdCustomization - customize the httpd service
68+
type HttpdCustomization struct {
69+
// +kubebuilder:validation:Optional
70+
// CustomConfigSecret - customize the httpd vhost config using this parameter to specify
71+
// a secret that contains service config data. The content of each provided snippet gets
72+
// rendered as a go template and placed into /etc/httpd/conf/httpd_custom_<key> .
73+
// In the default httpd template at the end of the vhost those custom configs get
74+
// included using `Include conf/httpd_custom_<endpoint>_*`.
75+
// For information on how sections in httpd configuration get merged, check section
76+
// "How the sections are merged" in https://httpd.apache.org/docs/current/sections.html#merging
77+
CustomConfigSecret *string `json:"customConfigSecret,omitempty"`
78+
}
79+
6380
// CinderAPISpec defines the desired state of CinderAPI
6481
type CinderAPISpec struct {
6582
// Common input parameters for all Cinder services

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/cinder.openstack.org_cinderapis.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,11 @@ spec:
535535
- extraVol
536536
type: object
537537
type: array
538+
httpdCustomization:
539+
properties:
540+
customConfigSecret:
541+
type: string
542+
type: object
538543
networkAttachments:
539544
items:
540545
type: string

config/crd/bases/cinder.openstack.org_cinders.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ spec:
4949
items:
5050
type: string
5151
type: array
52+
httpdCustomization:
53+
properties:
54+
customConfigSecret:
55+
type: string
56+
type: object
5257
networkAttachments:
5358
items:
5459
type: string

controllers/cinder_controller.go

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"time"
2323

24+
"gopkg.in/yaml.v2"
2425
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
2526
"k8s.io/apimachinery/pkg/runtime"
2627
"k8s.io/apimachinery/pkg/types"
@@ -908,6 +909,14 @@ func (r *CinderReconciler) generateServiceConfigs(
908909
return err
909910
}
910911

912+
httpdOverrideSecret := &corev1.Secret{}
913+
if instance.Spec.CinderAPI.HttpdCustomization.CustomConfigSecret != nil && *instance.Spec.CinderAPI.HttpdCustomization.CustomConfigSecret != "" {
914+
httpdOverrideSecret, _, err = secret.GetSecret(ctx, h, *instance.Spec.CinderAPI.HttpdCustomization.CustomConfigSecret, instance.Namespace)
915+
if err != nil {
916+
return err
917+
}
918+
}
919+
911920
databaseAccount := db.GetAccount()
912921
dbSecret := db.GetSecret()
913922

@@ -926,6 +935,7 @@ func (r *CinderReconciler) generateServiceConfigs(
926935
templateParameters["TimeOut"] = instance.Spec.APITimeout
927936

928937
// create httpd vhost template parameters
938+
customTemplates := map[string]string{}
929939
httpdVhostConfig := map[string]interface{}{}
930940
for _, endpt := range []service.Endpoint{service.EndpointInternal, service.EndpointPublic} {
931941
endptConfig := map[string]interface{}{}
@@ -936,10 +946,27 @@ func (r *CinderReconciler) generateServiceConfigs(
936946
endptConfig["SSLCertificateFile"] = fmt.Sprintf("/etc/pki/tls/certs/%s.crt", endpt.String())
937947
endptConfig["SSLCertificateKeyFile"] = fmt.Sprintf("/etc/pki/tls/private/%s.key", endpt.String())
938948
}
949+
950+
endptConfig["Override"] = false
951+
if len(httpdOverrideSecret.Data) > 0 {
952+
endptConfig["Override"] = true
953+
for key, data := range httpdOverrideSecret.Data {
954+
if len(data) > 0 {
955+
customTemplates["httpd_custom_"+endpt.String()+"_"+key] = string(data)
956+
}
957+
}
958+
}
939959
httpdVhostConfig[endpt.String()] = endptConfig
940960
}
941961
templateParameters["VHosts"] = httpdVhostConfig
942962

963+
// Marshal the templateParameters map to YAML
964+
yamlData, err := yaml.Marshal(templateParameters)
965+
if err != nil {
966+
return fmt.Errorf("Error marshalling to YAML: %w", err)
967+
}
968+
customData[common.TemplateParameters] = string(yamlData)
969+
943970
configTemplates := []util.Template{
944971
{
945972
Name: fmt.Sprintf("%s-scripts", instance.Name),
@@ -949,13 +976,14 @@ func (r *CinderReconciler) generateServiceConfigs(
949976
Labels: labels,
950977
},
951978
{
952-
Name: fmt.Sprintf("%s-config-data", instance.Name),
953-
Namespace: instance.Namespace,
954-
Type: util.TemplateTypeConfig,
955-
InstanceType: instance.Kind,
956-
CustomData: customData,
957-
ConfigOptions: templateParameters,
958-
Labels: labels,
979+
Name: fmt.Sprintf("%s-config-data", instance.Name),
980+
Namespace: instance.Namespace,
981+
Type: util.TemplateTypeConfig,
982+
InstanceType: instance.Kind,
983+
CustomData: customData,
984+
ConfigOptions: templateParameters,
985+
StringTemplate: customTemplates,
986+
Labels: labels,
959987
},
960988
}
961989

go.mod

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/onsi/gomega v1.34.1
1111
github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20241213080025-18e54a028c8b
1212
github.com/openstack-k8s-operators/keystone-operator/api v0.5.1-0.20241212135809-dc78e7221d12
13-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241216113837-d172b3ac0f4e
13+
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250116145727-01a8948d5dd7
1414
github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.20241216113837-d172b3ac0f4e
1515
github.com/openstack-k8s-operators/lib-common/modules/test v0.5.1-0.20241216113837-d172b3ac0f4e
1616
github.com/openstack-k8s-operators/mariadb-operator/api v0.5.1-0.20241212160155-4e7d8f749820
@@ -22,7 +22,10 @@ require (
2222
sigs.k8s.io/controller-runtime v0.17.6
2323
)
2424

25-
require github.com/openstack-k8s-operators/cinder-operator/api v0.0.0-00010101000000-000000000000
25+
require (
26+
github.com/openstack-k8s-operators/cinder-operator/api v0.0.0-00010101000000-000000000000
27+
gopkg.in/yaml.v2 v2.4.0
28+
)
2629

2730
require (
2831
github.com/beorn7/perks v1.0.1 // indirect
@@ -73,7 +76,6 @@ require (
7376
google.golang.org/appengine v1.6.8 // indirect
7477
google.golang.org/protobuf v1.34.1 // indirect
7578
gopkg.in/inf.v0 v0.9.1 // indirect
76-
gopkg.in/yaml.v2 v2.4.0 // indirect
7779
gopkg.in/yaml.v3 v3.0.1 // indirect
7880
k8s.io/apiextensions-apiserver v0.29.10 // indirect
7981
k8s.io/component-base v0.29.10 // indirect

0 commit comments

Comments
 (0)