-
Notifications
You must be signed in to change notification settings - Fork 16
/
main.go
83 lines (70 loc) · 2.22 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"fmt"
"os"
"github.com/rancher/wrangler/pkg/kubeconfig"
"github.com/rancher/wrangler/pkg/schemes"
"github.com/rancher/wrangler/pkg/signals"
"github.com/sirupsen/logrus"
cli "github.com/urfave/cli/v2"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/rest"
apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
kubevirtv1 "kubevirt.io/api/core/v1"
harvesternetworkv1beta1 "github.com/harvester/harvester-network-controller/pkg/apis/network.harvesterhci.io/v1beta1"
"github.com/harvester/pcidevices/pkg/apis/devices.harvesterhci.io/v1beta1"
"github.com/harvester/pcidevices/pkg/controller"
)
const (
VERSION = "v0.1.0"
controllerName = "pcidevices-controller"
)
var (
localSchemeBuilder = runtime.SchemeBuilder{
v1beta1.AddToScheme,
}
AddToScheme = localSchemeBuilder.AddToScheme
Scheme = runtime.NewScheme()
)
func init() {
utilruntime.Must(AddToScheme(Scheme))
utilruntime.Must(schemes.AddToScheme(Scheme))
utilruntime.Must(apiregistrationv1.AddToScheme(Scheme))
utilruntime.Must(kubevirtv1.AddToScheme(Scheme))
utilruntime.Must(harvesternetworkv1beta1.AddToScheme(Scheme))
if debug := os.Getenv("DEBUG_LOGGING"); debug == "true" {
logrus.SetLevel(logrus.DebugLevel)
}
}
func main() {
// set up the kubeconfig and other args
var kubeConfig string
app := cli.NewApp()
app.Name = controllerName
app.Version = VERSION
app.Usage = "Harvester PCI Devices Controller, to discover PCI devices on the nodes of a cluster. Also manages PCI Device Claims, for use in PCI passthrough."
app.Flags = []cli.Flag{
&cli.StringFlag{
Name: "kubeconfig",
EnvVars: []string{"KUBECONFIG"},
Destination: &kubeConfig,
Usage: "Kube config for accessing k8s cluster",
},
}
app.Action = func(_ *cli.Context) error {
return run(kubeConfig)
}
if err := app.Run(os.Args); err != nil {
logrus.Fatal(err)
}
}
func run(kubeConfig string) error {
ctx := signals.SetupSignalContext()
var cfg *rest.Config
cfg, err := kubeconfig.GetNonInteractiveClientConfig(kubeConfig).ClientConfig()
if err != nil {
return fmt.Errorf("failed to find kubeconfig: %v", err)
}
return controller.Setup(ctx, cfg, Scheme)
}