Skip to content

Commit

Permalink
chore: align property key with template config
Browse files Browse the repository at this point in the history
  • Loading branch information
leonsteinhaeuser committed Jan 8, 2024
1 parent 936ae8d commit 25219f1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
10 changes: 5 additions & 5 deletions internal/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,28 +106,28 @@ func Bootstrap(chartLocation string, force bool) error {

files := []struct {
path string
content []byte
content string
propertyKey string
values string
}{
{
// pdb.yaml
path: filepath.Join(templateFolderLocation, PodDisruptionBudgetFileName),
content: []byte(fmt.Sprintf(pdbTemplate, metadata.Name)),
content: pdbTemplate,
propertyKey: "pdb",
values: pdbValuesYaml,
},
{
// networkpolicy.yaml
path: filepath.Join(templateFolderLocation, NetworkPolicyFileName),
content: []byte(fmt.Sprintf(networkPolicyTemplate, metadata.Name)),
content: networkPolicyTemplate,
propertyKey: "networkPolicy",
values: networkPolicyValuesYaml,
},
{
// servicemonitor.yaml
path: filepath.Join(templateFolderLocation, ServiceMonitorFileName),
content: []byte(fmt.Sprintf(serviceMonitorTemplate, metadata.Name)),
content: serviceMonitorTemplate,
propertyKey: "metrics",
values: serviceMonitorValuesYaml,
},
Expand All @@ -138,7 +138,7 @@ func Bootstrap(chartLocation string, force bool) error {
// There is no handle to a preferred output stream here.
fmt.Fprintf(os.Stderr, "WARNING: File %q already exists. Overwriting.\n", file.path)
}
if err := os.WriteFile(file.path, file.content, 0644); err != nil {
if err := os.WriteFile(file.path, []byte(fmt.Sprintf(file.content, metadata.Name, file.propertyKey)), 0644); err != nil {
return err
}
// write values.yaml if there is content
Expand Down
30 changes: 15 additions & 15 deletions internal/bootstrap/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,30 @@ const (

// manifest templates

const pdbTemplate = `{{- if .Values.pdb.enabled }}
const pdbTemplate = `{{- if .Values.%[2]s.enabled }}
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: {{ include "%[1]s.fullname" . }}
labels:
{{- include "%[1]s.labels" . | nindent 4 }}
{{- with .Values.pdb.annotations }}
{{- with .Values.%[2]s.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- with .Values.pdb.maxUnavailable }}
{{- with .Values.%[2]s.maxUnavailable }}
maxUnavailable: {{ . }}
{{- end }}
{{- with .Values.pdb.minAvailable }}
{{- with .Values.%[2]s.minAvailable }}
minAvailable: {{ . }}
{{- end }}
selector:
matchLabels:
{{- include "%[1]s.selectorLabels" . | nindent 6 }}
{{- include "%[1]s.selectorLabels" . | nindent 6 }}
{{- end }}
`
const networkPolicyTemplate = `{{- if .Values.networkPolicy.enabled }}
const networkPolicyTemplate = `{{- if .Values.%[2]s.enabled }}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
Expand All @@ -46,17 +46,17 @@ spec:
matchLabels:
{{- include "%[1]s.selectorLabels" . | nindent 6 }}
policyTypes:
{{- if .Values.networkPolicy.ingress }}
{{- if .Values.%[2]s.ingress }}
- Ingress
{{- end }}
{{- if .Values.networkPolicy.egress }}
{{- if .Values.%[2]s.egress }}
- Egress
{{- end }}
{{- with .Values.networkPolicy.ingress }}
{{- with .Values.%[2]s.ingress }}
ingress:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.networkPolicy.egress }}
{{- with .Values.%[2]s.egress }}
egress:
{{- toYaml . | nindent 4 }}
{{- end -}}
Expand All @@ -67,19 +67,19 @@ apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ template "%[1]s.fullname" . }}
{{- if .Values.%[1]s.serviceMonitor.namespace }}
namespace: {{ .Values.%[1]s.serviceMonitor.namespace }}
{{- if .Values.%[2]s.serviceMonitor.namespace }}
namespace: {{ .Values.%[2]s.serviceMonitor.namespace }}
{{- end }}
labels:
{{- include "%[1]s.labels" . | nindent 4 }}
spec:
endpoints:
- port: {{ .Values.service.port }}
path: {{ .Values.%[1]s.serviceMonitor.metricsPath }}
{{- with .Values.%[1]s.serviceMonitor.interval }}
path: {{ .Values.%[2]s.serviceMonitor.metricsPath }}
{{- with .Values.%[2]s.serviceMonitor.interval }}
interval: {{ . }}
{{- end }}
{{- with .Values.%[1]s.serviceMonitor.scrapeTimeout }}
{{- with .Values.%[2]s.serviceMonitor.scrapeTimeout }}
scrapeTimeout: {{ . }}
{{- end }}
selector:
Expand Down

0 comments on commit 25219f1

Please sign in to comment.