This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
forked from Sh4d1/drone-kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extensionsv1beta1.go
177 lines (151 loc) · 4.23 KB
/
extensionsv1beta1.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package main
import (
"log"
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/typed/extensions/v1beta1"
)
func applyDeploymentExtensionsV1beta1(deployment *extensionsv1beta1.Deployment, deploymentSet v1beta1.DeploymentInterface) error {
deploymentName := deployment.GetObjectMeta().GetName()
deployments, err := deploymentSet.List(metav1.ListOptions{})
if err != nil {
log.Println("Error when listing deployments")
return err
}
update := false
for _, dep := range deployments.Items {
if dep.GetObjectMeta().GetName() == deploymentName {
update = true
}
}
if update {
_, err := deploymentSet.Get(deploymentName, metav1.GetOptions{})
if err != nil {
log.Println("Error when getting old deployment")
return err
}
_, err = deploymentSet.Update(deployment)
if err != nil {
log.Println("Error when updating deployment")
return err
}
log.Println("Deployment " + deploymentName + " updated")
return err
} else {
_, err := deploymentSet.Create(deployment)
if err != nil {
log.Println("Error when creating deployment")
return err
}
log.Println("Deployment " + deploymentName + " created")
return err
}
}
func applyDaemonSetExtensionsV1beta1(daemonSet *extensionsv1beta1.DaemonSet, daemonSetSet v1beta1.DaemonSetInterface) error {
daemonSetName := daemonSet.GetObjectMeta().GetName()
daemonSets, err := daemonSetSet.List(metav1.ListOptions{})
if err != nil {
log.Println("Error when listing daemon sets")
return err
}
update := false
for _, dep := range daemonSets.Items {
if dep.GetObjectMeta().GetName() == daemonSetName {
update = true
}
}
if update {
_, err := daemonSetSet.Get(daemonSetName, metav1.GetOptions{})
if err != nil {
log.Println("Error when getting old daemon set")
return err
}
_, err = daemonSetSet.Update(daemonSet)
if err != nil {
log.Println("Error when updating daemonSet")
return err
}
log.Println("Deployment " + daemonSetName + " updated")
return err
} else {
_, err := daemonSetSet.Create(daemonSet)
if err != nil {
log.Println("Error when creating daemonSet")
return err
}
log.Println("Deployment " + daemonSetName + " created")
return err
}
}
func applyReplicaSetExtensionsV1beta1(replicaSet *extensionsv1beta1.ReplicaSet, replicaSetSet v1beta1.ReplicaSetInterface) error {
replicaSetName := replicaSet.GetObjectMeta().GetName()
replicaSets, err := replicaSetSet.List(metav1.ListOptions{})
if err != nil {
log.Println("Error when listing replica sets")
return err
}
update := false
for _, rep := range replicaSets.Items {
if rep.GetObjectMeta().GetName() == replicaSetName {
update = true
}
}
if update {
_, err := replicaSetSet.Get(replicaSetName, metav1.GetOptions{})
if err != nil {
log.Println("Error when getting old replica set")
return err
}
_, err = replicaSetSet.Update(replicaSet)
if err != nil {
log.Println("Error when updating replicaSet")
return err
}
log.Println("ReplicaSet " + replicaSetName + " updated")
return err
} else {
_, err := replicaSetSet.Create(replicaSet)
if err != nil {
log.Println("Error when creating replicaSet")
return err
}
log.Println("ReplicaSet " + replicaSetName + " created")
return err
}
}
func applyIngressExtensionsV1beta1(ingress *extensionsv1beta1.Ingress, ingressSet v1beta1.IngressInterface) error {
ingressName := ingress.GetObjectMeta().GetName()
ingresss, err := ingressSet.List(metav1.ListOptions{})
if err != nil {
log.Println("Error when listing ingress")
return err
}
update := false
for _, ing := range ingresss.Items {
if ing.GetObjectMeta().GetName() == ingressName {
update = true
}
}
if update {
_, err := ingressSet.Get(ingressName, metav1.GetOptions{})
if err != nil {
log.Println("Error when getting old ingress")
return err
}
_, err = ingressSet.Update(ingress)
if err != nil {
log.Println("Error when updating ingress")
return err
}
log.Println("Ingress " + ingressName + " updated")
return err
} else {
_, err := ingressSet.Create(ingress)
if err != nil {
log.Println("Error when creating ingress")
return err
}
log.Println("Ingress " + ingressName + " created")
return err
}
}