Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change: use build-deploy-tool for backup schedule generation #125

Merged
merged 28 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e17e10d
chore: use build-deploy-tool for backup generation
shreddedbacon Oct 4, 2022
54716a4
fix: use the same file name the script used
shreddedbacon Oct 4, 2022
d438d3f
chore: remove the old helmchart for k8up-schedule
shreddedbacon Oct 4, 2022
375ed68
chore: add baas-repo-pw secret creation
shreddedbacon Oct 5, 2022
f115b74
fix: actually put a bucket name in :)
shreddedbacon Oct 5, 2022
9a400fb
chore: add api/kind to templates
shreddedbacon Oct 6, 2022
b8f4628
chore: merge branch 'main' into backup-generation
shreddedbacon Nov 28, 2022
6960186
chore: support for v1 and v2 of k8up schedules
shreddedbacon Nov 28, 2022
8039684
chore: update go version in dockerfile
shreddedbacon Nov 28, 2022
59e52f9
chore: update go versions
shreddedbacon Nov 28, 2022
624dee8
chore: merge branch 'main' into backup-generation
shreddedbacon Dec 2, 2022
aa148c6
chore: add some basic service defaults and support for additional lag…
shreddedbacon Dec 2, 2022
b627ce3
chore: remove creationtimestamp from podspecs
shreddedbacon Dec 2, 2022
47c1194
chore: delete old prebackup pods if there are any
shreddedbacon Dec 2, 2022
5d3e22f
chore: add note about helper function
shreddedbacon Dec 2, 2022
dabbe1c
chore: fix mariadb prebackup command
shreddedbacon Dec 4, 2022
f3ce740
chore: add a featureflag wrap around k8upv2 support
shreddedbacon Dec 4, 2022
52c8d41
chore: add some messaging
shreddedbacon Dec 5, 2022
20a9c80
refactor: dont write empty templates
shreddedbacon Dec 5, 2022
3a208e2
chore: bump go version in makefile too
shreddedbacon Dec 5, 2022
43807e3
chore: merge conflict and fix up templating
shreddedbacon Jul 24, 2023
34b22e4
chore: add shared bucket override
shreddedbacon Jul 24, 2023
1d74c4d
chore: add initial readreplica support to prebackuppod
shreddedbacon Jul 24, 2023
c8606f1
Merge branch 'main' into backup-generation
shreddedbacon Oct 2, 2023
f3c6aa5
fix: remove unused metadata on prebackuppod
shreddedbacon Oct 3, 2023
3198d1a
fix: backupcommand for mariadb-dbaas
shreddedbacon Oct 3, 2023
5c02658
chore: merge main and fix conflicts
shreddedbacon Oct 9, 2023
8fb9ee9
chore: remove opensearch/elasticsearch prebackuppods and implement im…
shreddedbacon Oct 9, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: "^1.17"
go-version: "^1.18"
- name: Set up environment
run: echo "GOVERSION=$(go version)" >> $GITHUB_ENV
- name: Run GoReleaser
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
goversion:
- 1.17
- 1.18
steps:
-
name: Checkout PR
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lagoon-core-docker-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
goversion:
- 1.17
- 1.18
steps:
-
name: Checkout Branch or Tag
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: "^1.17"
go-version: "^1.18"
- name: Install ccv
run: >
curl -sSL https://github.com/smlx/ccv/releases/download/v0.3.2/ccv_0.3.2_linux_amd64.tar.gz
Expand Down Expand Up @@ -49,7 +49,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: "^1.17"
go-version: "^1.18"
- name: Set up environment
run: echo "GOVERSION=$(go version)" >> $GITHUB_ENV
- name: Run GoReleaser
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tag-to-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: "^1.17"
go-version: "^1.18"
- name: Set up environment
run: echo "GOVERSION=$(go version)" >> $GITHUB_ENV
- name: Run GoReleaser
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: "^1.17"
go-version: "^1.18"
- name: Run Tests
run: go test -v ./...
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ARG UPSTREAM_REPO
ARG UPSTREAM_TAG
ARG GO_VER
FROM ${UPSTREAM_REPO:-uselagoon}/commons:${UPSTREAM_TAG:-latest} as commons
FROM golang:${GO_VER:-1.17}-alpine3.16 as golang
FROM golang:${GO_VER:-1.18}-alpine as golang

RUN apk add --no-cache git
RUN go install github.com/a8m/envsubst/cmd/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
VERSION=$(shell echo $(shell git describe --abbrev=0 --tags)+$(shell git rev-parse --short=8 HEAD))
BUILD=$(shell date +%FT%T%z)
GO_VER=1.17
GO_VER=1.18
GOOS=linux
GOARCH=amd64
PKG=github.com/uselagoon/build-deploy-tool
Expand Down
20 changes: 19 additions & 1 deletion cmd/template_backups.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ var backupGeneration = &cobra.Command{
Aliases: []string{"schedule", "bs"},
Short: "Generate the backup schedule templates for a Lagoon build",
RunE: func(cmd *cobra.Command, args []string) error {
k8upVersion, err := cmd.Flags().GetString("version")
if err != nil {
return fmt.Errorf("error reading domain flag: %v", err)
}
generator, err := generatorInput(true)
if err != nil {
return err
}
generator.BackupConfiguration.K8upVersion = k8upVersion
return BackupTemplateGeneration(generator)
},
}
Expand All @@ -33,14 +38,27 @@ func BackupTemplateGeneration(g generator.GeneratorInput,
}
savedTemplates := g.SavedTemplatesPath

// generate the backup schedule templates
templateYAML, err := backuptemplate.GenerateBackupSchedule(*lagoonBuild.BuildValues)
if err != nil {
return fmt.Errorf("couldn't generate template: %v", err)
}
helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, "backups"), templateYAML)
if len(templateYAML) > 0 {
helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, "k8up-lagoon-backup-schedule"), templateYAML)
}

// generate any prebackuppod templates
templateYAML, err = backuptemplate.GeneratePreBackupPod(*lagoonBuild.BuildValues)
if err != nil {
return fmt.Errorf("couldn't generate template: %v", err)
}
if len(templateYAML) > 0 {
helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, "prebackuppods"), templateYAML)
}
return nil
}

func init() {
templateCmd.AddCommand(backupGeneration)
backupGeneration.Flags().StringP("version", "", "v1", "The version of k8up used.")
}
21 changes: 17 additions & 4 deletions cmd/template_backups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func TestBackupTemplateGeneration(t *testing.T) {
templatePath string
controllerDevSchedule string
controllerPRSchedule string
k8upVersion string
}
tests := []struct {
name string
Expand All @@ -54,6 +55,7 @@ func TestBackupTemplateGeneration(t *testing.T) {
buildType: "branch",
lagoonVersion: "v2.7.x",
branch: "main",
k8upVersion: "v1",
projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"},{"name":"LAGOON_FASTLY_SERVICE_IDS","value":"example.com:service-id:true:annotationscom","scope":"build"}]`,
envVars: `[]`,
lagoonYAML: "../test-resources/template-backups/test1/lagoon.yml",
Expand All @@ -72,7 +74,8 @@ func TestBackupTemplateGeneration(t *testing.T) {
buildType: "branch",
lagoonVersion: "v2.7.x",
branch: "main",
projectVars: `[{"name":"LAGOON_BACKUP_DEV_SCHEDULE","value":"1,31 23 * * *","scope":"build"},{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"},{"name":"LAGOON_FASTLY_SERVICE_IDS","value":"example.com:service-id:true:annotationscom","scope":"build"}]`,
k8upVersion: "v1",
projectVars: `[{"name":"LAGOON_FEATURE_FLAG_CUSTOM_BACKUP_CONFIG","value":"enabled","scope":"global"},{"name":"LAGOON_BACKUP_DEV_SCHEDULE","value":"1,31 23 * * *","scope":"build"},{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"},{"name":"LAGOON_FASTLY_SERVICE_IDS","value":"example.com:service-id:true:annotationscom","scope":"build"}]`,
envVars: `[]`,
lagoonYAML: "../test-resources/template-backups/test2/lagoon.yml",
templatePath: "../test-resources/template-backups/output",
Expand All @@ -90,6 +93,7 @@ func TestBackupTemplateGeneration(t *testing.T) {
buildType: "branch",
lagoonVersion: "v2.7.x",
branch: "main",
k8upVersion: "v1",
projectVars: `[{"name":"LAGOON_BACKUP_DEV_SCHEDULE","value":"1,31 23 * * *","scope":"build"},{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"},{"name":"LAGOON_FASTLY_SERVICE_IDS","value":"example.com:service-id:true:annotationscom","scope":"build"}]`,
envVars: `[]`,
lagoonYAML: "../test-resources/template-backups/test3/lagoon.yml",
Expand All @@ -111,7 +115,8 @@ func TestBackupTemplateGeneration(t *testing.T) {
prBaseBranch: "main2",
lagoonVersion: "v2.7.x",
branch: "main",
projectVars: `[{"name":"LAGOON_BAAS_CUSTOM_BACKUP_ACCESS_KEY","value":"abcdefg","scope":"build"},{"name":"LAGOON_BAAS_CUSTOM_BACKUP_SECRET_KEY","value":"abcdefg1234567","scope":"build"},{"name":"LAGOON_BACKUP_DEV_SCHEDULE","value":"1,31 23 * * *","scope":"build"},{"name":"LAGOON_BACKUP_PR_SCHEDULE","value":"3,33 12 * * *","scope":"build"},{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"},{"name":"LAGOON_FASTLY_SERVICE_IDS","value":"example.com:service-id:true:annotationscom","scope":"build"}]`,
k8upVersion: "v1",
projectVars: `[{"name":"LAGOON_FEATURE_FLAG_CUSTOM_BACKUP_CONFIG","value":"enabled","scope":"global"},{"name":"LAGOON_BAAS_CUSTOM_BACKUP_ACCESS_KEY","value":"abcdefg","scope":"build"},{"name":"LAGOON_BAAS_CUSTOM_BACKUP_SECRET_KEY","value":"abcdefg1234567","scope":"build"},{"name":"LAGOON_BACKUP_DEV_SCHEDULE","value":"1,31 23 * * *","scope":"build"},{"name":"LAGOON_BACKUP_PR_SCHEDULE","value":"3,33 12 * * *","scope":"build"},{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"},{"name":"LAGOON_FASTLY_SERVICE_IDS","value":"example.com:service-id:true:annotationscom","scope":"build"}]`,
envVars: `[]`,
lagoonYAML: "../test-resources/template-backups/test4/lagoon.yml",
templatePath: "../test-resources/template-backups/output",
Expand All @@ -132,7 +137,8 @@ func TestBackupTemplateGeneration(t *testing.T) {
prBaseBranch: "main2",
lagoonVersion: "v2.7.x",
branch: "main",
projectVars: `[{"name":"LAGOON_BAAS_CUSTOM_RESTORE_ACCESS_KEY","value":"abcdefg","scope":"build"},{"name":"LAGOON_BAAS_CUSTOM_RESTORE_SECRET_KEY","value":"abcdefg1234567","scope":"build"},{"name":"LAGOON_BACKUP_DEV_SCHEDULE","value":"1,31 23 * * *","scope":"build"},{"name":"LAGOON_BACKUP_PR_SCHEDULE","value":"3,33 12 * * *","scope":"build"},{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"},{"name":"LAGOON_FASTLY_SERVICE_IDS","value":"example.com:service-id:true:annotationscom","scope":"build"}]`,
k8upVersion: "v1",
projectVars: `[{"name":"LAGOON_FEATURE_FLAG_CUSTOM_BACKUP_CONFIG","value":"enabled","scope":"global"},{"name":"LAGOON_BAAS_CUSTOM_RESTORE_ACCESS_KEY","value":"abcdefg","scope":"build"},{"name":"LAGOON_BAAS_CUSTOM_RESTORE_SECRET_KEY","value":"abcdefg1234567","scope":"build"},{"name":"LAGOON_BACKUP_DEV_SCHEDULE","value":"1,31 23 * * *","scope":"build"},{"name":"LAGOON_BACKUP_PR_SCHEDULE","value":"3,33 12 * * *","scope":"build"},{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"},{"name":"LAGOON_FASTLY_SERVICE_IDS","value":"example.com:service-id:true:annotationscom","scope":"build"}]`,
envVars: `[]`,
lagoonYAML: "../test-resources/template-backups/test5/lagoon.yml",
templatePath: "../test-resources/template-backups/output",
Expand All @@ -150,6 +156,7 @@ func TestBackupTemplateGeneration(t *testing.T) {
buildType: "branch",
lagoonVersion: "v2.7.x",
branch: "main",
k8upVersion: "v1",
projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"},{"name":"LAGOON_FASTLY_SERVICE_IDS","value":"example.com:service-id:true:annotationscom","scope":"build"}]`,
envVars: `[]`,
lagoonYAML: "../test-resources/template-backups/test6/lagoon.yml",
Expand Down Expand Up @@ -249,6 +256,7 @@ func TestBackupTemplateGeneration(t *testing.T) {
RetryWaitMin: time.Duration(10) * time.Millisecond,
RetryWaitMax: time.Duration(50) * time.Millisecond,
})
generator.BackupConfiguration.K8upVersion = tt.args.k8upVersion

savedTemplates := tt.args.templatePath
err = os.MkdirAll(tt.args.templatePath, 0755)
Expand All @@ -257,7 +265,12 @@ func TestBackupTemplateGeneration(t *testing.T) {
}
defer os.RemoveAll(savedTemplates)

defer os.RemoveAll(savedTemplates)
ts := dbaasclient.TestDBaaSHTTPServer()
defer ts.Close()
err = os.Setenv("DBAAS_OPERATOR_HTTP", ts.URL)
if err != nil {
t.Errorf("%v", err)
}

if err := BackupTemplateGeneration(generator); (err != nil) != tt.wantErr {
t.Errorf("BackupTemplateGeneration() error = %v, wantErr %v", err, tt.wantErr)
Expand Down
59 changes: 34 additions & 25 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,69 +1,78 @@
module github.com/uselagoon/build-deploy-tool

go 1.17
go 1.18

require (
github.com/PaesslerAG/gval v1.1.2
github.com/amazeeio/dbaas-operator v0.3.0
github.com/compose-spec/compose-go v1.2.7
github.com/cxmcc/unixsums v0.0.0-20131125091133-89564297d82f
github.com/google/go-cmp v0.5.7
github.com/google/go-cmp v0.5.9
github.com/hashicorp/go-retryablehttp v0.5.4
github.com/imdario/mergo v0.3.13
github.com/spf13/cobra v1.4.0
github.com/k8up-io/k8up/v2 v2.5.2
github.com/spf13/cobra v1.5.0
github.com/uselagoon/machinery v0.0.7
github.com/vshn/k8up v1.99.99
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.23.6
k8s.io/apimachinery v0.23.6
k8s.io/client-go v0.23.6
k8s.io/api v0.25.3
k8s.io/apimachinery v0.25.3
k8s.io/client-go v0.25.3
sigs.k8s.io/yaml v1.3.0
)

require (
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/distribution/distribution/v3 v3.0.0-20210316161203-a01c71e2477e // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/go-logr/logr v1.2.0 // indirect
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/mattn/go-shellwords v1.0.12 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.7.1 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
golang.org/x/net v0.0.0-20220412020605-290c469a71a5 // indirect
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
golang.org/x/net v0.0.0-20220822230855-b0a4917ee28c // indirect
golang.org/x/oauth2 v0.0.0-20220622183110-fd043fe589d2 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/sys v0.0.0-20220818161305-2296e01440c6 // indirect
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f // indirect
golang.org/x/time v0.0.0-20220609170525-579cf78fd858 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.27.1 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.0 // indirect
k8s.io/klog/v2 v2.30.0 // indirect
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect
k8s.io/utils v0.0.0-20211116205334-6203023598ed // indirect
sigs.k8s.io/controller-runtime v0.9.6 // indirect
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.80.1 // indirect
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // indirect
k8s.io/utils v0.0.0-20221012122500-cfd413dd9e85 // indirect
sigs.k8s.io/controller-runtime v0.13.0 // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
)

replace github.com/compose-spec/compose-go v1.2.7 => github.com/shreddedbacon/compose-go v0.0.0-20220616064547-4e908a2865c1
Expand Down
Loading
Loading