From ab85aabe18f8e0abbdb47217a5db29949a04fe96 Mon Sep 17 00:00:00 2001 From: Morven Cao Date: Thu, 21 Jan 2021 00:24:36 +0800 Subject: [PATCH] fix revision missing for reverse translation. (#30206) * fix revision missing for reverse translation. * update test cases. * add releasenote. --- operator/pkg/translate/translate_value.go | 8 ++++ .../pkg/translate/translate_value_test.go | 42 +++++++++++++++++++ releasenotes/notes/30203.yaml | 9 ++++ 3 files changed, 59 insertions(+) create mode 100644 releasenotes/notes/30203.yaml diff --git a/operator/pkg/translate/translate_value.go b/operator/pkg/translate/translate_value.go index 1a3a851ecf12..0c93e431fdc6 100644 --- a/operator/pkg/translate/translate_value.go +++ b/operator/pkg/translate/translate_value.go @@ -447,6 +447,11 @@ func translateHPASpec(inPath string, outPath string, valueTree map[string]interf // There is no direct source from value.yaml for scaleTargetRef value, we need to construct from component name if found { + revision := "" + rev, ok := cpSpecTree["revision"] + if ok { + revision = rev.(string) + } st := make(map[string]interface{}) stVal := ` apiVersion: apps/v1 @@ -460,6 +465,9 @@ name: %s` // convert from values component name to correct deployment target if newPS == "pilot" { newPS = "istiod" + if revision != "" { + newPS = newPS + "-" + revision + } } stString := fmt.Sprintf(stVal, newPS) if err := yaml.Unmarshal([]byte(stString), &st); err != nil { diff --git a/operator/pkg/translate/translate_value_test.go b/operator/pkg/translate/translate_value_test.go index e465e3ce9617..165dc65e7260 100644 --- a/operator/pkg/translate/translate_value_test.go +++ b/operator/pkg/translate/translate_value_test.go @@ -637,6 +637,48 @@ spec: hub: docker.io/istio tag: 1.2.3 istioNamespace: istio-system +`, + }, + { + desc: "pilot env k8s setting with non-empty hpa values", + inIOPSpec: ` +spec: + revision: canary + components: + pilot: + enabled: true + values: + pilot: + autoscaleMin: 1 + autoscaleMax: 3 + cpu: + targetAverageUtilization: 80 +`, + want: ` +spec: + revision: canary + components: + pilot: + enabled: true + k8s: + hpaSpec: + maxReplicas: 3 + minReplicas: 1 + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: istiod-canary + metrics: + - type: Resource + resource: + name: cpu + targetAverageUtilization: 80 + values: + pilot: + autoscaleMin: 1 + autoscaleMax: 3 + cpu: + targetAverageUtilization: 80 `, }, } diff --git a/releasenotes/notes/30203.yaml b/releasenotes/notes/30203.yaml new file mode 100644 index 000000000000..b05f651a416f --- /dev/null +++ b/releasenotes/notes/30203.yaml @@ -0,0 +1,9 @@ +apiVersion: release-notes/v2 +kind: bug-fix +area: installation +issue: + - 30203 +releaseNotes: +- | + **Fixed** revision is not applied to the scale target reference of HorizontalPodAutoscaler when helm values for hpa are specified explicitly. +