@@ -103,42 +103,55 @@ local util(k) = {
103
103
// For example, passing "volumeMount.withSubPath(subpath)" will result in
104
104
// a subpath mixin.
105
105
configVolumeMount(name, path, volumeMountMixin={})::
106
- local container = k.core.v1.container,
107
- deployment = k.apps.v1.deployment,
108
- volumeMount = k.core.v1.volumeMount,
109
- volume = k.core.v1.volume,
110
- addMount(c) = c + container.withVolumeMountsMixin(
111
- volumeMount.new(name, path) +
112
- volumeMountMixin,
113
- );
114
-
115
- deployment.mapContainers(addMount) +
116
- deployment.mixin.spec.template.spec.withVolumesMixin([
117
- volume.fromConfigMap(name, name),
118
- ]),
106
+ $.volumeMounts([$.volumeMountItem(name, path, volumeMountMixin)]),
119
107
120
108
// configMapVolumeMount adds a configMap to deployment-like objects.
121
109
// It will also add an annotation hash to ensure the pods are re-deployed
122
110
// when the config map changes.
123
111
configMapVolumeMount(configMap, path, volumeMountMixin={})::
124
- local name = configMap.metadata.name,
125
- hash = std.md5(std.toString (configMap)),
126
- container = k.core.v1.container,
112
+ $.volumeMounts([$.configMapVolumeMountItem(configMap, path, volumeMountMixin)]),
113
+
114
+
115
+ // configMapVolumeMountItem represents a config map to be mounted.
116
+ // It is used in the volumeMounts function
117
+ configMapVolumeMountItem(configMap, path, volumeMountMixin={})::
118
+ local name = configMap.metadata.name;
119
+ local annotations = { ['%s-hash' % name]: std.md5(std.toString (configMap)) };
120
+ $.volumeMountItem(name, path, volumeMountMixin, annotations),
121
+
122
+ // volumeMountItem represents a volume to be mounted.
123
+ // It is used in the volumeMounts function
124
+ volumeMountItem(name, path, volumeMountMixin={}, annotations={}):: {
125
+ name: name,
126
+ path: path,
127
+ volumeMountMixin: volumeMountMixin,
128
+ annotations: annotations,
129
+ },
130
+
131
+ // volumeMounts adds an array of volumeMountItem to deployment-like objects.
132
+ // It can also add a set of annotations for each mount
133
+ volumeMounts(mounts)::
134
+ local container = k.core.v1.container,
127
135
deployment = k.apps.v1.deployment,
128
136
volumeMount = k.core.v1.volumeMount,
129
- volume = k.core.v1.volume,
130
- addMount(c) = c + container.withVolumeMountsMixin(
131
- volumeMount.new(name, path) +
132
- volumeMountMixin,
137
+ volume = k.core.v1.volume;
138
+ local addMounts(c) = c + container.withVolumeMountsMixin([
139
+ volumeMount.new(m.name, m.path) +
140
+ m.volumeMountMixin
141
+ for m in mounts
142
+ ]);
143
+ local annotations = std.foldl (
144
+ function (acc, ann) acc + ann,
145
+ [m.annotations for m in mounts],
146
+ {}
133
147
);
134
148
135
- deployment.mapContainers(addMount) +
136
- deployment.mixin.spec.template.spec.withVolumesMixin([
137
- volume.fromConfigMap(name, name),
138
- ]) +
139
- deployment.mixin.spec.template.metadata.withAnnotationsMixin({
140
- ['%s-hash' % name]: hash,
141
- }),
149
+ deployment.mapContainers(addMounts)
150
+ + deployment.mixin.spec.template.spec.withVolumesMixin([
151
+ volume.fromConfigMap(m.name, m.name)
152
+ for m in mounts
153
+ ])
154
+ + (if annotations != {} then deployment.mixin.spec.template.metadata.withAnnotationsMixin(annotations) else {}),
142
155
143
156
hostVolumeMount(name, hostPath, path, readOnly=false, volumeMountMixin={})::
144
157
local container = k.core.v1.container,
0 commit comments