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 build_args support in buildconfig #424

Merged
merged 1 commit into from
May 16, 2017

Conversation

surajnarwade
Copy link
Contributor

now args provided under build in docker-compose file can be available in buildconfig.
it solves #406

@k8s-ci-robot
Copy link
Contributor

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.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Feb 13, 2017
@procrypt
Copy link
Contributor

procrypt commented Feb 13, 2017

@surajnarwade Please run gofmt on pkg/transformer/openshift/openshift.go tests are failing.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Feb 13, 2017
@surajnarwade surajnarwade force-pushed the add-build-args branch 2 times, most recently from 9ed1b03 to 2e9596c Compare February 13, 2017 08:25
@surajnarwade
Copy link
Contributor Author

cc: @cdrage @kadel @containscafeine @surajssd

envList := []kapi.EnvVar{}
for i, v := range service.BuildArgs {
envList = append(envList, kapi.EnvVar{Name: i, Value: v})
}
Copy link
Contributor

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?

@concaf
Copy link
Contributor

concaf commented Feb 13, 2017

@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 func TestInitBuildConfig(t *testing.T) in openshift_test.go.

Going through the other tests for the first time might take some time, so take some time :)

@kadel
Copy link
Member

kadel commented Feb 14, 2017

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.

@surajnarwade
Copy link
Contributor Author

@containscafeine @kadel thanks, I am adding tests

@surajnarwade surajnarwade force-pushed the add-build-args branch 4 times, most recently from 65b1d21 to 33e97cb Compare February 15, 2017 15:53
@@ -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."
Copy link
Member

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.

Copy link
Member

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

@surajnarwade
Copy link
Contributor Author

cc @cdrage @kadel

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")
Copy link
Member

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

Copy link
Member

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

Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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"

Copy link
Member

Choose a reason for hiding this comment

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

remove extra newline

Copy link
Member

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

@cdrage
Copy link
Member

cdrage commented Feb 22, 2017

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?

@kadel
Copy link
Member

kadel commented Feb 23, 2017

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?

I did some digging, and found out that it is caused by this: #445

@surajnarwade surajnarwade force-pushed the add-build-args branch 5 times, most recently from 74c8136 to 95e469c Compare February 25, 2017 19:55
@surajnarwade
Copy link
Contributor Author

@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"
Copy link
Member

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

Copy link
Contributor Author

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{}
Copy link
Member

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

Copy link
Member

@cdrage cdrage May 9, 2017

Choose a reason for hiding this comment

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

use api

Copy link
Contributor Author

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

Copy link
Member

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})
Copy link
Member

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

Copy link
Contributor Author

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"}}
Copy link
Member

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) {
Copy link
Member

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"
Copy link
Member

@cdrage cdrage May 9, 2017

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:

Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@surajssd , yes

@surajnarwade surajnarwade force-pushed the add-build-args branch 5 times, most recently from 9095ab8 to c3f529f Compare May 9, 2017 14:29
@surajnarwade
Copy link
Contributor Author

cc @cdrage

@@ -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
Copy link
Member

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"

Copy link
Member

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
Copy link
Member

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:

?

Copy link
Contributor Author

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

Copy link
Contributor Author

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

Copy link
Member

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

Copy link
Member

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!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

@surajnarwade surajnarwade force-pushed the add-build-args branch 2 times, most recently from a79f9a5 to 32d84e5 Compare May 15, 2017 16:55
@cdrage
Copy link
Member

cdrage commented May 15, 2017

After all the changes, this LGTM 👍

@@ -17,13 +17,13 @@ limitations under the License.
package openshift

import (
"k8s.io/kubernetes/pkg/api"
Copy link
Member

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 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@surajssd okay

NAME: web
command: "sleep 3600"
foo1:
build:
Copy link
Member

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?

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
@surajssd
Copy link
Member

Cool this LGTM!

@surajssd surajssd merged commit 7e785bb into kubernetes:master May 16, 2017
@surajssd
Copy link
Member

@surajnarwade thanks for the hard work!

@surajnarwade
Copy link
Contributor Author

@surajssd, finally :)

@arcolife
Copy link

thanks everyone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. component/OpenShift rebase needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants