Skip to content

Commit 84fa20b

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 84fa20b

15 files changed

+194
-19
lines changed

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: 41 additions & 11 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"
@@ -230,10 +231,11 @@ func (r *CinderReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
230231

231232
// fields to index to reconcile when change
232233
const (
233-
passwordSecretField = ".spec.secret"
234-
caBundleSecretNameField = ".spec.tls.caBundleSecretName"
235-
tlsAPIInternalField = ".spec.tls.api.internal.secretName"
236-
tlsAPIPublicField = ".spec.tls.api.public.secretName"
234+
passwordSecretField = ".spec.secret"
235+
caBundleSecretNameField = ".spec.tls.caBundleSecretName"
236+
tlsAPIInternalField = ".spec.tls.api.internal.secretName"
237+
tlsAPIPublicField = ".spec.tls.api.public.secretName"
238+
httpdCustomServiceConfigSecretField = ".spec.httpdCustomization.customServiceConfigSecret"
237239
)
238240

239241
var (
@@ -246,6 +248,7 @@ var (
246248
caBundleSecretNameField,
247249
tlsAPIInternalField,
248250
tlsAPIPublicField,
251+
httpdCustomServiceConfigSecretField,
249252
}
250253
)
251254

@@ -908,6 +911,14 @@ func (r *CinderReconciler) generateServiceConfigs(
908911
return err
909912
}
910913

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

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

928939
// create httpd vhost template parameters
940+
customTemplates := map[string]string{}
929941
httpdVhostConfig := map[string]interface{}{}
930942
for _, endpt := range []service.Endpoint{service.EndpointInternal, service.EndpointPublic} {
931943
endptConfig := map[string]interface{}{}
@@ -936,10 +948,27 @@ func (r *CinderReconciler) generateServiceConfigs(
936948
endptConfig["SSLCertificateFile"] = fmt.Sprintf("/etc/pki/tls/certs/%s.crt", endpt.String())
937949
endptConfig["SSLCertificateKeyFile"] = fmt.Sprintf("/etc/pki/tls/private/%s.key", endpt.String())
938950
}
951+
952+
endptConfig["Override"] = false
953+
if len(httpdOverrideSecret.Data) > 0 {
954+
endptConfig["Override"] = true
955+
for key, data := range httpdOverrideSecret.Data {
956+
if len(data) > 0 {
957+
customTemplates["httpd_custom_"+endpt.String()+"_"+key] = string(data)
958+
}
959+
}
960+
}
939961
httpdVhostConfig[endpt.String()] = endptConfig
940962
}
941963
templateParameters["VHosts"] = httpdVhostConfig
942964

965+
// Marshal the templateParameters map to YAML
966+
yamlData, err := yaml.Marshal(templateParameters)
967+
if err != nil {
968+
return fmt.Errorf("Error marshalling to YAML: %w", err)
969+
}
970+
customData[common.TemplateParameters] = string(yamlData)
971+
943972
configTemplates := []util.Template{
944973
{
945974
Name: fmt.Sprintf("%s-scripts", instance.Name),
@@ -949,13 +978,14 @@ func (r *CinderReconciler) generateServiceConfigs(
949978
Labels: labels,
950979
},
951980
{
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,
981+
Name: fmt.Sprintf("%s-config-data", instance.Name),
982+
Namespace: instance.Namespace,
983+
Type: util.TemplateTypeConfig,
984+
InstanceType: instance.Kind,
985+
CustomData: customData,
986+
ConfigOptions: templateParameters,
987+
StringTemplate: customTemplates,
988+
Labels: labels,
959989
},
960990
}
961991

controllers/cinderapi_controller.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,18 @@ func (r *CinderAPIReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Man
311311
return err
312312
}
313313

314+
// index httpdOverrideSecretField
315+
if err := mgr.GetFieldIndexer().IndexField(context.Background(), &cinderv1beta1.CinderAPI{}, httpdCustomServiceConfigSecretField, func(rawObj client.Object) []string {
316+
// Extract the secret name from the spec, if one is provided
317+
cr := rawObj.(*cinderv1beta1.CinderAPI)
318+
if cr.Spec.HttpdCustomization.CustomConfigSecret == nil {
319+
return nil
320+
}
321+
return []string{*cr.Spec.HttpdCustomization.CustomConfigSecret}
322+
}); err != nil {
323+
return err
324+
}
325+
314326
return ctrl.NewControllerManagedBy(mgr).
315327
For(&cinderv1beta1.CinderAPI{}).
316328
Owns(&keystonev1.KeystoneService{}).

0 commit comments

Comments
 (0)