-
Notifications
You must be signed in to change notification settings - Fork 86
/
options.go
102 lines (85 loc) · 3.88 KB
/
options.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
package spoke
import (
"fmt"
"time"
"github.com/pkg/errors"
"github.com/spf13/pflag"
"k8s.io/apiserver/pkg/server/healthz"
"open-cluster-management.io/ocm/pkg/registration/helpers"
)
var ClientCertHealthCheckInterval = 30 * time.Second
// SpokeAgentOptions holds configuration for spoke cluster agent
type SpokeAgentOptions struct {
BootstrapKubeconfig string
BootstrapKubeconfigSecret string
HubKubeconfigSecret string
SpokeExternalServerURLs []string
ClusterHealthCheckPeriod time.Duration
MaxCustomClusterClaims int
ClientCertExpirationSeconds int32
ClusterAnnotations map[string]string
clientCertHealthChecker *clientCertHealthChecker
bootstrapKubeconfigHealthChecker *bootstrapKubeconfigHealthChecker
}
func NewSpokeAgentOptions() *SpokeAgentOptions {
options := &SpokeAgentOptions{
BootstrapKubeconfigSecret: "bootstrap-hub-kubeconfig",
HubKubeconfigSecret: "hub-kubeconfig-secret",
ClusterHealthCheckPeriod: 1 * time.Minute,
MaxCustomClusterClaims: 20,
clientCertHealthChecker: &clientCertHealthChecker{
interval: ClientCertHealthCheckInterval,
},
}
options.bootstrapKubeconfigHealthChecker = &bootstrapKubeconfigHealthChecker{
bootstrapKubeconfigSecretName: &options.BootstrapKubeconfigSecret,
}
return options
}
// AddFlags registers flags for Agent
func (o *SpokeAgentOptions) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&o.BootstrapKubeconfig, "bootstrap-kubeconfig", o.BootstrapKubeconfig,
"The path of the kubeconfig file for agent bootstrap.")
fs.StringVar(&o.BootstrapKubeconfigSecret, "bootstrap-kubeconfig-secret", o.BootstrapKubeconfigSecret,
"The name of secret in component namespace storing kubeconfig for agent bootstrap.")
fs.StringVar(&o.HubKubeconfigSecret, "hub-kubeconfig-secret", o.HubKubeconfigSecret,
"The name of secret in component namespace storing kubeconfig for hub.")
fs.StringArrayVar(&o.SpokeExternalServerURLs, "spoke-external-server-urls", o.SpokeExternalServerURLs,
"A list of reachable spoke cluster api server URLs for hub cluster.")
fs.DurationVar(&o.ClusterHealthCheckPeriod, "cluster-healthcheck-period", o.ClusterHealthCheckPeriod,
"The period to check managed cluster kube-apiserver health")
fs.IntVar(&o.MaxCustomClusterClaims, "max-custom-cluster-claims", o.MaxCustomClusterClaims,
"The max number of custom cluster claims to expose.")
fs.Int32Var(&o.ClientCertExpirationSeconds, "client-cert-expiration-seconds", o.ClientCertExpirationSeconds,
"The requested duration in seconds of validity of the issued client certificate. If this is not set, "+
"the value of --cluster-signing-duration command-line flag of the kube-controller-manager will be used.")
fs.StringToStringVar(&o.ClusterAnnotations, "cluster-annotations", o.ClusterAnnotations, `the annotations with the reserve
prefix "agent.open-cluster-management.io" set on ManagedCluster when creating only, other actors can update it afterwards.`)
}
// Validate verifies the inputs.
func (o *SpokeAgentOptions) Validate() error {
if o.BootstrapKubeconfig == "" {
return errors.New("bootstrap-kubeconfig is required")
}
// if SpokeExternalServerURLs is specified we validate every URL in it, we expect the spoke external server URL is https
if len(o.SpokeExternalServerURLs) != 0 {
for _, serverURL := range o.SpokeExternalServerURLs {
if !helpers.IsValidHTTPSURL(serverURL) {
return fmt.Errorf("%q is invalid", serverURL)
}
}
}
if o.ClusterHealthCheckPeriod <= 0 {
return errors.New("cluster healthcheck period must greater than zero")
}
if o.ClientCertExpirationSeconds != 0 && o.ClientCertExpirationSeconds < 3600 {
return errors.New("client certificate expiration seconds must greater or qual to 3600")
}
return nil
}
func (o *SpokeAgentOptions) GetHealthCheckers() []healthz.HealthChecker {
return []healthz.HealthChecker{
o.bootstrapKubeconfigHealthChecker,
o.clientCertHealthChecker,
}
}