Skip to content

Commit 285ee36

Browse files
committed
Merge branch 'master' into JENKINS-63847
2 parents bf74076 + 2b2b0ce commit 285ee36

File tree

17 files changed

+131
-51
lines changed

17 files changed

+131
-51
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,28 @@ pipeline {
494494
}
495495
```
496496

497+
Run steps within a container by default. Steps will be nested within an implicit `container(name) {...}` block instead
498+
of being executed in the jnlp container.
499+
500+
```
501+
pipeline {
502+
agent {
503+
kubernetes {
504+
defaultContainer 'maven'
505+
yamlFile 'KubernetesPod.yaml'
506+
}
507+
}
508+
509+
stages {
510+
stage('Run maven') {
511+
steps {
512+
sh 'mvn -version'
513+
}
514+
}
515+
}
516+
}
517+
```
518+
497519
Run the Pipeline or individual stage within a custom workspace - not required unless explicitly stated.
498520

499521
```

examples/kaniko-declarative.groovy

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ spec:
2424
image: gcr.io/kaniko-project/executor:debug-539ddefcae3fd6b411a95982a830d987f4214251
2525
imagePullPolicy: Always
2626
command:
27-
- /busybox/cat
28-
tty: true
27+
- sleep
28+
args:
29+
- 9999999
2930
volumeMounts:
3031
- name: jenkins-docker-cfg
3132
mountPath: /kaniko/.docker

examples/kaniko-gcr.groovy

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ spec:
1616
image: gcr.io/kaniko-project/executor:debug
1717
imagePullPolicy: Always
1818
command:
19-
- /busybox/cat
20-
tty: true
19+
- sleep
20+
args:
21+
- 9999999
2122
volumeMounts:
2223
- name: kaniko-secret
2324
mountPath: /secret

examples/multi-container.groovy

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ spec:
99
containers:
1010
- name: maven
1111
image: maven:3.3.9-jdk-8-alpine
12-
command: ['cat']
13-
tty: true
12+
command:
13+
- sleep
14+
args:
15+
- 9999999
1416
- name: golang
1517
image: golang:1.8.0
16-
command: ['cat']
17-
tty: true
18+
command:
19+
- sleep
20+
args:
21+
- 9999999
1822
"""
1923
) {
2024

examples/openshift-home-yaml.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ spec:
1818
value: /home/jenkins
1919
- name: maven
2020
image: maven:3.6.3-jdk-8
21-
command: ['cat']
22-
tty: true
21+
command: ['sleep']
22+
args: ['9999999']
2323
volumeMounts:
2424
- name: home-volume
2525
mountPath: /home/jenkins

examples/selenium.groovy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ spec:
1010
containers:
1111
- name: maven-firefox
1212
image: maven:3.3.9-jdk-8-alpine
13-
command: ['cat']
14-
tty: true
13+
command: ['sleep']
14+
args: ['9999999']
1515
- name: maven-chrome
1616
image: maven:3.3.9-jdk-8-alpine
17-
command: ['cat']
18-
tty: true
17+
command: ['sleep']
18+
args: ['9999999']
1919
- name: selenium-hub
2020
image: selenium/hub:3.4.0
2121
- name: selenium-chrome

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
</developers>
4040

4141
<properties>
42-
<revision>1.28.5</revision>
42+
<revision>1.28.6</revision>
4343
<changelist>-SNAPSHOT</changelist>
4444
<!-- in minikube
4545
minikube ip | sed -e 's/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1.1/' -->

src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesComputer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void taskCompletedWithProblems(Executor executor, Queue.Task task, long d
6969

7070
@Exported
7171
public List<Container> getContainers() throws KubernetesAuthException, IOException {
72-
if(!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
72+
if(!Jenkins.get().hasPermission(Computer.EXTENDED_READ)) {
7373
LOGGER.log(Level.FINE, " Computer {0} getContainers, lack of admin permission, returning empty list", this);
7474
return Collections.emptyList();
7575
}
@@ -90,7 +90,7 @@ public List<Container> getContainers() throws KubernetesAuthException, IOExcepti
9090

9191
@Exported
9292
public List<Event> getPodEvents() throws KubernetesAuthException, IOException {
93-
if(!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
93+
if(!Jenkins.get().hasPermission(Computer.EXTENDED_READ)) {
9494
LOGGER.log(Level.FINE, " Computer {0} getPodEvents, lack of admin permission, returning empty list", this);
9595
return Collections.emptyList();
9696
}
@@ -124,7 +124,7 @@ public List<Event> getPodEvents() throws KubernetesAuthException, IOException {
124124

125125
public void doContainerLog(@QueryParameter String containerId,
126126
StaplerRequest req, StaplerResponse rsp) throws KubernetesAuthException, IOException {
127-
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
127+
Jenkins.get().checkPermission(Computer.EXTENDED_READ);
128128

129129
ByteBuffer outputStream = new ByteBuffer();
130130
KubernetesSlave slave = getNode();

src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesLauncher.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,19 @@ public synchronized void launch(SlaveComputer computer, TaskListener listener) {
138138
Metrics.metricRegistry().counter(MetricNames.CREATION_FAILED).inc();
139139
int httpCode = e.getCode();
140140
if (400 <= httpCode && httpCode < 500) { // 4xx
141-
runListener.getLogger().printf("ERROR: Unable to create pod %s %s/%s.%n%s%n", cloudName, namespace, pod.getMetadata().getName(), e.getMessage());
142-
PodUtils.cancelQueueItemFor(pod, e.getMessage());
141+
if (httpCode == 403 && e.getMessage().contains("is forbidden: exceeded quota")) {
142+
runListener.getLogger().printf("WARNING: Unable to create pod: %s %s/%s because kubernetes resource quota exceeded. %n%s%nRetrying...%n%n",
143+
cloudName, namespace, pod.getMetadata().getName(), e.getMessage());
144+
}
145+
else if (httpCode == 409 && e.getMessage().contains("Operation cannot be fulfilled on resourcequotas")) {
146+
// See: https://github.com/kubernetes/kubernetes/issues/67761 ; A retry usually works.
147+
runListener.getLogger().printf("WARNING: Unable to create pod: %s %s/%s because kubernetes resource quota update conflict. %n%s%nRetrying...%n%n",
148+
cloudName, namespace, pod.getMetadata().getName(), e.getMessage());
149+
}
150+
else {
151+
runListener.getLogger().printf("ERROR: Unable to create pod %s %s/%s.%n%s%n", cloudName, namespace, pod.getMetadata().getName(), e.getMessage());
152+
PodUtils.cancelQueueItemFor(pod, e.getMessage());
153+
}
143154
} else if (500 <= httpCode && httpCode < 600) { // 5xx
144155
LOGGER.log(FINE,"Kubernetes returned HTTP code {0} {1}. Retrying...", new Object[] {e.getCode(), e.getStatus()});
145156
} else {

src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/ContainerExecDecorator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ private Proc doLaunch(boolean quiet, String[] cmdEnvs, OutputStream outputForCal
363363
}
364364

365365
// Send to proc caller as well if they sent one
366-
if (outputForCaller != null && !outputForCaller.equals(stream)) {
366+
if (outputForCaller != null && !outputForCaller.equals(printStream)) {
367367
stream = new TeeOutputStream(outputForCaller, stream);
368368
}
369369
ByteArrayOutputStream error = new ByteArrayOutputStream();

0 commit comments

Comments
 (0)