feat: add pdb to chart create util

Signed-off-by: Naseem Ullah <24660299+naseemkullah@users.noreply.github.com>
pull/10740/head
Naseem Ullah 4 years ago
parent 2153f70747
commit 5746c7593c
No known key found for this signature in database
GPG Key ID: 86CADBF6CB95B15F

@ -30,6 +30,8 @@ import (
"helm.sh/helm/v3/pkg/helmpath" "helm.sh/helm/v3/pkg/helmpath"
) )
const expectedNumberOfTemplates = 10
func TestCreateCmd(t *testing.T) { func TestCreateCmd(t *testing.T) {
defer ensure.HelmHome(t)() defer ensure.HelmHome(t)()
cname := "testchart" cname := "testchart"
@ -106,7 +108,6 @@ func TestCreateStarterCmd(t *testing.T) {
t.Errorf("Wrong API version: %q", c.Metadata.APIVersion) t.Errorf("Wrong API version: %q", c.Metadata.APIVersion)
} }
expectedNumberOfTemplates := 9
if l := len(c.Templates); l != expectedNumberOfTemplates { if l := len(c.Templates); l != expectedNumberOfTemplates {
t.Errorf("Expected %d templates, got %d", expectedNumberOfTemplates, l) 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) t.Errorf("Wrong API version: %q", c.Metadata.APIVersion)
} }
expectedNumberOfTemplates := 9
if l := len(c.Templates); l != expectedNumberOfTemplates { if l := len(c.Templates); l != expectedNumberOfTemplates {
t.Errorf("Expected %d templates, got %d", expectedNumberOfTemplates, l) t.Errorf("Expected %d templates, got %d", expectedNumberOfTemplates, l)
} }

@ -63,6 +63,8 @@ const (
ServiceAccountName = TemplatesDir + sep + "serviceaccount.yaml" ServiceAccountName = TemplatesDir + sep + "serviceaccount.yaml"
// HorizontalPodAutoscalerName is the name of the example hpa file. // HorizontalPodAutoscalerName is the name of the example hpa file.
HorizontalPodAutoscalerName = TemplatesDir + sep + "hpa.yaml" 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 is the name of the example NOTES.txt file.
NotesName = TemplatesDir + sep + "NOTES.txt" NotesName = TemplatesDir + sep + "NOTES.txt"
// HelpersName is the name of the example helpers file. // HelpersName is the name of the example helpers file.
@ -180,6 +182,9 @@ autoscaling:
targetCPUUtilizationPercentage: 80 targetCPUUtilizationPercentage: 80
# targetMemoryUtilizationPercentage: 80 # targetMemoryUtilizationPercentage: 80
podDisruptionBudget: {}
# maxUnavailable: 1
nodeSelector: {} nodeSelector: {}
tolerations: [] tolerations: []
@ -399,6 +404,20 @@ spec:
{{- end }} {{- end }}
` `
const defaultPodDisruptionBudget = `{{- if .Values.podDisruptionBudget -}}
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: {{ include "<CHARTNAME>.fullname" . }}
labels:
{{- include "<CHARTNAME>.labels" . | nindent 4 }}
spec:
{{- toYaml .Values.podDisruptionBudget | nindent 2 }}
selector:
{{- include "<CHARTNAME>.selectorLabels" . | nindent 4 }}
{{- end }}
`
const defaultNotes = `1. Get the application URL by running these commands: const defaultNotes = `1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }} {{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }} {{- range $host := .Values.ingress.hosts }}
@ -630,6 +649,11 @@ func Create(name, dir string) (string, error) {
path: filepath.Join(cdir, HorizontalPodAutoscalerName), path: filepath.Join(cdir, HorizontalPodAutoscalerName),
content: transform(defaultHorizontalPodAutoscaler, name), content: transform(defaultHorizontalPodAutoscaler, name),
}, },
{
// pdb.yaml
path: filepath.Join(cdir, PodDisruptionBudgetName),
content: transform(defaultPodDisruptionBudget, name),
},
{ {
// NOTES.txt // NOTES.txt
path: filepath.Join(cdir, NotesName), path: filepath.Join(cdir, NotesName),

@ -50,8 +50,11 @@ func TestCreate(t *testing.T) {
ChartfileName, ChartfileName,
DeploymentName, DeploymentName,
HelpersName, HelpersName,
HorizontalPodAutoscalerName,
IgnorefileName, IgnorefileName,
IngressFileName,
NotesName, NotesName,
PodDisruptionBudgetName,
ServiceAccountName, ServiceAccountName,
ServiceName, ServiceName,
TemplatesDir, TemplatesDir,

Loading…
Cancel
Save