Skip to content

Commit e3e8e41

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 placement-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: keystone-internal.openstack.svc TLS: true public: Override: false SSLCertificateFile: /etc/pki/tls/certs/public.crt SSLCertificateKeyFile: /etc/pki/tls/private/public.key ServerName: keystone-public.openstack.svc TLS: true MemcachedServers: memcached-0.memcached.openstack.svc:11212 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 <[email protected]>
1 parent f10f6a2 commit e3e8e41

17 files changed

+210
-13
lines changed

api/bases/manila.openstack.org_manilaapis.yaml

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

api/bases/manila.openstack.org_manilas.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,11 @@ spec:
557557
items:
558558
type: string
559559
type: array
560+
httpdCustomization:
561+
properties:
562+
customConfigSecret:
563+
type: string
564+
type: object
560565
networkAttachments:
561566
items:
562567
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/manila-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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +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/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241216113837-d172b3ac0f4e h1:hf4kVQBkyG79WcHBxdQ25QrDBbGFdarebS1Tc0Xclq4=
7777
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=
7880
github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.20241216113837-d172b3ac0f4e h1:Qz0JFEoRDUyjEWorNY3LggwxTsmpMtQkcpmZDQulGHQ=
7981
github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.20241216113837-d172b3ac0f4e/go.mod h1:tfgBeLRqmlH/NQkLPe7396rj+t0whv2wPuMb8Ttvh8w=
8082
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=

api/v1beta1/manilaapi_types.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ type ManilaAPITemplateCore struct {
5353
// +operator-sdk:csv:customresourcedefinitions:type=spec
5454
// TLS - Parameters related to the TLS
5555
TLS tls.API `json:"tls,omitempty"`
56+
57+
// +kubebuilder:validation:Optional
58+
// HttpdCustomization - customize the httpd service
59+
HttpdCustomization HttpdCustomization `json:"httpdCustomization,omitempty"`
5660
}
5761

5862
// APIOverrideSpec to override the generated manifest of several child resources.
@@ -62,6 +66,19 @@ type APIOverrideSpec struct {
6266
Service map[service.Endpoint]service.RoutedOverrideSpec `json:"service,omitempty"`
6367
}
6468

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

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/manila.openstack.org_manilaapis.yaml

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

config/crd/bases/manila.openstack.org_manilas.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,11 @@ spec:
557557
items:
558558
type: string
559559
type: array
560+
httpdCustomization:
561+
properties:
562+
customConfigSecret:
563+
type: string
564+
type: object
560565
networkAttachments:
561566
items:
562567
type: string

controllers/manila_controller.go

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"fmt"
2222

23+
"gopkg.in/yaml.v2"
2324
"k8s.io/apimachinery/pkg/types"
2425
"k8s.io/utils/ptr"
2526

@@ -215,10 +216,11 @@ func (r *ManilaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
215216

216217
// fields to index to reconcile when change
217218
const (
218-
passwordSecretField = ".spec.secret"
219-
caBundleSecretNameField = ".spec.tls.caBundleSecretName"
220-
tlsAPIInternalField = ".spec.tls.api.internal.secretName"
221-
tlsAPIPublicField = ".spec.tls.api.public.secretName"
219+
passwordSecretField = ".spec.secret"
220+
caBundleSecretNameField = ".spec.tls.caBundleSecretName"
221+
tlsAPIInternalField = ".spec.tls.api.internal.secretName"
222+
tlsAPIPublicField = ".spec.tls.api.public.secretName"
223+
httpdCustomServiceConfigSecretField = ".spec.httpdCustomization.customServiceConfigSecret"
222224
)
223225

224226
var (
@@ -231,6 +233,7 @@ var (
231233
caBundleSecretNameField,
232234
tlsAPIInternalField,
233235
tlsAPIPublicField,
236+
httpdCustomServiceConfigSecretField,
234237
}
235238
)
236239

@@ -880,6 +883,14 @@ func (r *ManilaReconciler) generateServiceConfig(
880883
return err
881884
}
882885

886+
httpdOverrideSecret := &corev1.Secret{}
887+
if instance.Spec.ManilaAPI.HttpdCustomization.CustomConfigSecret != nil && *instance.Spec.ManilaAPI.HttpdCustomization.CustomConfigSecret != "" {
888+
httpdOverrideSecret, _, err = secret.GetSecret(ctx, h, *instance.Spec.ManilaAPI.HttpdCustomization.CustomConfigSecret, instance.Namespace)
889+
if err != nil {
890+
return err
891+
}
892+
}
893+
883894
databaseAccount := db.GetAccount()
884895
databaseSecret := db.GetSecret()
885896

@@ -900,6 +911,7 @@ func (r *ManilaReconciler) generateServiceConfig(
900911
}
901912

902913
// create httpd vhost template parameters
914+
customTemplates := map[string]string{}
903915
httpdVhostConfig := map[string]interface{}{}
904916
for _, endpt := range []service.Endpoint{service.EndpointInternal, service.EndpointPublic} {
905917
endptConfig := map[string]interface{}{}
@@ -910,10 +922,27 @@ func (r *ManilaReconciler) generateServiceConfig(
910922
endptConfig["SSLCertificateFile"] = fmt.Sprintf("/etc/pki/tls/certs/%s.crt", endpt.String())
911923
endptConfig["SSLCertificateKeyFile"] = fmt.Sprintf("/etc/pki/tls/private/%s.key", endpt.String())
912924
}
925+
926+
endptConfig["Override"] = false
927+
if len(httpdOverrideSecret.Data) > 0 {
928+
endptConfig["Override"] = true
929+
for key, data := range httpdOverrideSecret.Data {
930+
if len(data) > 0 {
931+
customTemplates["httpd_custom_"+endpt.String()+"_"+key] = string(data)
932+
}
933+
}
934+
}
913935
httpdVhostConfig[endpt.String()] = endptConfig
914936
}
915937
templateParameters["VHosts"] = httpdVhostConfig
916938

939+
// Marshal the templateParameters map to YAML
940+
yamlData, err := yaml.Marshal(templateParameters)
941+
if err != nil {
942+
return fmt.Errorf("Error marshalling to YAML: %w", err)
943+
}
944+
customData[common.TemplateParameters] = string(yamlData)
945+
917946
configTemplates := []util.Template{
918947
// ScriptsConfigMap
919948
{
@@ -925,13 +954,14 @@ func (r *ManilaReconciler) generateServiceConfig(
925954
},
926955
// ConfigMap
927956
{
928-
Name: fmt.Sprintf("%s-config-data", instance.Name),
929-
Namespace: instance.Namespace,
930-
Type: util.TemplateTypeConfig,
931-
InstanceType: instance.Kind,
932-
CustomData: customData,
933-
ConfigOptions: templateParameters,
934-
Labels: labels,
957+
Name: fmt.Sprintf("%s-config-data", instance.Name),
958+
Namespace: instance.Namespace,
959+
Type: util.TemplateTypeConfig,
960+
InstanceType: instance.Kind,
961+
CustomData: customData,
962+
ConfigOptions: templateParameters,
963+
StringTemplate: customTemplates,
964+
Labels: labels,
935965
},
936966
}
937967

controllers/manilaapi_controller.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,18 @@ func (r *ManilaAPIReconciler) SetupWithManager(mgr ctrl.Manager) error {
309309
return err
310310
}
311311

312+
// index httpdOverrideSecretField
313+
if err := mgr.GetFieldIndexer().IndexField(context.Background(), &manilav1beta1.ManilaAPI{}, httpdCustomServiceConfigSecretField, func(rawObj client.Object) []string {
314+
// Extract the secret name from the spec, if one is provided
315+
cr := rawObj.(*manilav1beta1.ManilaAPI)
316+
if cr.Spec.HttpdCustomization.CustomConfigSecret == nil {
317+
return nil
318+
}
319+
return []string{*cr.Spec.HttpdCustomization.CustomConfigSecret}
320+
}); err != nil {
321+
return err
322+
}
323+
312324
return ctrl.NewControllerManagedBy(mgr).
313325
For(&manilav1beta1.ManilaAPI{}).
314326
Owns(&keystonev1.KeystoneService{}).
@@ -947,6 +959,12 @@ func (r *ManilaAPIReconciler) generateServiceConfig(
947959
}
948960
customData[manila.DefaultsConfigFileName] = string(manilaSecret.Data[manila.DefaultsConfigFileName])
949961
customData[manila.CustomConfigFileName] = string(manilaSecret.Data[manila.CustomConfigFileName])
962+
//customData[common.TemplateParameters] = string(manilaSecret.Data[common.TemplateParameters])
963+
//for _, key := range maps.Keys(manilaSecret.Data) {
964+
// if strings.HasPrefix(key, "httpd_custom_") {
965+
// customData[key] = string(manilaSecret.Data[key])
966+
// }
967+
//}
950968

951969
customSecrets := ""
952970
for _, secretName := range instance.Spec.CustomServiceConfigSecrets {

0 commit comments

Comments
 (0)