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
/
appsv1beta1.go
93 lines (79 loc) · 2.24 KB
/
appsv1beta1.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
package main
import (
"log"
appsv1beta1 "k8s.io/api/apps/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/typed/apps/v1beta1"
)
func applyDeploymentAppsV1beta1(deployment *appsv1beta1.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 applyStatefulSetAppsV1beta1(statefulSet *appsv1beta1.StatefulSet, statefulSetSet v1beta1.StatefulSetInterface) error {
statefulSetName := statefulSet.GetObjectMeta().GetName()
statefulSets, err := statefulSetSet.List(metav1.ListOptions{})
if err != nil {
log.Println("Error when listing stateful sets")
return err
}
update := false
for _, sta := range statefulSets.Items {
if sta.GetObjectMeta().GetName() == statefulSetName {
update = true
}
}
if update {
_, err := statefulSetSet.Get(statefulSetName, metav1.GetOptions{})
if err != nil {
log.Println("Error when getting old stateful set")
return err
}
_, err = statefulSetSet.Update(statefulSet)
if err != nil {
log.Println("Error when updating statefulSet")
return err
}
log.Println("StatefulSet " + statefulSetName + " updated")
return err
} else {
_, err := statefulSetSet.Create(statefulSet)
if err != nil {
log.Println("Error when creating statefulSet")
return err
}
log.Println("StatefulSet " + statefulSetName + " created")
return err
}
}