Skip to content

Commit

Permalink
Configure tls_enabled for swifts cache
Browse files Browse the repository at this point in the history
configure tls_enabled which is either true/false depending on if
the memcached instance supports tls.

Jira: OSPRH-5283
  • Loading branch information
stuggi committed Apr 8, 2024
1 parent feee616 commit 4a61ede
Show file tree
Hide file tree
Showing 15 changed files with 171 additions and 52 deletions.
8 changes: 4 additions & 4 deletions api/bases/swift.openstack.org_swiftproxies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ spec:
default: false
description: Encrypts new objects at rest
type: boolean
memcachedServers:
default: ""
description: List of memcached servers.
memcachedInstance:
default: memcached
description: Memcached instance name.
type: string
networkAttachments:
description: NetworkAttachments is a list of NetworkAttachment resource
Expand Down Expand Up @@ -315,7 +315,7 @@ spec:
type: object
required:
- containerImageProxy
- memcachedServers
- memcachedInstance
- rabbitMqClusterName
- replicas
- secret
Expand Down
16 changes: 8 additions & 8 deletions api/bases/swift.openstack.org_swifts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ spec:
default: false
description: Encrypts new objects at rest
type: boolean
memcachedServers:
default: ""
description: List of memcached servers.
memcachedInstance:
default: memcached
description: Memcached instance name.
type: string
networkAttachments:
description: NetworkAttachments is a list of NetworkAttachment
Expand Down Expand Up @@ -342,7 +342,7 @@ spec:
type: object
required:
- containerImageProxy
- memcachedServers
- memcachedInstance
- rabbitMqClusterName
- replicas
- secret
Expand Down Expand Up @@ -414,9 +414,9 @@ spec:
description: DefaultConfigOverwrite - can be used to add additionalfiles.
Those get added to the service config dir in /etc/<servicename>-conf.d
type: object
memcachedServers:
default: ""
description: List of memcached servers.
memcachedInstance:
default: memcached
description: Memcached instance name.
type: string
networkAttachments:
description: NetworkAttachments is a list of NetworkAttachment
Expand All @@ -442,7 +442,7 @@ spec:
- containerImageContainer
- containerImageObject
- containerImageProxy
- memcachedServers
- memcachedInstance
- replicas
- storageClass
- storageRequest
Expand Down
8 changes: 4 additions & 4 deletions api/bases/swift.openstack.org_swiftstorages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ spec:
description: DefaultConfigOverwrite - can be used to add additionalfiles.
Those get added to the service config dir in /etc/<servicename>-conf.d
type: object
memcachedServers:
default: ""
description: List of memcached servers.
memcachedInstance:
default: memcached
description: Memcached instance name.
type: string
networkAttachments:
description: NetworkAttachments is a list of NetworkAttachment resource
Expand All @@ -98,7 +98,7 @@ spec:
- containerImageContainer
- containerImageObject
- containerImageProxy
- memcachedServers
- memcachedInstance
- replicas
- storageClass
- storageRequest
Expand Down
6 changes: 3 additions & 3 deletions api/v1beta1/swiftproxy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ type SwiftProxySpecCore struct {
NetworkAttachments []string `json:"networkAttachments,omitempty"`

// +kubebuilder:validation:Required
// +kubebuilder:default=""
// List of memcached servers.
MemcachedServers string `json:"memcachedServers"`
// +kubebuilder:default=memcached
// Memcached instance name.
MemcachedInstance string `json:"memcachedInstance"`

// +kubebuilder:validation:Required
// +kubebuilder:default=rabbitmq
Expand Down
6 changes: 3 additions & 3 deletions api/v1beta1/swiftstorage_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ type SwiftStorageSpecCore struct {
NetworkAttachments []string `json:"networkAttachments,omitempty"`

// +kubebuilder:validation:Required
// +kubebuilder:default=""
// List of memcached servers.
MemcachedServers string `json:"memcachedServers"`
// +kubebuilder:default=memcached
// Memcached instance name.
MemcachedInstance string `json:"memcachedInstance"`

// +kubebuilder:validation:Optional
// +kubebuilder:default=false
Expand Down
8 changes: 4 additions & 4 deletions config/crd/bases/swift.openstack.org_swiftproxies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ spec:
default: false
description: Encrypts new objects at rest
type: boolean
memcachedServers:
default: ""
description: List of memcached servers.
memcachedInstance:
default: memcached
description: Memcached instance name.
type: string
networkAttachments:
description: NetworkAttachments is a list of NetworkAttachment resource
Expand Down Expand Up @@ -315,7 +315,7 @@ spec:
type: object
required:
- containerImageProxy
- memcachedServers
- memcachedInstance
- rabbitMqClusterName
- replicas
- secret
Expand Down
16 changes: 8 additions & 8 deletions config/crd/bases/swift.openstack.org_swifts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ spec:
default: false
description: Encrypts new objects at rest
type: boolean
memcachedServers:
default: ""
description: List of memcached servers.
memcachedInstance:
default: memcached
description: Memcached instance name.
type: string
networkAttachments:
description: NetworkAttachments is a list of NetworkAttachment
Expand Down Expand Up @@ -342,7 +342,7 @@ spec:
type: object
required:
- containerImageProxy
- memcachedServers
- memcachedInstance
- rabbitMqClusterName
- replicas
- secret
Expand Down Expand Up @@ -414,9 +414,9 @@ spec:
description: DefaultConfigOverwrite - can be used to add additionalfiles.
Those get added to the service config dir in /etc/<servicename>-conf.d
type: object
memcachedServers:
default: ""
description: List of memcached servers.
memcachedInstance:
default: memcached
description: Memcached instance name.
type: string
networkAttachments:
description: NetworkAttachments is a list of NetworkAttachment
Expand All @@ -442,7 +442,7 @@ spec:
- containerImageContainer
- containerImageObject
- containerImageProxy
- memcachedServers
- memcachedInstance
- replicas
- storageClass
- storageRequest
Expand Down
8 changes: 4 additions & 4 deletions config/crd/bases/swift.openstack.org_swiftstorages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ spec:
description: DefaultConfigOverwrite - can be used to add additionalfiles.
Those get added to the service config dir in /etc/<servicename>-conf.d
type: object
memcachedServers:
default: ""
description: List of memcached servers.
memcachedInstance:
default: memcached
description: Memcached instance name.
type: string
networkAttachments:
description: NetworkAttachments is a list of NetworkAttachment resource
Expand All @@ -98,7 +98,7 @@ spec:
- containerImageContainer
- containerImageObject
- containerImageProxy
- memcachedServers
- memcachedInstance
- replicas
- storageClass
- storageRequest
Expand Down
14 changes: 6 additions & 8 deletions controllers/swift_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,8 @@ func (r *SwiftReconciler) reconcileNormal(ctx context.Context, instance *swiftv1
condition.MemcachedReadyCondition, condition.MemcachedReadyMessage)
// run check memcached - end

memcachedServers := memcached.GetMemcachedServerListString()

// create or update Swift storage
swiftStorage, op, err := r.storageCreateOrUpdate(ctx, instance, memcachedServers)
swiftStorage, op, err := r.storageCreateOrUpdate(ctx, instance)
if err != nil {
instance.Status.Conditions.Set(condition.FalseCondition(
swiftv1.SwiftStorageReadyCondition,
Expand Down Expand Up @@ -313,7 +311,7 @@ func (r *SwiftReconciler) reconcileNormal(ctx context.Context, instance *swiftv1
}

// create or update Swift proxy
swiftProxy, op, err := r.proxyCreateOrUpdate(ctx, instance, memcachedServers)
swiftProxy, op, err := r.proxyCreateOrUpdate(ctx, instance)
if err != nil {
instance.Status.Conditions.Set(condition.FalseCondition(
swiftv1.SwiftProxyReadyCondition,
Expand Down Expand Up @@ -399,7 +397,7 @@ func (r *SwiftReconciler) ringCreateOrUpdate(ctx context.Context, instance *swif
return deployment, op, err
}

func (r *SwiftReconciler) storageCreateOrUpdate(ctx context.Context, instance *swiftv1.Swift, memcachedServers string) (*swiftv1.SwiftStorage, controllerutil.OperationResult, error) {
func (r *SwiftReconciler) storageCreateOrUpdate(ctx context.Context, instance *swiftv1.Swift) (*swiftv1.SwiftStorage, controllerutil.OperationResult, error) {

swiftStorageSpec := swiftv1.SwiftStorageSpec{
ContainerImageAccount: instance.Spec.SwiftStorage.ContainerImageAccount,
Expand All @@ -411,7 +409,7 @@ func (r *SwiftReconciler) storageCreateOrUpdate(ctx context.Context, instance *s
StorageClass: instance.Spec.SwiftStorage.StorageClass,
StorageRequest: instance.Spec.SwiftStorage.StorageRequest,
NetworkAttachments: instance.Spec.SwiftStorage.NetworkAttachments,
MemcachedServers: memcachedServers,
MemcachedInstance: instance.Spec.MemcachedInstance,
ContainerSharderEnabled: instance.Spec.SwiftStorage.ContainerSharderEnabled,
DefaultConfigOverwrite: instance.Spec.SwiftStorage.DefaultConfigOverwrite,
},
Expand All @@ -437,7 +435,7 @@ func (r *SwiftReconciler) storageCreateOrUpdate(ctx context.Context, instance *s
return deployment, op, err
}

func (r *SwiftReconciler) proxyCreateOrUpdate(ctx context.Context, instance *swiftv1.Swift, memcachedServers string) (*swiftv1.SwiftProxy, controllerutil.OperationResult, error) {
func (r *SwiftReconciler) proxyCreateOrUpdate(ctx context.Context, instance *swiftv1.Swift) (*swiftv1.SwiftProxy, controllerutil.OperationResult, error) {

swiftProxySpec := swiftv1.SwiftProxySpec{
ContainerImageProxy: instance.Spec.SwiftProxy.ContainerImageProxy,
Expand All @@ -448,7 +446,7 @@ func (r *SwiftReconciler) proxyCreateOrUpdate(ctx context.Context, instance *swi
PasswordSelectors: instance.Spec.SwiftProxy.PasswordSelectors,
Override: instance.Spec.SwiftProxy.Override,
NetworkAttachments: instance.Spec.SwiftProxy.NetworkAttachments,
MemcachedServers: memcachedServers,
MemcachedInstance: instance.Spec.MemcachedInstance,
TLS: instance.Spec.SwiftProxy.TLS,
DefaultConfigOverwrite: instance.Spec.SwiftProxy.DefaultConfigOverwrite,
EncryptionEnabled: instance.Spec.SwiftProxy.EncryptionEnabled,
Expand Down
58 changes: 57 additions & 1 deletion controllers/swiftproxy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import (
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"
"github.com/openstack-k8s-operators/lib-common/modules/common/util"

memcachedv1 "github.com/openstack-k8s-operators/infra-operator/apis/memcached/v1beta1"
rabbitmqv1 "github.com/openstack-k8s-operators/infra-operator/apis/rabbitmq/v1beta1"
keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1"
swiftv1beta1 "github.com/openstack-k8s-operators/swift-operator/api/v1beta1"
Expand Down Expand Up @@ -533,14 +534,36 @@ func (r *SwiftProxyReconciler) Reconcile(ctx context.Context, req ctrl.Request)
return ctrl.Result{}, err
}

//
// Check for required memcached used for caching
//
memcached, err := memcachedv1.GetMemcachedByName(ctx, helper, instance.Spec.MemcachedInstance, instance.Namespace)
if err != nil {
if apierrors.IsNotFound(err) {
instance.Status.Conditions.Set(condition.FalseCondition(
condition.MemcachedReadyCondition,
condition.RequestedReason,
condition.SeverityInfo,
condition.MemcachedReadyWaitingMessage))
return ctrl.Result{RequeueAfter: 10 * time.Second}, fmt.Errorf("memcached %s not found", instance.Spec.MemcachedInstance)
}
instance.Status.Conditions.Set(condition.FalseCondition(
condition.MemcachedReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
condition.MemcachedReadyErrorMessage,
err.Error()))
return ctrl.Result{}, err
}

// Create a Secret populated with content from templates/
tpl := swiftproxy.SecretTemplates(
instance,
serviceLabels,
keystonePublicURL,
keystoneInternalURL,
password,
instance.Spec.MemcachedServers,
memcached,
bindIP,
secretRef,
os.GetRegion(),
Expand Down Expand Up @@ -674,6 +697,8 @@ func (r *SwiftProxyReconciler) Reconcile(ctx context.Context, req ctrl.Request)

// SetupWithManager sets up the controller with the Manager.
func (r *SwiftProxyReconciler) SetupWithManager(mgr ctrl.Manager) error {
logger := mgr.GetLogger()

// index passwordSecretField
if err := mgr.GetFieldIndexer().IndexField(context.Background(), &swiftv1beta1.SwiftProxy{}, passwordSecretField, func(rawObj client.Object) []string {
// Extract the secret name from the spec, if one is provided
Expand Down Expand Up @@ -722,6 +747,35 @@ func (r *SwiftProxyReconciler) SetupWithManager(mgr ctrl.Manager) error {
return err
}

memcachedFn := func(ctx context.Context, o client.Object) []reconcile.Request {
result := []reconcile.Request{}

// get all SwiftProxy CRs
crList := &swiftv1beta1.SwiftProxyList{}
listOpts := []client.ListOption{
client.InNamespace(o.GetNamespace()),
}
if err := r.Client.List(context.Background(), crList, listOpts...); err != nil {
logger.Error(err, "Unable to retrieve SwiftProxy CRs %w")
return nil
}

for _, cr := range crList.Items {
if o.GetName() == cr.Spec.MemcachedInstance {
name := client.ObjectKey{
Namespace: o.GetNamespace(),
Name: cr.Name,
}
logger.Info(fmt.Sprintf("Memcached %s is used by SwiftProxy CR %s", o.GetName(), cr.Name))
result = append(result, reconcile.Request{NamespacedName: name})
}
}
if len(result) > 0 {
return result
}
return nil
}

return ctrl.NewControllerManagedBy(mgr).
For(&swiftv1beta1.SwiftProxy{}).
Owns(&corev1.Secret{}).
Expand All @@ -735,6 +789,8 @@ func (r *SwiftProxyReconciler) SetupWithManager(mgr ctrl.Manager) error {
handler.EnqueueRequestsFromMapFunc(r.findObjectsForSrc),
builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}),
).
Watches(&memcachedv1.Memcached{},
handler.EnqueueRequestsFromMapFunc(memcachedFn)).
Complete(r)
}

Expand Down
Loading

0 comments on commit 4a61ede

Please sign in to comment.