Skip to content

Commit

Permalink
Add DefaultConfigOverwrite option
Browse files Browse the repository at this point in the history
This allows customizing configurations of all required Swift services if
needed. The keys are parsed as well using the existing
templateParameters, allowing content to be filled with
internal values like secrets - for example Keystone credentials. An
example might look like this:

    defaultConfigOverwrite:
      proxy-server.conf: |
        [filter:authtoken]
        password = {{ .ServicePassword }}
  • Loading branch information
cschwede committed Feb 1, 2024
1 parent 010c730 commit 9548677
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 9 deletions.
8 changes: 8 additions & 0 deletions api/bases/swift.openstack.org_swiftproxies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ spec:
containerImageProxy:
description: Swift Proxy Container Image URL
type: string
defaultConfigOverwrite:
additionalProperties:
type: string
description: ConfigOverwrite - interface to overwrite default config
files like e.g. logging.conf But can also be used to add additional
files. Those get added to the service config dir in /etc/<service>
.
type: object
memcachedServers:
default: ""
description: List of memcached servers.
Expand Down
16 changes: 16 additions & 0 deletions api/bases/swift.openstack.org_swifts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ spec:
containerImageProxy:
description: Swift Proxy Container Image URL
type: string
defaultConfigOverwrite:
additionalProperties:
type: string
description: ConfigOverwrite - interface to overwrite default
config files like e.g. logging.conf But can also be used to
add additional files. Those get added to the service config
dir in /etc/<service> .
type: object
memcachedServers:
default: ""
description: List of memcached servers.
Expand Down Expand Up @@ -344,6 +352,14 @@ spec:
containerImageProxy:
description: Image URL for Swift proxy service
type: string
defaultConfigOverwrite:
additionalProperties:
type: string
description: ConfigOverwrite - interface to overwrite default
config files like e.g. logging.conf But can also be used to
add additional files. Those get added to the service config
dir in /etc/<service> .
type: object
memcachedServers:
default: ""
description: List of memcached servers.
Expand Down
8 changes: 8 additions & 0 deletions api/bases/swift.openstack.org_swiftstorages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ spec:
containerImageProxy:
description: Image URL for Swift proxy service
type: string
defaultConfigOverwrite:
additionalProperties:
type: string
description: ConfigOverwrite - interface to overwrite default config
files like e.g. logging.conf But can also be used to add additional
files. Those get added to the service config dir in /etc/<service>
.
type: object
memcachedServers:
default: ""
description: List of memcached servers.
Expand Down
5 changes: 5 additions & 0 deletions api/v1beta1/swiftproxy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ type SwiftProxySpec struct {
// +kubebuilder:default=""
// List of memcached servers.
MemcachedServers string `json:"memcachedServers"`

// +kubebuilder:validation:Optional
// ConfigOverwrite - interface to overwrite default config files like e.g. logging.conf
// But can also be used to add additional files. Those get added to the service config dir in /etc/<service> .
DefaultConfigOverwrite map[string]string `json:"defaultConfigOverwrite,omitempty"`
}

// ProxyOverrideSpec to override the generated manifest of several child resources.
Expand Down
5 changes: 5 additions & 0 deletions api/v1beta1/swiftstorage_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ type SwiftStorageSpec struct {
// +kubebuilder:default=""
// List of memcached servers.
MemcachedServers string `json:"memcachedServers"`

// +kubebuilder:validation:Optional
// ConfigOverwrite - interface to overwrite default config files like e.g. logging.conf
// But can also be used to add additional files. Those get added to the service config dir in /etc/<service> .
DefaultConfigOverwrite map[string]string `json:"defaultConfigOverwrite,omitempty"`
}

// SwiftStorageStatus defines the observed state of SwiftStorage
Expand Down
14 changes: 14 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions config/crd/bases/swift.openstack.org_swiftproxies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ spec:
containerImageProxy:
description: Swift Proxy Container Image URL
type: string
defaultConfigOverwrite:
additionalProperties:
type: string
description: ConfigOverwrite - interface to overwrite default config
files like e.g. logging.conf But can also be used to add additional
files. Those get added to the service config dir in /etc/<service>
.
type: object
memcachedServers:
default: ""
description: List of memcached servers.
Expand Down
16 changes: 16 additions & 0 deletions config/crd/bases/swift.openstack.org_swifts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ spec:
containerImageProxy:
description: Swift Proxy Container Image URL
type: string
defaultConfigOverwrite:
additionalProperties:
type: string
description: ConfigOverwrite - interface to overwrite default
config files like e.g. logging.conf But can also be used to
add additional files. Those get added to the service config
dir in /etc/<service> .
type: object
memcachedServers:
default: ""
description: List of memcached servers.
Expand Down Expand Up @@ -344,6 +352,14 @@ spec:
containerImageProxy:
description: Image URL for Swift proxy service
type: string
defaultConfigOverwrite:
additionalProperties:
type: string
description: ConfigOverwrite - interface to overwrite default
config files like e.g. logging.conf But can also be used to
add additional files. Those get added to the service config
dir in /etc/<service> .
type: object
memcachedServers:
default: ""
description: List of memcached servers.
Expand Down
8 changes: 8 additions & 0 deletions config/crd/bases/swift.openstack.org_swiftstorages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ spec:
containerImageProxy:
description: Image URL for Swift proxy service
type: string
defaultConfigOverwrite:
additionalProperties:
type: string
description: ConfigOverwrite - interface to overwrite default config
files like e.g. logging.conf But can also be used to add additional
files. Those get added to the service config dir in /etc/<service>
.
type: object
memcachedServers:
default: ""
description: List of memcached servers.
Expand Down
20 changes: 11 additions & 9 deletions controllers/swift_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ func (r *SwiftReconciler) storageCreateOrUpdate(ctx context.Context, instance *s
SwiftConfSecret: instance.Spec.SwiftConfSecret,
NetworkAttachments: instance.Spec.SwiftStorage.NetworkAttachments,
MemcachedServers: memcachedServers,
DefaultConfigOverwrite: instance.Spec.SwiftStorage.DefaultConfigOverwrite,
}

deployment := &swiftv1.SwiftStorage{
Expand All @@ -420,15 +421,16 @@ func (r *SwiftReconciler) storageCreateOrUpdate(ctx context.Context, instance *s
func (r *SwiftReconciler) proxyCreateOrUpdate(ctx context.Context, instance *swiftv1.Swift, memcachedServers string) (*swiftv1.SwiftProxy, controllerutil.OperationResult, error) {

swiftProxySpec := swiftv1.SwiftProxySpec{
Replicas: instance.Spec.SwiftProxy.Replicas,
ContainerImageProxy: instance.Spec.SwiftProxy.ContainerImageProxy,
Secret: instance.Spec.SwiftProxy.Secret,
ServiceUser: instance.Spec.SwiftProxy.ServiceUser,
PasswordSelectors: instance.Spec.SwiftProxy.PasswordSelectors,
SwiftConfSecret: instance.Spec.SwiftConfSecret,
Override: instance.Spec.SwiftProxy.Override,
NetworkAttachments: instance.Spec.SwiftProxy.NetworkAttachments,
MemcachedServers: memcachedServers,
Replicas: instance.Spec.SwiftProxy.Replicas,
ContainerImageProxy: instance.Spec.SwiftProxy.ContainerImageProxy,
Secret: instance.Spec.SwiftProxy.Secret,
ServiceUser: instance.Spec.SwiftProxy.ServiceUser,
PasswordSelectors: instance.Spec.SwiftProxy.PasswordSelectors,
SwiftConfSecret: instance.Spec.SwiftConfSecret,
Override: instance.Spec.SwiftProxy.Override,
NetworkAttachments: instance.Spec.SwiftProxy.NetworkAttachments,
MemcachedServers: memcachedServers,
DefaultConfigOverwrite: instance.Spec.SwiftProxy.DefaultConfigOverwrite,
}

deployment := &swiftv1.SwiftProxy{
Expand Down
7 changes: 7 additions & 0 deletions pkg/swiftproxy/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ func SecretTemplates(
templateParameters["KeystoneInternalURL"] = keystoneInternalURL
templateParameters["MemcachedServers"] = memcachedServers

customData := map[string]string{}
for key, data := range instance.Spec.DefaultConfigOverwrite {
rendered, _ := util.ExecuteTemplateData(data, templateParameters)
customData[key] = rendered
}

return []util.Template{
{
Name: fmt.Sprintf("%s-config-data", instance.Name),
Expand All @@ -46,6 +52,7 @@ func SecretTemplates(
InstanceType: instance.Kind,
ConfigOptions: templateParameters,
Labels: labels,
CustomData: customData,
},
{
Name: fmt.Sprintf("%s-scripts", instance.Name),
Expand Down
7 changes: 7 additions & 0 deletions pkg/swiftstorage/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ func ConfigMapTemplates(instance *swiftv1beta1.SwiftStorage, labels map[string]s
templateParameters := make(map[string]interface{})
templateParameters["MemcachedServers"] = memcachedServers

customData := map[string]string{}
for key, data := range instance.Spec.DefaultConfigOverwrite {
rendered, _ := util.ExecuteTemplateData(data, templateParameters)
customData[key] = rendered
}

return []util.Template{
{
Name: fmt.Sprintf("%s-config-data", instance.Name),
Expand All @@ -34,6 +40,7 @@ func ConfigMapTemplates(instance *swiftv1beta1.SwiftStorage, labels map[string]s
InstanceType: instance.Kind,
Labels: labels,
ConfigOptions: templateParameters,
CustomData: customData,
},
{
Name: fmt.Sprintf("%s-scripts", instance.Name),
Expand Down

0 comments on commit 9548677

Please sign in to comment.