Skip to content

Commit

Permalink
atlasmigration: allow config for dev_db
Browse files Browse the repository at this point in the history
  • Loading branch information
giautm committed Apr 11, 2024
1 parent 62744a8 commit 0235a64
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 1 deletion.
7 changes: 7 additions & 0 deletions api/v1alpha1/atlasmigration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ type (
Cloud Cloud `json:"cloud,omitempty"`
// Dir defines the directory to use for migrations as a configmap key reference.
Dir Dir `json:"dir"`
// DevURL is the URL of the database to use for normalization and calculations.
// If not specified, the operator will spin up a temporary database container to use for these operations.
// +optional
DevURL string `json:"devURL"`
// DevURLFrom is a reference to a secret containing the URL of the database to use for normalization and calculations.
// +optional
DevURLFrom Secret `json:"devURLFrom,omitempty"`
// RevisionsSchema defines the schema that revisions table resides in
RevisionsSchema string `json:"revisionsSchema,omitempty"`
// BaselineVersion defines the baseline version of the database on the first migration.
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/atlasschema_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ type (
TargetSpec `json:",inline"`
// Desired Schema of the target.
Schema Schema `json:"schema,omitempty"`
// +optional
// DevURL is the URL of the database to use for normalization and calculations.
// If not specified, the operator will spin up a temporary database container to use for these operations.
// +optional
DevURL string `json:"devURL"`
// DevURLFrom is a reference to a secret containing the URL of the database to use for normalization and calculations.
// +optional
Expand Down
1 change: 1 addition & 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.

32 changes: 32 additions & 0 deletions charts/atlas-operator/templates/crds/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,38 @@ spec:
x-kubernetes-map-type: atomic
type: object
type: object
devURL:
description: |-
DevURL is the URL of the database to use for normalization and calculations.
If not specified, the operator will spin up a temporary database container to use for these operations.
type: string
devURLFrom:
description: DevURLFrom is a reference to a secret containing the
URL of the database to use for normalization and calculations.
properties:
secretKeyRef:
description: SecretKeyRef defines the secret key reference to
use for the user.
properties:
key:
description: The key of the secret to select from. Must be
a valid secret key.
type: string
name:
description: |-
Name of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?
type: string
optional:
description: Specify whether the Secret or its key must be
defined
type: boolean
required:
- key
type: object
x-kubernetes-map-type: atomic
type: object
dir:
description: Dir defines the directory to use for migrations as a
configmap key reference.
Expand Down
32 changes: 32 additions & 0 deletions config/crd/bases/db.atlasgo.io_atlasmigrations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,38 @@ spec:
x-kubernetes-map-type: atomic
type: object
type: object
devURL:
description: |-
DevURL is the URL of the database to use for normalization and calculations.
If not specified, the operator will spin up a temporary database container to use for these operations.
type: string
devURLFrom:
description: DevURLFrom is a reference to a secret containing the
URL of the database to use for normalization and calculations.
properties:
secretKeyRef:
description: SecretKeyRef defines the secret key reference to
use for the user.
properties:
key:
description: The key of the secret to select from. Must be
a valid secret key.
type: string
name:
description: |-
Name of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?
type: string
optional:
description: Specify whether the Secret or its key must be
defined
type: boolean
required:
- key
type: object
x-kubernetes-map-type: atomic
type: object
dir:
description: Dir defines the directory to use for migrations as a
configmap key reference.
Expand Down
9 changes: 9 additions & 0 deletions controllers/atlasmigration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ func (r *AtlasMigrationReconciler) extractData(ctx context.Context, res *dbv1alp
s = res.Spec
data = &migrationData{
EnvName: defaultEnvName,
DevURL: s.DevURL,
RevisionsSchema: s.RevisionsSchema,
Baseline: s.Baseline,
ExecOrder: string(s.ExecOrder),
Expand Down Expand Up @@ -386,6 +387,14 @@ func (r *AtlasMigrationReconciler) extractData(ctx context.Context, res *dbv1alp
default:
return nil, errors.New("no directory specified")
}
if s := s.DevURLFrom.SecretKeyRef; s != nil {
// SecretKeyRef is set, get the secret value
// then override the dev url.
data.DevURL, err = getSecretValue(ctx, r, res.Namespace, s)
if err != nil {
return nil, err
}
}
return data, nil
}

Expand Down

0 comments on commit 0235a64

Please sign in to comment.