Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support tolerations #40

Merged
merged 2 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/v1/polardbxcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions api/v1/xstore_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 15 additions & 0 deletions api/v1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -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 <key,value,effect> using
the matching operator <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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <key,value,effect> using the matching
operator <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:
Expand Down
41 changes: 41 additions & 0 deletions charts/polardbx-operator/crds/polardbx.aliyun.com_xstores.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <key,value,effect> using the matching
operator <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:
Expand Down
13 changes: 13 additions & 0 deletions pkg/operator/v1/polardbx/factory/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -580,6 +586,7 @@ func (f *objectFactory) newDeployment4CN(group string, mr *matchingRule, mustSta
HostNetwork: template.HostNetwork,
ShareProcessNamespace: pointer.Bool(true),
Affinity: affinity,
Tolerations: tolerations,
},
},
},
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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,
},
},
Expand Down
4 changes: 3 additions & 1 deletion pkg/operator/v1/polardbx/factory/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/operator/v1/xstore/factory/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
{
Expand Down
Loading