Skip to content

Commit fb357e7

Browse files
committed
e2e: kubectl rollout daemonset
1 parent 07e714c commit fb357e7

File tree

7 files changed

+425
-0
lines changed

7 files changed

+425
-0
lines changed
Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
/*
2+
Copyright 2021 The Kubernetes Authors.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
package io.kubernetes.client.e2e.kubectl
14+
15+
import io.kubernetes.client.openapi.models.V1Deployment
16+
import io.kubernetes.client.openapi.models.V1StatefulSet
17+
18+
import java.nio.charset.StandardCharsets
19+
20+
import io.kubernetes.client.extended.kubectl.History
21+
import io.kubernetes.client.extended.kubectl.Kubectl
22+
import io.kubernetes.client.openapi.Configuration
23+
import io.kubernetes.client.openapi.models.V1DaemonSet
24+
import io.kubernetes.client.openapi.models.V1PodTemplateSpec
25+
import io.kubernetes.client.util.ClientBuilder
26+
import io.kubernetes.client.util.Streams
27+
import io.kubernetes.client.util.Yaml
28+
import spock.lang.Specification
29+
30+
class KubectlRolloutTest extends Specification {
31+
32+
def "Kubectl rollout daemonset should work"() {
33+
given:
34+
def apiClient = ClientBuilder.defaultClient()
35+
Configuration.setDefaultApiClient(apiClient)
36+
// initial daemonset has only one container
37+
def daemonSet = Yaml.load(getResourceFileAsString("test-daemonset.yaml"))
38+
// updating daemonset has two containers
39+
def updatingDaemonSet = Yaml.load(getResourceFileAsString("test-daemonset-updated.yaml"))
40+
41+
when:
42+
def createdDaemonSet = Kubectl.create(V1DaemonSet.class)
43+
.resource(daemonSet)
44+
.execute()
45+
then:
46+
createdDaemonSet != null
47+
48+
when:
49+
List<History> histories = Kubectl.rollout(V1DaemonSet.class)
50+
.history()
51+
.namespace(daemonSet.metadata.namespace)
52+
.name(daemonSet.metadata.name)
53+
.execute()
54+
then:
55+
histories.size() == 1
56+
57+
58+
when:
59+
def updatedDaemonSet = Kubectl.replace(V1DaemonSet.class)
60+
.resource(updatingDaemonSet)
61+
.execute()
62+
then:
63+
updatedDaemonSet != null
64+
65+
when:
66+
histories = Kubectl.rollout(V1DaemonSet.class)
67+
.history()
68+
.namespace(daemonSet.metadata.namespace)
69+
.name(daemonSet.metadata.name)
70+
.execute()
71+
then:
72+
histories.size() == 2
73+
74+
when:
75+
V1PodTemplateSpec template = Kubectl.rollout(V1DaemonSet.class)
76+
.history()
77+
.revision(2)
78+
.namespace(daemonSet.metadata.namespace)
79+
.name(daemonSet.metadata.name)
80+
.execute()
81+
then:
82+
template != null
83+
template.spec.containers.size() == 2
84+
85+
cleanup:
86+
Kubectl.delete(V1DaemonSet.class)
87+
.namespace(daemonSet.metadata.namespace)
88+
.name(daemonSet.metadata.name)
89+
.execute()
90+
}
91+
92+
93+
def "Kubectl rollout deployment should work"() {
94+
given:
95+
def apiClient = ClientBuilder.defaultClient()
96+
Configuration.setDefaultApiClient(apiClient)
97+
// initial deployment has only one container
98+
def deployment = Yaml.load(getResourceFileAsString("test-deployment.yaml"))
99+
// updating deployment has two containers
100+
def updatingDeployment = Yaml.load(getResourceFileAsString("test-deployment-updated.yaml"))
101+
102+
when:
103+
def createdDeployment = Kubectl.create(V1Deployment.class)
104+
.resource(deployment)
105+
.execute()
106+
then:
107+
createdDeployment != null
108+
109+
when:
110+
List<History> histories = Kubectl.rollout(V1Deployment.class)
111+
.history()
112+
.namespace(deployment.metadata.namespace)
113+
.name(deployment.metadata.name)
114+
.execute()
115+
then:
116+
histories.size() == 1
117+
118+
119+
when:
120+
def updatedDaemonSet = Kubectl.replace(V1Deployment.class)
121+
.resource(updatingDeployment)
122+
.execute()
123+
then:
124+
updatedDaemonSet != null
125+
126+
when:
127+
histories = Kubectl.rollout(V1Deployment.class)
128+
.history()
129+
.namespace(deployment.metadata.namespace)
130+
.name(deployment.metadata.name)
131+
.execute()
132+
then:
133+
histories.size() == 2
134+
135+
when:
136+
V1PodTemplateSpec template = Kubectl.rollout(V1Deployment.class)
137+
.history()
138+
.revision(2)
139+
.namespace(deployment.metadata.namespace)
140+
.name(deployment.metadata.name)
141+
.execute()
142+
then:
143+
template != null
144+
template.spec.containers.size() == 2
145+
146+
cleanup:
147+
Kubectl.delete(V1Deployment.class)
148+
.namespace(deployment.metadata.namespace)
149+
.name(deployment.metadata.name)
150+
.execute()
151+
}
152+
153+
154+
155+
def "Kubectl rollout statefulset should work"() {
156+
given:
157+
def apiClient = ClientBuilder.defaultClient()
158+
Configuration.setDefaultApiClient(apiClient)
159+
// initial deployment has only one container
160+
def statefulset = Yaml.load(getResourceFileAsString("test-statefulset.yaml"))
161+
// updating deployment has two containers
162+
def updatingStatefulSet = Yaml.load(getResourceFileAsString("test-statefulset-updated.yaml"))
163+
164+
when:
165+
def createdStatefulSet = Kubectl.create(V1StatefulSet.class)
166+
.resource(statefulset)
167+
.execute()
168+
then:
169+
createdStatefulSet != null
170+
171+
when:
172+
List<History> histories = Kubectl.rollout(V1StatefulSet.class)
173+
.history()
174+
.namespace(statefulset.metadata.namespace)
175+
.name(statefulset.metadata.name)
176+
.execute()
177+
then:
178+
histories.size() == 1
179+
180+
181+
when:
182+
def updatedDaemonSet = Kubectl.replace(V1StatefulSet.class)
183+
.resource(updatingStatefulSet)
184+
.execute()
185+
then:
186+
updatedDaemonSet != null
187+
188+
when:
189+
histories = Kubectl.rollout(V1StatefulSet.class)
190+
.history()
191+
.namespace(statefulset.metadata.namespace)
192+
.name(statefulset.metadata.name)
193+
.execute()
194+
then:
195+
histories.size() == 2
196+
197+
when:
198+
V1PodTemplateSpec template = Kubectl.rollout(V1StatefulSet.class)
199+
.history()
200+
.revision(2)
201+
.namespace(statefulset.metadata.namespace)
202+
.name(statefulset.metadata.name)
203+
.execute()
204+
then:
205+
template != null
206+
template.spec.containers.size() == 2
207+
208+
cleanup:
209+
Kubectl.delete(V1StatefulSet.class)
210+
.namespace(statefulset.metadata.namespace)
211+
.name(statefulset.metadata.name)
212+
.execute()
213+
}
214+
215+
216+
217+
218+
private String getResourceFileAsString(String filename) {
219+
def url = this.getClass().getClassLoader().getResource(filename)
220+
return Streams.toString(new InputStreamReader(url.openStream(), StandardCharsets.UTF_8));
221+
}
222+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
apiVersion: apps/v1
2+
kind: DaemonSet
3+
metadata:
4+
name: fluentd-elasticsearch
5+
namespace: default
6+
labels:
7+
k8s-app: fluentd-logging
8+
spec:
9+
selector:
10+
matchLabels:
11+
name: fluentd-elasticsearch
12+
template:
13+
metadata:
14+
labels:
15+
name: fluentd-elasticsearch
16+
spec:
17+
tolerations:
18+
# this toleration is to have the daemonset runnable on master nodes
19+
# remove it if your masters can't run pods
20+
- key: node-role.kubernetes.io/master
21+
operator: Exists
22+
effect: NoSchedule
23+
containers:
24+
- name: fluentd-elasticsearch
25+
image: quay.io/fluentd_elasticsearch/fluentd:v2.5.2
26+
resources:
27+
limits:
28+
memory: 200Mi
29+
requests:
30+
cpu: 100m
31+
memory: 200Mi
32+
volumeMounts:
33+
- name: varlog
34+
mountPath: /var/log
35+
- name: varlibdockercontainers
36+
mountPath: /var/lib/docker/containers
37+
readOnly: true
38+
- name: fluentd-elasticsearch-2
39+
image: quay.io/fluentd_elasticsearch/fluentd:v2.5.2
40+
resources:
41+
limits:
42+
memory: 200Mi
43+
requests:
44+
cpu: 100m
45+
memory: 200Mi
46+
volumeMounts:
47+
- name: varlog
48+
mountPath: /var/log
49+
- name: varlibdockercontainers
50+
mountPath: /var/lib/docker/containers
51+
readOnly: true
52+
terminationGracePeriodSeconds: 30
53+
volumes:
54+
- name: varlog
55+
hostPath:
56+
path: /var/log
57+
- name: varlibdockercontainers
58+
hostPath:
59+
path: /var/lib/docker/containers
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
apiVersion: apps/v1
2+
kind: DaemonSet
3+
metadata:
4+
name: fluentd-elasticsearch
5+
namespace: default
6+
labels:
7+
k8s-app: fluentd-logging
8+
spec:
9+
selector:
10+
matchLabels:
11+
name: fluentd-elasticsearch
12+
template:
13+
metadata:
14+
labels:
15+
name: fluentd-elasticsearch
16+
spec:
17+
tolerations:
18+
# this toleration is to have the daemonset runnable on master nodes
19+
# remove it if your masters can't run pods
20+
- key: node-role.kubernetes.io/master
21+
operator: Exists
22+
effect: NoSchedule
23+
containers:
24+
- name: fluentd-elasticsearch
25+
image: quay.io/fluentd_elasticsearch/fluentd:v2.5.2
26+
resources:
27+
limits:
28+
memory: 200Mi
29+
requests:
30+
cpu: 100m
31+
memory: 200Mi
32+
volumeMounts:
33+
- name: varlog
34+
mountPath: /var/log
35+
- name: varlibdockercontainers
36+
mountPath: /var/lib/docker/containers
37+
readOnly: true
38+
terminationGracePeriodSeconds: 30
39+
volumes:
40+
- name: varlog
41+
hostPath:
42+
path: /var/log
43+
- name: varlibdockercontainers
44+
hostPath:
45+
path: /var/lib/docker/containers
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: nginx-deployment
5+
namespace: default
6+
labels:
7+
app: nginx
8+
spec:
9+
replicas: 3
10+
selector:
11+
matchLabels:
12+
app: nginx
13+
template:
14+
metadata:
15+
labels:
16+
app: nginx
17+
spec:
18+
containers:
19+
- name: nginx
20+
image: nginx:1.14.2
21+
ports:
22+
- containerPort: 80
23+
- name: nginx-2
24+
image: nginx:1.14.2
25+
ports:
26+
- containerPort: 80
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: nginx-deployment
5+
namespace: default
6+
labels:
7+
app: nginx
8+
spec:
9+
replicas: 3
10+
selector:
11+
matchLabels:
12+
app: nginx
13+
template:
14+
metadata:
15+
labels:
16+
app: nginx
17+
spec:
18+
containers:
19+
- name: nginx
20+
image: nginx:1.14.2
21+
ports:
22+
- containerPort: 80

0 commit comments

Comments
 (0)