From b9a8e98bcafd6482dbb540c9ab189e2d246bf9ca Mon Sep 17 00:00:00 2001 From: Naseem Date: Sat, 11 Jan 2020 00:38:55 -0500 Subject: [PATCH 1/7] Add hpa boilerplate Signed-off-by: Naseem --- cmd/helm/create_test.go | 4 ++-- pkg/chartutil/create.go | 46 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/cmd/helm/create_test.go b/cmd/helm/create_test.go index 0a9b7b9a5..bbb8d394a 100644 --- a/cmd/helm/create_test.go +++ b/cmd/helm/create_test.go @@ -106,7 +106,7 @@ func TestCreateStarterCmd(t *testing.T) { t.Errorf("Wrong API version: %q", c.Metadata.APIVersion) } - expectedNumberOfTemplates := 8 + expectedNumberOfTemplates := 9 if l := len(c.Templates); l != expectedNumberOfTemplates { t.Errorf("Expected %d templates, got %d", expectedNumberOfTemplates, l) } @@ -174,7 +174,7 @@ func TestCreateStarterAbsoluteCmd(t *testing.T) { t.Errorf("Wrong API version: %q", c.Metadata.APIVersion) } - expectedNumberOfTemplates := 8 + expectedNumberOfTemplates := 9 if l := len(c.Templates); l != expectedNumberOfTemplates { t.Errorf("Expected %d templates, got %d", expectedNumberOfTemplates, l) } diff --git a/pkg/chartutil/create.go b/pkg/chartutil/create.go index 390f12f4c..90bf4ec48 100644 --- a/pkg/chartutil/create.go +++ b/pkg/chartutil/create.go @@ -53,6 +53,8 @@ const ( ServiceName = TemplatesDir + sep + "service.yaml" // ServiceAccountName is the name of the example serviceaccount file. ServiceAccountName = TemplatesDir + sep + "serviceaccount.yaml" + // HorizontalPodAutoscalerName is the name of the example hpa file. + HorizontalPodAutoscalerName = TemplatesDir + sep + "hpa.yaml" // NotesName is the name of the example NOTES.txt file. NotesName = TemplatesDir + sep + "NOTES.txt" // HelpersName is the name of the example helpers file. @@ -149,6 +151,13 @@ resources: {} # cpu: 100m # memory: 128Mi +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + nodeSelector: {} tolerations: [] @@ -231,7 +240,9 @@ metadata: labels: {{- include ".labels" . | nindent 4 }} spec: +{{- if not .Values.autoscaling.enabled }} replicas: {{ .Values.replicaCount }} +{{- end }} selector: matchLabels: {{- include ".selectorLabels" . | nindent 6 }} @@ -312,6 +323,36 @@ metadata: {{- end -}} ` +const defaultHorizontalPodAutoscaler = `{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2beta1 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include ".fullname" . }} + labels: + {{- include ".labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include ".fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} +` + const defaultNotes = `1. Get the application URL by running these commands: {{- if .Values.ingress.enabled }} {{- range $host := .Values.ingress.hosts }} @@ -517,6 +558,11 @@ func Create(name, dir string) (string, error) { path: filepath.Join(cdir, ServiceAccountName), content: transform(defaultServiceAccount, name), }, + { + // hpa.yaml + path: filepath.Join(cdir, HorizontalPodAutoscalerName), + content: transform(defaultHorizontalPodAutoscaler, name), + }, { // NOTES.txt path: filepath.Join(cdir, NotesName), From 00201ffaa8e0c725b1acd429f5e5a712f30378d1 Mon Sep 17 00:00:00 2001 From: Jon Leonard Date: Thu, 26 Mar 2020 11:12:30 -0400 Subject: [PATCH 2/7] pass subchart notes option to install client Signed-off-by: Jon Leonard --- cmd/helm/upgrade.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/helm/upgrade.go b/cmd/helm/upgrade.go index af8ff68e3..48eac0b0f 100644 --- a/cmd/helm/upgrade.go +++ b/cmd/helm/upgrade.go @@ -112,6 +112,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { instClient.Atomic = client.Atomic instClient.PostRenderer = client.PostRenderer instClient.DisableOpenAPIValidation = client.DisableOpenAPIValidation + instClient.SubNotes = client.SubNotes rel, err := runInstall(args, instClient, valueOpts, out) if err != nil { From e2b70b2f4b94c071e8fe08487cffb006bcde1df7 Mon Sep 17 00:00:00 2001 From: Jon Leonard Date: Thu, 26 Mar 2020 13:20:30 -0400 Subject: [PATCH 3/7] add testing for upgrade --install with subchart notes Signed-off-by: Jon Leonard --- .../upgrade-install-with-subchart-notes.txt | 11 +++++++ .../chart-with-subchart-notes/Chart.yaml | 4 +++ .../charts/subchart-with-notes/Chart.yaml | 4 +++ .../subchart-with-notes/templates/NOTES.txt | 1 + .../charts/subchart-with-notes/values.yaml | 0 .../requirements.yaml | 3 ++ .../templates/NOTES.txt | 1 + .../chart-with-subchart-notes/values.yaml | 0 cmd/helm/upgrade_test.go | 32 +++++++++++++++++++ 9 files changed, 56 insertions(+) create mode 100644 cmd/helm/testdata/output/upgrade-install-with-subchart-notes.txt create mode 100644 cmd/helm/testdata/testcharts/chart-with-subchart-notes/Chart.yaml create mode 100644 cmd/helm/testdata/testcharts/chart-with-subchart-notes/charts/subchart-with-notes/Chart.yaml create mode 100644 cmd/helm/testdata/testcharts/chart-with-subchart-notes/charts/subchart-with-notes/templates/NOTES.txt create mode 100644 cmd/helm/testdata/testcharts/chart-with-subchart-notes/charts/subchart-with-notes/values.yaml create mode 100644 cmd/helm/testdata/testcharts/chart-with-subchart-notes/requirements.yaml create mode 100644 cmd/helm/testdata/testcharts/chart-with-subchart-notes/templates/NOTES.txt create mode 100644 cmd/helm/testdata/testcharts/chart-with-subchart-notes/values.yaml diff --git a/cmd/helm/testdata/output/upgrade-install-with-subchart-notes.txt b/cmd/helm/testdata/output/upgrade-install-with-subchart-notes.txt new file mode 100644 index 000000000..767b8c5d9 --- /dev/null +++ b/cmd/helm/testdata/output/upgrade-install-with-subchart-notes.txt @@ -0,0 +1,11 @@ +Release "wacky-bunny" has been upgraded. Happy Helming! +NAME: wacky-bunny +LAST DEPLOYED: Fri Sep 2 22:04:05 1977 +NAMESPACE: default +STATUS: deployed +REVISION: 2 +TEST SUITE: None +NOTES: +SUBCHART NOTES + +PARENT NOTES diff --git a/cmd/helm/testdata/testcharts/chart-with-subchart-notes/Chart.yaml b/cmd/helm/testdata/testcharts/chart-with-subchart-notes/Chart.yaml new file mode 100644 index 000000000..6ea036678 --- /dev/null +++ b/cmd/helm/testdata/testcharts/chart-with-subchart-notes/Chart.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +description: Chart with subchart notes +name: chart-with-subchart-notes +version: 0.0.1 diff --git a/cmd/helm/testdata/testcharts/chart-with-subchart-notes/charts/subchart-with-notes/Chart.yaml b/cmd/helm/testdata/testcharts/chart-with-subchart-notes/charts/subchart-with-notes/Chart.yaml new file mode 100644 index 000000000..5ac27f2fd --- /dev/null +++ b/cmd/helm/testdata/testcharts/chart-with-subchart-notes/charts/subchart-with-notes/Chart.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +description: Subchart with notes +name: subchart-with-notes +version: 0.0.1 diff --git a/cmd/helm/testdata/testcharts/chart-with-subchart-notes/charts/subchart-with-notes/templates/NOTES.txt b/cmd/helm/testdata/testcharts/chart-with-subchart-notes/charts/subchart-with-notes/templates/NOTES.txt new file mode 100644 index 000000000..1f61a294e --- /dev/null +++ b/cmd/helm/testdata/testcharts/chart-with-subchart-notes/charts/subchart-with-notes/templates/NOTES.txt @@ -0,0 +1 @@ +SUBCHART NOTES diff --git a/cmd/helm/testdata/testcharts/chart-with-subchart-notes/charts/subchart-with-notes/values.yaml b/cmd/helm/testdata/testcharts/chart-with-subchart-notes/charts/subchart-with-notes/values.yaml new file mode 100644 index 000000000..e69de29bb diff --git a/cmd/helm/testdata/testcharts/chart-with-subchart-notes/requirements.yaml b/cmd/helm/testdata/testcharts/chart-with-subchart-notes/requirements.yaml new file mode 100644 index 000000000..6351bf042 --- /dev/null +++ b/cmd/helm/testdata/testcharts/chart-with-subchart-notes/requirements.yaml @@ -0,0 +1,3 @@ +dependencies: + - name: subchart-with-notes + version: 0.0.1 diff --git a/cmd/helm/testdata/testcharts/chart-with-subchart-notes/templates/NOTES.txt b/cmd/helm/testdata/testcharts/chart-with-subchart-notes/templates/NOTES.txt new file mode 100644 index 000000000..9e166d370 --- /dev/null +++ b/cmd/helm/testdata/testcharts/chart-with-subchart-notes/templates/NOTES.txt @@ -0,0 +1 @@ +PARENT NOTES diff --git a/cmd/helm/testdata/testcharts/chart-with-subchart-notes/values.yaml b/cmd/helm/testdata/testcharts/chart-with-subchart-notes/values.yaml new file mode 100644 index 000000000..e69de29bb diff --git a/cmd/helm/upgrade_test.go b/cmd/helm/upgrade_test.go index 3cecbe6d3..4956c0247 100644 --- a/cmd/helm/upgrade_test.go +++ b/cmd/helm/upgrade_test.go @@ -196,6 +196,38 @@ func TestUpgradeWithStringValue(t *testing.T) { } +func TestUpgradeInstallWithSubchartNotes(t *testing.T) { + + releaseName := "wacky-bunny-v1" + relMock, ch, _ := prepareMockRelease(releaseName, t) + + defer resetEnv()() + + store := storageFixture() + + store.Create(relMock(releaseName, 1, ch)) + + cmd := fmt.Sprintf("upgrade %s -i --render-subchart-notes '%s'", releaseName, "testdata/testcharts/chart-with-subchart-notes") + _, _, err := executeActionCommandC(store, cmd) + if err != nil { + t.Errorf("unexpected error, got '%v'", err) + } + + upgradedRel, err := store.Get(releaseName, 2) + if err != nil { + t.Errorf("unexpected error, got '%v'", err) + } + + if !strings.Contains(upgradedRel.Info.Notes, "PARENT NOTES") { + t.Errorf("The parent notes are not set correctly. NOTES: %s", upgradedRel.Info.Notes) + } + + if !strings.Contains(upgradedRel.Info.Notes, "SUBCHART NOTES") { + t.Errorf("The subchart notes are not set correctly. NOTES: %s", upgradedRel.Info.Notes) + } + +} + func TestUpgradeWithValuesFile(t *testing.T) { releaseName := "funny-bunny-v4" From a7e79ee434abe23a9d6977f08516cb21da8b39ae Mon Sep 17 00:00:00 2001 From: Jon Leonard Date: Thu, 26 Mar 2020 13:29:38 -0400 Subject: [PATCH 4/7] Delete unneeded chart output Signed-off-by: Jon Leonard --- .../output/upgrade-install-with-subchart-notes.txt | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 cmd/helm/testdata/output/upgrade-install-with-subchart-notes.txt diff --git a/cmd/helm/testdata/output/upgrade-install-with-subchart-notes.txt b/cmd/helm/testdata/output/upgrade-install-with-subchart-notes.txt deleted file mode 100644 index 767b8c5d9..000000000 --- a/cmd/helm/testdata/output/upgrade-install-with-subchart-notes.txt +++ /dev/null @@ -1,11 +0,0 @@ -Release "wacky-bunny" has been upgraded. Happy Helming! -NAME: wacky-bunny -LAST DEPLOYED: Fri Sep 2 22:04:05 1977 -NAMESPACE: default -STATUS: deployed -REVISION: 2 -TEST SUITE: None -NOTES: -SUBCHART NOTES - -PARENT NOTES From 3706aa7ca666fda6d8301c55118fa1c092f124a2 Mon Sep 17 00:00:00 2001 From: Matt Butcher Date: Mon, 30 Mar 2020 16:33:19 -0600 Subject: [PATCH 5/7] fix: update unit test for go 1.14 error string change (#7835) * fix: update unit test for go 1.14 error string change Signed-off-by: Matt Butcher * changed strategy based on conversation with Adam Signed-off-by: Matt Butcher --- pkg/repo/chartrepo_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/repo/chartrepo_test.go b/pkg/repo/chartrepo_test.go index c6b227acf..f50d6a2b6 100644 --- a/pkg/repo/chartrepo_test.go +++ b/pkg/repo/chartrepo_test.go @@ -308,7 +308,7 @@ func TestErrorFindChartInRepoURL(t *testing.T) { if _, err := FindChartInRepoURL("http://someserver/something", "nginx", "", "", "", "", g); err == nil { t.Errorf("Expected error for bad chart URL, but did not get any errors") - } else if !strings.Contains(err.Error(), `looks like "http://someserver/something" is not a valid chart repository or cannot be reached: Get http://someserver/something/index.yaml`) { + } else if !strings.Contains(err.Error(), `looks like "http://someserver/something" is not a valid chart repository or cannot be reached`) { t.Errorf("Expected error for bad chart URL, but got a different error (%v)", err) } From cfdd466192f672bf18655981cad249d3e82dad5f Mon Sep 17 00:00:00 2001 From: Jon Leonard Date: Tue, 31 Mar 2020 12:12:39 -0400 Subject: [PATCH 6/7] update test chart to helm3 format Signed-off-by: Jon Leonard --- .../testdata/testcharts/chart-with-subchart-notes/Chart.yaml | 5 ++++- .../charts/subchart-with-notes/Chart.yaml | 2 +- .../testcharts/chart-with-subchart-notes/requirements.yaml | 3 --- 3 files changed, 5 insertions(+), 5 deletions(-) delete mode 100644 cmd/helm/testdata/testcharts/chart-with-subchart-notes/requirements.yaml diff --git a/cmd/helm/testdata/testcharts/chart-with-subchart-notes/Chart.yaml b/cmd/helm/testdata/testcharts/chart-with-subchart-notes/Chart.yaml index 6ea036678..90545a6a3 100644 --- a/cmd/helm/testdata/testcharts/chart-with-subchart-notes/Chart.yaml +++ b/cmd/helm/testdata/testcharts/chart-with-subchart-notes/Chart.yaml @@ -1,4 +1,7 @@ -apiVersion: v1 +apiVersion: v2 description: Chart with subchart notes name: chart-with-subchart-notes version: 0.0.1 +dependencies: + - name: subchart-with-notes + version: 0.0.1 diff --git a/cmd/helm/testdata/testcharts/chart-with-subchart-notes/charts/subchart-with-notes/Chart.yaml b/cmd/helm/testdata/testcharts/chart-with-subchart-notes/charts/subchart-with-notes/Chart.yaml index 5ac27f2fd..f0fead9ee 100644 --- a/cmd/helm/testdata/testcharts/chart-with-subchart-notes/charts/subchart-with-notes/Chart.yaml +++ b/cmd/helm/testdata/testcharts/chart-with-subchart-notes/charts/subchart-with-notes/Chart.yaml @@ -1,4 +1,4 @@ -apiVersion: v1 +apiVersion: v2 description: Subchart with notes name: subchart-with-notes version: 0.0.1 diff --git a/cmd/helm/testdata/testcharts/chart-with-subchart-notes/requirements.yaml b/cmd/helm/testdata/testcharts/chart-with-subchart-notes/requirements.yaml deleted file mode 100644 index 6351bf042..000000000 --- a/cmd/helm/testdata/testcharts/chart-with-subchart-notes/requirements.yaml +++ /dev/null @@ -1,3 +0,0 @@ -dependencies: - - name: subchart-with-notes - version: 0.0.1 From f927275461d048a095c7720e296690ebf169af31 Mon Sep 17 00:00:00 2001 From: Jon Leonard Date: Tue, 31 Mar 2020 12:14:40 -0400 Subject: [PATCH 7/7] remove unneeded values files from testchart Signed-off-by: Jon Leonard --- .../charts/subchart-with-notes/values.yaml | 0 .../testdata/testcharts/chart-with-subchart-notes/values.yaml | 0 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 cmd/helm/testdata/testcharts/chart-with-subchart-notes/charts/subchart-with-notes/values.yaml delete mode 100644 cmd/helm/testdata/testcharts/chart-with-subchart-notes/values.yaml diff --git a/cmd/helm/testdata/testcharts/chart-with-subchart-notes/charts/subchart-with-notes/values.yaml b/cmd/helm/testdata/testcharts/chart-with-subchart-notes/charts/subchart-with-notes/values.yaml deleted file mode 100644 index e69de29bb..000000000 diff --git a/cmd/helm/testdata/testcharts/chart-with-subchart-notes/values.yaml b/cmd/helm/testdata/testcharts/chart-with-subchart-notes/values.yaml deleted file mode 100644 index e69de29bb..000000000