Skip to content

Commit

Permalink
Define proxy version override annotation (linkerd#2593)
Browse files Browse the repository at this point in the history
* Define proxy version override annotation
* Don't override global linkerd version during inject

This ensures consistent usages of the config.linkerd.io/linkerd-version and
linkerd.io/proxy-version annotations. The former will only be used to track
overridden version, while the latter shows the cluster's current default
version.

* Rename proxy version config override annotation

Signed-off-by: Ivan Sim <[email protected]>
Signed-off-by: [email protected] <[email protected]>
  • Loading branch information
ihcsim authored and KatherineMelnyk committed Apr 5, 2019
1 parent 51da98d commit 208feab
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cli/cmd/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func (options *injectOptions) fetchConfigsOrDefault() (*config.All, error) {
// storing the corresponding annotations and values.
func (options *proxyConfigOptions) overrideConfigs(configs *config.All, overrideAnnotations map[string]string) {
if options.linkerdVersion != "" {
configs.Global.Version = options.linkerdVersion
overrideAnnotations[k8s.ProxyVersionOverrideAnnotation] = options.linkerdVersion
}

if len(options.ignoreInboundPorts) > 0 {
Expand Down
5 changes: 4 additions & 1 deletion cli/cmd/inject_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ func TestUninjectAndInject(t *testing.T) {
defaultConfig := testInstallConfig()
defaultConfig.Global.Version = "testinjectversion"

overrideConfig := testInstallConfig()
overrideConfig.Global.Version = "override"

proxyResourceConfig := testInstallConfig()
proxyResourceConfig.Global.Version = defaultConfig.Global.Version
proxyResourceConfig.Proxy.Resource = &config.ResourceRequirements{
Expand Down Expand Up @@ -179,7 +182,7 @@ func TestUninjectAndInject(t *testing.T) {
inputFileName: "inject_emojivoto_deployment_config_overrides.input.yml",
goldenFileName: "inject_emojivoto_deployment_config_overrides.golden.yml",
reportFileName: "inject_emojivoto_deployment.report",
testInjectConfig: defaultConfig,
testInjectConfig: overrideConfig,
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ spec:
metadata:
annotations:
config.linkerd.io/admin-port: "9998"
config.linkerd.io/linkerd-version: override
config.linkerd.io/proxy-cpu-limit: "1"
config.linkerd.io/proxy-cpu-request: "0.5"
config.linkerd.io/proxy-memory-limit: 256Mi
Expand All @@ -22,7 +23,7 @@ spec:
config.linkerd.io/skip-outbound-ports: "9999"
linkerd.io/created-by: linkerd/cli dev-undefined
linkerd.io/identity-mode: default
linkerd.io/proxy-version: testinjectversion
linkerd.io/proxy-version: override
creationTimestamp: null
labels:
app: web-svc
Expand Down Expand Up @@ -102,7 +103,7 @@ spec:
value: linkerd-identity.$(_l5d_ns).serviceaccount.identity.$(_l5d_ns).$(_l5d_trustdomain)
- name: LINKERD2_PROXY_DESTINATION_SVC_NAME
value: linkerd-controller.$(_l5d_ns).serviceaccount.identity.$(_l5d_ns).$(_l5d_trustdomain)
image: gcr.io/linkerd-io/proxy:testinjectversion
image: gcr.io/linkerd-io/proxy:override
imagePullPolicy: IfNotPresent
livenessProbe:
httpGet:
Expand Down Expand Up @@ -145,7 +146,7 @@ spec:
- 7777,8888,4190,9998
- --outbound-ports-to-ignore
- "9999"
image: gcr.io/linkerd-io/proxy-init:testinjectversion
image: gcr.io/linkerd-io/proxy-init:override
imagePullPolicy: IfNotPresent
name: linkerd-init
resources: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ spec:
metadata:
annotations:
config.linkerd.io/admin-port: "9998"
config.linkerd.io/linkerd-version: override
config.linkerd.io/proxy-cpu-limit: "1"
config.linkerd.io/proxy-cpu-request: "0.5"
config.linkerd.io/proxy-memory-limit: 256Mi
Expand Down
11 changes: 9 additions & 2 deletions pkg/inject/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,11 +636,11 @@ func (conf *ResourceConfig) getOverride(annotation string) string {
}

func (conf *ResourceConfig) taggedProxyImage() string {
return fmt.Sprintf("%s:%s", conf.proxyImage(), conf.configs.GetGlobal().GetVersion())
return fmt.Sprintf("%s:%s", conf.proxyImage(), conf.proxyVersion())
}

func (conf *ResourceConfig) taggedProxyInitImage() string {
return fmt.Sprintf("%s:%s", conf.proxyInitImage(), conf.configs.GetGlobal().GetVersion())
return fmt.Sprintf("%s:%s", conf.proxyInitImage(), conf.proxyVersion())
}

func (conf *ResourceConfig) proxyImage() string {
Expand All @@ -657,6 +657,13 @@ func (conf *ResourceConfig) proxyImagePullPolicy() v1.PullPolicy {
return v1.PullPolicy(conf.configs.GetProxy().GetProxyImage().GetPullPolicy())
}

func (conf *ResourceConfig) proxyVersion() string {
if override := conf.getOverride(k8s.ProxyVersionOverrideAnnotation); override != "" {
return override
}
return conf.configs.GetGlobal().GetVersion()
}

func (conf *ResourceConfig) proxyControlPort() int32 {
if override := conf.getOverride(k8s.ProxyControlPortAnnotation); override != "" {
controlPort, err := strconv.ParseInt(override, 10, 32)
Expand Down
20 changes: 18 additions & 2 deletions pkg/inject/inject_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
type expectedProxyConfigs struct {
image string
imagePullPolicy corev1.PullPolicy
imageVersion string
controlPort int32
inboundPort int32
adminPort int32
Expand Down Expand Up @@ -64,7 +65,12 @@ func TestConfigAccessors(t *testing.T) {
LogLevel: &config.LogLevel{Level: "info,linkerd2_proxy=debug"},
DisableExternalProfiles: false,
}
globalConfig := &config.Global{LinkerdNamespace: "linkerd"}

globalConfig := &config.Global{
LinkerdNamespace: "linkerd",
Version: "default",
}

configs := &config.All{Global: globalConfig, Proxy: proxyConfig}

var testCases = []struct {
Expand Down Expand Up @@ -92,14 +98,16 @@ func TestConfigAccessors(t *testing.T) {
k8s.ProxyMemoryLimitAnnotation: "256",
k8s.ProxyUIDAnnotation: "8500",
k8s.ProxyLogLevelAnnotation: "debug,linkerd2_proxy=debug",
k8s.ProxyEnableExternalProfilesAnnotation: "false"},
k8s.ProxyEnableExternalProfilesAnnotation: "false",
k8s.ProxyVersionOverrideAnnotation: "override"},
},
corev1.PodSpec{},
},
},
expected: expectedProxyConfigs{
image: "gcr.io/linkerd-io/proxy",
imagePullPolicy: corev1.PullPolicy("Always"),
imageVersion: "override",
controlPort: int32(4000),
inboundPort: int32(5000),
adminPort: int32(5001),
Expand Down Expand Up @@ -163,6 +171,7 @@ func TestConfigAccessors(t *testing.T) {
expected: expectedProxyConfigs{
image: "gcr.io/linkerd-io/proxy",
imagePullPolicy: corev1.PullPolicy("IfNotPresent"),
imageVersion: "default",
controlPort: int32(9000),
inboundPort: int32(6000),
adminPort: int32(6001),
Expand Down Expand Up @@ -245,6 +254,13 @@ func TestConfigAccessors(t *testing.T) {
}
})

t.Run("proxyVersion", func(t *testing.T) {
expected := testCase.expected.imageVersion
if actual := resourceConfig.proxyVersion(); expected != actual {
t.Errorf("Expected: %v Actual: %v", expected, actual)
}
})

t.Run("proxyControlPort", func(t *testing.T) {
expected := testCase.expected.controlPort
if actual := resourceConfig.proxyControlPort(); expected != actual {
Expand Down
3 changes: 3 additions & 0 deletions pkg/k8s/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ const (
// disableExternalProfilesAnnotation config.
ProxyEnableExternalProfilesAnnotation = ProxyConfigAnnotationsPrefix + "/enable-external-profiles"

// ProxyVersionOverrideAnnotation can be used to override the proxy version config.
ProxyVersionOverrideAnnotation = ProxyConfigAnnotationsPrefix + "/proxy-version"

// IdentityModeDefault is assigned to IdentityModeAnnotation to
// use the control plane's default identity scheme.
IdentityModeDefault = "default"
Expand Down

0 comments on commit 208feab

Please sign in to comment.