forked from nais/naisd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
naisd.go
58 lines (43 loc) · 1.33 KB
/
naisd.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
package main
import (
"flag"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"net/http"
"github.com/golang/glog"
"github.com/nais/naisd/api"
)
const Port string = ":8081"
func main() {
kubeconfig := flag.String("kubeconfig", "", "Path to a kubeconfig file")
fasitUrl := flag.String("fasit-url", "https://fasit.example.no", "URL to fasit instance")
clusterSubdomain := flag.String("cluster-subdomain", "nais-example.nais.example.no", "Cluster sub-domain")
flag.Parse()
glog.Infof("using fasit instance %s", *fasitUrl)
glog.Infof("running on port %s", Port)
err := http.ListenAndServe(Port, api.Api{newClientSet(*kubeconfig), *fasitUrl, *clusterSubdomain}.NewApi())
if err != nil {
panic(err)
}
}
// returns config using kubeconfig if provided, else from cluster context
func newClientSet(kubeconfig string) kubernetes.Interface {
var config *rest.Config
var err error
if kubeconfig != "" {
glog.Infof("using provided kubeconfig")
config, err = clientcmd.BuildConfigFromFlags("", kubeconfig)
} else {
glog.Infof("no kubeconfig provided, assuming we are running inside a cluster")
config, err = rest.InClusterConfig()
}
if err != nil {
panic(err.Error())
}
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
panic(err.Error())
}
return clientset
}