diff --git a/examples/example-cluster.yaml b/examples/example-cluster.yaml index 63a7e864d..89c89531b 100644 --- a/examples/example-cluster.yaml +++ b/examples/example-cluster.yaml @@ -26,10 +26,21 @@ spec: ## Specify additional pod specification # podSpec: + # affinity: + # podAntiAffinity: + # preferredDuringSchedulingIgnoredDuringExecution: + # weight: 100 + # podAffinityTerm: + # topologyKey: "kubernetes.io/hostname" + # labelSelector: + # matchlabels: # resources: # requests: # memory: 1G # cpu: 200m + # tolerations: [] + # priorityClassName: + # serviceAccountName: default ## Specify additional volume specification # volumeSpec: diff --git a/pkg/apis/mysql/v1alpha1/mysqlcluster_types.go b/pkg/apis/mysql/v1alpha1/mysqlcluster_types.go index 91deb5824..4da7abde9 100644 --- a/pkg/apis/mysql/v1alpha1/mysqlcluster_types.go +++ b/pkg/apis/mysql/v1alpha1/mysqlcluster_types.go @@ -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 diff --git a/pkg/apis/mysql/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/mysql/v1alpha1/zz_generated.deepcopy.go index 933ec0ca5..a5f5e41e5 100644 --- a/pkg/apis/mysql/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/mysql/v1alpha1/zz_generated.deepcopy.go @@ -380,7 +380,11 @@ func (in *PodSpec) DeepCopyInto(out *PodSpec) { } } in.Resources.DeepCopyInto(&out.Resources) - in.Affinity.DeepCopyInto(&out.Affinity) + if in.Affinity != nil { + in, out := &in.Affinity, &out.Affinity + *out = new(v1.Affinity) + (*in).DeepCopyInto(*out) + } if in.NodeSelector != nil { in, out := &in.NodeSelector, &out.NodeSelector *out = make(map[string]string, len(*in)) @@ -388,6 +392,13 @@ func (in *PodSpec) DeepCopyInto(out *PodSpec) { (*out)[key] = val } } + if in.Tolerations != nil { + in, out := &in.Tolerations, &out.Tolerations + *out = make([]v1.Toleration, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } return } diff --git a/pkg/controller/mysqlcluster/internal/syncer/statefullset.go b/pkg/controller/mysqlcluster/internal/syncer/statefullset.go index 564ddf85a..479474839 100644 --- a/pkg/controller/mysqlcluster/internal/syncer/statefullset.go +++ b/pkg/controller/mysqlcluster/internal/syncer/statefullset.go @@ -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, } } diff --git a/pkg/internal/mysqlcluster/defaults.go b/pkg/internal/mysqlcluster/defaults.go index 3d5418df4..bfd76fe17 100644 --- a/pkg/internal/mysqlcluster/defaults.go +++ b/pkg/internal/mysqlcluster/defaults.go @@ -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(), + }, }, }, },