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 22
/
main.go
165 lines (137 loc) · 9.32 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
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/aws-operator/v14/flag"
"github.com/giantswarm/aws-operator/v14/pkg/project"
"github.com/giantswarm/aws-operator/v14/server"
"github.com/giantswarm/aws-operator/v14/service"
)
var (
f *flag.Flag = flag.New()
)
func main() {
err := mainE(context.Background())
if err != nil {
panic(microerror.JSON(err))
}
}
func mainE(ctx context.Context) error {
var err error
var logger micrologger.Logger
{
c := micrologger.Config{}
logger, 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 sorted out.
serverFactory := func(v *viper.Viper) microserver.Server {
// Create a new custom service which implements business logic.
var newService *service.Service
{
c := service.Config{
Logger: logger,
Flag: f,
Viper: v,
}
newService, err = service.New(c)
if err != nil {
panic(microerror.JSON(err))
}
go newService.Boot(ctx)
}
// Create a new custom server which bundles our endpoints.
var newServer microserver.Server
{
c := server.Config{
Logger: logger,
Service: newService,
Viper: v,
}
newServer, err = server.New(c)
if err != nil {
panic(microerror.JSON(err))
}
}
return newServer
}
// Create a new microkit command which manages our custom microservice.
var newCommand command.Command
{
c := command.Config{
Logger: logger,
ServerFactory: serverFactory,
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.Service.AWS.AlikeInstances, "", "Overrides for the ASG's mixed instance policy.")
daemonCommand.PersistentFlags().StringSlice(f.Service.AWS.AvailabilityZones, []string{}, "Availability zones as a slice.")
daemonCommand.PersistentFlags().String(f.Service.AWS.HostAccessKey.ID, "", "AWS access key ID for the user authorized to assume Control Plane role.")
daemonCommand.PersistentFlags().String(f.Service.AWS.HostAccessKey.Secret, "", "AWS access key secret for the user authorized to assume Control Plane role.")
daemonCommand.PersistentFlags().String(f.Service.AWS.HostAccessKey.Session, "", "AWS session token for for the user authorized to assume Control Plane role.")
daemonCommand.PersistentFlags().String(f.Service.AWS.Region, "", "Region for checking for orphaned AWS resources.")
daemonCommand.PersistentFlags().String(f.Service.AWS.Role.ARN, "", "AWS role ARN for the Control Plane cluster account.")
daemonCommand.PersistentFlags().String(f.Service.AWS.RouteTables, "", "Names of the public route tables in control plane separated by commas, required for accessing public ELBs from tenant nodes.")
daemonCommand.PersistentFlags().String(f.Service.AWS.VaultAddress, "", "Server address for Vault encryption.")
daemonCommand.PersistentFlags().Bool(f.Service.AWS.AdvancedMonitoringEC2, false, "Advanced EC2 monitoring.")
daemonCommand.PersistentFlags().Bool(f.Service.AWS.LoggingBucket.Delete, false, "Should be logging bucket deleted.")
daemonCommand.PersistentFlags().Bool(f.Service.AWS.Route53.Enabled, true, "Should Route 53 be enabled.")
daemonCommand.PersistentFlags().String(f.Service.AWS.PodInfraContainerImage, "", "Image to be used for the pause container. If empty, default image from gcr.io/google_containers/pause-amd64 is used.")
daemonCommand.PersistentFlags().Bool(f.Service.AWS.IncludeTags, true, "Should resource tags be included (especially for restricted regions, like S3 buckets in China regions).")
daemonCommand.PersistentFlags().Int(f.Service.AWS.S3AccessLogsExpiration, 365, "S3 access logs expiration policy.")
daemonCommand.PersistentFlags().String(f.Service.AWS.TrustedAdvisor.Enabled, "", "Whether trusted advisor metrics collection is enabled.")
daemonCommand.PersistentFlags().Bool(f.Service.AWS.CNI.ExternalSNAT, false, "Whether External SNAT for the AWS CNI is enabled.")
daemonCommand.PersistentFlags().Int(f.Service.Cluster.Calico.CIDR, 0, "Calico CIDR of guest clusters.")
daemonCommand.PersistentFlags().Int(f.Service.Cluster.Calico.MTU, 0, "Calico MTU of guest clusters.")
daemonCommand.PersistentFlags().String(f.Service.Cluster.Calico.Subnet, "", "Calico subnet of guest clusters.")
daemonCommand.PersistentFlags().String(f.Service.Cluster.Docker.Daemon.CIDR, "", "CIDR of the Docker daemon bridge configured in guest clusters.")
daemonCommand.PersistentFlags().String(f.Service.Cluster.Kubernetes.API.ClusterIPRange, "", "Service IP range within guest clusters.")
daemonCommand.PersistentFlags().String(f.Service.Cluster.Kubernetes.ClusterDomain, "", "Internal Kubernetes domain.")
daemonCommand.PersistentFlags().String(f.Service.Cluster.Kubernetes.NetworkSetup.Docker.Image, "", "Full docker image of networksetup.")
daemonCommand.PersistentFlags().String(f.Service.Cluster.Kubernetes.SSH.UserList, "", "Comma separated list of ssh users and their public key in format `username:publickey`, being installed in the guest cluster nodes.")
daemonCommand.PersistentFlags().String(f.Service.Guest.Ignition.Path, "/opt/ignition", "Default path for the ignition base directory.")
daemonCommand.PersistentFlags().String(f.Service.Guest.SSH.SSOPublicKey, "", "Public key for trusted SSO CA.")
daemonCommand.PersistentFlags().String(f.Service.Installation.Name, "", "Installation name for tagging AWS resources.")
daemonCommand.PersistentFlags().String(f.Service.Installation.Guest.IPAM.Network.CIDR, "", "Guest cluster network segment from which IPAM allocates subnets.")
daemonCommand.PersistentFlags().Int(f.Service.Installation.Guest.IPAM.Network.SubnetMaskBits, 24, "Number of bits in guest cluster subnet network mask.")
daemonCommand.PersistentFlags().Int(f.Service.Installation.Guest.IPAM.Network.PrivateSubnetMaskBits, 25, "Number of bits in guest cluster private subnet network mask. This must be smaller than SubnetMaskBits.")
daemonCommand.PersistentFlags().Int(f.Service.Installation.Guest.IPAM.Network.PublicSubnetMaskBits, 25, "Number of bits in guest cluster public subnet network mask. This must be smaller than SubnetMaskBits.")
daemonCommand.PersistentFlags().String(f.Service.Installation.Guest.Kubernetes.API.Auth.Provider.OIDC.ClientID, "", "OIDC authorization provider ClientID.")
daemonCommand.PersistentFlags().String(f.Service.Installation.Guest.Kubernetes.API.Auth.Provider.OIDC.IssuerURL, "", "OIDC authorization provider IssuerURL.")
daemonCommand.PersistentFlags().String(f.Service.Installation.Guest.Kubernetes.API.Auth.Provider.OIDC.UsernameClaim, "", "OIDC authorization provider UsernameClaim.")
daemonCommand.PersistentFlags().String(f.Service.Installation.Guest.Kubernetes.API.Auth.Provider.OIDC.GroupsClaim, "", "OIDC authorization provider GroupsClaim.")
daemonCommand.PersistentFlags().Bool(f.Service.Installation.Guest.Kubernetes.API.Security.Whitelist.Private.Enabled, false, "Enable or disable guest cluster k8s private API whitelisting.")
daemonCommand.PersistentFlags().String(f.Service.Installation.Guest.Kubernetes.API.Security.Whitelist.Private.SubnetList, "", "Subnet list for guest cluster k8s private API whitelisting.")
daemonCommand.PersistentFlags().Bool(f.Service.Installation.Guest.Kubernetes.API.Security.Whitelist.Public.Enabled, false, "Enable or disable guest cluster k8s public API whitelisting.")
daemonCommand.PersistentFlags().String(f.Service.Installation.Guest.Kubernetes.API.Security.Whitelist.Public.SubnetList, "", "Subnet list for guest cluster k8s public API whitelisting.")
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".`)
err = newCommand.CobraCommand().Execute()
if err != nil {
return microerror.Mask(err)
}
return nil
}