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

set env vars on oc new-app of template #12048

Merged
merged 1 commit into from
Dec 1, 2016

Conversation

gabemontero
Copy link
Contributor

@csrwng PTAL

(the simplicity of the change seems to good to be true ... let me know what if anything I am missing - thx)

Copy link
Contributor

@csrwng csrwng left a comment

Choose a reason for hiding this comment

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

Just a couple of comments but looks good otherwise

// before returning, if this is a template run, and environment variables were passed in, let's apply to the environment variables
// to every pod template object
if len(templateObjects) > 0 {
for i := range objects {
Copy link
Contributor

Choose a reason for hiding this comment

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

you should iterate over templateObjects since generated objects already have the environment applied to them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, in the spirit of this, I moved (and will soon push) the loop into the buildTemplate method. It seems to work correctly based on local testing, but let me know if I'm missing some ramification of such a move.

@@ -62,6 +62,7 @@ os::cmd::expect_success_and_text 'oc new-app ruby-helloworld-sample -o yaml' 'MY
os::cmd::expect_success_and_text 'oc new-app ruby-helloworld-sample -o yaml' 'ADMIN_USERNAME'
os::cmd::expect_success_and_text 'oc new-app ruby-helloworld-sample -o yaml' 'ADMIN_PASSWORD'
os::cmd::expect_success_and_text 'oc new-app ruby-helloworld-sample --param MYSQL_PASSWORD=hello -o yaml' 'hello'
os::cmd::expect_success 'oc new-app -e FOO=BAR -f examples/jenkins/jenkins-ephemeral-template.json -o json | grep FOO'
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if it's possible, but ideally we should prove to ourselves that for generated objects the environment is applied only once.

Copy link
Contributor

Choose a reason for hiding this comment

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

When looking for text in output prefer os::cmd::expect_success_and_(not_)text rather than grep.

When looking for specific output, prefer to inspect the created object in the server (create it, then oc get ... -o jsonpath ... so you can be certain you are not picking up some other unrelated FOO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, switched to expect_success_and_text.

I could not get -o jsonpath to work as we needed. I'm punting on that one unless someone can enlighten me.

By introducing along with expect_success_and_text the use of grep and wc (saw other examples of this in test/cmd/*.sh), I can confirm that the env var is applied only once.

That said, my initial assumption is that the use of -e should override any pre-existing env vars set in the template. Is that correct @csrwng? If so, the current implementation is not overriding.

I'll push the existing changes up for review momentarily and then investigate the "to override or not override" angle.

@@ -62,6 +62,7 @@ os::cmd::expect_success_and_text 'oc new-app ruby-helloworld-sample -o yaml' 'MY
os::cmd::expect_success_and_text 'oc new-app ruby-helloworld-sample -o yaml' 'ADMIN_USERNAME'
os::cmd::expect_success_and_text 'oc new-app ruby-helloworld-sample -o yaml' 'ADMIN_PASSWORD'
os::cmd::expect_success_and_text 'oc new-app ruby-helloworld-sample --param MYSQL_PASSWORD=hello -o yaml' 'hello'
os::cmd::expect_success 'oc new-app -e FOO=BAR -f examples/jenkins/jenkins-ephemeral-template.json -o json | grep FOO'
Copy link
Contributor

Choose a reason for hiding this comment

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

When looking for text in output prefer os::cmd::expect_success_and_(not_)text rather than grep.

When looking for specific output, prefer to inspect the created object in the server (create it, then oc get ... -o jsonpath ... so you can be certain you are not picking up some other unrelated FOO.

@gabemontero
Copy link
Contributor Author

Intermediate responses to comments pushed ... in the interim will dive into override question I noted earlier.

@gabemontero
Copy link
Contributor Author

Have override sorted out ... will push momentarily

@gabemontero
Copy link
Contributor Author

Latest pushed ... PTAL

@@ -62,6 +62,8 @@ os::cmd::expect_success_and_text 'oc new-app ruby-helloworld-sample -o yaml' 'MY
os::cmd::expect_success_and_text 'oc new-app ruby-helloworld-sample -o yaml' 'ADMIN_USERNAME'
os::cmd::expect_success_and_text 'oc new-app ruby-helloworld-sample -o yaml' 'ADMIN_PASSWORD'
os::cmd::expect_success_and_text 'oc new-app ruby-helloworld-sample --param MYSQL_PASSWORD=hello -o yaml' 'hello'
os::cmd::expect_success_and_text 'oc new-app -e FOO=BAR -f examples/jenkins/jenkins-ephemeral-template.json -o json | grep FOO | wc -l' '1'
os::cmd::expect_success_and_text 'oc new-app -e OPENSHIFT_ENABLE_OAUTH=false -f examples/jenkins/jenkins-ephemeral-template.json -o json | grep -A 1 OPENSHIFT_ENABLE_OAUTH | grep false | wc -l' '1'
Copy link
Contributor

Choose a reason for hiding this comment

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

I think a better approach here would be (wrapped in the correct os::cmd invocations):

oc new-app -e OPENSHIFT_ENABLE_OAUTH=false -f examples/jenkins/jenkins-ephemeral-template.json
oc get <whatever_object> -o jsonpath=<path_to_environment_field>

Then you could directly check that whatever part of whatever object you are creating has the field you need. The grep -A1 check is understandably very fragile.

If you want to do counting, etc, use a Golang template.

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 an example, I manually run oc new-app on the jenkins template. It creates a DC named jenkins. I then run:

oc get dc/jenkins -o jsonpath='.spec.replicas'

When using -o json, the value of replicas is clearly 1. However, running the above -o jsonpath command simply returns:

.spec.replicas

with nothing about the actual value being 1. How do you get the actual value?

Copy link
Contributor

Choose a reason for hiding this comment

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

You'll need to surround the JSONPath with braces:

oc get dc/jenkins -o jsonpath='{.spec.replicas}'

See the k8s documentation for more detail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah ... it needs to be oc get dc/jenkins -o jsonpath='{.spec.replicas}'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Figured it out as @stevekuznetsov was posting :-) ... thanks @stevekuznetsov

@gabemontero
Copy link
Contributor Author

gabemontero commented Nov 30, 2016 via email

@gabemontero
Copy link
Contributor Author

OK pushed update .... now using -o jsonpath ... thx @stevekuznetsov again for the help

fyi ... was able to leverage it with oc new-app, so no actual creation of objects.

Not sure if jsonpath filter along with os::cmd::expect_success_and_text will complain if more than one entry matches the search criteria per @csrwng 's request (unlike the grep/wc version), but I agree this is cleaner.

PTAL

@@ -62,6 +62,8 @@ os::cmd::expect_success_and_text 'oc new-app ruby-helloworld-sample -o yaml' 'MY
os::cmd::expect_success_and_text 'oc new-app ruby-helloworld-sample -o yaml' 'ADMIN_USERNAME'
os::cmd::expect_success_and_text 'oc new-app ruby-helloworld-sample -o yaml' 'ADMIN_PASSWORD'
os::cmd::expect_success_and_text 'oc new-app ruby-helloworld-sample --param MYSQL_PASSWORD=hello -o yaml' 'hello'
os::cmd::expect_success_and_text 'oc new-app -e FOO=BAR -f examples/jenkins/jenkins-ephemeral-template.json -o jsonpath="{.items[?(@.kind==\"DeploymentConfig\")].spec.template.spec.containers[0].env[?(@.name==\"FOO\")].value}" ' 'BAR'
Copy link
Contributor

Choose a reason for hiding this comment

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

As you mention this will output more than one value if you match more than one environment variable. I would suggest expecting the text '^BAR$' to combat that. Other than that, these look good to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I was trying to refer to 2 instances of FOO=BAR in the env[], but based on what you are saying is also a concern FOO1=BAR1 and FOO2=BAR2

Will push the update momentarily - thx.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update pushed

Copy link
Contributor

@stevekuznetsov stevekuznetsov left a comment

Choose a reason for hiding this comment

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

Test look good to me. Deferring to @csrwng for the rest.

}
}
}
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

@gabemontero pls remove

Copy link
Contributor Author

Choose a reason for hiding this comment

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

daahhhhhh - forgot that :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

update pushed

@csrwng
Copy link
Contributor

csrwng commented Dec 1, 2016

LGTM [merge]

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to 53215d9

@openshift-bot
Copy link
Contributor

[Test]ing while waiting on the merge queue

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to 53215d9

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/11843/) (Base Commit: 166273b)

@openshift-bot
Copy link
Contributor

openshift-bot commented Dec 1, 2016

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/11851/) (Base Commit: 3929053) (Image: devenv-rhel7_5454)

@openshift-bot openshift-bot merged commit 91f6636 into openshift:master Dec 1, 2016
@gabemontero gabemontero deleted the newAppEnvs branch December 1, 2016 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants