Skip to content

Commit

Permalink
Allow specifying more podSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
AMecea committed May 10, 2019
1 parent 522b85e commit 9b6b46f
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 21 deletions.
11 changes: 11 additions & 0 deletions examples/example-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,21 @@ spec:

## Specify additional pod specification
# podSpec:
# affinity:
# podAntiAffinity:
# preferredDuringSchedulingIgnoredDuringExecution:
# weight: 100
# podAffinityTerm:
# topologyKey: "kubernetes.io/hostname"
# labelSelector:
# matchlabels: <cluster-labels>
# resources:
# requests:
# memory: 1G
# cpu: 200m
# tolerations: []
# priorityClassName:
# serviceAccountName: default

## Specify additional volume specification
# volumeSpec:
Expand Down
13 changes: 8 additions & 5 deletions pkg/apis/mysql/v1alpha1/mysqlcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,14 @@ type PodSpec struct {
ImagePullPolicy core.PullPolicy `json:"imagePullPolicy,omitempty"`
ImagePullSecrets []core.LocalObjectReference `json:"imagePullSecrets,omitempty"`

Labels map[string]string `json:"labels,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
Resources core.ResourceRequirements `json:"resources,omitempty"`
Affinity core.Affinity `json:"affinity,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
Resources core.ResourceRequirements `json:"resources,omitempty"`
Affinity *core.Affinity `json:"affinity,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
PriorityClassName string `json:"priorityClassName,omitempty"`
Tolerations []core.Toleration `json:"tolerations,omitempty"`
ServiceAccountName string `json:"serviceAccountName,omitempty"`
}

// VolumeSpec is the desired spec for storing mysql data. Only one of its
Expand Down
13 changes: 12 additions & 1 deletion pkg/apis/mysql/v1alpha1/zz_generated.deepcopy.go

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

15 changes: 9 additions & 6 deletions pkg/controller/mysqlcluster/internal/syncer/statefullset.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,20 @@ func (s *sfsSyncer) SyncFn(in runtime.Object) error {
func (s *sfsSyncer) ensurePodSpec() core.PodSpec {
fsGroup := int64(999) // mysql user UID
return core.PodSpec{
InitContainers: s.ensureInitContainersSpec(),
Containers: s.ensureContainersSpec(),
Volumes: s.ensureVolumes(),
Affinity: &s.cluster.Spec.PodSpec.Affinity,
NodeSelector: s.cluster.Spec.PodSpec.NodeSelector,
ImagePullSecrets: s.cluster.Spec.PodSpec.ImagePullSecrets,
InitContainers: s.ensureInitContainersSpec(),
Containers: s.ensureContainersSpec(),
Volumes: s.ensureVolumes(),
SecurityContext: &core.PodSecurityContext{
// mount volumes with mysql gid
FSGroup: &fsGroup,
RunAsUser: &fsGroup,
},
Affinity: s.cluster.Spec.PodSpec.Affinity,
ImagePullSecrets: s.cluster.Spec.PodSpec.ImagePullSecrets,
NodeSelector: s.cluster.Spec.PodSpec.NodeSelector,
PriorityClassName: s.cluster.Spec.PodSpec.PriorityClassName,
Tolerations: s.cluster.Spec.PodSpec.Tolerations,
ServiceAccountName: s.cluster.Spec.PodSpec.ServiceAccountName,
}
}

Expand Down
20 changes: 11 additions & 9 deletions pkg/internal/mysqlcluster/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,17 @@ func (cluster *MysqlCluster) SetDefaults(opt *options.Options) {
}

// set pod antiaffinity to nodes stay away from other nodes.
if cluster.Spec.PodSpec.Affinity.PodAntiAffinity == nil {
cluster.Spec.PodSpec.Affinity.PodAntiAffinity = &core.PodAntiAffinity{
PreferredDuringSchedulingIgnoredDuringExecution: []core.WeightedPodAffinityTerm{
core.WeightedPodAffinityTerm{
Weight: 100,
PodAffinityTerm: core.PodAffinityTerm{
TopologyKey: "kubernetes.io/hostname",
LabelSelector: &metav1.LabelSelector{
MatchLabels: cluster.GetLabels(),
if cluster.Spec.PodSpec.Affinity == nil {
cluster.Spec.PodSpec.Affinity = &core.Affinity{
PodAntiAffinity: &core.PodAntiAffinity{
PreferredDuringSchedulingIgnoredDuringExecution: []core.WeightedPodAffinityTerm{
core.WeightedPodAffinityTerm{
Weight: 100,
PodAffinityTerm: core.PodAffinityTerm{
TopologyKey: "kubernetes.io/hostname",
LabelSelector: &metav1.LabelSelector{
MatchLabels: cluster.GetLabels(),
},
},
},
},
Expand Down

0 comments on commit 9b6b46f

Please sign in to comment.