Skip to content

Commit

Permalink
Update CRD version (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
allanger committed Mar 9, 2023
1 parent 43931c3 commit 85da3c4
Show file tree
Hide file tree
Showing 55 changed files with 2,272 additions and 465 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:

env:
product_name: db-operator
go_version: "1.17"
go_version: "1.18"
go_os: linux
go_arch: amd64
main_go_path: .
Expand All @@ -20,10 +20,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Check Code Style
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3
with:
version: v1.49.0 ## https://github.com/golangci/golangci-lint/releases
args: --timeout 3m0s
Expand All @@ -33,23 +33,23 @@ jobs:
needs: lint
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v2

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ${{ env.go_version }}

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/image-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ jobs:
docker_arch: "arm64/v8"
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ${{ env.go_version }}

Expand All @@ -43,14 +43,14 @@ jobs:
uses: docker/setup-buildx-action@v2

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Login to Dockerhub
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.17.4-alpine3.15 as builder
FROM golang:1.18.10-alpine3.17 as builder

RUN apk update && apk upgrade && \
apk add --no-cache bash build-base
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ generate: controller-gen ## generate supporting code for custom resource types

CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.7.0)
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.11.3)

# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
Expand Down
27 changes: 27 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Code generated by tool. DO NOT EDIT.
# This file is used to track the info used to scaffold your project
# and allow the plugins properly work.
# More info: https://book.kubebuilder.io/reference/project-config.html
domain: kci.rocks
layout:
- go.kubebuilder.io/v3
Expand All @@ -19,4 +23,27 @@ resources:
kind: Database
path: github.com/kloeckner-i/db-operator/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
domain: kci.rocks
kind: Database
path: github.com/kloeckner-i/db-operator/api/v1beta1
version: v1beta1
webhooks:
conversion: true
defaulting: true
validation: true
webhookVersion: v1
- api:
crdVersion: v1
domain: kci.rocks
kind: DbInstance
path: github.com/kloeckner-i/db-operator/api/v1beta1
version: v1beta1
webhooks:
conversion: true
defaulting: true
validation: true
webhookVersion: v1
version: "3"
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ DB Operator provides following features:
The repository contains helm charts for db-operator is moved to https://github.com/kloeckner-i/charts
New chart after db-operator > 1.2.7, db-instances > 1.3.0 will be only available in new repository.

## CRD Versions are upgraded!
Now both `DbInstance` and `Database` resources are upgraded to `v1beta1`.
In case you were using `connectionStringTemplate`, make sure I've migrated to `secretsTempaltes` before upgrading, because `connectionStringTemplate` is removed in this version. Everything else should go seamless. We've added `Webhooks` that will take care of resources with an old API version and convert them to the newer one.

### Downloading old charts

Installing older version of charts is still possible.
Expand Down
40 changes: 40 additions & 0 deletions api/v1alpha1/database_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ package v1alpha1
import (
"errors"

"github.com/kloeckner-i/db-operator/api/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/conversion"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -150,3 +153,40 @@ func (db *Database) IsMonitoringEnabled() (bool, error) {
func (db *Database) InstanceAccessSecretName() string {
return "dbin-" + db.Spec.Instance + "-access-secret"
}

// ConvertTo converts this v1alpha1 to v1beta1. (upgrade)
func (db *Database) ConvertTo(dstRaw conversion.Hub) error {

dst := dstRaw.(*v1beta1.Database)
dst.ObjectMeta = db.ObjectMeta

dst.Spec.Backup = v1beta1.DatabaseBackup(db.Spec.Backup)
dst.Spec.Cleanup = db.Spec.Cleanup
dst.Spec.DeletionProtected = db.Spec.DeletionProtected
dst.Spec.Instance = db.Spec.Instance
dst.Spec.Postgres.DropPublicSchema = db.Spec.Postgres.DropPublicSchema
dst.Spec.Postgres.Extensions = db.Spec.Extensions
dst.Spec.Postgres.Schemas = db.Spec.Postgres.Schemas
dst.Spec.SecretName = db.Spec.SecretName
dst.Spec.SecretsTemplates = db.Spec.SecretsTemplates

return nil
}

// ConvertFrom converts from the Hub version (v1beta1) to (v1alpha1). (downgrade)
func (dst *Database) ConvertFrom(srcRaw conversion.Hub) error {
db := srcRaw.(*v1beta1.Database)
dst.ObjectMeta = db.ObjectMeta

dst.Spec.Backup = DatabaseBackup(db.Spec.Backup)
dst.Spec.Cleanup = db.Spec.Cleanup
dst.Spec.DeletionProtected = db.Spec.DeletionProtected
dst.Spec.Instance = db.Spec.Instance
dst.Spec.Postgres.DropPublicSchema = db.Spec.Postgres.DropPublicSchema
dst.Spec.Extensions = db.Spec.Postgres.Extensions
dst.Spec.Postgres.Schemas = db.Spec.Postgres.Schemas
dst.Spec.SecretName = db.Spec.SecretName
dst.Spec.SecretsTemplates = db.Spec.SecretsTemplates

return nil
}
45 changes: 44 additions & 1 deletion api/v1alpha1/dbinstance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ package v1alpha1
import (
"errors"

"github.com/kloeckner-i/db-operator/api/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)

// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
Expand Down Expand Up @@ -188,6 +190,47 @@ func (dbin *DbInstance) IsMonitoringEnabled() bool {
if dbin.Spec.Monitoring.Enabled == false {
return false
}

return true
}

// ConvertTo converts this v1alpha1 to v1beta1. (upgrade)
func (dbin *DbInstance) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*v1beta1.DbInstance)
dst.ObjectMeta = dbin.ObjectMeta
dst.Spec.AdminUserSecret = v1beta1.NamespacedName(dbin.Spec.AdminUserSecret)
dst.Spec.Backup = v1beta1.DbInstanceBackup(dbin.Spec.Backup)
if dbin.Spec.DbInstanceSource.Generic != nil {
dst.Spec.DbInstanceSource.Generic = (*v1beta1.GenericInstance)(dbin.Spec.DbInstanceSource.Generic)
} else if dbin.Spec.DbInstanceSource.Google != nil {

dst.Spec.DbInstanceSource.Google.APIEndpoint = dbin.Spec.DbInstanceSource.Google.APIEndpoint
dst.Spec.DbInstanceSource.Google.InstanceName = dbin.Spec.DbInstanceSource.Google.InstanceName
dst.Spec.DbInstanceSource.Google.ClientSecret = v1beta1.NamespacedName(dbin.Spec.DbInstanceSource.Google.ClientSecret)
dst.Spec.DbInstanceSource.Google.ConfigmapName = v1beta1.NamespacedName(dbin.Spec.Google.ConfigmapName)
}
dst.Spec.Engine = dbin.Spec.Engine
dst.Spec.Monitoring = v1beta1.DbInstanceMonitoring(dbin.Spec.Monitoring)
dst.Spec.SSLConnection = v1beta1.DbInstanceSSLConnection(dbin.Spec.SSLConnection)
return nil
}

// ConvertFrom converts from the Hub version (v1beta1) to (v1alpha1). (downgrade)
func (dst *DbInstance) ConvertFrom(srcRaw conversion.Hub) error {
dbin := srcRaw.(*v1beta1.DbInstance)
dst.ObjectMeta = dbin.ObjectMeta
dst.Spec.AdminUserSecret = NamespacedName(dbin.Spec.AdminUserSecret)
dst.Spec.Backup = DbInstanceBackup(dbin.Spec.Backup)
if dbin.Spec.DbInstanceSource.Generic != nil {
dst.Spec.DbInstanceSource.Generic = (*GenericInstance)(dbin.Spec.DbInstanceSource.Generic)
} else if dbin.Spec.DbInstanceSource.Google != nil {

dst.Spec.DbInstanceSource.Google.APIEndpoint = dbin.Spec.DbInstanceSource.Google.APIEndpoint
dst.Spec.DbInstanceSource.Google.InstanceName = dbin.Spec.DbInstanceSource.Google.InstanceName
dst.Spec.DbInstanceSource.Google.ClientSecret = NamespacedName(dbin.Spec.DbInstanceSource.Google.ClientSecret)
dst.Spec.DbInstanceSource.Google.ConfigmapName = NamespacedName(dbin.Spec.Google.ConfigmapName)
}
dst.Spec.Engine = dbin.Spec.Engine
dst.Spec.Monitoring = DbInstanceMonitoring(dbin.Spec.Monitoring)
dst.Spec.SSLConnection = DbInstanceSSLConnection(dbin.Spec.SSLConnection)
return nil
}
Loading

0 comments on commit 85da3c4

Please sign in to comment.