This repository has been archived by the owner on Dec 30, 2020. It is now read-only.
/
kubernetes.go
69 lines (64 loc) · 1.76 KB
/
kubernetes.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
package actions
import (
"fmt"
"github.com/AlexsJones/gravitywell/configuration"
"github.com/AlexsJones/gravitywell/kinds"
"github.com/AlexsJones/gravitywell/platform"
logger "github.com/sirupsen/logrus"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"os"
"path"
"path/filepath"
"strconv"
)
func clientForCluster(clusterName string) (*rest.Config, kubernetes.Interface) {
logger.Info(fmt.Sprintf("\n\nSwitching to cluster: %s\n\n", clusterName))
restclient, k8siface, err := platform.GetKubeClient(clusterName)
if err != nil {
logger.Error(err.Error())
os.Exit(1)
}
return restclient, k8siface
}
func ExecuteKubernetesAction(action kinds.Execute, clusterName string,
deployment kinds.Application,
commandFlag configuration.CommandFlag, opt configuration.Options, repoName string) {
var deploymentPath = "."
shouldAwaitDeployment := false
if tp, ok := action.Configuration["Path"]; ok && tp != "" {
deploymentPath = tp
}
if tp, ok := action.Configuration["AwaitDeployment"]; ok && tp != "" {
b, err := strconv.ParseBool(tp)
if err != nil {
logger.Error(err.Error())
}
shouldAwaitDeployment = b
}
fileList := []string{}
err := filepath.Walk(path.Join(opt.TempVCSPath,
repoName, deploymentPath),
func(path string, f os.FileInfo, err error) error {
if err != nil {
return err
}
if f.IsDir() {
logger.Info("Ignoring directory %s", fmt.Sprintf(path))
return nil
}
fileList = append(fileList, path)
return nil
})
if err != nil {
logger.Fatal(err.Error())
}
_, k8siface := clientForCluster(clusterName)
err = platform.GenerateDeploymentPlan(
k8siface, fileList,
deployment.Namespace, opt, commandFlag, shouldAwaitDeployment)
if err != nil {
logger.Error(err.Error())
}
//---------------------------------
}