Skip to content

Allow to set NodeSelector via spec.deployments.nodeSelector - #658

Merged
knative-prow-robot merged 2 commits into
knative:mainfrom
nak3:add-nodeselector
Jun 12, 2021
Merged

knative-prow-robot merged 2 commits into
knative:mainfrom
nak3:add-nodeselector

Conversation

@nak3

@nak3 nak3 commented Jun 10, 2021

Copy link
Copy Markdown
Contributor

Part of #5

This patch adds spec.deployments.nodeSelector to set nodeSelector on
each deployment.

For example, when the following CR is created,

apiVersion: operator.knative.dev/v1alpha1
kind: KnativeServing
metadata:
  name: ks
  namespace: knative-serving
spec:
  high-availability:
    replicas: 1
  deployments:
  - name: webhook
    nodeSelector:
      foo: ba

The webhook deployment has spec.template.spec.nodeSelector.

$ kubectl get deploy -n knative-serving  webhook -o jsonpath={.spec.template.spec.nodeSelector}
{"foo":"bar"}

/cc @houshengbo @markusthoemmes @matzew

Part of #5

This patch adds `spec.deployments.nodeSelector` to set nodeSelector on
each deployment.

For example, when the following CR is created,
```
apiVersion: operator.knative.dev/v1alpha1
kind: KnativeServing
metadata:
  name: ks
  namespace: knative-serving
spec:
  high-availability:
    replicas: 1
  deployments:
  - name: webhook
    nodeSelector:
      foo: bar

```

The webhook deployment has `spec.template.spec.nodeSelector`.

```
$ kubectl get deploy -n knative-serving  webhook -o jsonpath={.spec.template.spec.nodeSelector}
{"foo":"bar"}
```
@knative-prow-robot knative-prow-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 10, 2021
@google-cla google-cla Bot added the cla: yes Indicates the PR's author has signed the CLA. label Jun 10, 2021
@knative-metrics-robot

Copy link
Copy Markdown

The following is the coverage report on the affected files.
Say /test pull-knative-operator-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/common/deployments_override.go 84.4% 85.7% 1.3

@markusthoemmes markusthoemmes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks spot on to me!

/hold

For feedback from others.

@knative-prow-robot knative-prow-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 10, 2021
@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 10, 2021
@knative-prow-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: markusthoemmes, nak3

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 10, 2021

func replaceNodeSelector(override *v1alpha1.DeploymentOverride, deployment *appsv1.Deployment) {
if len(override.NodeSelector) > 0 {
deployment.Spec.Template.Spec.NodeSelector = override.NodeSelector

@houshengbo houshengbo Jun 10, 2021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feature is fine.
My question is whether to overwrite or replace for the nodeselector.
NodeSelector is a key-value map, the same to Labels and Annotations.
For Labels and Annotations, we add the override into the existing map, but for NodeSelector, we replace the existing with the override. Why not keep the existing keys, that is not in override for NodeSelector?
For example,
If override is {"key1": "val1"}, there is an existing map {"key": "val"}, we will end up with {"key1": "val1"}, not {"key1": "val1", "key": "val"}. The existing "key" is gone.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's useful to merge node selectors. IIRC they're in an AND combination, so adding more would likely result in no nodes matching anymore. Plus: We don't have preset node selectors at all.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I made this by design because of the reason Markus mentioned.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I am ok with this PR.

@nak3

nak3 commented Jun 12, 2021

Copy link
Copy Markdown
Contributor Author

/hold cancel

@knative-prow-robot knative-prow-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 12, 2021
@nak3

nak3 commented Jun 12, 2021

Copy link
Copy Markdown
Contributor Author

@nak3

nak3 commented Jun 12, 2021

Copy link
Copy Markdown
Contributor Author

/test pull-knative-operator-serving-upgrade-tests

@knative-prow-robot
knative-prow-robot merged commit 8cb752e into knative:main Jun 12, 2021
@nak3
nak3 deleted the add-nodeselector branch June 12, 2021 07:09
knative-prow-robot pushed a commit to knative/docs that referenced this pull request Jun 15, 2021
* Add `nodeSelector` to override system deployments by operator

This patch adds docs for knative/operator#658.
It adds `nodeSelector` to override system deployments by operator.

* Fix broken format

* Update docs/admin/install/operator/configuring-serving-cr.md

Co-authored-by: Ashleigh Brennan <abrennan@redhat.com>

* Update docs/admin/install/operator/configuring-serving-cr.md

Co-authored-by: Ashleigh Brennan <abrennan@redhat.com>

* Update docs/admin/install/operator/configuring-serving-cr.md

Co-authored-by: Ashleigh Brennan <abrennan@redhat.com>

* Update docs/admin/install/operator/configuring-serving-cr.md

Co-authored-by: Ashleigh Brennan <abrennan@redhat.com>

Co-authored-by: Ashleigh Brennan <abrennan@redhat.com>
RichardJJG pushed a commit to RichardJJG/docs that referenced this pull request Jul 1, 2021
…e#3789)

* Add `nodeSelector` to override system deployments by operator

This patch adds docs for knative/operator#658.
It adds `nodeSelector` to override system deployments by operator.

* Fix broken format

* Update docs/admin/install/operator/configuring-serving-cr.md

Co-authored-by: Ashleigh Brennan <abrennan@redhat.com>

* Update docs/admin/install/operator/configuring-serving-cr.md

Co-authored-by: Ashleigh Brennan <abrennan@redhat.com>

* Update docs/admin/install/operator/configuring-serving-cr.md

Co-authored-by: Ashleigh Brennan <abrennan@redhat.com>

* Update docs/admin/install/operator/configuring-serving-cr.md

Co-authored-by: Ashleigh Brennan <abrennan@redhat.com>

Co-authored-by: Ashleigh Brennan <abrennan@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants