-
Notifications
You must be signed in to change notification settings - Fork 168
/
Copy pathmain.go
51 lines (44 loc) · 1.13 KB
/
main.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
package main
import (
log "github.com/sirupsen/logrus"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"github.com/caicloud/cyclone/pkg/cicd/cd"
)
func main() {
configure, err := cd.LoadConfig()
if err != nil {
log.Fatal(err)
}
log.Infof("To update %s: '%s/%s'", configure.Deployment.Type, configure.Deployment.Namespace, configure.Deployment.Name)
for _, u := range configure.Images {
log.Infof("Container: %s --> %s", u.Container, u.Image)
}
client := getClient("")
err = cd.UpdateDeployment(client, configure)
if err != nil {
log.Errorf("%v", err)
log.Fatal(err)
}
}
func getClient(kubeConfigPath string) kubernetes.Interface {
var config *rest.Config
var err error
if kubeConfigPath != "" {
config, err = clientcmd.BuildConfigFromFlags("", kubeConfigPath)
if err != nil {
log.Fatalf("create config error: %v", err)
}
} else {
config, err = rest.InClusterConfig()
if err != nil {
log.Fatalf("create config error: %v", err)
}
}
client, err := kubernetes.NewForConfig(config)
if err != nil {
log.Fatalf("create client error: %v", err)
}
return client
}