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

Namespaces for Container Label Keys #660

Merged
merged 14 commits into from
Jun 10, 2018

Conversation

eaglerainbow
Copy link
Contributor

@eaglerainbow eaglerainbow commented Jun 8, 2018

As by-product of #658, we have detected that https://docs.docker.com/config/labels-custom-metadata/ requests consumers of docker to use namespaces for their container label keys.

This PR proposes to prefix container label keys used with com.nirima.jenkins.plugins.docker..
Moreover, it refactors the existing coding such that all labels are centrally available at a constant interface.

Mapping between old and new label keys

Old Label Key Identifier New Label Key Identifier
JenkinsId com.nirima.jenkins.plugins.docker.JenkinsId
JenkinsServerUrl com.nirima.jenkins.plugins.docker.JenkinsServerUrl
JenkinsContainerImage com.nirima.jenkins.plugins.docker.JenkinsContainerImage
JenkinsNodeName com.nirima.jenkins.plugins.docker.JenkinsNodeName
JenkinsTemplateName com.nirima.jenkins.plugins.docker.JenkinsTemplateName

@eaglerainbow
Copy link
Contributor Author

Disclaimer: I am currently a little unsure about the lifecycle aspects of this PR: Adding the prefix to the label keys must be (more or less) considered an incompatible change. Though, we are not aware of any consumer of the labels besides ourselves. As such, the (consistent) change of this constant value would not be harming as such. However, with this change applied, we assume that at the point of time the update happens, no containers are left on the docker instance. Otherwise, those docker containers would get "lost".

@pjdarton: What is the committment to our consumers and the administrators w.r.t. updating this plugin? Is there a committment out there that we must be "blue/green deployable"?

@pjdarton
Copy link
Member

pjdarton commented Jun 9, 2018

I think that the labels that the plugin puts on it's containers could be considered private to the plugin.
It is possible for uses to write scripts etc to take advantage of the labels that older versions have used so I guess we should ensure that there are straightforward instructions about migration in (or linked to) the change log...
So, with that in mind, I would suggest that the issue or or we link to (when updating the change log file) should contain a before-and-after summary of label changes in its initial description so that users can easily adapt their scripts after upgrading the plugin.

As for loosing containers: a plugin upgrade requires a Jenkins restart; restarts will (normally) happen only once no build jobs are running; docker containers get terminated at the end of a build; so, under normal circumstances, we won't lose containers as there won't be any to lose.

i.e. I think we should be ok.

@eaglerainbow
Copy link
Contributor Author

Ok, thanks for the feedback.
With https://github.com/eaglerainbow/docker-plugin/blob/f5083176c917ff73a70ec06500b3ab8224320db0/CHANGELOG.md I have adjusted the CHANGELOG.md in such a way that with the next (patch/minor) release a mapping from "old state" to "new state" is made available. Do you think that this is sufficient?

Besides that, any other comments, e.g. on coding level?
I checked FB, and it finds this PR acceptable...

Copy link
Member

@pjdarton pjdarton left a comment

Choose a reason for hiding this comment

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

Overall I agree with what's being done here, but we need to undo the code churn on the import statements and the changelog.

*
* Label keys defined in this interface already have this namespace prefixed.
*/
static final String PLUGIN_LABEL_KEY_NAMESPACE = "com.nirima.jenkins.plugins.docker.";
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this needs to be visible outside this class.

I would also question if it would, in fact, be better to use .class.getPackage().getCanonicalName() + "." instead of hard-coding the text.
(I can see arguments for & against; I'm not too fussed either way, just as long as both options have been considered)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think this needs to be visible outside this class.

public interfaces in java do not permit to specify an attribute to be private. It'll mean that we would have to make it an abstract class, which also has a co-notation which I don't like (as we don't want to implement this artifact at all anyway).

On the other hand, we have the counter-example already in this plugin with com.nirima.jenkins.plugins.docker.utils.Consts. If we already have an approach for such cases, we should stick to one concept. I have adjusted it with 30c937b .

.class.getPackage().getCanonicalName() + "."

I did not think over that aspect too much yet. The only thing is that I always dislike, if constants change their value. That might happen, if someone is moving our own namespace around. However, on the other side, if somebody changes the namespace of this plugin, then it'll also be a good idea, if the constants will change (as most likely the "new version" of the plugin will be "something different").

I browsed a little through the coding. My impression is that it more tends to the concept of class-based reference than to absolute referencing. That is why I have adjusted the coding accordingly with 983fdc3.

CHANGELOG.md Outdated
@@ -1,5 +1,16 @@
# Changelog

## 1.1.x [draft only!]
Copy link
Member

Choose a reason for hiding this comment

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

I think this detailed explanation is best left to the PR description for this PR.
The changelog should just be one-line summaries with links to additional information as 99% of readers won't care about the details.

Also, I think it's best to leave updating the changelog itself to immediately after the official release because otherwise we might confuse people - the official wiki page links to this file in the master branch so the moment I merge changes it'll be visible to the masses, and folks will assume that if they have the latest release, they'll have all the changes listed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is wh I had marked it as "[draft only!]".
But I am ok with it that we remove the stuff in CHANGELOG.md and move it to a comment here.

I have done so with b058509

import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
Copy link
Member

Choose a reason for hiding this comment

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

I think you've allowed your IDE to re-arrange all the import statements here.
This makes it very difficult to see what changes have actually been made.

I'm not against changes that re-arrange the code for aesthetic reasons, but they should be kept separate from functional changes.

Copy link
Contributor Author

@eaglerainbow eaglerainbow Jun 10, 2018

Choose a reason for hiding this comment

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

I will comply to your request, but still I think it's wrong:
You are right that I have set up my IDE to automatically adjust imports. Imports, IMO, are (usually) just syntactic sugar, which I, as developer, do not need to take care of (I have plenty other things to do). These kind of activities do not change anything on semantic level.
If, by chance of this PR, we also clean up the code and don't need to start the entire CI for such a small thing, then this is good (I'd understand your concerns, if I had changed something in the coding, e.g. changes on sequence of methods, or such-a-like).
Would you have approved a PR, with only these aesthetic changes, if I had sent it separately?

reverted with 4ae4722

Copy link
Member

Choose a reason for hiding this comment

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

The idea is to ensure that important changes are kept to a minimalist set of changed lines of code so that they're easy to merge and will only cause merge conflicts of there is an actual conflict of functionality.

Aesthetic changes are also necessary to keep the code from getting too ugly but they do tend to touch lots and lots of lines of code when they happen, so they're almost impossible to merge with anything, so it's important that nobody ever needs to, which means that these kinds of changes have to be kept apart from functionality changes.

i.e. if you find the code intolerably ugly when working, and can't bear the thought of leaving it like that, do a tidy-up PR first ... or afterwards ... but not at the same time ;-)

import java.util.Map;

import static org.apache.commons.lang.StringUtils.isEmpty;
import static org.apache.commons.lang.StringUtils.trimToNull;
Copy link
Member

Choose a reason for hiding this comment

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

Import statement re-arrangement should not be part of this PR.
(Personally, I prefer to have static imports at the start too, but this is not what this PR is for)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see above.

Copy link
Contributor Author

@eaglerainbow eaglerainbow left a comment

Choose a reason for hiding this comment

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

all comments worked on. Back to you...

import java.util.Map;

import static org.apache.commons.lang.StringUtils.isEmpty;
import static org.apache.commons.lang.StringUtils.trimToNull;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

see above.

import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
Copy link
Contributor Author

@eaglerainbow eaglerainbow Jun 10, 2018

Choose a reason for hiding this comment

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

I will comply to your request, but still I think it's wrong:
You are right that I have set up my IDE to automatically adjust imports. Imports, IMO, are (usually) just syntactic sugar, which I, as developer, do not need to take care of (I have plenty other things to do). These kind of activities do not change anything on semantic level.
If, by chance of this PR, we also clean up the code and don't need to start the entire CI for such a small thing, then this is good (I'd understand your concerns, if I had changed something in the coding, e.g. changes on sequence of methods, or such-a-like).
Would you have approved a PR, with only these aesthetic changes, if I had sent it separately?

reverted with 4ae4722

*
* Label keys defined in this interface already have this namespace prefixed.
*/
static final String PLUGIN_LABEL_KEY_NAMESPACE = "com.nirima.jenkins.plugins.docker.";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think this needs to be visible outside this class.

public interfaces in java do not permit to specify an attribute to be private. It'll mean that we would have to make it an abstract class, which also has a co-notation which I don't like (as we don't want to implement this artifact at all anyway).

On the other hand, we have the counter-example already in this plugin with com.nirima.jenkins.plugins.docker.utils.Consts. If we already have an approach for such cases, we should stick to one concept. I have adjusted it with 30c937b .

.class.getPackage().getCanonicalName() + "."

I did not think over that aspect too much yet. The only thing is that I always dislike, if constants change their value. That might happen, if someone is moving our own namespace around. However, on the other side, if somebody changes the namespace of this plugin, then it'll also be a good idea, if the constants will change (as most likely the "new version" of the plugin will be "something different").

I browsed a little through the coding. My impression is that it more tends to the concept of class-based reference than to absolute referencing. That is why I have adjusted the coding accordingly with 983fdc3.

CHANGELOG.md Outdated
@@ -1,5 +1,16 @@
# Changelog

## 1.1.x [draft only!]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is wh I had marked it as "[draft only!]".
But I am ok with it that we remove the stuff in CHANGELOG.md and move it to a comment here.

I have done so with b058509

@pjdarton pjdarton merged commit 907a314 into jenkinsci:master Jun 10, 2018
@eaglerainbow eaglerainbow deleted the labelNamespace branch June 10, 2018 19:59
eaglerainbow added a commit to eaglerainbow/docker-plugin that referenced this pull request Jun 10, 2018
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.

2 participants