Reorganize install/inject config structs (#2202)

Signed-off-by: Kevin Lingerfelt <kl@buoyant.io>
This commit is contained in:
Kevin Lingerfelt 2019-02-05 12:50:42 -08:00 committed by GitHub
parent 2a7654ce78
commit 02f128ec5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 66 additions and 67 deletions

View File

@ -256,26 +256,13 @@ func injectPodSpec(t *v1.PodSpec, identity k8s.TLSIdentity, controlPlaneDNSNameO
Name: PodNamespaceEnvVarName,
ValueFrom: &v1.EnvVarSource{FieldRef: &v1.ObjectFieldSelector{FieldPath: "metadata.namespace"}},
},
{Name: "LINKERD2_PROXY_INBOUND_ACCEPT_KEEPALIVE", Value: fmt.Sprintf("%dms", defaultKeepaliveMs)},
{Name: "LINKERD2_PROXY_OUTBOUND_CONNECT_KEEPALIVE", Value: fmt.Sprintf("%dms", defaultKeepaliveMs)},
},
LivenessProbe: &proxyProbe,
ReadinessProbe: &proxyProbe,
}
if options.inboundAcceptKeepaliveMs != 0 {
sidecar.Env = append(sidecar.Env,
v1.EnvVar{
Name: "LINKERD2_PROXY_INBOUND_ACCEPT_KEEPALIVE",
Value: fmt.Sprintf("%dms", options.inboundAcceptKeepaliveMs),
})
}
if options.outboundConnectKeepaliveMs != 0 {
sidecar.Env = append(sidecar.Env,
v1.EnvVar{
Name: "LINKERD2_PROXY_OUTBOUND_CONNECT_KEEPALIVE",
Value: fmt.Sprintf("%dms", options.outboundConnectKeepaliveMs),
})
}
// Special case if the caller specifies that
// LINKERD2_PROXY_OUTBOUND_ROUTER_CAPACITY be set on the pod.
// We key off of any container image in the pod. Ideally we would instead key

View File

@ -73,6 +73,11 @@ type installConfig struct {
NoInitContainer bool
}
// installOptions holds values for command line flags that apply to the install
// command. All fields in this struct should have corresponding flags added in
// the newCmdInstall func later in this file. It also embeds proxyConfigOptions
// in order to hold values for command line flags that apply to both inject and
// install.
type installOptions struct {
controllerReplicas uint
controllerLogLevel string
@ -200,8 +205,8 @@ func validateAndBuildConfig(options *installOptions) (*installConfig, error) {
OutboundPort: options.outboundPort,
IgnoreInboundPorts: strings.Join(ignoreInboundPorts, ","),
IgnoreOutboundPorts: strings.Join(ignoreOutboundPorts, ","),
InboundAcceptKeepaliveMs: options.proxyConfigOptions.inboundAcceptKeepaliveMs,
OutboundConnectKeepaliveMs: options.proxyConfigOptions.inboundAcceptKeepaliveMs,
InboundAcceptKeepaliveMs: defaultKeepaliveMs,
OutboundConnectKeepaliveMs: defaultKeepaliveMs,
ProxyAutoInjectEnabled: options.proxyAutoInject,
ProxyInjectAnnotation: k8s.ProxyInjectAnnotation,
ProxyInjectDisabled: k8s.ProxyInjectDisabled,

View File

@ -222,60 +222,64 @@ func getPercentTLS(stats *pb.BasicStats) float64 {
return float64(stats.TlsRequestCount) / float64(reqTotal)
}
// proxyConfigOptions holds values for command line flags that apply to both the
// install and inject commands. All fields in this struct should have
// corresponding flags added in the addProxyConfigFlags func later in this file.
type proxyConfigOptions struct {
linkerdVersion string
proxyImage string
initImage string
dockerRegistry string
imagePullPolicy string
inboundPort uint
outboundPort uint
inboundAcceptKeepaliveMs uint
outboundConnectKeepaliveMs uint
ignoreInboundPorts []uint
ignoreOutboundPorts []uint
proxyUID int64
proxyLogLevel string
proxyAPIPort uint
proxyControlPort uint
proxyMetricsPort uint
proxyCPURequest string
proxyMemoryRequest string
proxyOutboundCapacity map[string]uint
tls string
disableExternalProfiles bool
noInitContainer bool
linkerdVersion string
proxyImage string
initImage string
dockerRegistry string
imagePullPolicy string
inboundPort uint
outboundPort uint
ignoreInboundPorts []uint
ignoreOutboundPorts []uint
proxyUID int64
proxyLogLevel string
proxyAPIPort uint
proxyControlPort uint
proxyMetricsPort uint
proxyCPURequest string
proxyMemoryRequest string
tls string
disableExternalProfiles bool
noInitContainer bool
// proxyOutboundCapacity is a special case that's only used for injecting the
// proxy into the control plane install, and as such it does not have a
// corresponding command line flag.
proxyOutboundCapacity map[string]uint
}
const (
optionalTLS = "optional"
defaultDockerRegistry = "gcr.io/linkerd-io"
defaultKeepaliveMs = 10000
)
func newProxyConfigOptions() *proxyConfigOptions {
return &proxyConfigOptions{
linkerdVersion: version.Version,
proxyImage: defaultDockerRegistry + "/proxy",
initImage: defaultDockerRegistry + "/proxy-init",
dockerRegistry: defaultDockerRegistry,
imagePullPolicy: "IfNotPresent",
inboundPort: 4143,
outboundPort: 4140,
ignoreInboundPorts: nil,
ignoreOutboundPorts: nil,
inboundAcceptKeepaliveMs: 10000,
outboundConnectKeepaliveMs: 10000,
proxyUID: 2102,
proxyLogLevel: "warn,linkerd2_proxy=info",
proxyAPIPort: 8086,
proxyControlPort: 4190,
proxyMetricsPort: 4191,
proxyOutboundCapacity: map[string]uint{},
proxyCPURequest: "",
proxyMemoryRequest: "",
tls: "",
disableExternalProfiles: false,
noInitContainer: false,
linkerdVersion: version.Version,
proxyImage: defaultDockerRegistry + "/proxy",
initImage: defaultDockerRegistry + "/proxy-init",
dockerRegistry: defaultDockerRegistry,
imagePullPolicy: "IfNotPresent",
inboundPort: 4143,
outboundPort: 4140,
ignoreInboundPorts: nil,
ignoreOutboundPorts: nil,
proxyUID: 2102,
proxyLogLevel: "warn,linkerd2_proxy=info",
proxyAPIPort: 8086,
proxyControlPort: 4190,
proxyMetricsPort: 4191,
proxyCPURequest: "",
proxyMemoryRequest: "",
tls: "",
disableExternalProfiles: false,
noInitContainer: false,
proxyOutboundCapacity: map[string]uint{},
}
}
@ -325,24 +329,27 @@ func (options *proxyConfigOptions) taggedProxyInitImage() string {
return fmt.Sprintf("%s:%s", image, options.linkerdVersion)
}
// addProxyConfigFlags adds command line flags for all fields in the
// proxyConfigOptions struct. To keep things organized, the flags should be
// added in the order that they're defined in the proxyConfigOptions struct.
func addProxyConfigFlags(cmd *cobra.Command, options *proxyConfigOptions) {
cmd.PersistentFlags().StringVarP(&options.linkerdVersion, "linkerd-version", "v", options.linkerdVersion, "Tag to be used for Linkerd images")
cmd.PersistentFlags().StringVar(&options.initImage, "init-image", options.initImage, "Linkerd init container image name")
cmd.PersistentFlags().StringVar(&options.proxyImage, "proxy-image", options.proxyImage, "Linkerd proxy container image name")
cmd.PersistentFlags().StringVar(&options.initImage, "init-image", options.initImage, "Linkerd init container image name")
cmd.PersistentFlags().StringVar(&options.dockerRegistry, "registry", options.dockerRegistry, "Docker registry to pull images from")
cmd.PersistentFlags().StringVar(&options.imagePullPolicy, "image-pull-policy", options.imagePullPolicy, "Docker image pull policy")
cmd.PersistentFlags().Int64Var(&options.proxyUID, "proxy-uid", options.proxyUID, "Run the proxy under this user ID")
cmd.PersistentFlags().StringVar(&options.proxyLogLevel, "proxy-log-level", options.proxyLogLevel, "Log level for the proxy")
cmd.PersistentFlags().UintVar(&options.inboundPort, "inbound-port", options.inboundPort, "Proxy port to use for inbound traffic")
cmd.PersistentFlags().UintVar(&options.outboundPort, "outbound-port", options.outboundPort, "Proxy port to use for outbound traffic")
cmd.PersistentFlags().UintSliceVar(&options.ignoreInboundPorts, "skip-inbound-ports", options.ignoreInboundPorts, "Ports that should skip the proxy and send directly to the application")
cmd.PersistentFlags().UintSliceVar(&options.ignoreOutboundPorts, "skip-outbound-ports", options.ignoreOutboundPorts, "Outbound ports that should skip the proxy")
cmd.PersistentFlags().Int64Var(&options.proxyUID, "proxy-uid", options.proxyUID, "Run the proxy under this user ID")
cmd.PersistentFlags().StringVar(&options.proxyLogLevel, "proxy-log-level", options.proxyLogLevel, "Log level for the proxy")
cmd.PersistentFlags().UintVar(&options.proxyAPIPort, "api-port", options.proxyAPIPort, "Port where the Linkerd controller is running")
cmd.PersistentFlags().UintVar(&options.proxyControlPort, "control-port", options.proxyControlPort, "Proxy port to use for control")
cmd.PersistentFlags().UintVar(&options.proxyMetricsPort, "metrics-port", options.proxyMetricsPort, "Proxy port to serve metrics on")
cmd.PersistentFlags().StringVar(&options.tls, "tls", options.tls, "Enable TLS; valid settings: \"optional\"")
cmd.PersistentFlags().StringVar(&options.proxyCPURequest, "proxy-cpu", options.proxyCPURequest, "Amount of CPU units that the proxy sidecar requests")
cmd.PersistentFlags().StringVar(&options.proxyMemoryRequest, "proxy-memory", options.proxyMemoryRequest, "Amount of Memory that the proxy sidecar requests")
cmd.PersistentFlags().UintSliceVar(&options.ignoreInboundPorts, "skip-inbound-ports", options.ignoreInboundPorts, "Ports that should skip the proxy and send directly to the application")
cmd.PersistentFlags().UintSliceVar(&options.ignoreOutboundPorts, "skip-outbound-ports", options.ignoreOutboundPorts, "Outbound ports that should skip the proxy")
cmd.PersistentFlags().StringVar(&options.tls, "tls", options.tls, "Enable TLS; valid settings: \"optional\"")
cmd.PersistentFlags().BoolVar(&options.disableExternalProfiles, "disable-external-profiles", options.disableExternalProfiles, "Disables service profiles for non-Kubernetes services")
cmd.PersistentFlags().BoolVar(&options.noInitContainer, "linkerd-cni-enabled", options.noInitContainer, "Experimental: Omit the proxy-init container when injecting the proxy; requires the linkerd-cni plugin to already be installed")
cmd.PersistentFlags().MarkHidden("linkerd-cni-enabled")