forked from UKHomeOffice-attic/drone-kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkube.go
97 lines (89 loc) · 1.85 KB
/
kube.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
package main
import (
"fmt"
"log"
"strings"
"time"
)
func zeroReplicas(artifact Artifact, token string) (bool, error) {
if debug {
log.Println("zeroReplicas")
}
json := `{"spec": {"replicas": 0}}`
req := ReqEnvelope{
Verb: "PATCH",
Token: token,
Url: fmt.Sprintf("%s/%s", artifact.Url, artifact.Metadata.Name),
Json: []byte(json),
}
res, err := doRequest(req)
if err != nil {
log.Fatal(err)
}
time.Sleep(time.Second * 5)
return res, err
}
func deleteArtifact(artifact Artifact, token string) (bool, error) {
if debug {
log.Println("deleteArtifact")
}
if strings.Contains(artifact.Kind, "ReplicationController") {
res, err := zeroReplicas(artifact, token)
if err != nil {
log.Fatal(err)
}
if res {
if debug {
log.Println("Replicas set to Zero")
}
}
}
url := fmt.Sprintf("%s/%s", artifact.Url, artifact.Metadata.Name)
if debug {
log.Println(url)
}
param := ReqEnvelope{
Url: url,
Token: token,
Verb: "DELETE",
}
return doRequest(param)
}
func existsArtifact(artifact Artifact, token string) (bool, error) {
aUrl := fmt.Sprintf("%s/%s", artifact.Url, artifact.Metadata.Name)
if debug {
log.Println("existsArtifact " + aUrl)
}
req := ReqEnvelope{
Url: aUrl,
Token: token,
Verb: "GET",
}
return doRequest(req)
}
func createArtifact(artifact Artifact, token string) {
if debug {
log.Println("createArtifact ")
}
deployments = append(deployments, artifact.Metadata.Name)
param := ReqEnvelope{
Url: artifact.Url,
Token: token,
Json: artifact.Data,
Verb: "POST",
}
doRequest(param)
}
func updateArtifact(artifact Artifact, token string) {
if debug {
log.Println("updateArtifact ")
}
artifact.Url = fmt.Sprintf("%s/%s", artifact.Url, artifact.Metadata.Name)
param := ReqEnvelope{
Url: artifact.Url,
Token: token,
Json: artifact.Data,
Verb: "PUT",
}
doRequest(param)
}