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

Add tolerations and nodeselectors to jobs #342

Merged
merged 2 commits into from
Sep 12, 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
3 changes: 3 additions & 0 deletions api/v1/ytsaurus_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,9 @@ type YtsaurusSpec struct {
// If UpdateSelector is not empty EnableFullUpdate is ignored.
UpdateSelector UpdateSelector `json:"updateSelector"`

NodeSelector map[string]string `json:"nodeSelector,omitempty"`
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`

Bootstrap *BootstrapSpec `json:"bootstrap,omitempty"`

Discovery DiscoverySpec `json:"discovery,omitempty"`
Expand Down
14 changes: 14 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.

34 changes: 34 additions & 0 deletions config/crd/bases/cluster.ytsaurus.tech_ytsaurus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14887,6 +14887,10 @@ spec:
type: object
x-kubernetes-map-type: atomic
type: object
nodeSelector:
additionalProperties:
type: string
type: object
oauthService:
properties:
host:
Expand Down Expand Up @@ -34371,6 +34375,36 @@ spec:
- portCount
type: object
type: array
tolerations:
items:
description: |-
The pod this Toleration is attached to tolerates any taint that matches
the trip
properties:
effect:
description: Effect indicates the taint effect to match. Empty
means match all taint effects.
type: string
key:
description: Key is the taint key that the toleration applies
to.
type: string
operator:
description: Operator represents a key's relationship to the
value.
type: string
tolerationSeconds:
description: |-
TolerationSeconds represents the period of time the toleration (which must be
of
format: int64
type: integer
value:
description: Value is the taint value the toleration matches
to.
type: string
type: object
type: array
ui:
properties:
description:
Expand Down
2 changes: 2 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1836,6 +1836,8 @@ _Appears in:_
| `isManaged` _boolean_ | | true | |
| `enableFullUpdate` _boolean_ | | true | |
| `updateSelector` _[UpdateSelector](#updateselector)_ | UpdateSelector is an experimental field. Behaviour may change.<br />If UpdateSelector is not empty EnableFullUpdate is ignored. | | Enum: [ Nothing StatelessOnly MasterOnly TabletNodesOnly ExecNodesOnly Everything] <br /> |
| `nodeSelector` _object (keys:string, values:string)_ | | | |
| `tolerations` _[Toleration](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#toleration-v1-core) array_ | | | |
| `bootstrap` _[BootstrapSpec](#bootstrapspec)_ | | | |
| `discovery` _[DiscoverySpec](#discoveryspec)_ | | | |
| `primaryMasters` _[MastersSpec](#mastersspec)_ | | | |
Expand Down
15 changes: 12 additions & 3 deletions pkg/components/chyt.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ func NewChyt(
"user",
consts.ClientConfigFileName,
ytsaurus.Spec.CoreImage,
cfgen.GetNativeClientConfig),
cfgen.GetNativeClientConfig,
ytsaurus.Spec.Tolerations,
ytsaurus.Spec.NodeSelector,
),
initEnvironment: NewInitJob(
&l,
chyt.APIProxy(),
Expand All @@ -63,7 +66,10 @@ func NewChyt(
"release",
consts.ClientConfigFileName,
chyt.GetResource().Spec.Image,
cfgen.GetNativeClientConfig),
cfgen.GetNativeClientConfig,
ytsaurus.Spec.Tolerations,
ytsaurus.Spec.NodeSelector,
),
initChPublicJob: NewInitJob(
&l,
chyt.APIProxy(),
Expand All @@ -72,7 +78,10 @@ func NewChyt(
"ch-public",
consts.ClientConfigFileName,
chyt.GetResource().Spec.Image,
cfgen.GetNativeClientConfig),
cfgen.GetNativeClientConfig,
ytsaurus.Spec.Tolerations,
ytsaurus.Spec.NodeSelector,
),
secret: resources.NewStringSecret(
l.GetSecretName(),
&l,
Expand Down
14 changes: 14 additions & 0 deletions pkg/components/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,17 @@ func getImageWithDefault(componentImage *string, defaultImage string) string {
}
return defaultImage
}

func getTolerationsWithDefault(componentTolerations, defaultTolerations []corev1.Toleration) []corev1.Toleration {
if len(componentTolerations) != 0 {
return componentTolerations
}
return defaultTolerations
}

func getNodeSelectorWithDefault(componentNodeSelector, defaultNodeSelector map[string]string) map[string]string {
if len(componentNodeSelector) != 0 {
return componentNodeSelector
}
return defaultNodeSelector
}
16 changes: 13 additions & 3 deletions pkg/components/init_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ type InitJob struct {
configHelper *ConfigHelper
initCompletedCondition string

image string
image string
tolerations []corev1.Toleration
nodeSelector map[string]string

builtJob *batchv1.Job
}
Expand All @@ -56,7 +58,10 @@ func NewInitJob(
conditionsManager apiproxy.ConditionManager,
imagePullSecrets []corev1.LocalObjectReference,
name, configFileName, image string,
generator ytconfig.YsonGeneratorFunc) *InitJob {
generator ytconfig.YsonGeneratorFunc,
tolerations []corev1.Toleration,
nodeSelector map[string]string,
) *InitJob {
return &InitJob{
baseComponent: baseComponent{
labeller: labeller,
Expand All @@ -66,10 +71,13 @@ func NewInitJob(
imagePullSecrets: imagePullSecrets,
initCompletedCondition: fmt.Sprintf("%s%sInitJobCompleted", name, labeller.GetFullComponentName()),
image: image,
tolerations: tolerations,
nodeSelector: nodeSelector,
initJob: resources.NewJob(
labeller.GetInitJobName(name),
labeller,
apiProxy),
apiProxy,
),
configHelper: NewConfigHelper(
labeller,
apiProxy,
Expand Down Expand Up @@ -120,6 +128,8 @@ func (j *InitJob) Build() *batchv1.Job {
createConfigVolume(consts.ConfigVolumeName, j.configHelper.GetConfigMapName(), &defaultMode),
},
RestartPolicy: corev1.RestartPolicyOnFailure,
Tolerations: j.tolerations,
NodeSelector: j.nodeSelector,
},
}
j.builtJob = job
Expand Down
1 change: 1 addition & 0 deletions pkg/components/init_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func newTestJob(ytsaurus *apiproxy.Ytsaurus) *InitJob {
consts.ClientConfigFileName,
"dummy-image",
func() ([]byte, error) { return []byte("dummy-cfg"), nil },
nil, nil,
)
}

Expand Down
7 changes: 6 additions & 1 deletion pkg/components/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ func NewMaster(cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus) *Master {
"default",
consts.ClientConfigFileName,
getImageWithDefault(resource.Spec.PrimaryMasters.InstanceSpec.Image, resource.Spec.CoreImage),
cfgen.GetNativeClientConfig)
cfgen.GetNativeClientConfig,
getTolerationsWithDefault(resource.Spec.PrimaryMasters.Tolerations, resource.Spec.Tolerations),
getNodeSelectorWithDefault(resource.Spec.PrimaryMasters.NodeSelector, resource.Spec.NodeSelector),
)

exitReadOnlyJob := NewInitJob(
&l,
Expand All @@ -81,6 +84,8 @@ func NewMaster(cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus) *Master {
consts.ClientConfigFileName,
getImageWithDefault(resource.Spec.PrimaryMasters.InstanceSpec.Image, resource.Spec.CoreImage),
cfgen.GetNativeClientConfig,
getTolerationsWithDefault(resource.Spec.PrimaryMasters.Tolerations, resource.Spec.Tolerations),
getNodeSelectorWithDefault(resource.Spec.PrimaryMasters.NodeSelector, resource.Spec.NodeSelector),
)

return &Master{
Expand Down
5 changes: 4 additions & 1 deletion pkg/components/query_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ func NewQueryTracker(
"qt-state",
consts.ClientConfigFileName,
getImageWithDefault(resource.Spec.QueryTrackers.InstanceSpec.Image, resource.Spec.CoreImage),
cfgen.GetNativeClientConfig),
cfgen.GetNativeClientConfig,
getTolerationsWithDefault(resource.Spec.QueryTrackers.Tolerations, resource.Spec.Tolerations),
getNodeSelectorWithDefault(resource.Spec.QueryTrackers.NodeSelector, resource.Spec.NodeSelector),
),
secret: resources.NewStringSecret(
l.GetSecretName(),
&l,
Expand Down
5 changes: 4 additions & 1 deletion pkg/components/queue_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ func NewQueueAgent(
"qa-state",
consts.ClientConfigFileName,
getImageWithDefault(resource.Spec.QueueAgents.InstanceSpec.Image, resource.Spec.CoreImage),
cfgen.GetNativeClientConfig),
cfgen.GetNativeClientConfig,
getTolerationsWithDefault(resource.Spec.QueueAgents.Tolerations, resource.Spec.Tolerations),
getNodeSelectorWithDefault(resource.Spec.QueueAgents.NodeSelector, resource.Spec.NodeSelector),
),
secret: resources.NewStringSecret(
l.GetSecretName(),
&l,
Expand Down
10 changes: 8 additions & 2 deletions pkg/components/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ func NewScheduler(
"user",
consts.ClientConfigFileName,
getImageWithDefault(resource.Spec.Schedulers.InstanceSpec.Image, resource.Spec.CoreImage),
cfgen.GetNativeClientConfig),
cfgen.GetNativeClientConfig,
getTolerationsWithDefault(resource.Spec.Schedulers.Tolerations, resource.Spec.Tolerations),
getNodeSelectorWithDefault(resource.Spec.Schedulers.NodeSelector, resource.Spec.NodeSelector),
),
initOpArchive: NewInitJob(
&l,
ytsaurus.APIProxy(),
Expand All @@ -89,7 +92,10 @@ func NewScheduler(
"op-archive",
consts.ClientConfigFileName,
getImageWithDefault(resource.Spec.Schedulers.InstanceSpec.Image, resource.Spec.CoreImage),
cfgen.GetNativeClientConfig),
cfgen.GetNativeClientConfig,
getTolerationsWithDefault(resource.Spec.Schedulers.Tolerations, resource.Spec.Tolerations),
getNodeSelectorWithDefault(resource.Spec.Schedulers.NodeSelector, resource.Spec.NodeSelector),
),
secret: resources.NewStringSecret(
l.GetSecretName(),
&l,
Expand Down
10 changes: 8 additions & 2 deletions pkg/components/spyt.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ func NewSpyt(
"user",
consts.ClientConfigFileName,
ytsaurus.Spec.CoreImage,
cfgen.GetNativeClientConfig),
cfgen.GetNativeClientConfig,
ytsaurus.Spec.Tolerations,
ytsaurus.Spec.NodeSelector,
),
initEnvironment: NewInitJob(
&l,
spyt.APIProxy(),
Expand All @@ -61,7 +64,10 @@ func NewSpyt(
"spyt-environment",
consts.ClientConfigFileName,
spyt.GetResource().Spec.Image,
cfgen.GetNativeClientConfig),
cfgen.GetNativeClientConfig,
ytsaurus.Spec.Tolerations,
ytsaurus.Spec.NodeSelector,
),
secret: resources.NewStringSecret(
l.GetSecretName(),
&l,
Expand Down
10 changes: 8 additions & 2 deletions pkg/components/strawberry_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ func NewStrawberryController(
"user",
consts.ClientConfigFileName,
getImageWithDefault(resource.Spec.StrawberryController.Image, resource.Spec.CoreImage),
cfgen.GetNativeClientConfig),
cfgen.GetNativeClientConfig,
getTolerationsWithDefault(resource.Spec.StrawberryController.Tolerations, resource.Spec.Tolerations),
getNodeSelectorWithDefault(resource.Spec.StrawberryController.NodeSelector, resource.Spec.NodeSelector),
),
initChytClusterJob: NewInitJob(
&l,
ytsaurus.APIProxy(),
Expand All @@ -93,7 +96,10 @@ func NewStrawberryController(
"cluster",
ChytInitClusterJobConfigFileName,
getImageWithDefault(resource.Spec.StrawberryController.Image, resource.Spec.CoreImage),
cfgen.GetChytInitClusterConfig),
cfgen.GetChytInitClusterConfig,
getTolerationsWithDefault(resource.Spec.StrawberryController.Tolerations, resource.Spec.Tolerations),
getNodeSelectorWithDefault(resource.Spec.StrawberryController.NodeSelector, resource.Spec.NodeSelector),
),
secret: resources.NewStringSecret(
l.GetSecretName(),
&l,
Expand Down
5 changes: 4 additions & 1 deletion pkg/components/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ func NewUI(cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus, master Compon
"default",
consts.ClientConfigFileName,
getImageWithDefault(resource.Spec.UI.Image, resource.Spec.CoreImage),
cfgen.GetNativeClientConfig),
cfgen.GetNativeClientConfig,
getTolerationsWithDefault(resource.Spec.UI.Tolerations, resource.Spec.Tolerations),
getNodeSelectorWithDefault(resource.Spec.UI.NodeSelector, resource.Spec.NodeSelector),
),
secret: resources.NewStringSecret(
l.GetSecretName(),
&l,
Expand Down
5 changes: 4 additions & 1 deletion pkg/components/yql_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ func NewYQLAgent(cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus, master
"yql-agent-environment",
consts.ClientConfigFileName,
getImageWithDefault(resource.Spec.YQLAgents.Image, resource.Spec.CoreImage),
cfgen.GetNativeClientConfig),
cfgen.GetNativeClientConfig,
getTolerationsWithDefault(resource.Spec.YQLAgents.Tolerations, resource.Spec.Tolerations),
getNodeSelectorWithDefault(resource.Spec.YQLAgents.NodeSelector, resource.Spec.NodeSelector),
),
secret: resources.NewStringSecret(
l.GetSecretName(),
&l,
Expand Down
5 changes: 4 additions & 1 deletion pkg/components/ytsaurus_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ func NewYtsaurusClient(
"user",
consts.ClientConfigFileName,
resource.Spec.CoreImage,
cfgen.GetNativeClientConfig),
cfgen.GetNativeClientConfig,
resource.Spec.Tolerations,
resource.Spec.NodeSelector,
),
secret: resources.NewStringSecret(
l.GetSecretName(),
&l,
Expand Down
34 changes: 34 additions & 0 deletions ytop-chart/templates/crds/ytsaurus.cluster.ytsaurus.tech.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14898,6 +14898,10 @@ spec:
type: object
x-kubernetes-map-type: atomic
type: object
nodeSelector:
additionalProperties:
type: string
type: object
oauthService:
properties:
host:
Expand Down Expand Up @@ -34382,6 +34386,36 @@ spec:
- portCount
type: object
type: array
tolerations:
items:
description: |-
The pod this Toleration is attached to tolerates any taint that matches
the trip
properties:
effect:
description: Effect indicates the taint effect to match. Empty
means match all taint effects.
type: string
key:
description: Key is the taint key that the toleration applies
to.
type: string
operator:
description: Operator represents a key's relationship to the
value.
type: string
tolerationSeconds:
description: |-
TolerationSeconds represents the period of time the toleration (which must be
of
format: int64
type: integer
value:
description: Value is the taint value the toleration matches
to.
type: string
type: object
type: array
ui:
properties:
description:
Expand Down
Loading