diff --git a/cmd/helm/create_test.go b/cmd/helm/create_test.go index 1db6bed52..2f0e780fe 100644 --- a/cmd/helm/create_test.go +++ b/cmd/helm/create_test.go @@ -30,6 +30,8 @@ import ( "helm.sh/helm/v3/pkg/helmpath" ) +const expectedNumberOfTemplates = 10 + func TestCreateCmd(t *testing.T) { defer ensure.HelmHome(t)() cname := "testchart" @@ -106,7 +108,6 @@ func TestCreateStarterCmd(t *testing.T) { t.Errorf("Wrong API version: %q", c.Metadata.APIVersion) } - expectedNumberOfTemplates := 9 if l := len(c.Templates); l != expectedNumberOfTemplates { t.Errorf("Expected %d templates, got %d", expectedNumberOfTemplates, l) } @@ -174,7 +175,6 @@ func TestCreateStarterAbsoluteCmd(t *testing.T) { t.Errorf("Wrong API version: %q", c.Metadata.APIVersion) } - 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 ca79e7ab2..a3071cebc 100644 --- a/pkg/chartutil/create.go +++ b/pkg/chartutil/create.go @@ -63,6 +63,8 @@ const ( ServiceAccountName = TemplatesDir + sep + "serviceaccount.yaml" // HorizontalPodAutoscalerName is the name of the example hpa file. HorizontalPodAutoscalerName = TemplatesDir + sep + "hpa.yaml" + // PodDisruptionBudgetName is the name of the example pdb file. + PodDisruptionBudgetName = TemplatesDir + sep + "pdb.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. @@ -180,6 +182,9 @@ autoscaling: targetCPUUtilizationPercentage: 80 # targetMemoryUtilizationPercentage: 80 +podDisruptionBudget: {} + # maxUnavailable: 1 + nodeSelector: {} tolerations: [] @@ -399,6 +404,20 @@ spec: {{- end }} ` +const defaultPodDisruptionBudget = `{{- if .Values.podDisruptionBudget -}} +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: {{ include ".fullname" . }} + labels: + {{- include ".labels" . | nindent 4 }} +spec: + {{- toYaml .Values.podDisruptionBudget | nindent 2 }} + selector: + {{- include ".selectorLabels" . | nindent 4 }} +{{- end }} +` + const defaultNotes = `1. Get the application URL by running these commands: {{- if .Values.ingress.enabled }} {{- range $host := .Values.ingress.hosts }} @@ -630,6 +649,11 @@ func Create(name, dir string) (string, error) { path: filepath.Join(cdir, HorizontalPodAutoscalerName), content: transform(defaultHorizontalPodAutoscaler, name), }, + { + // pdb.yaml + path: filepath.Join(cdir, PodDisruptionBudgetName), + content: transform(defaultPodDisruptionBudget, name), + }, { // NOTES.txt path: filepath.Join(cdir, NotesName), diff --git a/pkg/chartutil/create_test.go b/pkg/chartutil/create_test.go index f123a37cd..762faa6b8 100644 --- a/pkg/chartutil/create_test.go +++ b/pkg/chartutil/create_test.go @@ -50,8 +50,11 @@ func TestCreate(t *testing.T) { ChartfileName, DeploymentName, HelpersName, + HorizontalPodAutoscalerName, IgnorefileName, + IngressFileName, NotesName, + PodDisruptionBudgetName, ServiceAccountName, ServiceName, TemplatesDir,