-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
57 lines (45 loc) · 1.43 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
52
53
54
55
56
57
package main
import (
"context"
"time"
"github.com/sethvargo/go-githubactions"
"k8s.io/client-go/kubernetes"
_ "k8s.io/client-go/plugin/pkg/client/auth"
)
func main() {
action := githubactions.New()
input := ActionInput{
kubeconfigFile: action.GetInput("kubeconfig-file"),
clusterURL: action.GetInput("cluster-url"),
clusterToken: action.GetInput("cluster-token"),
namespace: action.GetInput("namespace"),
image: action.GetInput("image"),
jobName: action.GetInput("job-name"),
caFile: action.GetInput("ca-file"),
allowInsecure: action.GetInput("allow-insecure"),
}
action.Debugf("kubeconfig input %s\n", input.kubeconfigFile)
config, err := BuildK8sConfig(input)
if err != nil {
action.Fatalf("%v", err)
}
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
action.Fatalf("%v", err)
}
action = action.WithFieldsMap(map[string]string{
"job": input.jobName,
})
runner := NewJobRunner(clientset.BatchV1().Jobs(input.namespace), clientset.CoreV1().Pods(input.namespace), 5*time.Second, action)
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Minute)
logs, err := runner.RunJob(ctx, input.jobName, input.namespace, input.image)
defer cancel()
if err != nil {
if len(logs) == 0 {
action.Fatalf("%v", err)
} else {
action.Fatalf("job failed\njob logs:\n%s", logs)
}
}
action.Debugf("job completed successfully\njob logs:\n%s", logs)
}