-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.go
40 lines (38 loc) · 1.26 KB
/
deploy.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
package main
import (
"context"
"fmt"
"strings"
)
func deploy(status cloudBuilderStatus) error {
fmt.Println("DEPLOYING " + status.Images[0])
client, err := kubeConnect()
if err != nil {
return err
}
image := strings.Split(status.Images[0], ":")[0]
fmt.Println("Scanning cluster for namespaces...")
ctx := context.Background()
namespaces, err := client.CoreV1().ListNamespaces(ctx)
for _, namespace := range namespaces.Items {
fmt.Println("Scanning cluster for deployments...")
deployments, _ := client.ExtensionsV1Beta1().ListDeployments(ctx, namespace.Metadata.GetName())
for _, deployment := range deployments.Items {
_, ci := deployment.GetMetadata().GetAnnotations()["kube-ci"]
fmt.Println("Skipped deployment " + deployment.GetMetadata().GetName())
if !ci {
continue
}
fmt.Println("Deploying on " + deployment.GetMetadata().GetName())
for _, container := range deployment.Spec.Template.Spec.Containers {
if strings.HasPrefix(container.GetImage(), image) {
fmt.Println("Setting container " + container.GetName() + " image")
container.Image = &status.Images[0]
}
}
fmt.Println("Updating deployment " + deployment.GetMetadata().GetName())
client.ExtensionsV1Beta1().UpdateDeployment(ctx, deployment)
}
}
return nil
}