-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Conversation
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.
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 { |
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.
you should iterate over templateObjects since generated objects already have the environment applied to them.
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.
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' |
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.
Not sure if it's possible, but ideally we should prove to ourselves that for generated objects the environment is applied only once.
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.
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
.
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.
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' |
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.
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
.
fcdd379
to
b238e9e
Compare
Intermediate responses to comments pushed ... in the interim will dive into override question I noted earlier. |
Have override sorted out ... will push momentarily |
b238e9e
to
838fc79
Compare
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' |
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.
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.
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 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?
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.
You'll need to surround the JSONPath with braces:
oc get dc/jenkins -o jsonpath='{.spec.replicas}'
See the k8s documentation for more detail.
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.
Ah ... it needs to be oc get dc/jenkins -o jsonpath='{.spec.replicas}'
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.
Figured it out as @stevekuznetsov was posting :-) ... thanks @stevekuznetsov
On Wed, Nov 30, 2016 at 12:54 PM, Gabe Montero ***@***.***> wrote:
On Wed, Nov 30, 2016 at 12:34 PM, Steve Kuznetsov <
***@***.***> wrote:
> ***@***.**** requested changes on this pull request.
> ------------------------------
>
> In test/cmd/newapp.sh
> <#12048 (review)>
> :
>
> > @@ -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'
>
> 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
>
> When actually creating the objects, from what I can tell from the test
scripts, those objects will be present (and potentially impact) subsequent
commands ...
so I'm somewhat hesitant of that approach. In theory you can supply `-o
jsonpath` to `oc new-app` as well, but circumnavigating that morass
appeared more
problematic than doing it for `oc get` when I experimented with it :-)
... but if I could get it working for even `oc get` manually, maybe I'll
see what's additionally needed.
I'll contemplate / experiment some more.
…
> 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.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <#12048 (review)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ADbadEO9oCuHHmKPjfdZ9e1-6eUlhSyEks5rDbO7gaJpZM4K-Qik>
> .
>
|
838fc79
to
75ac180
Compare
OK pushed update .... now using fyi ... was able to leverage it with Not sure if jsonpath filter along with 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' |
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 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.
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.
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.
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.
Update pushed
75ac180
to
18c54db
Compare
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.
Test look good to me. Deferring to @csrwng for the rest.
} | ||
} | ||
} | ||
*/ |
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.
@gabemontero pls remove
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.
daahhhhhh - forgot that :-)
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.
update pushed
18c54db
to
21600bd
Compare
21600bd
to
53215d9
Compare
LGTM [merge] |
Evaluated for origin merge up to 53215d9 |
[Test]ing while waiting on the merge queue |
Evaluated for origin test up to 53215d9 |
continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/11843/) (Base Commit: 166273b) |
continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/11851/) (Base Commit: 3929053) (Image: devenv-rhel7_5454) |
@csrwng PTAL
(the simplicity of the change seems to good to be true ... let me know what if anything I am missing - thx)