-
Notifications
You must be signed in to change notification settings - Fork 749
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 build_args support in buildconfig #424
Conversation
Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please follow instructions at https://github.com/kubernetes/kubernetes/wiki/CLA-FAQ to sign the CLA. Once you've signed, please reply here (e.g. "I signed it!") and we'll verify. Thanks.
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
@surajnarwade Please run |
9ed1b03
to
2e9596c
Compare
envList := []kapi.EnvVar{} | ||
for i, v := range service.BuildArgs { | ||
envList = append(envList, kapi.EnvVar{Name: i, Value: v}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: how about using something like envName
or envVal
instead of i
and v
?
@surajnarwade works for me, good stuff :) Let's add some unit and functional tests now. For the functional ones, you can refer to the other tests in https://github.com/kubernetes-incubator/kompose/blob/master/script/test/cmd/tests.sh, should be straighforward. For the unit tests, this can be covered under Going through the other tests for the first time might take some time, so take some time :) |
I've tested this and it looks good. Just one small note here, this doesn't solve entire #406 just one part of it. But that is OK, just don't close #406 yet ;-) @surajnarwade Can you please add tests to this PR? Mainly Go tests. Otherwise code looks good. |
@containscafeine @kadel thanks, I am adding tests |
65b1d21
to
33e97cb
Compare
script/test/cmd/tests.sh
Outdated
@@ -177,6 +177,9 @@ convert::check_artifacts_generated "kompose -f $KOMPOSE_ROOT/examples/docker-com | |||
# Behavior with -o <dirname>/<filename> | |||
convert::check_artifacts_generated "kompose -f $KOMPOSE_ROOT/examples/docker-compose.yml convert -o $TEMP_DIR/output_file -j" "$TEMP_DIR/output_file" | |||
|
|||
# Test the presence of build args in buildconfig | |||
convert::expect_success_warning "kompose --provider openshift -f $KOMPOSE_ROOT/script/test/fixtures/buildargs/docker-compose.yml convert --stdout -j" "$KOMPOSE_ROOT/script/test/fixtures/buildargs/openshift-buildargs.json" "INFO Buildconfig using [email protected]:surajnarwade/kompose.git::add-build-args as source." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is info being read as warning here? if function expect_success
is failing then we should fix something in that function it seems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also this needs to be investigated how this test is passing even if we don't have function named: convert::expect_success_warning
but it's named as convert::expect_success_and_warning
33e97cb
to
391a112
Compare
for name, test := range testCases { | ||
t.Log("Test case: ", name) | ||
if test.field != test.value { | ||
t.Errorf("Expected: %#v, got: %#v", test.value, test.field) | ||
} | ||
} | ||
t.Log("Test case: Assert buildconfig buildargs") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this log should be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@surajnarwade This still needs to be removed.
|
||
|
||
RUN touch /test | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is there a Dockerfile here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
taken from examples for buildconfig
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
may be best to remove extra newlines from this :)
args: | ||
NAME: web | ||
command: "sleep 3600" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove extra newline
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@surajnarwade this still needs to be remove
Odd error happening: ===> Starting test <===
convert::expect_success_and_warning: Running: 'kompose --provider openshift -f /home/travis/gopath/src/github.com/kubernetes-incubator/kompose/script/test/fixtures/buildargs/docker-compose.yml convert --stdout -j' expected_output: '/home/travis/gopath/src/github.com/kubernetes-incubator/kompose/script/test/fixtures/buildargs/openshift-buildargs.json' expected_warning: 'Buildconfig using https://github.com/kubernetes-incubator/kompose.git::master as source.'
FAIL: converted output does not match Any idea? |
391a112
to
f60c6ef
Compare
I did some digging, and found out that it is caused by this: #445 |
74c8136
to
95e469c
Compare
@cdrage my bad, Updated PR for the same |
deployapi "github.com/openshift/origin/pkg/deploy/api" | ||
|
||
"github.com/kubernetes-incubator/kompose/pkg/kobject" | ||
"github.com/kubernetes-incubator/kompose/pkg/testutils" | ||
"github.com/kubernetes-incubator/kompose/pkg/transformer/kubernetes" | ||
"github.com/pkg/errors" | ||
kapi "k8s.io/kubernetes/pkg/api" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
errr.. why are we importing this twice? "k8s.io/kubernetes/pkg/api" is already imported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
@@ -200,6 +200,13 @@ func (o *OpenShift) initImageStream(name string, service kobject.ServiceConfig, | |||
// initBuildConfig initialize Openshifts BuildConfig Object | |||
func initBuildConfig(name string, service kobject.ServiceConfig, repo string, branch string) (*buildapi.BuildConfig, error) { | |||
contextDir, err := getAbsBuildContext(service.Build) | |||
envList := []kapi.EnvVar{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to use kapi
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use api
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as #602 puts kapi
instead of api
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, i see 👍 LGTM
if *envValue == "\x00" { | ||
*envValue = os.Getenv(envName) | ||
} | ||
envList = append(envList, kapi.EnvVar{Name: envName, Value: *envValue}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to use kapi
, use api
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reason: #602
@@ -288,9 +289,12 @@ func TestInitBuildConfig(t *testing.T) { | |||
serviceName := "serviceA" | |||
repo := "https://git.test.com/org/repo" | |||
branch := "somebranch" | |||
buildArgs := []kapi.EnvVar{{Name: "name", Value: "value"}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again, use just api
no kapi
for name, test := range testCases { | ||
t.Log("Test case: ", name) | ||
if test.field != test.value { | ||
t.Errorf("Expected: %#v, got: %#v", test.value, test.field) | ||
} | ||
} | ||
t.Log("Test case: Assert buildconfig buildargs") | ||
if !reflect.DeepEqual(bc.Spec.CommonSpec.Strategy.DockerStrategy.Env, buildArgs) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bit confused what this does, can you please elaborate with a comment above?
context: "./build" | ||
args: | ||
NAME: web | ||
command: "sleep 3600" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good to test all combinations, ex:
args:
NAME: web
args:
- NAME=web
args:
- NAME
args:
NAME:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@surajnarwade are all those combinations added?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@surajssd , yes
9095ab8
to
c3f529f
Compare
cc @cdrage |
script/test/cmd/tests.sh
Outdated
@@ -235,6 +239,6 @@ convert::expect_success "kompose --provider=openshift convert --stdout -j" "$KOM | |||
cd $CURRENT_DIR | |||
|
|||
# Removes generated output | |||
rm -rf /tmp/output-os.json | |||
rm -rf /tmp/output*.json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
recursive and force plus a *
= bad idea. very dangerous.
instead, please add:
rm /tmp/output-os.json
rm /tmp/output-buildarg-os.json
args: | ||
NAME: web | ||
command: "sleep 3600" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@surajnarwade this still needs to be remove
context: "./build" | ||
args: | ||
- NAME=web | ||
- foo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no tests for:
args:
NAME:
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cdrage , this type is not supported in build args, and as buildargs
is of map[string]*string
, it throws error,
ERRO Failed to unmarshall: Cannot unmarshal '<nil>' to type <nil> into a string value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and this format is not supported by libcompose
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@surajnarwade Alright, no worries. Despite it being valid YAML, it's something that's not listed on https://docs.docker.com/compose/compose-file/compose-file-v2/#args 👍 LGTM!
@@ -0,0 +1,12 @@ | |||
## Docker Compose Buildargs | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: s//n//
remove extra new line!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
a79f9a5
to
32d84e5
Compare
After all the changes, this LGTM 👍 |
@@ -17,13 +17,13 @@ limitations under the License. | |||
package openshift | |||
|
|||
import ( | |||
"k8s.io/kubernetes/pkg/api" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we remain consistent with openshit.go
and use the alias for k8s api import as kapi ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@surajssd okay
32d84e5
to
708a41a
Compare
NAME: web | ||
command: "sleep 3600" | ||
foo1: | ||
build: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: why is the indentation of this docker-compose file messed up?
708a41a
to
6f34dfa
Compare
now args provided under build in docker-compose file can be available in buildconfig. it solves kubernetes#406 Added unit test and functional test solves kubernetes#445 Separated key:"value" pairs by spaces
6f34dfa
to
8fc262b
Compare
Cool this LGTM! |
@surajnarwade thanks for the hard work! |
@surajssd, finally :) |
thanks everyone! |
now args provided under build in docker-compose file can be available in buildconfig.
it solves #406