diff --git a/api/v1/polardbxcluster_types.go b/api/v1/polardbxcluster_types.go index 7d58210..0b75170 100644 --- a/api/v1/polardbxcluster_types.go +++ b/api/v1/polardbxcluster_types.go @@ -97,6 +97,10 @@ type PolarDBXClusterSpec struct { // Exclusive if true, it means more resource isolation. // +optional Exclusive bool `json:"exclusive,omitempty"` + + // Tolerations specifies the tolerations of the Pods of the cluster. + // +optional + Tolerations []corev1.Toleration `json:"tolerations,omitempty"` } type PolarDBXClusterStatus struct { diff --git a/api/v1/xstore_types.go b/api/v1/xstore_types.go index 6172ef3..c341440 100644 --- a/api/v1/xstore_types.go +++ b/api/v1/xstore_types.go @@ -152,6 +152,10 @@ type XStoreSpec struct { // Exclusive if true, it means more resource isolation. // +optional Exclusive bool `json:"exclusive,omitempty"` + + // Tolerations specifies the tolerations of the Pods of the xstore. + // +optional + Tolerations []corev1.Toleration `json:"tolerations,omitempty"` } type XStoreStatus struct { diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index 5106b67..d1ab44e 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -25,6 +25,7 @@ import ( "github.com/alibaba/polardbx-operator/api/v1/polardbx" "github.com/alibaba/polardbx-operator/api/v1/systemtask" "github.com/alibaba/polardbx-operator/api/v1/xstore" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/intstr" @@ -699,6 +700,13 @@ func (in *PolarDBXClusterSpec) DeepCopyInto(out *PolarDBXClusterSpec) { } } out.TDE = in.TDE + if in.Tolerations != nil { + in, out := &in.Tolerations, &out.Tolerations + *out = make([]corev1.Toleration, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PolarDBXClusterSpec. @@ -1741,6 +1749,13 @@ func (in *XStoreSpec) DeepCopyInto(out *XStoreSpec) { (*in).DeepCopyInto(*out) } out.TDE = in.TDE + if in.Tolerations != nil { + in, out := &in.Tolerations, &out.Tolerations + *out = make([]corev1.Toleration, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new XStoreSpec. diff --git a/charts/polardbx-operator/crds/polardbx.aliyun.com_polardbxbackups.yaml b/charts/polardbx-operator/crds/polardbx.aliyun.com_polardbxbackups.yaml index 641a314..de6afe5 100644 --- a/charts/polardbx-operator/crds/polardbx.aliyun.com_polardbxbackups.yaml +++ b/charts/polardbx-operator/crds/polardbx.aliyun.com_polardbxbackups.yaml @@ -484,6 +484,48 @@ spec: description: KeyringPath represents the keyring path type: string type: object + tolerations: + description: Tolerations specifies the tolerations of the Pods + of the cluster. + items: + description: The pod this Toleration is attached to tolerates + any taint that matches the triple using + the matching operator . + properties: + effect: + description: Effect indicates the taint effect to match. + Empty means match all taint effects. When specified, allowed + values are NoSchedule, PreferNoSchedule and NoExecute. + type: string + key: + description: Key is the taint key that the toleration applies + to. Empty means match all taint keys. If the key is empty, + operator must be Exists; this combination means to match + all values and all keys. + type: string + operator: + description: Operator represents a key's relationship to + the value. Valid operators are Exists and Equal. Defaults + to Equal. Exists is equivalent to wildcard for value, + so that a pod can tolerate all taints of a particular + category. + type: string + tolerationSeconds: + description: TolerationSeconds represents the period of + time the toleration (which must be of effect NoExecute, + otherwise this field is ignored) tolerates the taint. + By default, it is not set, which means tolerate the taint + forever (do not evict). Zero and negative values will + be treated as 0 (evict immediately) by the system. + format: int64 + type: integer + value: + description: Value is the taint value the toleration matches + to. If the operator is Exists, the value should be empty, + otherwise just a regular string. + type: string + type: object + type: array topology: description: Topology defines the desired node topology and templates. properties: diff --git a/charts/polardbx-operator/crds/polardbx.aliyun.com_polardbxclusters.yaml b/charts/polardbx-operator/crds/polardbx.aliyun.com_polardbxclusters.yaml index bdf2705..33a784f 100644 --- a/charts/polardbx-operator/crds/polardbx.aliyun.com_polardbxclusters.yaml +++ b/charts/polardbx-operator/crds/polardbx.aliyun.com_polardbxclusters.yaml @@ -440,6 +440,47 @@ spec: description: KeyringPath represents the keyring path type: string type: object + tolerations: + description: Tolerations specifies the tolerations of the Pods of + the cluster. + items: + description: The pod this Toleration is attached to tolerates any + taint that matches the triple using the matching + operator . + properties: + effect: + description: Effect indicates the taint effect to match. Empty + means match all taint effects. When specified, allowed values + are NoSchedule, PreferNoSchedule and NoExecute. + type: string + key: + description: Key is the taint key that the toleration applies + to. Empty means match all taint keys. If the key is empty, + operator must be Exists; this combination means to match all + values and all keys. + type: string + operator: + description: Operator represents a key's relationship to the + value. Valid operators are Exists and Equal. Defaults to Equal. + Exists is equivalent to wildcard for value, so that a pod + can tolerate all taints of a particular category. + type: string + tolerationSeconds: + description: TolerationSeconds represents the period of time + the toleration (which must be of effect NoExecute, otherwise + this field is ignored) tolerates the taint. By default, it + is not set, which means tolerate the taint forever (do not + evict). Zero and negative values will be treated as 0 (evict + immediately) by the system. + format: int64 + type: integer + value: + description: Value is the taint value the toleration matches + to. If the operator is Exists, the value should be empty, + otherwise just a regular string. + type: string + type: object + type: array topology: description: Topology defines the desired node topology and templates. properties: diff --git a/charts/polardbx-operator/crds/polardbx.aliyun.com_xstores.yaml b/charts/polardbx-operator/crds/polardbx.aliyun.com_xstores.yaml index 0a68054..90e1631 100644 --- a/charts/polardbx-operator/crds/polardbx.aliyun.com_xstores.yaml +++ b/charts/polardbx-operator/crds/polardbx.aliyun.com_xstores.yaml @@ -298,6 +298,47 @@ spec: default: /data/mysql/mysql-keyring/keyring type: string type: object + tolerations: + description: Tolerations specifies the tolerations of the Pods of + the xstore. + items: + description: The pod this Toleration is attached to tolerates any + taint that matches the triple using the matching + operator . + properties: + effect: + description: Effect indicates the taint effect to match. Empty + means match all taint effects. When specified, allowed values + are NoSchedule, PreferNoSchedule and NoExecute. + type: string + key: + description: Key is the taint key that the toleration applies + to. Empty means match all taint keys. If the key is empty, + operator must be Exists; this combination means to match all + values and all keys. + type: string + operator: + description: Operator represents a key's relationship to the + value. Valid operators are Exists and Equal. Defaults to Equal. + Exists is equivalent to wildcard for value, so that a pod + can tolerate all taints of a particular category. + type: string + tolerationSeconds: + description: TolerationSeconds represents the period of time + the toleration (which must be of effect NoExecute, otherwise + this field is ignored) tolerates the taint. By default, it + is not set, which means tolerate the taint forever (do not + evict). Zero and negative values will be treated as 0 (evict + immediately) by the system. + format: int64 + type: integer + value: + description: Value is the taint value the toleration matches + to. If the operator is Exists, the value should be empty, + otherwise just a regular string. + type: string + type: object + type: array topology: description: Topology is the specification of topology of the xstore. properties: diff --git a/pkg/operator/v1/polardbx/factory/deployment.go b/pkg/operator/v1/polardbx/factory/deployment.go index 8eb2420..bf459b9 100644 --- a/pkg/operator/v1/polardbx/factory/deployment.go +++ b/pkg/operator/v1/polardbx/factory/deployment.go @@ -339,6 +339,10 @@ done ` ) +func (f *objectFactory) getTolerationsFrom(polardbx *polardbxv1.PolarDBXCluster) []corev1.Toleration { + return polardbx.Spec.Tolerations +} + func (f *objectFactory) newDeployment4CN(group string, mr *matchingRule, mustStaticPorts bool) (*appsv1.Deployment, error) { polardbx := f.rc.MustGetPolarDBX() topology := polardbx.Status.SpecSnapshot.Topology @@ -372,6 +376,8 @@ func (f *objectFactory) newDeployment4CN(group string, mr *matchingRule, mustSta nodeSelector, ) + tolerations := f.getTolerationsFrom(polardbx) + // Name & Labels & Annotations deployName := convention.NewDeploymentName(polardbx, polardbxmeta.RoleCN, group) cnType := polardbxmeta.CNTypeRW @@ -580,6 +586,7 @@ func (f *objectFactory) newDeployment4CN(group string, mr *matchingRule, mustSta HostNetwork: template.HostNetwork, ShareProcessNamespace: pointer.Bool(true), Affinity: affinity, + Tolerations: tolerations, }, }, }, @@ -655,6 +662,8 @@ func (f *objectFactory) newDeployment4CDC(group string, mr *matchingRule, mustSt nodeSelector, ) + tolerations := f.getTolerationsFrom(polardbx) + // Name & Labels deployName := convention.NewDeploymentName(polardbx, polardbxmeta.RoleCDC, group) @@ -802,6 +811,7 @@ func (f *objectFactory) newDeployment4CDC(group string, mr *matchingRule, mustSt DNSPolicy: dnsPolicy, ShareProcessNamespace: pointer.Bool(true), Affinity: affinity, + Tolerations: tolerations, // FIXME host network for CDC isn't supported // HostNetwork: template.HostNetwork, }, @@ -880,6 +890,8 @@ func (f *objectFactory) newDeployment4Columnar(group string, mr *matchingRule, m nodeSelector, ) + tolerations := f.getTolerationsFrom(polardbx) + // Name & Labels deployName := convention.NewDeploymentName(polardbx, polardbxmeta.RoleColumnar, group) @@ -956,6 +968,7 @@ func (f *objectFactory) newDeployment4Columnar(group string, mr *matchingRule, m DNSPolicy: dnsPolicy, ShareProcessNamespace: pointer.Bool(true), Affinity: affinity, + Tolerations: tolerations, HostNetwork: template.HostNetwork, }, }, diff --git a/pkg/operator/v1/polardbx/factory/storage.go b/pkg/operator/v1/polardbx/factory/storage.go index ecbf425..51ca2fd 100644 --- a/pkg/operator/v1/polardbx/factory/storage.go +++ b/pkg/operator/v1/polardbx/factory/storage.go @@ -386,6 +386,7 @@ func (f *objectFactory) newXStore( // Build affinity := f.newXStoreNodeSetAffinity(polardbx, nil) + tolerations := f.getTolerationsFrom(polardbx) nodeTemplate := &polardbxv1xstore.NodeTemplate{ ObjectMeta: polardbxv1common.PartialObjectMeta{ Labels: labels, @@ -468,7 +469,8 @@ func (f *objectFactory) newXStore( Enable: polardbx.Spec.TDE.Enable, KeyringPath: polardbx.Spec.TDE.KeyringPath, }, - Exclusive: polardbx.Spec.Exclusive, + Exclusive: polardbx.Spec.Exclusive, + Tolerations: tolerations, }, } restoreOpt := polardbx.Spec.Restore diff --git a/pkg/operator/v1/xstore/factory/pod.go b/pkg/operator/v1/xstore/factory/pod.go index b3bebfb..da23efe 100644 --- a/pkg/operator/v1/xstore/factory/pod.go +++ b/pkg/operator/v1/xstore/factory/pod.go @@ -218,6 +218,7 @@ func NewPod(rc *reconcile.Context, xstore *polardbxv1.XStore, nodeSet *polardbxv HostNetwork: boolutil.IsTrue(template.Spec.HostNetwork), ShareProcessNamespace: pointer.BoolPtr(true), Affinity: opts.NewAffinity(factoryCtx), + Tolerations: xstore.Spec.Tolerations, NodeName: hostPathVolume.Host, // If already bound, then assign to the same host. Containers: []corev1.Container{ {