Skip to content

Add --node-selector Flag for shp build/buildrun Commands #309

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

Merged

Conversation

rxinui
Copy link
Contributor

@rxinui rxinui commented Apr 21, 2025

Changes

Fixes #260

Add CLI flag --node to set .spec.nodeSelector to a Build or BuildRun

IMPORTANT: depends on PR 304

PR's codebase is tracking PR 304 by @karanibm6 as .spec.nodeSelector is only defined on builds.shipwright.io/v1beta1 as a consequence of the current main branch for CLI relying on builds.shipwright.io/v1alpha1 (see PR 1683)

Submitter Checklist

  • Includes tests if functionality changed/was added
  • Includes docs if changes are user-facing
  • Set a kind label on this PR
  • Release notes block has been filled in, or marked NONE

See the contributor guide
for details on coding conventions, github and prow interactions, and the code review process.

Release Notes

Add flag --node-selector to set the `.spec.nodeSelector` for `build` and `buildrun` on create

@pull-request-size pull-request-size bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Apr 21, 2025
@rxinui
Copy link
Contributor Author

rxinui commented Apr 21, 2025

cc: @adambkaplan

sorry for the delay

Copy link
Member

@adambkaplan adambkaplan left a comment

Choose a reason for hiding this comment

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

Great work so far!

I added my review of the items that appear directly related to the node selector change. The bulk of my comments are related to changing the name of the flag to --node-selector. Otherwise this is in very good shape. Once the v1beta1 API PR is merged this can be rebased + unblocked.

@adambkaplan
Copy link
Member

/ok-to-test

@openshift-ci openshift-ci bot added the ok-to-test Indicates a non-member PR verified by an org member that is safe to test. label Apr 22, 2025
@rxinui
Copy link
Contributor Author

rxinui commented Apr 23, 2025

As requested, a new bats test is added for shp build run <mybuild> --node-selector which works as expected. However, there is a use case where I have doubts.

Context: since --node-selector is added to shp build create and shp build run, the field .spec.nodeSelector is can now be defined on Build and BuildRun.

Doubt: when running successively the following

# create mybuild with pre-defined nodeSelector
shp build create mybuild --node-selector="foo=bar" --source-git-url=https://github.com/shipwright-io/sample-go --output-image=my-fake-image
# run mybuild
shp build run mybuild

Outcome: BuildRun does not have .spec.nodeSelector specified

apiVersion: shipwright.io/v1beta1
kind: BuildRun
metadata:
  creationTimestamp: "2025-04-23T14:40:59Z"
  generateName: mybuild-
  generation: 1
  labels:
    build.shipwright.io/generation: "1"
    build.shipwright.io/name: mybuild
  name: mybuild-4blqb
  namespace: default
  resourceVersion: "510650"
  uid: 2d74cd53-88fd-469c-a44a-1a5d744027f5
spec: # missing .nodeSelector
  build:
    name: mybuild
status:
  buildSpec:
    nodeSelector: # present in status
      foo: bar
    output:
      image: my-fake-image
# ...

Expectation:

  • A. It is the expected behaviour, where pre-defined .spec.nodeSelector should not be embedded within BuildRun unless specified on shp build run --node-selector?
  • B. It is a missing feature, we must include .spec.nodeSelector pre-defined by shp build create command within the BuildRun unless it is overriden by shp build run --node-selector (current behaviour)

In case of A, we should consider allowing --node-selector only on shp build run and shp buildrun create.

@rxinui rxinui force-pushed the ship-0039/260-v1beta1 branch from 4fb92dc to 37984fa Compare April 23, 2025 16:25
@adambkaplan
Copy link
Member

Expectation:

  • A. It is the expected behaviour, where pre-defined .spec.nodeSelector should not be embedded within BuildRun unless specified on shp build run --node-selector?
  • B. It is a missing feature, we must include .spec.nodeSelector pre-defined by shp build create command within the BuildRun unless it is overriden by shp build run --node-selector (current behaviour)

In case of A, we should consider allowing --node-selector only on shp build run and shp buildrun create.

This is expected behavior. Our API has the following convention for settings that are "shared" across Build and BuildRun:

  1. The value in the BuildRun is chosen first.
  2. If no value exists in the BuildRun, but it references a Build object, use the value in the referenced Build object.
  3. If no value exists in the referenced Build object, use the "default" behavior for a nil/empty value.

The status field is used to communicate what the controller inferred from the BuildRun and Build settings.

@adambkaplan
Copy link
Member

In case of A, we should consider allowing --node-selector only on shp build run and shp buildrun create

shp build run is in many ways an alias to shp buildrun create. Not 100% identical, but they both result in a workload being executed. Sharing these flags ensures feature parity.

@rxinui
Copy link
Contributor Author

rxinui commented Apr 23, 2025

In case of A, we should consider allowing --node-selector only on shp build run and shp buildrun create

shp build run is in many ways an alias to shp buildrun create. Not 100% identical, but they both result in a workload being executed. Sharing these flags ensures feature parity.

Thank you for the clarification @adambkaplan

Everything is sorted on my side. Waiting for #304 to be merged to proceed further.

@rxinui rxinui force-pushed the ship-0039/260-v1beta1 branch from 37984fa to c73dfc3 Compare April 29, 2025 14:28
@pull-request-size pull-request-size bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Apr 29, 2025
@rxinui
Copy link
Contributor Author

rxinui commented Apr 29, 2025

@adambkaplan @SaschaSchwarze0 I have rebased to the latest commit which includes v1beta1. Please trigger the /ok-to-test . Note: this blocks PR 311

The checks are green on my forked repository.

@rxinui rxinui requested a review from adambkaplan April 30, 2025 18:04
Copy link
Member

@adambkaplan adambkaplan left a comment

Choose a reason for hiding this comment

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

/approve

Code changes itself look good! There are only two items IMO that need to be fixed before this merges:

  1. Revert the changes in the vendor directory (unclear where this newline change came from).
  2. Squash commits.

Copy link
Contributor

openshift-ci bot commented Apr 30, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: adambkaplan

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

The pull request process is described here

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

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 30, 2025
- test: add bats for `shp build run`
- test: add unit tests

Signed-off-by: rxinui <[email protected]>
@rxinui rxinui force-pushed the ship-0039/260-v1beta1 branch from c73dfc3 to 3027458 Compare April 30, 2025 18:50
@rxinui rxinui requested a review from adambkaplan April 30, 2025 18:51
@rxinui
Copy link
Contributor Author

rxinui commented Apr 30, 2025

@adambkaplan ready to be merged, commit is squashed.

@adambkaplan adambkaplan changed the title Ship 0039/260 v1beta1 Add --node-selector Flag for shp build/buildrun Commands Apr 30, 2025
@adambkaplan adambkaplan added the kind/feature Categorizes issue or PR as related to a new feature. label Apr 30, 2025
@adambkaplan adambkaplan added this to the release-v0.16.0 milestone Apr 30, 2025
Copy link
Member

@adambkaplan adambkaplan left a comment

Choose a reason for hiding this comment

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

/lgtm

Looks good!

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Apr 30, 2025
@openshift-merge-bot openshift-merge-bot bot merged commit 63a617e into shipwright-io:main Apr 30, 2025
10 checks passed
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. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

SHIP-0039: Command line option to set node selector on Build/BuildRun
2 participants