Skip to content

Commit

Permalink
make the actions into a list
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkarlsen committed Sep 28, 2023
1 parent bd82ead commit 6333c35
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 8 deletions.
15 changes: 12 additions & 3 deletions api/v1alpha1/migration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ type MigrationSpec struct {
// +kubebuilder:validation:Required
Database Database `json:"database"`

// settings for flyway
FlywayConfiguration FlywayConfiguration `json:"flywayConfiguration"`

// settings defining the SQL migrations
// +kubebuilder:validation:Required
MigrationSource MigrationSource `json:"migrationSource"`
Expand Down Expand Up @@ -87,13 +90,19 @@ func (r *Migration) GetCredentials() v1.SecretReference {
}
}

// MigrationSource defines the source for the flyway-migrations.
type MigrationSource struct {

type FlywayConfiguration struct {
// Reference to the flyway image to use.
// +kubebuilder:validation:Optional
FlywayImage string `json:"flywayImage"`

// The flyway actions to apply, like "info", "migrate"
// +kubebuilder:default={"info", "migrate", "info"}
CommandLines []string `json:"commandLines"`
}

// MigrationSource defines the source for the flyway-migrations.
type MigrationSource struct {

// Reference to the image holding the SQLs to migrate
// +kubebuilder:validation:Required
ImageRef string `json:"imageRef"`
Expand Down
21 changes: 21 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 19 additions & 3 deletions config/crd/bases/flyway.davidkarlsen.com_migrations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,24 @@ spec:
- jdbcUrl
- username
type: object
flywayConfiguration:
description: settings for flyway
properties:
commandLines:
default:
- info
- migrate
- info
description: The flyway actions to apply
items:
type: string
type: array
flywayImage:
description: Reference to the flyway image to use.
type: string
required:
- commandLines
type: object
migrationSource:
description: settings defining the SQL migrations
properties:
Expand All @@ -90,9 +108,6 @@ spec:
default: UTF-8
description: The encoding of the SQL-files.
type: string
flywayImage:
description: Reference to the flyway image to use.
type: string
imageRef:
description: Reference to the image holding the SQLs to migrate
type: string
Expand All @@ -113,6 +128,7 @@ spec:
type: object
required:
- database
- flywayConfiguration
- migrationSource
type: object
status:
Expand Down
11 changes: 9 additions & 2 deletions internal/controller/jobutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,17 @@ func hasSucceeded(job *batchv1.Job) bool {
}

func getFlywayImage(migration *flywayv1alpha1.Migration) string {
image, _ := lo.Coalesce(migration.Spec.MigrationSource.FlywayImage, env.GetDefault(envNameFlywayImage, defaultFlywayImage))
image, _ := lo.Coalesce(migration.Spec.FlywayConfiguration.FlywayImage, env.GetDefault(envNameFlywayImage, defaultFlywayImage))
return image
}

func getFlywayArgs(migration *flywayv1alpha1.Migration) []string {
args := migration.Spec.FlywayConfiguration.CommandLines
args = append(args, "-outputType=json")

return args
}

func createJobSpec(migration *flywayv1alpha1.Migration) *batchv1.Job {
const targetPath = "/mnt/target/"
envVars := []corev1.EnvVar{
Expand Down Expand Up @@ -109,7 +116,7 @@ func createJobSpec(migration *flywayv1alpha1.Migration) *batchv1.Job {
Name: "flyway",
Image: getFlywayImage(migration),
ImagePullPolicy: corev1.PullAlways,
Args: []string{"info", "migrate", "info", "-outputType=json"},
Args: getFlywayArgs(migration),
Env: envVars,
VolumeMounts: []corev1.VolumeMount{
{
Expand Down

0 comments on commit 6333c35

Please sign in to comment.