Skip to content

Commit 4fb92dc

Browse files
committed
ref: change --node to --node-selector flag
- test: add bats for `shp build run` Signed-off-by: rxinui <[email protected]>
1 parent b78860d commit 4fb92dc

File tree

8 files changed

+37
-13
lines changed

8 files changed

+37
-13
lines changed

docs/shp_build_create.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ shp build create <name> [flags]
1919
```
2020
-e, --env stringArray specify a key-value pair for an environment variable to set for the build container (default [])
2121
-h, --help help for create
22-
--node stringArray set of key-value pairs that correspond to labels of a node to match (default [])
22+
--node-selector stringArray set of key-value pairs that correspond to labels of a node to match (default [])
2323
--output-image string image employed during the building process
2424
--output-image-annotation stringArray specify a set of key-value pairs that correspond to annotations to set on the output image (default [])
2525
--output-image-label stringArray specify a set of key-value pairs that correspond to labels to set on the output image (default [])

docs/shp_build_run.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ shp build run <name> [flags]
2222
-e, --env stringArray specify a key-value pair for an environment variable to set for the build container (default [])
2323
-F, --follow Start a build and watch its log until it completes or fails.
2424
-h, --help help for run
25-
--node stringArray set of key-value pairs that correspond to labels of a node to match (default [])
25+
--node-selector stringArray set of key-value pairs that correspond to labels of a node to match (default [])
2626
--output-image string image employed during the building process
2727
--output-image-annotation stringArray specify a set of key-value pairs that correspond to annotations to set on the output image (default [])
2828
--output-image-label stringArray specify a set of key-value pairs that correspond to labels to set on the output image (default [])

docs/shp_build_upload.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ shp build upload <build-name> [path/to/source|.] [flags]
3232
-e, --env stringArray specify a key-value pair for an environment variable to set for the build container (default [])
3333
-F, --follow Start a build and watch its log until it completes or fails.
3434
-h, --help help for upload
35-
--node stringArray set of key-value pairs that correspond to labels of a node to match (default [])
35+
--node-selector stringArray set of key-value pairs that correspond to labels of a node to match (default [])
3636
--output-image string image employed during the building process
3737
--output-image-annotation stringArray specify a set of key-value pairs that correspond to annotations to set on the output image (default [])
3838
--output-image-label stringArray specify a set of key-value pairs that correspond to labels to set on the output image (default [])

docs/shp_buildrun_create.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ shp buildrun create <name> [flags]
2121
--buildref-name string name of build resource to reference
2222
-e, --env stringArray specify a key-value pair for an environment variable to set for the build container (default [])
2323
-h, --help help for create
24-
--node stringArray set of key-value pairs that correspond to labels of a node to match (default [])
24+
--node-selector stringArray set of key-value pairs that correspond to labels of a node to match (default [])
2525
--output-image string image employed during the building process
2626
--output-image-annotation stringArray specify a set of key-value pairs that correspond to annotations to set on the output image (default [])
2727
--output-image-label stringArray specify a set of key-value pairs that correspond to labels to set on the output image (default [])

pkg/shp/flags/build.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func BuildSpecFromFlags(flags *pflag.FlagSet) (*buildv1beta1.BuildSpec, *string,
5656
imageLabelsFlags(flags, spec.Output.Labels)
5757
imageAnnotationsFlags(flags, spec.Output.Annotations)
5858
buildRetentionFlags(flags, spec.Retention)
59-
buildNodeFlags(flags, spec.NodeSelector)
59+
buildNodeSelectorFlags(flags, spec.NodeSelector)
6060
var dockerfile, builderImage string
6161
dockerfileFlags(flags, &dockerfile)
6262
builderImageFlag(flags, &builderImage)

pkg/shp/flags/buildrun.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func BuildRunSpecFromFlags(flags *pflag.FlagSet) *buildv1beta1.BuildRunSpec {
4040
imageLabelsFlags(flags, spec.Output.Labels)
4141
imageAnnotationsFlags(flags, spec.Output.Annotations)
4242
buildRunRetentionFlags(flags, spec.Retention)
43-
buildNodeFlags(flags, spec.NodeSelector)
43+
buildNodeSelectorFlags(flags, spec.NodeSelector)
4444
return spec
4545
}
4646

pkg/shp/flags/flags.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const (
6565
// RetentionTTLAfterSucceededFlag command-line flag.
6666
RetentionTTLAfterSucceededFlag = "retention-ttl-after-succeeded"
6767
// NodeSelectorFlag command-line flag.
68-
NodeSelectorFlag = "node"
68+
NodeSelectorFlag = "node-selector"
6969
)
7070

7171
// sourceFlags flags for ".spec.source"
@@ -261,8 +261,8 @@ func serviceAccountFlags(flags *pflag.FlagSet, sa *string) {
261261

262262
}
263263

264-
// buildNodeFlags registers flags for adding BuildSpec.NodeSelector
265-
func buildNodeFlags(flags *pflag.FlagSet, nodeSelectorLabels map[string]string) {
264+
// buildNodeSelectorFlags registers flags for adding BuildSpec.NodeSelector
265+
func buildNodeSelectorFlags(flags *pflag.FlagSet, nodeSelectorLabels map[string]string) {
266266
flags.Var(NewMapValue(nodeSelectorLabels), NodeSelectorFlag, "set of key-value pairs that correspond to labels of a node to match")
267267
}
268268

test/e2e/node-selector.bats

+28-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ teardown() {
1818
build_name=$(random_name)
1919

2020
# create a Build with node selector
21-
run shp build create ${build_name} --source-url=https://github.com/shipwright-io/sample-go --output-image=my-fake-image --node="kubernetes.io/hostname=node-1"
21+
run shp build create ${build_name} --source-git-url=https://github.com/shipwright-io/sample-go --output-image=my-fake-image --node-selector="kubernetes.io/hostname=node-1"
2222
assert_success
2323

2424
# ensure that the build was successfully created
@@ -36,7 +36,7 @@ teardown() {
3636
build_name=$(random_name)
3737

3838
# create a Build with node selector
39-
run shp build create ${build_name} --source-url=https://github.com/shipwright-io/sample-go --output-image=my-fake-image --node="kubernetes.io/hostname=node-1" --node="kubernetes.io/os=linux"
39+
run shp build create ${build_name} --source-git-url=https://github.com/shipwright-io/sample-go --output-image=my-fake-image --node-selector="kubernetes.io/hostname=node-1" --node-selector="kubernetes.io/os=linux"
4040
assert_success
4141

4242
# ensure that the build was successfully created
@@ -56,7 +56,7 @@ teardown() {
5656
build_name=$(random_name)
5757

5858
# create a Build with node selector
59-
run shp buildrun create ${buildrun_name} --buildref-name=${build_name} --node="kubernetes.io/hostname=node-1"
59+
run shp buildrun create ${buildrun_name} --buildref-name=${build_name} --node-selector="kubernetes.io/hostname=node-1"
6060
assert_success
6161

6262
# ensure that the build was successfully created
@@ -75,7 +75,7 @@ teardown() {
7575
build_name=$(random_name)
7676

7777
# create a Build with node selector
78-
run shp buildrun create ${buildrun_name} --buildref-name=${build_name} --node="kubernetes.io/hostname=node-1" --node="kubernetes.io/os=linux"
78+
run shp buildrun create ${buildrun_name} --buildref-name=${build_name} --node-selector="kubernetes.io/hostname=node-1" --node-selector="kubernetes.io/os=linux"
7979
assert_success
8080

8181
# ensure that the build was successfully created
@@ -87,4 +87,28 @@ teardown() {
8787

8888
assert_output --partial '"kubernetes.io/hostname":"node-1"'
8989
assert_output --partial '"kubernetes.io/os":"linux"'
90+
}
91+
92+
93+
@test "shp build run with node-selector set" {
94+
# generate random names for our build
95+
build_name=$(random_name)
96+
97+
# create a Build with node selector
98+
run shp build create ${build_name} --source-git-url=https://github.com/shipwright-io/sample-go --output-image=my-fake-image
99+
assert_success
100+
101+
# ensure that the build was successfully created
102+
assert_output --partial "Created build \"${build_name}\""
103+
104+
# get the build object
105+
run kubectl get builds.shipwright.io/${build_name}
106+
assert_success
107+
108+
run shp build run ${build_name} --node-selector="kubernetes.io/hostname=node-1"
109+
110+
# get the jsonpath of Build object .spec.nodeSelector
111+
run kubectl get buildruns.shipwright.io -ojsonpath='{.items[*].spec.nodeSelector}'
112+
assert_success
113+
assert_output --partial '"kubernetes.io/hostname":"node-1"'
90114
}

0 commit comments

Comments
 (0)