Skip to content

Commit

Permalink
Merge pull request #83 from dciabrin/nodeselector
Browse files Browse the repository at this point in the history
galera: support for node selection and pod affinity
  • Loading branch information
openshift-merge-robot authored Mar 24, 2023
2 parents 979250c + 0c33ade commit 01a691f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
6 changes: 6 additions & 0 deletions api/bases/mariadb.openstack.org_galeras.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ spec:
default: quay.io/tripleozedcentos9/openstack-mariadb:current-tripleo
description: Name of the galera container image to run
type: string
nodeSelector:
additionalProperties:
type: string
description: NodeSelector to target subset of worker nodes running
this service
type: object
replicas:
default: 1
description: Size of the galera cluster deployment
Expand Down
3 changes: 3 additions & 0 deletions api/v1beta1/galera_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ type GaleraSpec struct {
// Size of the galera cluster deployment
Replicas int32 `json:"replicas"`
// +kubebuilder:validation:Optional
// NodeSelector to target subset of worker nodes running this service
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
// +kubebuilder:validation:Optional
// Adoption configuration
AdoptionRedirect AdoptionRedirectSpec `json:"adoptionRedirect"`
}
Expand Down
9 changes: 8 additions & 1 deletion 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/mariadb.openstack.org_galeras.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ spec:
default: quay.io/tripleozedcentos9/openstack-mariadb:current-tripleo
description: Name of the galera container image to run
type: string
nodeSelector:
additionalProperties:
type: string
description: NodeSelector to target subset of worker nodes running
this service
type: object
replicas:
default: 1
description: Size of the galera cluster deployment
Expand Down
21 changes: 19 additions & 2 deletions pkg/statefulset.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package mariadb

import (
common "github.com/openstack-k8s-operators/lib-common/modules/common"
"github.com/openstack-k8s-operators/lib-common/modules/common/affinity"
mariadbv1 "github.com/openstack-k8s-operators/mariadb-operator/api/v1beta1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand All @@ -16,7 +18,7 @@ func StatefulSet(g *mariadbv1.Galera) *appsv1.StatefulSet {
runAsUser := int64(0)
storage := g.Spec.StorageClass
storageRequest := resource.MustParse(g.Spec.StorageRequest)
dep := &appsv1.StatefulSet{
sts := &appsv1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: g.Namespace,
Expand Down Expand Up @@ -259,5 +261,20 @@ func StatefulSet(g *mariadbv1.Galera) *appsv1.StatefulSet {
},
},
}
return dep

// If possible two pods of the same service should not
// run on the same worker node. If this is not possible
// the get still created on the same worker node.
sts.Spec.Template.Spec.Affinity = affinity.DistributePods(
common.AppSelector,
[]string{
name,
},
corev1.LabelHostname,
)
if g.Spec.NodeSelector != nil && len(g.Spec.NodeSelector) > 0 {
sts.Spec.Template.Spec.NodeSelector = g.Spec.NodeSelector
}

return sts
}

0 comments on commit 01a691f

Please sign in to comment.