forked from keel-hq/keel
/
converter.go
63 lines (48 loc) · 1.62 KB
/
converter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package k8s
import (
apps_v1 "k8s.io/api/apps/v1"
v1beta1 "k8s.io/api/batch/v1beta1"
core_v1 "k8s.io/api/core/v1"
)
func getContainerImages(containers []core_v1.Container) []string {
var images []string
for _, c := range containers {
images = append(images, c.Image)
}
return images
}
func getImagePullSecrets(imagePullSecrets []core_v1.LocalObjectReference) []string {
var secrets []string
for _, s := range imagePullSecrets {
secrets = append(secrets, s.Name)
}
return secrets
}
// deployments
func getDeploymentIdentifier(d *apps_v1.Deployment) string {
return "deployment/" + d.Namespace + "/" + d.Name
}
func updateDeploymentContainer(d *apps_v1.Deployment, index int, image string) {
d.Spec.Template.Spec.Containers[index].Image = image
}
// stateful sets https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/
func getStatefulSetIdentifier(ss *apps_v1.StatefulSet) string {
return "statefulset/" + ss.Namespace + "/" + ss.Name
}
func updateStatefulSetContainer(ss *apps_v1.StatefulSet, index int, image string) {
ss.Spec.Template.Spec.Containers[index].Image = image
}
// daemonsets
func getDaemonsetSetIdentifier(s *apps_v1.DaemonSet) string {
return "daemonset/" + s.Namespace + "/" + s.Name
}
func updateDaemonsetSetContainer(s *apps_v1.DaemonSet, index int, image string) {
s.Spec.Template.Spec.Containers[index].Image = image
}
// cron
func getCronJobIdentifier(s *v1beta1.CronJob) string {
return "cronjob/" + s.Namespace + "/" + s.Name
}
func updateCronJobContainer(s *v1beta1.CronJob, index int, image string) {
s.Spec.JobTemplate.Spec.Template.Spec.Containers[index].Image = image
}