Skip to content

Commit c7e8b09

Browse files
committed
etcd-manager: Use image volumes to mount etcd images
1 parent 200ce48 commit c7e8b09

File tree

3 files changed

+107
-142
lines changed

3 files changed

+107
-142
lines changed

pkg/model/components/etcdmanager/model.go

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ func (b *EtcdManagerBuilder) buildPod(etcdCluster kops.EtcdClusterSpec, instance
236236
}
237237
}
238238

239-
{
239+
if b.Cluster.Spec.Containerd == nil || strings.HasPrefix(fi.ValueOf(b.Cluster.Spec.Containerd.Version), "1.") {
240240
utilMounts := []v1.VolumeMount{
241241
{
242242
MountPath: "/opt",
@@ -316,6 +316,31 @@ func (b *EtcdManagerBuilder) buildPod(etcdCluster kops.EtcdClusterSpec, instance
316316
initContainer := &pod.Spec.InitContainers[i]
317317
initContainer.Image = b.AssetBuilder.RemapImage(initContainer.Image)
318318
}
319+
} else {
320+
if b.Cluster.Spec.ControlPlaneKubelet == nil {
321+
b.Cluster.Spec.ControlPlaneKubelet = &kops.KubeletConfigSpec{}
322+
}
323+
if b.Cluster.Spec.ControlPlaneKubelet.FeatureGates == nil {
324+
b.Cluster.Spec.ControlPlaneKubelet.FeatureGates = make(map[string]string)
325+
}
326+
if _, found := b.Cluster.Spec.ControlPlaneKubelet.FeatureGates["ImageVolume"]; !found && b.IsKubernetesLT("1.35") {
327+
b.Cluster.Spec.ControlPlaneKubelet.FeatureGates["ImageVolume"] = "true"
328+
}
329+
330+
for _, etcdVersion := range etcdSupportedVersions() {
331+
if etcdVersion.SymlinkToVersion == "" {
332+
volume := v1.Volume{
333+
Name: "etcd-v" + strings.ReplaceAll(etcdVersion.Version, ".", "-"),
334+
VolumeSource: v1.VolumeSource{
335+
Image: &v1.ImageVolumeSource{
336+
Reference: b.AssetBuilder.RemapImage(etcdVersion.Image),
337+
PullPolicy: v1.PullIfNotPresent,
338+
},
339+
},
340+
}
341+
pod.Spec.Volumes = append(pod.Spec.Volumes, volume)
342+
}
343+
}
319344
}
320345

321346
{
@@ -331,6 +356,20 @@ func (b *EtcdManagerBuilder) buildPod(etcdCluster kops.EtcdClusterSpec, instance
331356

332357
// Remap image via AssetBuilder
333358
container.Image = b.AssetBuilder.RemapImage(container.Image)
359+
360+
if b.Cluster.Spec.Containerd != nil && !strings.HasPrefix(fi.ValueOf(b.Cluster.Spec.Containerd.Version), "1.") {
361+
for _, etcdVersion := range etcdSupportedVersions() {
362+
volumeMount := v1.VolumeMount{
363+
MountPath: "/opt/etcd-v" + etcdVersion.Version,
364+
}
365+
if etcdVersion.SymlinkToVersion == "" {
366+
volumeMount.Name = "etcd-v" + strings.ReplaceAll(etcdVersion.Version, ".", "-")
367+
} else {
368+
volumeMount.Name = "etcd-v" + strings.ReplaceAll(etcdVersion.SymlinkToVersion, ".", "-")
369+
}
370+
container.VolumeMounts = append(container.VolumeMounts, volumeMount)
371+
}
372+
}
334373
}
335374

336375
var clientHost string

pkg/model/components/etcdmanager/tests/minimal/cluster.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ spec:
2828
provider: Manager
2929
backups:
3030
backupStore: memfs://clusters.example.com/minimal.example.com/backups/etcd-events
31-
kubernetesVersion: v1.21.0
31+
containerd:
32+
version: 2.1.4
33+
kubernetesVersion: v1.33.0
3234
masterPublicName: api.minimal.example.com
3335
networkCIDR: 172.20.0.0/16
3436
networking:

pkg/model/components/etcdmanager/tests/minimal/tasks.yaml

Lines changed: 64 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -102,80 +102,34 @@ Contents: |
102102
name: pki
103103
- mountPath: /opt
104104
name: opt
105+
- mountPath: /opt/etcd-v3.4.13
106+
name: etcd-v3-4-13
107+
- mountPath: /opt/etcd-v3.4.3
108+
name: etcd-v3-4-13
109+
- mountPath: /opt/etcd-v3.5.0
110+
name: etcd-v3-5-21
111+
- mountPath: /opt/etcd-v3.5.1
112+
name: etcd-v3-5-21
113+
- mountPath: /opt/etcd-v3.5.13
114+
name: etcd-v3-5-21
115+
- mountPath: /opt/etcd-v3.5.17
116+
name: etcd-v3-5-21
117+
- mountPath: /opt/etcd-v3.5.21
118+
name: etcd-v3-5-21
119+
- mountPath: /opt/etcd-v3.5.3
120+
name: etcd-v3-5-21
121+
- mountPath: /opt/etcd-v3.5.4
122+
name: etcd-v3-5-21
123+
- mountPath: /opt/etcd-v3.5.6
124+
name: etcd-v3-5-21
125+
- mountPath: /opt/etcd-v3.5.7
126+
name: etcd-v3-5-21
127+
- mountPath: /opt/etcd-v3.5.9
128+
name: etcd-v3-5-21
105129
- mountPath: /var/log/etcd.log
106130
name: varlogetcd
107131
hostNetwork: true
108132
hostPID: true
109-
initContainers:
110-
- args:
111-
- --target-dir=/opt/kops-utils/
112-
- --src=/ko-app/kops-utils-cp
113-
command:
114-
- /ko-app/kops-utils-cp
115-
image: registry.k8s.io/kops/kops-utils-cp:1.33.0-beta.1
116-
name: kops-utils-cp
117-
resources: {}
118-
volumeMounts:
119-
- mountPath: /opt
120-
name: opt
121-
- args:
122-
- --target-dir=/opt/etcd-v3.4.13
123-
- --src=/usr/local/bin/etcd
124-
- --src=/usr/local/bin/etcdctl
125-
command:
126-
- /opt/kops-utils/kops-utils-cp
127-
image: registry.k8s.io/etcd:v3.4.13
128-
name: init-etcd-3-4-13
129-
resources: {}
130-
volumeMounts:
131-
- mountPath: /opt
132-
name: opt
133-
- args:
134-
- --target-dir=/opt/etcd-v3.5.21
135-
- --src=/usr/local/bin/etcd
136-
- --src=/usr/local/bin/etcdctl
137-
command:
138-
- /opt/kops-utils/kops-utils-cp
139-
image: registry.k8s.io/etcd:v3.5.21
140-
name: init-etcd-3-5-21
141-
resources: {}
142-
volumeMounts:
143-
- mountPath: /opt
144-
name: opt
145-
- args:
146-
- --symlink
147-
- --target-dir=/opt/etcd-v3.4.3
148-
- --src=/opt/etcd-v3.4.13/etcd
149-
- --src=/opt/etcd-v3.4.13/etcdctl
150-
command:
151-
- /opt/kops-utils/kops-utils-cp
152-
image: registry.k8s.io/kops/kops-utils-cp:1.33.0-beta.1
153-
name: init-etcd-symlinks-3-4-13
154-
resources: {}
155-
volumeMounts:
156-
- mountPath: /opt
157-
name: opt
158-
- args:
159-
- --symlink
160-
- --target-dir=/opt/etcd-v3.5.0
161-
- --target-dir=/opt/etcd-v3.5.1
162-
- --target-dir=/opt/etcd-v3.5.13
163-
- --target-dir=/opt/etcd-v3.5.17
164-
- --target-dir=/opt/etcd-v3.5.3
165-
- --target-dir=/opt/etcd-v3.5.4
166-
- --target-dir=/opt/etcd-v3.5.6
167-
- --target-dir=/opt/etcd-v3.5.7
168-
- --target-dir=/opt/etcd-v3.5.9
169-
- --src=/opt/etcd-v3.5.21/etcd
170-
- --src=/opt/etcd-v3.5.21/etcdctl
171-
command:
172-
- /opt/kops-utils/kops-utils-cp
173-
image: registry.k8s.io/kops/kops-utils-cp:1.33.0-beta.1
174-
name: init-etcd-symlinks-3-5-21
175-
resources: {}
176-
volumeMounts:
177-
- mountPath: /opt
178-
name: opt
179133
priorityClassName: system-cluster-critical
180134
tolerations:
181135
- key: CriticalAddonsOnly
@@ -195,6 +149,14 @@ Contents: |
195149
name: pki
196150
- emptyDir: {}
197151
name: opt
152+
- image:
153+
pullPolicy: IfNotPresent
154+
reference: registry.k8s.io/etcd:v3.4.13
155+
name: etcd-v3-4-13
156+
- image:
157+
pullPolicy: IfNotPresent
158+
reference: registry.k8s.io/etcd:v3.5.21
159+
name: etcd-v3-5-21
198160
- hostPath:
199161
path: /var/log/etcd-events.log
200162
type: FileOrCreate
@@ -244,80 +206,34 @@ Contents: |
244206
name: pki
245207
- mountPath: /opt
246208
name: opt
209+
- mountPath: /opt/etcd-v3.4.13
210+
name: etcd-v3-4-13
211+
- mountPath: /opt/etcd-v3.4.3
212+
name: etcd-v3-4-13
213+
- mountPath: /opt/etcd-v3.5.0
214+
name: etcd-v3-5-21
215+
- mountPath: /opt/etcd-v3.5.1
216+
name: etcd-v3-5-21
217+
- mountPath: /opt/etcd-v3.5.13
218+
name: etcd-v3-5-21
219+
- mountPath: /opt/etcd-v3.5.17
220+
name: etcd-v3-5-21
221+
- mountPath: /opt/etcd-v3.5.21
222+
name: etcd-v3-5-21
223+
- mountPath: /opt/etcd-v3.5.3
224+
name: etcd-v3-5-21
225+
- mountPath: /opt/etcd-v3.5.4
226+
name: etcd-v3-5-21
227+
- mountPath: /opt/etcd-v3.5.6
228+
name: etcd-v3-5-21
229+
- mountPath: /opt/etcd-v3.5.7
230+
name: etcd-v3-5-21
231+
- mountPath: /opt/etcd-v3.5.9
232+
name: etcd-v3-5-21
247233
- mountPath: /var/log/etcd.log
248234
name: varlogetcd
249235
hostNetwork: true
250236
hostPID: true
251-
initContainers:
252-
- args:
253-
- --target-dir=/opt/kops-utils/
254-
- --src=/ko-app/kops-utils-cp
255-
command:
256-
- /ko-app/kops-utils-cp
257-
image: registry.k8s.io/kops/kops-utils-cp:1.33.0-beta.1
258-
name: kops-utils-cp
259-
resources: {}
260-
volumeMounts:
261-
- mountPath: /opt
262-
name: opt
263-
- args:
264-
- --target-dir=/opt/etcd-v3.4.13
265-
- --src=/usr/local/bin/etcd
266-
- --src=/usr/local/bin/etcdctl
267-
command:
268-
- /opt/kops-utils/kops-utils-cp
269-
image: registry.k8s.io/etcd:v3.4.13
270-
name: init-etcd-3-4-13
271-
resources: {}
272-
volumeMounts:
273-
- mountPath: /opt
274-
name: opt
275-
- args:
276-
- --target-dir=/opt/etcd-v3.5.21
277-
- --src=/usr/local/bin/etcd
278-
- --src=/usr/local/bin/etcdctl
279-
command:
280-
- /opt/kops-utils/kops-utils-cp
281-
image: registry.k8s.io/etcd:v3.5.21
282-
name: init-etcd-3-5-21
283-
resources: {}
284-
volumeMounts:
285-
- mountPath: /opt
286-
name: opt
287-
- args:
288-
- --symlink
289-
- --target-dir=/opt/etcd-v3.4.3
290-
- --src=/opt/etcd-v3.4.13/etcd
291-
- --src=/opt/etcd-v3.4.13/etcdctl
292-
command:
293-
- /opt/kops-utils/kops-utils-cp
294-
image: registry.k8s.io/kops/kops-utils-cp:1.33.0-beta.1
295-
name: init-etcd-symlinks-3-4-13
296-
resources: {}
297-
volumeMounts:
298-
- mountPath: /opt
299-
name: opt
300-
- args:
301-
- --symlink
302-
- --target-dir=/opt/etcd-v3.5.0
303-
- --target-dir=/opt/etcd-v3.5.1
304-
- --target-dir=/opt/etcd-v3.5.13
305-
- --target-dir=/opt/etcd-v3.5.17
306-
- --target-dir=/opt/etcd-v3.5.3
307-
- --target-dir=/opt/etcd-v3.5.4
308-
- --target-dir=/opt/etcd-v3.5.6
309-
- --target-dir=/opt/etcd-v3.5.7
310-
- --target-dir=/opt/etcd-v3.5.9
311-
- --src=/opt/etcd-v3.5.21/etcd
312-
- --src=/opt/etcd-v3.5.21/etcdctl
313-
command:
314-
- /opt/kops-utils/kops-utils-cp
315-
image: registry.k8s.io/kops/kops-utils-cp:1.33.0-beta.1
316-
name: init-etcd-symlinks-3-5-21
317-
resources: {}
318-
volumeMounts:
319-
- mountPath: /opt
320-
name: opt
321237
priorityClassName: system-cluster-critical
322238
tolerations:
323239
- key: CriticalAddonsOnly
@@ -337,6 +253,14 @@ Contents: |
337253
name: pki
338254
- emptyDir: {}
339255
name: opt
256+
- image:
257+
pullPolicy: IfNotPresent
258+
reference: registry.k8s.io/etcd:v3.4.13
259+
name: etcd-v3-4-13
260+
- image:
261+
pullPolicy: IfNotPresent
262+
reference: registry.k8s.io/etcd:v3.5.21
263+
name: etcd-v3-5-21
340264
- hostPath:
341265
path: /var/log/etcd.log
342266
type: FileOrCreate

0 commit comments

Comments
 (0)