Skip to content

Commit daf8605

Browse files
authored
support arbitrary env-vars (#52)
1 parent d8958d7 commit daf8605

File tree

4 files changed

+127
-0
lines changed

4 files changed

+127
-0
lines changed

api/v1alpha1/migration_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ type FlywayConfiguration struct {
123123
// See https://documentation.red-gate.com/fd/baseline-on-migrate-224919695.html
124124
// +kubebuilder:validation:Optional
125125
BaselineOnMigrate *bool `json:"baselineOnMigrate"`
126+
127+
// Arbitrary entries to set as env-vars to Flyway migration job.
128+
// +kubebuilder:validation:Optional
129+
EnvVars []v1.EnvVar `json:"envVars"`
126130
}
127131

128132
// MigrationSource defines the source for the flyway-migrations.

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/flyway.davidkarlsen.com_migrations.yaml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,121 @@ spec:
8888
defaultSchema:
8989
description: The default flyway schema to use. See https://documentation.red-gate.com/fd/default-schema-184127496.html
9090
type: string
91+
envVars:
92+
description: Arbitrary entries to set as env-vars to Flyway migration
93+
job.
94+
items:
95+
description: EnvVar represents an environment variable present
96+
in a Container.
97+
properties:
98+
name:
99+
description: Name of the environment variable. Must be a
100+
C_IDENTIFIER.
101+
type: string
102+
value:
103+
description: 'Variable references $(VAR_NAME) are expanded
104+
using the previously defined environment variables in
105+
the container and any service environment variables. If
106+
a variable cannot be resolved, the reference in the input
107+
string will be unchanged. Double $$ are reduced to a single
108+
$, which allows for escaping the $(VAR_NAME) syntax: i.e.
109+
"$$(VAR_NAME)" will produce the string literal "$(VAR_NAME)".
110+
Escaped references will never be expanded, regardless
111+
of whether the variable exists or not. Defaults to "".'
112+
type: string
113+
valueFrom:
114+
description: Source for the environment variable's value.
115+
Cannot be used if value is not empty.
116+
properties:
117+
configMapKeyRef:
118+
description: Selects a key of a ConfigMap.
119+
properties:
120+
key:
121+
description: The key to select.
122+
type: string
123+
name:
124+
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
125+
TODO: Add other useful fields. apiVersion, kind,
126+
uid?'
127+
type: string
128+
optional:
129+
description: Specify whether the ConfigMap or its
130+
key must be defined
131+
type: boolean
132+
required:
133+
- key
134+
type: object
135+
x-kubernetes-map-type: atomic
136+
fieldRef:
137+
description: 'Selects a field of the pod: supports metadata.name,
138+
metadata.namespace, `metadata.labels[''<KEY>'']`,
139+
`metadata.annotations[''<KEY>'']`, spec.nodeName,
140+
spec.serviceAccountName, status.hostIP, status.podIP,
141+
status.podIPs.'
142+
properties:
143+
apiVersion:
144+
description: Version of the schema the FieldPath
145+
is written in terms of, defaults to "v1".
146+
type: string
147+
fieldPath:
148+
description: Path of the field to select in the
149+
specified API version.
150+
type: string
151+
required:
152+
- fieldPath
153+
type: object
154+
x-kubernetes-map-type: atomic
155+
resourceFieldRef:
156+
description: 'Selects a resource of the container: only
157+
resources limits and requests (limits.cpu, limits.memory,
158+
limits.ephemeral-storage, requests.cpu, requests.memory
159+
and requests.ephemeral-storage) are currently supported.'
160+
properties:
161+
containerName:
162+
description: 'Container name: required for volumes,
163+
optional for env vars'
164+
type: string
165+
divisor:
166+
anyOf:
167+
- type: integer
168+
- type: string
169+
description: Specifies the output format of the
170+
exposed resources, defaults to "1"
171+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
172+
x-kubernetes-int-or-string: true
173+
resource:
174+
description: 'Required: resource to select'
175+
type: string
176+
required:
177+
- resource
178+
type: object
179+
x-kubernetes-map-type: atomic
180+
secretKeyRef:
181+
description: Selects a key of a secret in the pod's
182+
namespace
183+
properties:
184+
key:
185+
description: The key of the secret to select from. Must
186+
be a valid secret key.
187+
type: string
188+
name:
189+
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
190+
TODO: Add other useful fields. apiVersion, kind,
191+
uid?'
192+
type: string
193+
optional:
194+
description: Specify whether the Secret or its key
195+
must be defined
196+
type: boolean
197+
required:
198+
- key
199+
type: object
200+
x-kubernetes-map-type: atomic
201+
type: object
202+
required:
203+
- name
204+
type: object
205+
type: array
91206
flywayImage:
92207
description: Reference to the flyway image to use.
93208
type: string

internal/controller/jobutil.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ func createJobSpec(migration *flywayv1alpha1.Migration) *batchv1.Job {
9292
Value: *migration.Spec.FlywayConfiguration.DefaultSchema,
9393
})
9494
}
95+
envVars = append(envVars, migration.Spec.FlywayConfiguration.EnvVars...)
9596
envVars = append(envVars, migration.Spec.MigrationSource.GetPlaceholdersAsEnvVars()...)
9697

9798
job := &batchv1.Job{

0 commit comments

Comments
 (0)