Skip to content

Commit

Permalink
Merge pull request #1 from Vlatombe/usage-restriction
Browse files Browse the repository at this point in the history
Usage restriction
  • Loading branch information
sixtyeight authored Jul 6, 2018
2 parents af6db40 + 3308580 commit f307c76
Show file tree
Hide file tree
Showing 23 changed files with 526 additions and 274 deletions.
38 changes: 38 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,44 @@ Known issues

See the full list of issues at [JIRA](https://issues.jenkins-ci.org/issues/?filter=15575)

Preserve resources other than CPU and memory

1.9.2
-----

* Combine all resources declared in requests and limits not just CPU and memory [#350](https://github.com/jenkinsci/kubernetes-plugin/pull/350)

1.9.1
-----

* Jenkins master in windows changes the file separator of `mountPath` incorrectly [#308](https://github.com/jenkinsci/kubernetes-plugin/pull/308) [JENKINS-47178](https://issues.jenkins-ci.org/browse/JENKINS-47178)

1.9.0
-----

* Update parent and Jenkins versions [#349](https://github.com/jenkinsci/kubernetes-plugin/pull/349)

1.8.4
-----

* Fix mountPath error provisioning `mountPath: Required value` [#346](https://github.com/jenkinsci/kubernetes-plugin/pull/346) [JENKINS-50525](https://issues.jenkins-ci.org/browse/JENKINS-50525)

1.8.3
-----

* Preserve unsupported directives in `PodTemplate` yaml, add explicit support for envFrom
[#348](https://github.com/jenkinsci/kubernetes-plugin/pull/348)

1.8.2
-----

* Do not emit empty strings for resource requests/limits
[#342](https://github.com/jenkinsci/kubernetes-plugin/pull/342)

1.8.1
-----
* Get the exit code the correct way. Solves problems with many pipeline steps that rely on tool outputs [#300](https://github.com/jenkinsci/kubernetes-plugin/pull/300) [JENKINS-50392](https://issues.jenkins-ci.org/browse/JENKINS-50392)

1.8.0
-----
* Validate label and container names with regex [#332](https://github.com/jenkinsci/kubernetes-plugin/pull/332) [#343](https://github.com/jenkinsci/kubernetes-plugin/pull/343) [JENKINS-51248](https://issues.jenkins-ci.org/browse/JENKINS-51248)
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM jenkins/jenkins:lts-alpine

ARG VERSION=1.7.0
ARG VERSION=1.9.2
RUN /usr/local/bin/install-plugins.sh kubernetes:${VERSION}

# COPY target/kubernetes.hpi /usr/share/jenkins/ref/plugins/kubernetes.hpi
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ spec:
}
```

You can use [`readFile` step](https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#code-readfile-code-read-file-from-workspace) to load the yaml from a file. It is also accessible from this plugin's configuration panel in the Jenkins console.
You can use [`readFile`](https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#code-readfile-code-read-file-from-workspace) or [`readTrusted`](https://jenkins.io/doc/pipeline/steps/coding-webhook/#readtrusted-read-trusted-file-from-scm) steps to load the yaml from a file. It is also accessible from this plugin's configuration panel in the Jenkins console.

#### Liveness Probe Usage
```groovy
Expand Down Expand Up @@ -702,4 +702,4 @@ Note: the JVM will use the memory `requests` as the heap limit (-Xmx)
# Related Projects

* [Kubernetes Pipeline plugin](https://github.com/jenkinsci/kubernetes-pipeline-plugin): pipeline extension to provide native support for using Kubernetes pods, secrets and volumes to perform builds
* [Kubernetes Secrets Credentials plugin](https://github.com/hoshsadiq/jenkins-kubernetes-secrets-credentials): Credentials provider that reads Kubernetes secrets
* [kubernetes-credentials](https://github.com/jenkinsci/kubernetes-credentials-plugin): Credentials provider that reads Kubernetes secrets
69 changes: 38 additions & 31 deletions examples/kaniko.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,43 @@
* https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/#create-a-secret-in-the-cluster-that-holds-your-authorization-token
*/

def label = "kaniko-${UUID.randomUUID().toString()}"
def label = "kaniko-${UUID.randomUUID().toString()}"

podTemplate(name: 'kaniko', label: label, yaml: """
kind: Pod
metadata:
name: kaniko
spec:
containers:
- name: kaniko
image: csanchez/kaniko:jenkins # we need a patched version of kaniko for now
imagePullPolicy: Always
command:
- cat
tty: true
volumeMounts:
- name: jenkins-docker-cfg
mountPath: /root
volumes:
- name: jenkins-docker-cfg
secret:
secretName: regcred
"""
) {
podTemplate(name: 'kaniko', label: label, yaml: """
kind: Pod
metadata:
name: kaniko
spec:
containers:
- name: kaniko
image: gcr.io/kaniko-project/executor:debug
imagePullPolicy: Always
command:
- /busybox/cat
tty: true
volumeMounts:
- name: jenkins-docker-cfg
mountPath: /root
volumes:
- name: jenkins-docker-cfg
projected:
sources:
- secret:
name: regcred
items:
- key: .dockerconfigjson
path: .docker/config.json
"""
) {

node(label) {
stage('Build with Kaniko') {
git 'https://github.com/jenkinsci/docker-jnlp-slave.git'
container('kaniko') {
sh '/kaniko/executor -c . --insecure-skip-tls-verify --destination=mydockerregistry:5000/myorg/myimage'
}
}
}
}
node(label) {
stage('Build with Kaniko') {
git 'https://github.com/jenkinsci/docker-jnlp-slave.git'
container(name: 'kaniko', shell: '/busybox/sh') {
sh '''#!/busybox/sh
/kaniko/executor -f `pwd`/Dockerfile -c `pwd` --insecure-skip-tls-verify --destination=mydockerregistry:5000/myorg/myimage
'''
}
}
}
}
68 changes: 23 additions & 45 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>3.0</version>
<version>3.12</version>
</parent>

<groupId>org.csanchez.jenkins.plugins</groupId>
<artifactId>kubernetes</artifactId>
<version>1.7.2-SNAPSHOT</version>
<version>1.9.3-SNAPSHOT</version>
<name>Kubernetes plugin</name>
<description>Jenkins plugin to run dynamic agents in a Kubernetes cluster</description>
<packaging>hpi</packaging>
Expand Down Expand Up @@ -40,39 +40,17 @@
<properties>
<!-- in minikube
minikube ip | sed -e 's/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1.1/' -->
<connectorHost></connectorHost>
<connectorHost />
<java.level>8</java.level>

<!-- dependency versions -->
<jenkins.version>2.32.1</jenkins.version>

<kubernetes-client.version>3.1.10</kubernetes-client.version>

<!-- jenkins plugins versions -->
<jenkins-basic-steps.version>2.3</jenkins-basic-steps.version>
<jenkins-credentials.version>2.1.11</jenkins-credentials.version>
<jenkins-kubernetes-credentials.version>0.3.0</jenkins-kubernetes-credentials.version>
<jenkins-durable-task.version>1.16</jenkins-durable-task.version>
<jenkins-durable-task-step.version>2.11</jenkins-durable-task-step.version>
<jenkins-structs.version>1.6</jenkins-structs.version>
<jenkins-workflow-cps.version>2.29</jenkins-workflow-cps.version>
<jenkins-workflow-job.version>2.9</jenkins-workflow-job.version>
<jenkins-workflow-step-api.version>2.11</jenkins-workflow-step-api.version>
<jenkins-workflow-support.version>2.14</jenkins-workflow-support.version>
<jenkins-workflow-api.version>2.11</jenkins-workflow-api.version>
<jenkins-workflow-scm-step.version>2.4</jenkins-workflow-scm-step.version>
<jenkins-scm-api.version>2.0.7</jenkins-scm-api.version>
<jenkins-declarative.version>1.1.2</jenkins-declarative.version>
<jenkins-script-security.version>1.26</jenkins-script-security.version>

<jenkins.version>2.107.3</jenkins.version>
<no-test-jar>false</no-test-jar>
</properties>

<dependencies>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
<version>${kubernetes-client.version}</version>
<version>3.2.0</version>
<exclusions>
<!-- Jackson logic comes from plugins -->
<exclusion>
Expand Down Expand Up @@ -100,7 +78,7 @@
<dependency>
<groupId>org.jenkinsci.plugins</groupId>
<artifactId>kubernetes-credentials</artifactId>
<version>${jenkins-kubernetes-credentials.version}</version>
<version>0.3.0</version>
</dependency>

<dependency> <!-- Requires Permission -->
Expand All @@ -112,7 +90,7 @@
<dependency> <!-- OnceRetentionStrategy -->
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>durable-task</artifactId>
<version>${jenkins-durable-task.version}</version>
<version>1.16</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand All @@ -122,82 +100,82 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>${jenkins-workflow-step-api.version}</version>
<version>2.11</version>
</dependency>
<dependency> <!-- DeclarativeAgent -->
<groupId>org.jenkinsci.plugins</groupId>
<artifactId>pipeline-model-extensions</artifactId>
<version>${jenkins-declarative.version}</version>
<version>1.1.2</version>
<optional>true</optional>
</dependency>

<!-- for testing -->
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-job</artifactId>
<version>${jenkins-workflow-job.version}</version>
<version>2.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-basic-steps</artifactId>
<version>${jenkins-basic-steps.version}</version>
<version>2.3</version>
<scope>test</scope>
</dependency>
<dependency> <!-- StepConfigTester -->
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>${jenkins-workflow-step-api.version}</version>
<version>2.11</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-support</artifactId>
<version>${jenkins-workflow-support.version}</version>
<version>2.14</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-durable-task-step</artifactId>
<version>${jenkins-durable-task-step.version}</version>
<version>2.11</version>
<scope>test</scope>
</dependency>
<dependency> <!-- SemaphoreStep -->
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-support</artifactId>
<version>${jenkins-workflow-support.version}</version>
<version>2.14</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-scm-step</artifactId>
<version>${jenkins-workflow-scm-step.version}</version>
<version>2.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>scm-api</artifactId>
<version>${jenkins-scm-api.version}</version>
<version>2.0.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkinsci.plugins</groupId>
<artifactId>pipeline-model-definition</artifactId>
<version>${jenkins-declarative.version}</version>
<version>1.1.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-api</artifactId>
<version>${jenkins-workflow-api.version}</version>
<version>2.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<version>${jenkins-workflow-cps.version}</version>
<version>2.29</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -233,7 +211,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials</artifactId>
<version>${jenkins-credentials.version}</version>
<version>2.1.11</version>
</dependency>

<!-- just to fix enforcer RequireUpperBoundDeps -->
Expand All @@ -245,7 +223,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
<version>${jenkins-structs.version}</version>
<version>1.6</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand All @@ -255,7 +233,7 @@
<dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-core</artifactId>
<version>1.6.0</version>
<version>1.7.0</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.google.common.base.Preconditions;

import hudson.Extension;
import hudson.Util;
import hudson.model.AbstractDescribableImpl;
import hudson.model.Descriptor;
import hudson.model.DescriptorVisibilityFilter;
Expand Down Expand Up @@ -151,7 +152,7 @@ public String getDisplayName() {

@DataBoundSetter
public void setWorkingDir(String workingDir) {
this.workingDir = workingDir;
this.workingDir = Util.fixEmpty(workingDir);
}

public String getWorkingDir() {
Expand Down Expand Up @@ -238,6 +239,15 @@ public void setResourceRequestCpu(String resourceRequestCpu) {
this.resourceRequestCpu = resourceRequestCpu;
}

public String getShell() {
return shell;
}

@DataBoundSetter
public void setShell(String shell) {
this.shell = shell;
}

public Map<String,Object> getAsArgs() {
Map<String,Object> argMap = new TreeMap<>();

Expand Down Expand Up @@ -374,12 +384,8 @@ public int hashCode() {
return result;
}

public String getShell() {
return shell;
}

@DataBoundSetter
public void setShell(String shell) {
this.shell = shell;
private Object readResolve() {
this.workingDir = Util.fixEmpty(workingDir);
return this;
}
}
Loading

0 comments on commit f307c76

Please sign in to comment.