-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
63 lines (58 loc) · 1.88 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
58
59
60
61
62
63
package main
import (
"flag"
"fmt"
"io"
"log"
"os"
"github.com/galleybytes/monitor/projects/terraform-operator-remote-controller/internal/tfhandler"
"github.com/galleybytes/monitor/projects/terraform-operator-remote-controller/pkg/tfoapiclient"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog/v2"
)
func kubernetesConfig(kubeconfigPath string) *rest.Config {
config, err := clientcmd.BuildConfigFromFlags("", kubeconfigPath)
if err != nil {
log.Fatal("Failed to get config for clientset")
}
return config
}
func readFile(filename string) []byte {
if filename == "" {
return []byte{}
}
b, err := os.ReadFile(filename)
if err != nil {
log.Panic(err)
}
return b
}
func main() {
var insecureSkipVerify bool
klog.InitFlags(flag.CommandLine)
flag.BoolVar(&insecureSkipVerify, "insecure-skip-verify", false, "Allow conneting to API server without unverified HTTPS")
flag.Parse()
flag.Set("logtostderr", "false")
flag.Set("alsologtostderr", "false")
klog.SetOutput(io.Discard)
kubeconfig := os.Getenv("KUBECONFIG")
clientName := os.Getenv("CLIENT_NAME")
proto := os.Getenv("TFO_API_PROTOCOL")
host := os.Getenv("TFO_API_HOST")
port := os.Getenv("TFO_API_PORT")
user := os.Getenv("TFO_API_LOGIN_USER")
password := os.Getenv("TFO_API_LOGIN_PASSWORD")
clusterManifest := readFile(os.Getenv("TFO_API_CLUSTER_MANIFEST"))
vClusterManifest := readFile(os.Getenv("TFO_API_VCLUSTER_MANIFEST"))
postJobContainerImage := os.Getenv("POST_JOB_CONTAINER_IMAGE")
url := fmt.Sprintf("%s://%s:%s", proto, host, port)
clientSetup := tfoapiclient.ClientSetup{
ClusterName: clientName,
ClusterManifest: clusterManifest,
VClusterManifest: vClusterManifest,
}
tfinformer := tfhandler.NewInformer(kubernetesConfig(kubeconfig), clientSetup, url, user, password, insecureSkipVerify, postJobContainerImage)
tfinformer.Run()
os.Exit(1) // should this be 0 instead?
}