-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
139 lines (112 loc) · 4.59 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package main
import (
"context"
"github.com/giantswarm/microerror"
"github.com/giantswarm/microkit/command"
microserver "github.com/giantswarm/microkit/server"
"github.com/giantswarm/micrologger"
"github.com/spf13/viper"
"github.com/giantswarm/cluster-operator/v5/flag"
"github.com/giantswarm/cluster-operator/v5/pkg/project"
"github.com/giantswarm/cluster-operator/v5/server"
"github.com/giantswarm/cluster-operator/v5/service"
)
var (
f = flag.New()
)
func main() {
err := mainE()
if err != nil {
panic(microerror.JSON(err))
}
}
func mainE() error {
var err error
ctx := context.Background()
// Create a new logger that is used by all packages.
var newLogger micrologger.Logger
{
newLogger, err = micrologger.New(micrologger.Config{})
if err != nil {
return microerror.Mask(err)
}
}
// Define server factory to create the custom server once all command line
// flags are parsed and all microservice configuration is processed.
newServerFactory := func(v *viper.Viper) microserver.Server {
// New custom service implements the business logic.
var newService *service.Service
{
serviceConfig := service.Config{
Flag: f,
Logger: newLogger,
Viper: v,
Description: project.Description(),
GitCommit: project.GitSHA(),
ProjectName: project.Name(),
Source: project.Source(),
Version: project.Version(),
}
newService, err = service.New(serviceConfig)
if err != nil {
panic(microerror.JSON(err))
}
go newService.Boot(ctx)
}
// New custom server that bundles microkit endpoints.
var newServer microserver.Server
{
c := server.Config{
Logger: newLogger,
Service: newService,
Viper: v,
ProjectName: project.Name(),
}
newServer, err = server.New(c)
if err != nil {
panic(microerror.JSON(err))
}
}
return newServer
}
// Create a new microkit command that manages operator daemon.
var newCommand command.Command
{
c := command.Config{
Logger: newLogger,
ServerFactory: newServerFactory,
Description: project.Description(),
GitCommit: project.GitSHA(),
Name: project.Name(),
Source: project.Source(),
Version: project.Version(),
}
newCommand, err = command.New(c)
if err != nil {
return microerror.Mask(err)
}
}
daemonCommand := newCommand.DaemonCommand().CobraCommand()
daemonCommand.PersistentFlags().String(f.Guest.Cluster.Calico.CIDR, "", "Prefix length for the CIDR block used by Calico.")
daemonCommand.PersistentFlags().String(f.Guest.Cluster.Calico.Subnet, "", "Network address for the CIDR block used by Calico.")
daemonCommand.PersistentFlags().String(f.Guest.Cluster.Kubernetes.API.ClusterIPRange, "", "CIDR Range for Pods in cluster.")
daemonCommand.PersistentFlags().String(f.Guest.Cluster.Kubernetes.ClusterDomain, "cluster.local", "Internal Kubernetes domain.")
daemonCommand.PersistentFlags().String(f.Guest.Cluster.Vault.Certificate.TTL, "", "Vault certificate TTL.")
daemonCommand.PersistentFlags().String(f.Service.Image.Registry.Domain, "quay.io", "Image registry.")
daemonCommand.PersistentFlags().String(f.Service.KubeConfig.Secret.Namespace, "giantswarm", "The namespace where kubeconfig secrets are located.")
daemonCommand.PersistentFlags().String(f.Service.Kubernetes.Address, "", "Address used to connect to Kubernetes. When empty in-cluster config is created.")
daemonCommand.PersistentFlags().Bool(f.Service.Kubernetes.InCluster, true, "Whether to use the in-cluster config to authenticate with Kubernetes.")
daemonCommand.PersistentFlags().String(f.Service.Kubernetes.TLS.CAFile, "", "Certificate authority file path to use to authenticate with Kubernetes.")
daemonCommand.PersistentFlags().String(f.Service.Kubernetes.TLS.CrtFile, "", "Certificate file path to use to authenticate with Kubernetes.")
daemonCommand.PersistentFlags().String(f.Service.Kubernetes.TLS.KeyFile, "", "Key file path to use to authenticate with Kubernetes.")
daemonCommand.PersistentFlags().String(f.Service.Installation.Name, "", "Name of the installation.")
daemonCommand.PersistentFlags().String(f.Service.Provider.Kind, "", "Provider of the installation. One of aws, azure, kvm.")
daemonCommand.PersistentFlags().String(f.Service.Release.App.Config.Default, "", "Default properties for app.")
daemonCommand.PersistentFlags().String(f.Service.Release.App.Config.Override, "", "Overriding properties for app.")
daemonCommand.PersistentFlags().Bool(f.Service.Release.App.Config.KiamWatchDogEnabled, true, "Enable Kiam Watchdog.")
err = newCommand.CobraCommand().Execute()
if err != nil {
return microerror.Mask(err)
}
return nil
}