This repository has been archived by the owner on Oct 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.go
113 lines (92 loc) · 3.79 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
package main
import (
"os"
"github.com/giantswarm/microkit/command"
microserver "github.com/giantswarm/microkit/server"
"github.com/giantswarm/micrologger"
"github.com/spf13/viper"
"github.com/giantswarm/cert-operator/flag"
"github.com/giantswarm/cert-operator/server"
"github.com/giantswarm/cert-operator/service"
)
var (
description string = "The cert-operator handles certificates for Kubernetes clusters running on Giantnetes."
f *flag.Flag = flag.New()
gitCommit string = "n/a"
name string = "cert-operator"
source string = "https://github.com/giantswarm/cert-operator"
)
func main() {
var err error
// Create a new logger which is used by all packages.
var newLogger micrologger.Logger
{
loggerConfig := micrologger.DefaultConfig()
loggerConfig.IOWriter = os.Stdout
newLogger, err = micrologger.New(loggerConfig)
if err != nil {
panic(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
{
serviceConfig := service.DefaultConfig()
serviceConfig.Flag = f
serviceConfig.Logger = newLogger
serviceConfig.Viper = v
serviceConfig.Description = description
serviceConfig.GitCommit = gitCommit
serviceConfig.Name = name
serviceConfig.Source = source
newService, err = service.New(serviceConfig)
if err != nil {
panic(err)
}
go newService.Boot()
}
// Create a new custom server which bundles our endpoints.
var newServer microserver.Server
{
serverConfig := server.DefaultConfig()
serverConfig.MicroServerConfig.Logger = newLogger
serverConfig.MicroServerConfig.ServiceName = name
serverConfig.MicroServerConfig.Viper = v
serverConfig.Service = newService
newServer, err = server.New(serverConfig)
if err != nil {
panic(err)
}
}
return newServer
}
// Create a new microkit command which manages our custom microservice.
var newCommand command.Command
{
commandConfig := command.DefaultConfig()
commandConfig.Logger = newLogger
commandConfig.ServerFactory = newServerFactory
commandConfig.Description = description
commandConfig.GitCommit = gitCommit
commandConfig.Name = name
commandConfig.Source = source
newCommand, err = command.New(commandConfig)
if err != nil {
panic(err)
}
}
daemonCommand := newCommand.DaemonCommand().CobraCommand()
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.Vault.Config.Address, "", "Address used to connect to Vault.")
daemonCommand.PersistentFlags().String(f.Service.Vault.Config.Token, "", "Token used to authenticate against Vault.")
daemonCommand.PersistentFlags().String(f.Service.Vault.Config.PKI.CA.TTL, "", "TTL used to generate a new Cluster CA.")
daemonCommand.PersistentFlags().String(f.Service.Vault.Config.PKI.CommonName.Format, "", "Common name used to generate a new Cluster CA.")
newCommand.CobraCommand().Execute()
}