Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions .github/workflows/cd-image-canary-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ on:
jobs:
push:
runs-on: ubuntu-latest
strategy:
matrix:
edition: [enterprise, community]
include:
- edition: enterprise
atlas_image_suffix: ""
tag_suffix: ""
- edition: community
atlas_image_suffix: "-community"
tag_suffix: "-community"
steps:
- uses: actions/checkout@v2
- name: Set up Docker Buildx
Expand All @@ -42,14 +52,15 @@ jobs:
with:
images: ${{ secrets.DOCKERHUB_USERNAME }}/atlas-operator
tags: |
type=schedule
type=sha
type=ref,event=branch
type=semver,pattern={{version}}
type=schedule,suffix=${{ matrix.tag_suffix }}
type=sha,suffix=${{ matrix.tag_suffix }}
type=ref,event=branch,suffix=${{ matrix.tag_suffix }}
type=semver,pattern={{version}},suffix=${{ matrix.tag_suffix }}
labels: |
io.ariga.atlas.version=${{ steps.atlas.outputs.version }}
io.ariga.atlas.edition=${{ matrix.edition }}
org.opencontainers.image.title=atlas-operator
org.opencontainers.image.description=Atlas Operator
org.opencontainers.image.description=Atlas Operator (${{ matrix.edition }} edition)
org.opencontainers.image.url=https://atlasgo.io
org.opencontainers.image.vendor=Ariga
org.opencontainers.image.source=https://github.com/ariga/atlas-operator/blob/master/Dockerfile
Expand All @@ -59,6 +70,7 @@ jobs:
context: .
build-args: |
ATLAS_VERSION=${{ steps.atlas.outputs.version }}
ATLAS_IMAGE=arigaio/atlas:${{ steps.atlas.outputs.version }}${{ matrix.atlas_image_suffix }}
OPERATOR_VERSION=v${{ steps.meta.outputs.version }}
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
Expand Down
18 changes: 15 additions & 3 deletions .github/workflows/cd-operator-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,18 @@ jobs:
helm-test:
uses: ./.github/workflows/ci-test-helm.yaml
docker-build:
name: Build
name: Build (${{ matrix.edition }})
runs-on: ubuntu-latest
strategy:
matrix:
edition: [enterprise, community]
include:
- edition: enterprise
atlas_image_suffix: ""
tag_suffix: ""
- edition: community
atlas_image_suffix: "-community"
tag_suffix: "-community"
steps:
- uses: actions/checkout@v2
- name: Set up Docker Buildx
Expand All @@ -47,11 +57,12 @@ jobs:
with:
images: ${{ secrets.DOCKERHUB_USERNAME }}/atlas-operator
tags: |
type=semver,pattern={{version}},value=${{ github.ref_name }}
type=semver,pattern={{version}}${{ matrix.tag_suffix }},value=${{ github.ref_name }}
labels: |
io.ariga.atlas.version=${{ steps.atlas.outputs.version }}
io.ariga.atlas.edition=${{ matrix.edition }}
org.opencontainers.image.title=atlas-operator
org.opencontainers.image.description=Atlas Operator
org.opencontainers.image.description=Atlas Operator (${{ matrix.edition }} edition)
org.opencontainers.image.url=https://atlasgo.io
org.opencontainers.image.vendor=Ariga
org.opencontainers.image.source=https://github.com/ariga/atlas-operator/blob/master/Dockerfile
Expand All @@ -61,6 +72,7 @@ jobs:
context: .
build-args: |
ATLAS_VERSION=${{ steps.atlas.outputs.version }}
ATLAS_IMAGE=arigaio/atlas:${{ steps.atlas.outputs.version }}${{ matrix.atlas_image_suffix }}
OPERATOR_VERSION=${{ github.ref_name }}
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
Expand Down
11 changes: 5 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,16 @@ RUN --mount=type=cache,target=/go/pkg/mod \
go build -ldflags "-X 'main.version=${OPERATOR_VERSION}'" \
-o manager -a cmd/main.go

FROM alpine:3.20 as atlas
RUN apk add --no-cache curl
# Enterprise (default): ATLAS_IMAGE=arigaio/atlas:${ATLAS_VERSION}
# Community: ATLAS_IMAGE=arigaio/atlas:${ATLAS_VERSION}-community
ARG ATLAS_VERSION=latest
ENV ATLAS_VERSION=${ATLAS_VERSION}
RUN curl -sSf https://atlasgo.sh | sh
ARG ATLAS_IMAGE=arigaio/atlas:${ATLAS_VERSION}
FROM ${ATLAS_IMAGE} AS atlas

FROM alpine:3.20
WORKDIR /
COPY --from=builder /workspace/manager .
COPY --from=atlas /usr/local/bin/atlas /usr/local/bin
RUN chmod +x /usr/local/bin/atlas
COPY --from=atlas --chmod=755 /atlas /usr/local/bin/atlas
ENV ATLAS_KUBERNETES_OPERATOR=1
USER 65532:65532
# Workaround for the issue with x/tools/imports
Expand Down
4 changes: 4 additions & 0 deletions api/v1alpha1/atlasmigration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ type (
// BackoffLimit is the number of retries on error.
// +kubebuilder:default=20
BackoffLimit int `json:"backoffLimit,omitempty"`
// AllowDirty allows applying migrations to a database that has schemas
// not managed by Atlas (e.g., system schemas in TiDB).
// +optional
AllowDirty bool `json:"allowDirty,omitempty"`
}
CloudV0 struct {
URL string `json:"url,omitempty"`
Expand Down
17 changes: 12 additions & 5 deletions internal/controller/atlasmigration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ type (
Baseline string
ExecOrder string
MigrateDown bool
AllowDirty bool
ObservedHash string
RemoteDir *dbv1alpha1.Remote
Config *hclwrite.File
Expand Down Expand Up @@ -274,17 +275,21 @@ func (r *AtlasMigrationReconciler) reconcile(ctx context.Context, data *migratio
return r.resultErr(res, err, dbv1alpha1.ReasonCreatingAtlasClient)
}
var whoami *atlasexec.WhoAmI
hasCloudConfig := data.Cloud != nil && data.Cloud.Token != ""

switch whoami, err = c.WhoAmI(ctx, &atlasexec.WhoAmIParams{Vars: data.Vars}); {
case errors.Is(err, atlasexec.ErrRequireLogin):
log.Info("the resource is not connected to Atlas Cloud")
if data.Config != nil {
err = errors.New("login is required to use custom atlas.hcl config")
if hasCloudConfig {
return r.resultErr(res, err, dbv1alpha1.ReasonWhoAmI)
}
case errors.Is(err, atlasexec.ErrRequireEnterprise):
if hasCloudConfig {
return r.resultErr(res, err, dbv1alpha1.ReasonWhoAmI)
}
case err != nil:
return r.resultErr(res, err, dbv1alpha1.ReasonWhoAmI)
default:
log.Info("the resource is connected to Atlas Cloud", "org", whoami.Org)
log.Info("connected to Atlas Cloud", "org", whoami.Org)
}
log.Info("reconciling migration", "env", data.EnvName)
// Check if there are any pending migration files
Expand Down Expand Up @@ -381,7 +386,8 @@ func (r *AtlasMigrationReconciler) reconcile(ctx context.Context, data *migratio
TriggerType: atlasexec.TriggerTypeKubernetes,
TriggerVersion: dbv1alpha1.VersionFromContext(ctx),
},
Vars: data.Vars,
Vars: data.Vars,
AllowDirty: data.AllowDirty,
})
if err != nil {
return r.resultCLIErr(res, err, "Migrating")
Expand Down Expand Up @@ -437,6 +443,7 @@ func (r *AtlasMigrationReconciler) extractData(ctx context.Context, res *dbv1alp
Baseline: s.Baseline,
ExecOrder: string(s.ExecOrder),
MigrateDown: false,
AllowDirty: s.AllowDirty,
}
)
data.Config, err = s.GetConfig(ctx, r, res.Namespace)
Expand Down
9 changes: 7 additions & 2 deletions internal/controller/atlasschema_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,15 @@ func (r *AtlasSchemaReconciler) Reconcile(ctx context.Context, req ctrl.Request)
// Below this line is the main logic of the controller.
// ====================================================
var whoami *atlasexec.WhoAmI
hasCloudConfig := data.Cloud != nil

switch whoami, err = cli.WhoAmI(ctx, &atlasexec.WhoAmIParams{Vars: data.Vars}); {
case errors.Is(err, atlasexec.ErrRequireLogin):
log.Info("the resource is not connected to Atlas Cloud")
if data.Config != nil {
if hasCloudConfig {
return r.resultErr(res, err, dbv1alpha1.ReasonWhoAmI)
}
case errors.Is(err, atlasexec.ErrRequireEnterprise):
if hasCloudConfig {
return r.resultErr(res, err, dbv1alpha1.ReasonWhoAmI)
}
case err != nil:
Expand Down