-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[JENKINS-58670] Pod Labels UI #551
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodLabel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package org.csanchez.jenkins.plugins.kubernetes; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import hudson.Extension; | ||
import hudson.model.AbstractDescribableImpl; | ||
import hudson.model.Descriptor; | ||
import org.jenkinsci.Symbol; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
import javax.validation.constraints.NotNull; | ||
import java.io.Serializable; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.csanchez.jenkins.plugins.kubernetes.PodTemplateUtils.substituteEnv; | ||
|
||
public class PodLabel extends AbstractDescribableImpl<PodLabel> implements Serializable { | ||
|
||
private static final long serialVersionUID = -5667326362260252552L; | ||
|
||
private String key; | ||
private String value; | ||
|
||
@DataBoundConstructor | ||
public PodLabel(String key, String value) { | ||
this.key = key; | ||
this.value = value; | ||
} | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
|
||
public void setKey(String key) { | ||
this.key = key; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
public void setValue(String value) { | ||
this.value = value; | ||
} | ||
|
||
/** | ||
* Create map from collection of labels. Values that environment variables placeholders will be resolved. | ||
* @see PodTemplateUtils#substituteEnv(String) | ||
* @param labels collection of pod labels to convert to a map | ||
* @return immutable map of pod labels | ||
*/ | ||
@NotNull | ||
static Map<String, String> toMap(@NotNull Iterable<PodLabel> labels) { | ||
ImmutableMap.Builder<String, String> builder = ImmutableMap.<String, String>builder(); | ||
if (labels != null) { | ||
for (PodLabel podLabel : labels) { | ||
builder.put(podLabel.getKey(), substituteEnv(podLabel.getValue())); | ||
} | ||
} | ||
return builder.build(); | ||
} | ||
|
||
/** | ||
* Create list of pod labels from a map of label key values. | ||
* @param labels labels map | ||
* @return list of pod labels | ||
*/ | ||
@NotNull | ||
static List<PodLabel> fromMap(@NotNull Map<String, String> labels) { | ||
List<PodLabel> list = new ArrayList<>(); | ||
for (Map.Entry<String, String> label : labels.entrySet()) { | ||
list.add(new PodLabel(label.getKey(), label.getValue())); | ||
} | ||
return list; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
PodLabel that = (PodLabel) o; | ||
|
||
return key != null ? key.equals(that.key) : that.key == null; | ||
|
||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return key != null ? key.hashCode() : 0; | ||
} | ||
|
||
@Extension | ||
@Symbol("podLabel") | ||
public static class DescriptorImpl extends Descriptor<PodLabel> { | ||
@Override | ||
public String getDisplayName() { | ||
return "Pod Label"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/resources/org/csanchez/jenkins/plugins/kubernetes/KubernetesCloud/help-labels.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<div> | ||
<a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/labels">Labels</a> | ||
for all Pods started by the plugin. Pods that match these labels count toward the <strong>Concurrency Limit</strong>. | ||
<p> | ||
If not configured, all Pods will be created with <code>jenkins=slave</code> by default. | ||
</p> | ||
<p>Examples: | ||
<ul> | ||
<li><code>jenkins=slave</code></li> | ||
<li><code>app.kubernetes.io/managed-by=jenkins</code></li> | ||
<li><code>app.kubernetes.io/part-of=cicd</code></li> | ||
</ul> | ||
</p> | ||
</div> |
16 changes: 16 additions & 0 deletions
16
src/main/resources/org/csanchez/jenkins/plugins/kubernetes/PodLabel/config.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!-- | ||
Config page | ||
--> | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" | ||
xmlns:t="/lib/hudson" xmlns:f="/lib/form"> | ||
|
||
<f:entry field="key" title="${%Key}"> | ||
<f:textbox/> | ||
</f:entry> | ||
|
||
<f:entry field="value" title="${%Value}"> | ||
<f:textbox/> | ||
</f:entry> | ||
|
||
</j:jelly> |
24 changes: 24 additions & 0 deletions
24
src/main/resources/org/csanchez/jenkins/plugins/kubernetes/PodLabel/config_zh_CN.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# The MIT License | ||
# | ||
# Copyright (c) 2018, Alauda | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
# THE SOFTWARE. | ||
|
||
Key=\u952E | ||
Value=\u503C |
6 changes: 6 additions & 0 deletions
6
src/main/resources/org/csanchez/jenkins/plugins/kubernetes/PodLabel/help-key.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Valid label keys have two segments: an optional prefix and name, separated by a slash (<code>/</code>). The name | ||
segment is required and must be 63 characters or less, beginning and ending with an alphanumeric character | ||
(<code>[a-z0-9A-Z]</code>) with dashes (<code>-</code>), underscores (<code>_</code>), dots (<code>.</code>), and | ||
alphanumerics between. The prefix is optional. If specified, the prefix must be a DNS subdomain: a series of DNS | ||
labels separated by dots (<code>.</code>), not longer than 253 characters in total, followed by a slash (<code>/</code>). | ||
|
3 changes: 3 additions & 0 deletions
3
src/main/resources/org/csanchez/jenkins/plugins/kubernetes/PodLabel/help-value.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Valid label values must be 63 characters or less and must be empty or begin and end with an alphanumeric character | ||
(<code>[a-z0-9A-Z]</code>) with dashes (<code>-</code>), underscores (<code>_</code>), dots (<code>.</code>), | ||
and alphanumerics between. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
To achieve backward compatibility, you need to keep the old field as
@deprecated / transient
, then migrate the data inreadResolve()
method.