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

Bug1277038 - Differ between oc env updates(removes/adds) the resource(s) envvars and when it doesnt #6104

Closed
wants to merge 1 commit into from

Conversation

jhadvig
Copy link
Member

@jhadvig jhadvig commented Nov 26, 2015

When adding/removing envvars with oc env cmd, differ between states when the command actually updates the resource(s) and when it doesnt.
Eg: When updating resource by adding the envvar with a value that is already present in the resource, or removing a envvar that is not present, the printed output will look accordingly:
replicationcontroller "database-1" nothing to update
instead of
replicationcontroller "database-1" updated

  • added a TC

Wasnt sure if we also wanna print due to which envar the resource wasnt updated (eg1. removing envvar thats not present in the resource || updating envar with the same value), since we would have to revrite some parts of the env.go and will end up with dup. messages in case user would want to update all rcs/dc with wrong envars(eg1).

@fabianofranz thoughts ?

@fabianofranz
Copy link
Member

[test]

@liggitt
Copy link
Contributor

liggitt commented Nov 27, 2015

Will conflict/overlap with #5819
How do we treat deletions of resources which don't exist?

@jhadvig
Copy link
Member Author

jhadvig commented Nov 27, 2015

@liggitt I've already spoken with @Kargakis about the overlap and this PR doesn't solve this issue.
So we could either:

Don't have any strong feelings about both solutions. Thoughts ?

@0xmichalis
Copy link
Contributor

#5819 supersedes this. The success message there needs fixing though, @jhadvig may want to rebase your changes regarding it once it gets merged.

@jhadvig
Copy link
Member Author

jhadvig commented Nov 30, 2015

@Kargakis yes, once the our PR is merged, will rebase. Thx

@openshift-bot openshift-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 2, 2015
@jhadvig
Copy link
Member Author

jhadvig commented Dec 2, 2015

@fabianofranz I've updated the PR after #5819 got merged
Now when deleting envs that aren't present in the pod's container the oc will return:

$ oc env dc/frontend TEST1- TEST2-
environment variable "TEST1" not found in ruby-helloworld container
environment variable "TEST2" not found in ruby-helloworld container
deploymentconfig "frontend" nothing to update

PTAL

@liggitt
Copy link
Contributor

liggitt commented Dec 2, 2015

What do the label/annotate commands do in this case?

@openshift-bot openshift-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 2, 2015
@jhadvig
Copy link
Member Author

jhadvig commented Dec 2, 2015

@liggitt I've already proposed this kind of change for the label cmd to upstream and it was merged aswell kubernetes/kubernetes#17946

Regarding the annotate cmd, its not returning this kind of info(for now)

for _, env := range remove {
_, ok := findEnv(c.Env, env)
if !ok {
infosMsgs[i] = append(infosMsgs[i], fmt.Sprintf("environment variable %q not found in %s container\n", env, c.Name))
Copy link
Contributor

Choose a reason for hiding this comment

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

So if something has multiple containers, one of which has an envvar, and you remove the envvar, you'll always get a message saying the other container didn't have that var? That doesn't seem necessary.

Copy link
Member Author

Choose a reason for hiding this comment

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

if user is updating the envars in a pod, by default it will update all the containers. For that reason user should specify --containers flag I guess.

Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't print warnings that an envvar they wanted to remove didn't exist in all containers. If it existed in at least one, that's probably fine

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, how about printing them with glog at some higher verbosity ?

Copy link
Contributor

Choose a reason for hiding this comment

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

nah, if I ask to remove envvar B, and it exists in one container but not another, I don't consider that failure or warning-worthy

@jhadvig
Copy link
Member Author

jhadvig commented Dec 3, 2015

@liggitt updated
ptal

continue
outputMsg := "updated"
if !updated[i] {
outputMsg = "nothing to update"
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of doing this and nesting all the code, do this:

if !updated[i] {
   cmdutil.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, "didn't need to update")
   continue
}
// rest of the code...

Copy link
Contributor

Choose a reason for hiding this comment

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

Also it would be nice if this (no need for update) was handled by CreateTwoWayMergePatch by returning an empty byte slice and not by us but that's not the case: kubernetes/kubernetes#17022

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually @liggitt if we pin the size of an empty patch (a couple of bytes) to a constant and check for it, wouldn't it be better?

Copy link
Member Author

Choose a reason for hiding this comment

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

The size of empty patch 2

Copy link
Contributor

Choose a reason for hiding this comment

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

It's {}, right? Not sure how I feel about checking that. I think I would rather have updateEnv additionally return a boolean indicating whether any updates were made

@jhadvig
Copy link
Member Author

jhadvig commented Dec 4, 2015

@liggitt @Kargakis I've updated the PR. updateEnv will additionally return bool whether container envvars had been updated
ptal

@@ -371,7 +384,11 @@ func updateEnv(existing []kapi.EnvVar, env []kapi.EnvVar, remove []string) []kap
covered.Insert(e.Name)
out = append(out, e)
}
return out
envUpdated := true
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of using reflection, I'd rather initialize envUpdated to false at the top, and set it to true in the loop where we know we're making changes

Copy link
Member Author

Choose a reason for hiding this comment

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

Then the line which would be setting envUpdate to false would need to be basically in all three if statements and also at the end of the for loops, due to the logic the out variable is build. Would rather prevent prevent that.

Copy link
Contributor

Choose a reason for hiding this comment

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

I still would rather set it explicitly... I think some of the complexity would be reduced by handling each case (removed, modified, added) in its own loop

Copy link
Member Author

Choose a reason for hiding this comment

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

ok, will rewrite the logic and set it explicitly :)

@jhadvig
Copy link
Member Author

jhadvig commented Dec 8, 2015

@liggitt cleaned the logic a bit as suggested.
ptal

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to 2cbfd4a

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test FAILURE (https://ci.openshift.redhat.com/jenkins/job/test_pull_requests_origin/7677/)

var envUpdated bool
var updated = make([]bool, len(infos))
for i, info := range infos {
updated[i] = false
Copy link
Contributor

Choose a reason for hiding this comment

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

defaults to false already

covered.Insert(e.Name)
out = append(out, newer)
continue
envUpdated = true
Copy link
Contributor

Choose a reason for hiding this comment

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

only if the value has changed, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this is probably a tight enough check

@danmcp
Copy link

danmcp commented Jan 20, 2016

@jhadvig Bump

@openshift-bot
Copy link
Contributor

Origin Action Required: Pull request cannot be automatically merged, please rebase your branch from latest HEAD and push again

@openshift-bot openshift-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 12, 2016
@openshift-bot openshift-bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Apr 30, 2016
@openshift-bot openshift-bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels May 24, 2016
@openshift-bot openshift-bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jun 7, 2016
@danmcp
Copy link

danmcp commented Jun 14, 2016

Closing due to age and inactivity. Feel free to reopen if you are going to continue working on it.

@danmcp danmcp closed this Jun 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants