Skip to content

Commit

Permalink
Merge pull request #299 from olliewalsh/node_selectors
Browse files Browse the repository at this point in the history
Ensure nodeSelector logic is consistent for all operators
  • Loading branch information
openshift-merge-bot[bot] authored Nov 21, 2024
2 parents 107d1aa + 9da4697 commit 6ab57de
Show file tree
Hide file tree
Showing 17 changed files with 182 additions and 5 deletions.
6 changes: 6 additions & 0 deletions api/bases/swift.openstack.org_swiftproxies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ spec:
items:
type: string
type: array
nodeSelector:
additionalProperties:
type: string
description: NodeSelector to target subset of worker nodes running
this service
type: object
override:
description: Override, provides the ability to override the generated
manifest of several child resources.
Expand Down
6 changes: 6 additions & 0 deletions api/bases/swift.openstack.org_swiftrings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ spec:
format: int64
minimum: 1
type: integer
nodeSelector:
additionalProperties:
type: string
description: NodeSelector to target subset of worker nodes running
this service
type: object
partPower:
default: 10
description: Partition power of the Swift rings
Expand Down
24 changes: 24 additions & 0 deletions api/bases/swift.openstack.org_swifts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ spec:
items:
type: string
type: array
nodeSelector:
additionalProperties:
type: string
description: NodeSelector to target subset of worker nodes running
this service
type: object
storageClass:
default: ""
description: Storage class. This is passed to SwiftStorage unless
Expand Down Expand Up @@ -95,6 +101,12 @@ spec:
items:
type: string
type: array
nodeSelector:
additionalProperties:
type: string
description: NodeSelector to target subset of worker nodes running
this service
type: object
override:
description: Override, provides the ability to override the generated
manifest of several child resources.
Expand Down Expand Up @@ -362,6 +374,12 @@ spec:
format: int64
minimum: 1
type: integer
nodeSelector:
additionalProperties:
type: string
description: NodeSelector to target subset of worker nodes running
this service
type: object
partPower:
default: 10
description: Partition power of the Swift rings
Expand Down Expand Up @@ -424,6 +442,12 @@ spec:
items:
type: string
type: array
nodeSelector:
additionalProperties:
type: string
description: NodeSelector to target subset of worker nodes running
this service
type: object
replicas:
default: 1
format: int32
Expand Down
6 changes: 6 additions & 0 deletions api/bases/swift.openstack.org_swiftstorages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ spec:
items:
type: string
type: array
nodeSelector:
additionalProperties:
type: string
description: NodeSelector to target subset of worker nodes running
this service
type: object
replicas:
default: 1
format: int32
Expand Down
4 changes: 4 additions & 0 deletions api/v1beta1/swift_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ type SwiftSpecBase struct {
// +kubebuilder:default=memcached
// Memcached instance name.
MemcachedInstance string `json:"memcachedInstance"`

// +kubebuilder:validation:Optional
// NodeSelector to target subset of worker nodes running this service
NodeSelector *map[string]string `json:"nodeSelector,omitempty"`
}

// SwiftStatus defines the observed state of Swift
Expand Down
4 changes: 4 additions & 0 deletions api/v1beta1/swiftproxy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ type SwiftProxySpecCore struct {
// +kubebuilder:default=false
// Enables ceilometer in the swift proxy and creates required resources
CeilometerEnabled bool `json:"ceilometerEnabled"`

// +kubebuilder:validation:Optional
// NodeSelector to target subset of worker nodes running this service
NodeSelector *map[string]string `json:"nodeSelector,omitempty"`
}

// ProxyOverrideSpec to override the generated manifest of several child resources.
Expand Down
4 changes: 4 additions & 0 deletions api/v1beta1/swiftring_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ type SwiftRingSpecCore struct {
// +operator-sdk:csv:customresourcedefinitions:type=spec
// TLS - Parameters related to the TLS
TLS tls.Ca `json:"tls,omitempty"`

// +kubebuilder:validation:Optional
// NodeSelector to target subset of worker nodes running this service
NodeSelector *map[string]string `json:"nodeSelector,omitempty"`
}

// SwiftRingStatus defines the observed state of SwiftRing
Expand Down
4 changes: 4 additions & 0 deletions api/v1beta1/swiftstorage_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ type SwiftStorageSpecCore struct {
// DefaultConfigOverwrite - can be used to add additionalfiles. Those get
// added to the service config dir in /etc/<servicename>-conf.d
DefaultConfigOverwrite map[string]string `json:"defaultConfigOverwrite,omitempty"`

// +kubebuilder:validation:Optional
// NodeSelector to target subset of worker nodes running this service
NodeSelector *map[string]string `json:"nodeSelector,omitempty"`
}

// SwiftStorageStatus defines the observed state of SwiftStorage
Expand Down
44 changes: 44 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.

6 changes: 6 additions & 0 deletions config/crd/bases/swift.openstack.org_swiftproxies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ spec:
items:
type: string
type: array
nodeSelector:
additionalProperties:
type: string
description: NodeSelector to target subset of worker nodes running
this service
type: object
override:
description: Override, provides the ability to override the generated
manifest of several child resources.
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/swift.openstack.org_swiftrings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ spec:
format: int64
minimum: 1
type: integer
nodeSelector:
additionalProperties:
type: string
description: NodeSelector to target subset of worker nodes running
this service
type: object
partPower:
default: 10
description: Partition power of the Swift rings
Expand Down
24 changes: 24 additions & 0 deletions config/crd/bases/swift.openstack.org_swifts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ spec:
items:
type: string
type: array
nodeSelector:
additionalProperties:
type: string
description: NodeSelector to target subset of worker nodes running
this service
type: object
storageClass:
default: ""
description: Storage class. This is passed to SwiftStorage unless
Expand Down Expand Up @@ -95,6 +101,12 @@ spec:
items:
type: string
type: array
nodeSelector:
additionalProperties:
type: string
description: NodeSelector to target subset of worker nodes running
this service
type: object
override:
description: Override, provides the ability to override the generated
manifest of several child resources.
Expand Down Expand Up @@ -362,6 +374,12 @@ spec:
format: int64
minimum: 1
type: integer
nodeSelector:
additionalProperties:
type: string
description: NodeSelector to target subset of worker nodes running
this service
type: object
partPower:
default: 10
description: Partition power of the Swift rings
Expand Down Expand Up @@ -424,6 +442,12 @@ spec:
items:
type: string
type: array
nodeSelector:
additionalProperties:
type: string
description: NodeSelector to target subset of worker nodes running
this service
type: object
replicas:
default: 1
format: int32
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/swift.openstack.org_swiftstorages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ spec:
items:
type: string
type: array
nodeSelector:
additionalProperties:
type: string
description: NodeSelector to target subset of worker nodes running
this service
type: object
replicas:
default: 1
format: int32
Expand Down
15 changes: 15 additions & 0 deletions controllers/swift_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,14 @@ func (r *SwiftReconciler) ringCreateOrUpdate(ctx context.Context, instance *swif
PartPower: instance.Spec.SwiftRing.PartPower,
MinPartHours: instance.Spec.SwiftRing.MinPartHours,
TLS: instance.Spec.SwiftProxy.TLS.Ca,
NodeSelector: instance.Spec.SwiftRing.NodeSelector,
},
}

if swiftRingSpec.NodeSelector == nil {
swiftRingSpec.NodeSelector = instance.Spec.NodeSelector
}

deployment := &swiftv1.SwiftRing{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-ring", instance.Name),
Expand Down Expand Up @@ -462,9 +467,14 @@ func (r *SwiftReconciler) storageCreateOrUpdate(ctx context.Context, instance *s
MemcachedInstance: instance.Spec.MemcachedInstance,
ContainerSharderEnabled: instance.Spec.SwiftStorage.ContainerSharderEnabled,
DefaultConfigOverwrite: instance.Spec.SwiftStorage.DefaultConfigOverwrite,
NodeSelector: instance.Spec.SwiftStorage.NodeSelector,
},
}

if swiftStorageSpec.NodeSelector == nil {
swiftStorageSpec.NodeSelector = instance.Spec.NodeSelector
}

deployment := &swiftv1.SwiftStorage{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-storage", instance.Name),
Expand Down Expand Up @@ -502,9 +512,14 @@ func (r *SwiftReconciler) proxyCreateOrUpdate(ctx context.Context, instance *swi
EncryptionEnabled: instance.Spec.SwiftProxy.EncryptionEnabled,
RabbitMqClusterName: instance.Spec.SwiftProxy.RabbitMqClusterName,
CeilometerEnabled: instance.Spec.SwiftProxy.CeilometerEnabled,
NodeSelector: instance.Spec.SwiftProxy.NodeSelector,
},
}

if swiftProxySpec.NodeSelector == nil {
swiftProxySpec.NodeSelector = instance.Spec.NodeSelector
}

deployment := &swiftv1.SwiftProxy{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-proxy", instance.Name),
Expand Down
10 changes: 8 additions & 2 deletions pkg/swiftproxy/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func Deployment(
envVars := map[string]env.Setter{}
envVars["CONFIG_HASH"] = env.SetValue(configHash)

return &appsv1.Deployment{
deployment := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: instance.Name,
Namespace: instance.Namespace,
Expand Down Expand Up @@ -173,5 +173,11 @@ func Deployment(
},
},
},
}, nil
}

if instance.Spec.NodeSelector != nil {
deployment.Spec.Template.Spec.NodeSelector = *instance.Spec.NodeSelector
}

return deployment, nil
}
8 changes: 7 additions & 1 deletion pkg/swiftring/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func GetRingJob(instance *swiftv1beta1.SwiftRing, labels map[string]string) *bat
volumeMounts = append(volumeMounts, instance.Spec.TLS.CreateVolumeMounts(nil)...)
}

return &batchv1.Job{
job := &batchv1.Job{
ObjectMeta: metav1.ObjectMeta{
Name: instance.Name + "-rebalance",
Namespace: instance.Namespace,
Expand Down Expand Up @@ -83,4 +83,10 @@ func GetRingJob(instance *swiftv1beta1.SwiftRing, labels map[string]string) *bat
},
},
}

if instance.Spec.NodeSelector != nil {
job.Spec.Template.Spec.NodeSelector = *instance.Spec.NodeSelector
}

return job
}
Loading

0 comments on commit 6ab57de

Please sign in to comment.