This repository has been archived by the owner on Dec 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
main.go
142 lines (116 loc) · 5.94 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
140
141
142
package main
import (
"fmt"
"github.com/giantswarm/microerror"
"github.com/giantswarm/microkit/command"
microserver "github.com/giantswarm/microkit/server"
"github.com/giantswarm/micrologger"
"github.com/giantswarm/versionbundle"
"github.com/spf13/viper"
"github.com/giantswarm/kvm-operator/v4/flag"
"github.com/giantswarm/kvm-operator/v4/pkg/project"
"github.com/giantswarm/kvm-operator/v4/server"
"github.com/giantswarm/kvm-operator/v4/service"
)
var (
f *flag.Flag = flag.New()
)
func main() {
err := mainError()
if err != nil {
panic(fmt.Sprintf("%#v\n", err))
}
}
func mainError() error {
var err error
// Create a new logger which is used by all packages.
var newLogger micrologger.Logger
{
c := micrologger.Config{}
newLogger, err = micrologger.New(c)
if err != nil {
return microerror.Mask(err)
}
}
// We define a server factory to create the custom server once all command
// line flags are parsed and all microservice configuration is storted out.
newServerFactory := func(v *viper.Viper) microserver.Server {
// Create a new custom service which implements business logic.
var newService *service.Service
{
c := service.Config{
Logger: newLogger,
Flag: f,
Viper: v,
}
newService, err = service.New(c)
if err != nil {
panic(fmt.Sprintf("%#v", err))
}
go newService.Boot()
}
// Create a new custom server which bundles our endpoints.
var newServer microserver.Server
{
c := server.Config{
Logger: newLogger,
Service: newService,
Viper: v,
}
newServer, err = server.New(c)
if err != nil {
panic(fmt.Sprintf("%#v", err))
}
}
return newServer
}
// Create a new microkit command which manages our custom microservice.
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(),
VersionBundles: []versionbundle.Bundle{project.NewVersionBundle()},
}
newCommand, err = command.New(c)
if err != nil {
return microerror.Mask(err)
}
}
daemonCommand := newCommand.DaemonCommand().CobraCommand()
daemonCommand.PersistentFlags().String(f.Service.Installation.DNS.Servers, "", "Comma separated list of DNS servers.")
daemonCommand.PersistentFlags().String(f.Service.Installation.NTP.Servers, "", "Comma separated list of NTPservers.")
daemonCommand.PersistentFlags().String(f.Service.Installation.Workload.Kubernetes.API.Auth.Provider.OIDC.ClientID, "", "OIDC authorization provider ClientID.")
daemonCommand.PersistentFlags().String(f.Service.Installation.Workload.Kubernetes.API.Auth.Provider.OIDC.IssuerURL, "", "OIDC authorization provider IssuerURL.")
daemonCommand.PersistentFlags().String(f.Service.Installation.Workload.Kubernetes.API.Auth.Provider.OIDC.UsernameClaim, "", "OIDC authorization provider UsernameClaim.")
daemonCommand.PersistentFlags().String(f.Service.Installation.Workload.Kubernetes.API.Auth.Provider.OIDC.UsernamePrefix, "", "OIDC authorization provider UsernamePrefix.")
daemonCommand.PersistentFlags().String(f.Service.Installation.Workload.Kubernetes.API.Auth.Provider.OIDC.GroupsClaim, "", "OIDC authorization provider GroupsClaim.")
daemonCommand.PersistentFlags().String(f.Service.Installation.Workload.Kubernetes.API.Auth.Provider.OIDC.GroupsPrefix, "", "OIDC authorization provider GroupsPrefix.")
daemonCommand.PersistentFlags().String(f.Service.RBAC.ClusterRole.General, "", "Name of existing general ClusterRole to be used for workload cluster node pods.")
daemonCommand.PersistentFlags().String(f.Service.RBAC.ClusterRole.PSP, "", "Name of existing ClusterRole with PSP to be used for workload cluster node pods.")
daemonCommand.PersistentFlags().String(f.Service.Kubernetes.Address, "http://127.0.0.1:6443", "Address used to connect to Kubernetes. When empty in-cluster config is created.")
daemonCommand.PersistentFlags().Bool(f.Service.Kubernetes.InCluster, false, "Whether to use the in-cluster config to authenticate with Kubernetes.")
daemonCommand.PersistentFlags().String(f.Service.Kubernetes.KubeConfig, "", "KubeConfig used to connect to Kubernetes. When empty other settings are used.")
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.Registry.DockerhubToken, "", "Token used to authenticate/authorize to DockerHub.")
daemonCommand.PersistentFlags().String(f.Service.Registry.Domain, "docker.io", "Image registry domain.")
daemonCommand.PersistentFlags().StringSlice(f.Service.Registry.Mirrors, []string{}, `Image registry mirror domains. Can be set only if registry domain is "docker.io".`)
daemonCommand.PersistentFlags().String(f.Service.Workload.Ignition.Path, "/opt/ignition", "Default path for the ignition base directory.")
daemonCommand.PersistentFlags().String(f.Service.Workload.Proxy.HTTP, "", "URL of proxy for HTTP requests.")
daemonCommand.PersistentFlags().String(f.Service.Workload.Proxy.HTTPS, "", "URL of proxy for HTTPS requests.")
daemonCommand.PersistentFlags().StringSlice(f.Service.Workload.Proxy.NoProxy, []string{}, "List of addresses that need not to go through the proxy.")
daemonCommand.PersistentFlags().String(f.Service.Workload.SSH.SSOPublicKey, "", "Public key for trusted SSO CA.")
daemonCommand.PersistentFlags().Bool(f.Service.TerminateUnhealthyNodes, false, "Whether to terminate unhealthy nodes on all WCs by default.")
err = newCommand.CobraCommand().Execute()
if err != nil {
return microerror.Mask(err)
}
return nil
}