-
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
Port mapping #165
Merged
Merged
Port mapping #165
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1156fcb
add port mapping
derfred 10e2123
update readme
derfred e611b2f
add UI for exposing ports
derfred 7d07776
add guard for upgrades
derfred 5572422
Added Help Document for the the port mapping
a892171
Clear out any ports and then add the new ones.
2d2d89b
Address Code Review Comments
4900c73
Remove null check.
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
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
118 changes: 118 additions & 0 deletions
118
src/main/java/org/csanchez/jenkins/plugins/kubernetes/PortMapping.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,118 @@ | ||
package org.csanchez.jenkins.plugins.kubernetes; | ||
|
||
import hudson.Extension; | ||
import hudson.model.AbstractDescribableImpl; | ||
import hudson.model.Descriptor; | ||
import org.jenkinsci.Symbol; | ||
import io.fabric8.kubernetes.api.model.ContainerPort; | ||
|
||
import java.io.Serializable; | ||
|
||
import org.kohsuke.stapler.DataBoundConstructor; | ||
import org.kohsuke.stapler.DataBoundSetter; | ||
|
||
public class PortMapping extends AbstractDescribableImpl<PortMapping> implements Serializable { | ||
|
||
private String name; | ||
private Integer containerPort; | ||
private Integer hostPort; | ||
|
||
@DataBoundConstructor | ||
public PortMapping(String name, Integer containerPort) { | ||
this.name = name; | ||
this.containerPort = containerPort; | ||
} | ||
|
||
public PortMapping(String name, Integer containerPort, Integer hostPort) { | ||
this.name = name; | ||
this.containerPort = containerPort; | ||
this.hostPort = hostPort; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setContainerPort(Integer containerPort) { | ||
this.containerPort = containerPort; | ||
} | ||
|
||
public Integer getContainerPort() { | ||
return containerPort; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setHostPort(Integer hostPort) { | ||
this.hostPort = hostPort; | ||
} | ||
|
||
public Integer getHostPort() { | ||
return hostPort; | ||
} | ||
|
||
public ContainerPort toPort() { | ||
ContainerPort p = new ContainerPort(); | ||
p.setName(name); | ||
p.setContainerPort(containerPort); | ||
if(hostPort != null) { | ||
p.setHostPort(hostPort); | ||
} | ||
return p; | ||
} | ||
|
||
public String toString() { | ||
return String.format("%s,%d", name, containerPort); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
final int prime = 31; | ||
int result = 1; | ||
result = prime * result + ((name == null) ? 0 : name.hashCode()); | ||
result = prime * result + ((containerPort == null) ? 0 : containerPort); | ||
result = prime * result + ((hostPort == null) ? 0 : hostPort); | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) | ||
return true; | ||
if (obj == null) | ||
return false; | ||
if (getClass() != obj.getClass()) | ||
return false; | ||
PortMapping other = (PortMapping) obj; | ||
if (name == null) { | ||
if (other.name != null) | ||
return false; | ||
} else if (!name.equals(other.name)) | ||
return false; | ||
if (containerPort == null) { | ||
if (other.containerPort != null) | ||
return false; | ||
} else if (!containerPort.equals(other.containerPort)) | ||
return false; | ||
if (hostPort == null) { | ||
if (other.hostPort != null) | ||
return false; | ||
} else if (!hostPort.equals(other.hostPort)) | ||
return false; | ||
return true; | ||
} | ||
|
||
@Extension | ||
@Symbol("portMapping") | ||
public static class DescriptorImpl extends Descriptor<PortMapping> { | ||
@Override | ||
public String getDisplayName() { | ||
return "Container Exposed Ports"; | ||
} | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
src/main/resources/org/csanchez/jenkins/plugins/kubernetes/PortMapping/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,20 @@ | ||
<!-- | ||
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="name" title="${%Name}"> | ||
<f:textbox/> | ||
</f:entry> | ||
|
||
<f:entry field="containerPort" title="${%ContainerPort}"> | ||
<f:textbox/> | ||
</f:entry> | ||
|
||
<f:entry field="hostPort" title="${%HostPort}"> | ||
<f:textbox/> | ||
</f:entry> | ||
|
||
</j:jelly> |
1 change: 1 addition & 0 deletions
1
...ain/resources/org/csanchez/jenkins/plugins/kubernetes/PortMapping/help-containerPort.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 @@ | ||
Port to expose into the pod |
1 change: 1 addition & 0 deletions
1
src/main/resources/org/csanchez/jenkins/plugins/kubernetes/PortMapping/help-hostPort.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 @@ | ||
Port to expose onto the host |
1 change: 1 addition & 0 deletions
1
src/main/resources/org/csanchez/jenkins/plugins/kubernetes/PortMapping/help-name.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 @@ | ||
The name of the port |
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.
no need to check for null now