This repository has been archived by the owner on Jun 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 307
/
values.star
92 lines (80 loc) · 3.56 KB
/
values.star
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
load("@ytt:data", "data")
load("@ytt:assert", "assert")
load("@ytt:overlay", "overlay")
#! Use this library for functions that operate on the values data.
# helpers
def secret_name():
if values.credential.useDefaultSecret:
return values.credential.name
end
return values.backupStorageLocation.spec.existingSecret.name
end
def resource(kind, name):
return {"kind": kind,"metadata":{"name": name}}
end
def labels():
return {"component": "velero"}
end
# validations
def validate_storage():
values.backupStorageLocation.spec.provider or assert.fail("backupStorageLocation needs a provider, velero needs at least one backup storage location")
values.backupStorageLocation.spec.objectStorage.bucket or assert.fail("backupStorageLocation needs a bucket")
end
# Note: aws and azure are the only object storage providers that the TCE Velero package supports.
# Neither vSphere or Docker provides storage.
def validate_storage_provider():
providers = ["aws", "azure"]
if values.backupStorageLocation.spec.provider:
values.backupStorageLocation.spec.provider in providers or assert.fail("infrastructure provider should be either aws or azure")
end
end
# Note: Docker does not provide snapshotting capabilities.
def validate_snapshot_provider():
if values.volumeSnapshotLocation.snapshotsEnabled:
providers = ["aws", "azure", "vsphere"]
if values.volumeSnapshotLocation.spec.provider:
values.volumeSnapshotLocation.spec.provider in providers or assert.fail("a snapshot provider should be either aws, vsphere or azure")
end
end
end
def validate_provider_config():
if values.backupStorageLocation.spec.provider == "aws":
values.backupStorageLocation.spec.configAWS.region or assert.fail("a region must be set for the AWS backup storage location")
end
if values.backupStorageLocation.spec.provider == "azure":
values.backupStorageLocation.spec.configAzure.resourceGroup or assert.fail("a resourceGroup must be set for the Azure backup storage location")
values.backupStorageLocation.spec.configAzure.storageAccount or assert.fail("a storageAccount must be set for the Azure backup storage location")
end
if values.volumeSnapshotLocation.snapshotsEnabled:
if values.volumeSnapshotLocation.spec.provider == "aws":
values.volumeSnapshotLocation.spec.configAWS.region or assert.fail("a region must be set for the AWS volume snapshot location")
end
end
end
def validate_secret():
if values.credential.useDefaultSecret:
values.credential.name or assert.fail("must specify a name for the default secret to be used by Velero")
values.credential.secretContents or assert.fail("must specify the content for the default secret to be used by Velero")
values.credential.secretContents.cloud != None or assert.fail("the default secret must have a key named `cloud`")
values.credential.secretContents.cloud or assert.fail("the default secret key `cloud` must contain the raw credentials")
else:
values.backupStorageLocation.spec.existingSecret.name or assert.fail("must specify the name of the existing secret to be used by Velero")
values.backupStorageLocation.spec.existingSecret.key or assert.fail("must specify the key of the existing secret to be used by Velero")
end
end
def validate_velero():
validate_funcs = [
validate_storage_provider,
validate_snapshot_provider,
validate_provider_config,
validate_storage,
validate_secret,
]
for validate_func in validate_funcs:
validate_func()
end
end
# export
values = data.values
velero_app = overlay.subset({"metadata": {"labels": labels()}})
validate_velero()