Skip to content

Commit

Permalink
chore(common): fix tests and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
stavros-k committed Feb 10, 2024
1 parent 8658808 commit a46f233
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 21 deletions.
47 changes: 47 additions & 0 deletions library/common-test/tests/lists/volumeScheduleList_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
suite: volumeSnapshotList spec test
templates:
- common.yaml
release:
name: test-release-name
namespace: test-release-namespace
tests:
- it: should generate correct spec
set:
schedulesList:
- name: example1
enabled: true
schedule: "0 2 * * *"
- name: example2
enabled: true
schedule: "0 2 * * *"
useOwnerReferencesInBackup: true
asserts:
- documentIndex: &scheduleDoc 0
isKind:
of: Schedule
- documentIndex: *scheduleDoc
isAPIVersion:
of: velero.io/v1
- documentIndex: *scheduleDoc
equal:
path: spec
value:
schedule: 0 2 * * *
template:
includedNamespaces:
- test-release-namespace
- documentIndex: &scheduleDoc 1
isKind:
of: Schedule
- documentIndex: *scheduleDoc
isAPIVersion:
of: velero.io/v1
- documentIndex: *scheduleDoc
equal:
path: spec
value:
schedule: "0 2 * * *"
useOwnerReferencesInBackup: true
template:
includedNamespaces:
- test-release-namespace
6 changes: 4 additions & 2 deletions library/common-test/tests/veleroSchedule/spec_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ tests:
includedNamespaces:
- test-release-namespace

- it: should generate correct spec with template
- it: should generate correct spec with template and override on includedNamespaces
set:
schedules:
my-sched:
Expand All @@ -60,6 +60,8 @@ tests:
ttl: 720h
includeClusterResources: true
snapshotVolumes: true
includedNamespaces:
- some-namespace
asserts:
- documentIndex: &scheduleDoc 0
isKind:
Expand All @@ -77,7 +79,7 @@ tests:
includeClusterResources: true
snapshotVolumes: true
includedNamespaces:
- test-release-namespace
- some-namespace

# Failures
- it: should fail without schedule
Expand Down
2 changes: 1 addition & 1 deletion library/common/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ maintainers:
name: common
sources: null
type: library
version: 17.3.9
version: 17.3.10
33 changes: 20 additions & 13 deletions library/common/templates/class/velero/_schedule.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ objectData:
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData }}
{{- $namespace := (include "tc.v1.common.lib.metadata.namespace" (dict "rootCtx" $rootCtx "objectData" $objectData "caller" "Schedule")) -}}

{{/* Get existing BSLs */}}
{{- $lookupBSL := (lookup "velero.io/v1" "BackupStorageLocation" "" "") -}}
{{- if and $lookupBSL $lookupBSL.items -}}
{{- $lookupBSL = $lookupBSL.items -}}
{{- end -}}
{{- range $BSL := $lookupBSL -}}
{{- $namespace = $BSL.metadata.namespace -}}
{{/* TODO: Why we only keep one namespace of the found BSLs?
In this case we can just get the `| first` item
*/}}
{{- range $bsl := $lookupBSL.items -}}
{{- $namespace = $bsl.metadata.namespace -}}
{{- end }}
---
apiVersion: velero.io/v1
Expand All @@ -44,7 +46,7 @@ spec:
useOwnerReferencesInBackup: {{ $objectData.useOwnerReferencesInBackup }}
{{- end }}
template:
{{- if not $objectData.template }}
{{- if not $objectData.template }}
includeClusterResources: true
includedNamespaces:
- {{ include "tc.v1.common.lib.metadata.namespace" (dict "rootCtx" $rootCtx "objectData" $objectData "caller" "Schedule") }}
Expand All @@ -56,10 +58,18 @@ spec:
- matchLabels:
owner: helm
name: {{ $rootCtx.Release.Name }}
{{- end -}}

{{- with $objectData.template }}
{{- end -}}
{{- with $objectData.template }}
{{/*
TODO: This toYaml should **not** be here if any of the checks
below renders when a key is present. Currently, checks below
only render when a key is not present, which is mostly safe
to use along with the toYaml.
*/}}
{{- toYaml . | nindent 4 }}
{{- if not (hasKey . "includeClusterResources") }}
includeClusterResources: true
{{- end -}}
{{- if not .orLabelSelectors }}
orLabelSelectors:
- matchLabels:
Expand All @@ -74,8 +84,5 @@ spec:
includedNamespaces:
- {{ include "tc.v1.common.lib.metadata.namespace" (dict "rootCtx" $rootCtx "objectData" $objectData "caller" "Schedule") }}
{{- end -}}
{{- if not (hasKey . "includeClusterResources") }}
includeClusterResources: true
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
8 changes: 3 additions & 5 deletions library/common/templates/lib/velero/_providerSecret.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
{{- $prefix := .prefix -}}

{{- $creds := "" -}}
{{- $provider := "" -}}
{{/* Make sure provider is a string */}}
{{- $provider := $objectData.provider | toString -}}

{{/* Use credential provider when creating secret for VSL */}}
{{/* Make sure provider is a string */}}
{{- if eq $prefix "vsl" -}}
{{- $provider = $objectData.credential.provider | toString -}}
{{- else -}}
{{- $provider = $objectData.provider | toString -}}
{{- end -}}


{{- if and (eq $provider "aws") $objectData.credential.aws -}}
{{- $creds = (include "tc.v1.common.lib.velero.provider.aws.secret" (dict "creds" $objectData.credential.aws) | fromYaml).data -}}
Expand Down

0 comments on commit a46f233

Please sign in to comment.