From 51b6b11f86cb0f3fca7ffdf26779390646b6867b Mon Sep 17 00:00:00 2001 From: Tamal Saha Date: Wed, 27 Dec 2023 08:05:32 -0800 Subject: [PATCH] Templatize wal-g images Signed-off-by: Tamal Saha --- catalog/kubedb/fmt/main.go | 50 ++++++++++++++++--- .../postgres/postgres-11.11-timescaledb.yaml | 12 +++++ .../raw/postgres/postgres-11.14-postgis.yaml | 2 +- .../raw/postgres/postgres-11.22-official.yaml | 4 +- .../raw/postgres/postgres-12.17-official.yaml | 4 +- .../postgres/postgres-12.6-timescaledb.yaml | 12 +++++ .../raw/postgres/postgres-12.9-postgis.yaml | 2 +- .../raw/postgres/postgres-13.13-official.yaml | 4 +- .../postgres/postgres-13.2-timescaledb.yaml | 12 +++++ .../raw/postgres/postgres-13.5-postgis.yaml | 2 +- .../raw/postgres/postgres-14.1-postgis.yaml | 2 +- .../postgres/postgres-14.1-timescaledb.yaml | 12 +++++ .../raw/postgres/postgres-14.10-official.yaml | 4 +- .../raw/postgres/postgres-15.5-official.yaml | 4 +- .../raw/postgres/postgres-16.1-official.yaml | 4 +- .../postgres/postgres-11.11-timescaledb.yaml | 12 +++++ .../postgres/postgres-12.6-timescaledb.yaml | 12 +++++ .../postgres/postgres-13.2-timescaledb.yaml | 12 +++++ .../postgres/postgres-14.1-timescaledb.yaml | 12 +++++ 19 files changed, 154 insertions(+), 24 deletions(-) diff --git a/catalog/kubedb/fmt/main.go b/catalog/kubedb/fmt/main.go index 3361da743..8b23cea60 100644 --- a/catalog/kubedb/fmt/main.go +++ b/catalog/kubedb/fmt/main.go @@ -159,8 +159,8 @@ func main() { for jp, val := range specUpdates { if apiKind == "" || apiKind == ri.Object.GetKind() { - if _, ok, _ := unstructured.NestedFieldNoCopy(ri.Object.Object, strings.Split(jp, ".")...); ok { - err = unstructured.SetNestedField(ri.Object.Object, val, strings.Split(jp, ".")...) + if ref, ok, _ := unstructured.NestedString(ri.Object.Object, strings.Split(jp, ".")...); ok { + err = unstructured.SetNestedField(ri.Object.Object, encodeTag(ref, val), strings.Split(jp, ".")...) if err != nil { panic(fmt.Sprintf("failed to set %s to %s in group=%s,kind=%s,name=%s", jp, val, ri.Object.GetAPIVersion(), ri.Object.GetKind(), ri.Object.GetName())) } @@ -487,21 +487,28 @@ func main() { var buf bytes.Buffer for i, obj := range v { - obj := obj.DeepCopy() + objCopy := obj.DeepCopy() - spec, _, err := unstructured.NestedMap(obj.Object, "spec") + spec, _, err := unstructured.NestedMap(objCopy.Object, "spec") if err != nil { panic(err) } for prop := range spec { templatizeRegistry := func(fields ...string) { fieldList := append([]string{"spec", prop}, fields...) - img, ok, _ := unstructured.NestedString(obj.Object, fieldList...) + img, ok, _ := unstructured.NestedString(objCopy.Object, fieldList...) if ok { - ref, err := name.ParseReference(img) + decodedImg := decodeTag(img) + ref, err := name.ParseReference(decodedImg) if err != nil { panic(err) } + + err = unstructured.SetNestedField(obj.Object, decodedImg, fieldList...) + if err != nil { + panic(err) + } + var newimg string switch ref.Registry { case "index.docker.io": @@ -521,7 +528,7 @@ func main() { if ref.Tag != "" && ref.Tag != "latest" { newimg += ":" + ref.Tag } - err = unstructured.SetNestedField(obj.Object, newimg, fieldList...) + err = unstructured.SetNestedField(objCopy.Object, newimg, fieldList...) if err != nil { panic(err) } @@ -538,7 +545,7 @@ func main() { data := map[string]interface{}{ "key": strings.ToLower(dbKind), - "object": obj.Object, + "object": objCopy.Object, } funcMap := sprig.TxtFuncMap() funcMap["toYaml"] = toYAML @@ -844,3 +851,30 @@ func Compare(i, j string) bool { } return strings.Compare(i, j) < 0 } + +func encodeTag(ref, tag string) string { + if idx := strings.IndexRune(ref, '('); idx == -1 { + return tag + } + + var sb strings.Builder + replace := false + for _, ch := range ref { + if ch == '(' { + replace = true + sb.WriteRune('(') + sb.WriteString(tag) + sb.WriteRune(')') + } else if ch == ')' { + replace = false + } else if !replace { + sb.WriteRune(ch) + } + } + return sb.String() +} + +func decodeTag(ref string) string { + r := strings.NewReplacer("(", "", ")", "") + return r.Replace(ref) +} diff --git a/catalog/kubedb/raw/postgres/postgres-11.11-timescaledb.yaml b/catalog/kubedb/raw/postgres/postgres-11.11-timescaledb.yaml index ccc536a32..9d89829bd 100644 --- a/catalog/kubedb/raw/postgres/postgres-11.11-timescaledb.yaml +++ b/catalog/kubedb/raw/postgres/postgres-11.11-timescaledb.yaml @@ -3,6 +3,18 @@ kind: PostgresVersion metadata: name: timescaledb-2.1.0-pg11 spec: + archiver: + addon: + name: postgres-addon + tasks: + manifestBackup: + name: ManifestBackup + manifestRestore: + name: ManifestRestore + volumeSnapshot: + name: VolumeSnapshot + walg: + image: ghcr.io/kubedb/postgres-archiver:(v0.0.1)_11.22-alpine coordinator: image: ghcr.io/kubedb/pg-coordinator:v0.23.0 db: diff --git a/catalog/kubedb/raw/postgres/postgres-11.14-postgis.yaml b/catalog/kubedb/raw/postgres/postgres-11.14-postgis.yaml index 3fac03aaa..bc56a045c 100644 --- a/catalog/kubedb/raw/postgres/postgres-11.14-postgis.yaml +++ b/catalog/kubedb/raw/postgres/postgres-11.14-postgis.yaml @@ -14,7 +14,7 @@ spec: volumeSnapshot: name: VolumeSnapshot walg: - image: ghcr.io/kubedb/postgres-archiver:v0.0.1_11.22-bookworm + image: ghcr.io/kubedb/postgres-archiver:(v0.0.1)_11.22-bookworm coordinator: image: ghcr.io/kubedb/pg-coordinator:v0.23.0 db: diff --git a/catalog/kubedb/raw/postgres/postgres-11.22-official.yaml b/catalog/kubedb/raw/postgres/postgres-11.22-official.yaml index 254403352..edff90757 100644 --- a/catalog/kubedb/raw/postgres/postgres-11.22-official.yaml +++ b/catalog/kubedb/raw/postgres/postgres-11.22-official.yaml @@ -14,7 +14,7 @@ spec: volumeSnapshot: name: VolumeSnapshot walg: - image: ghcr.io/kubedb/postgres-archiver:v0.0.1_11.22-alpine + image: ghcr.io/kubedb/postgres-archiver:(v0.0.1)_11.22-alpine coordinator: image: ghcr.io/kubedb/pg-coordinator:v0.23.0 db: @@ -58,7 +58,7 @@ spec: volumeSnapshot: name: VolumeSnapshot walg: - image: ghcr.io/kubedb/postgres-archiver:v0.0.1_11.22-bookworm + image: ghcr.io/kubedb/postgres-archiver:(v0.0.1)_11.22-bookworm coordinator: image: ghcr.io/kubedb/pg-coordinator:v0.23.0 db: diff --git a/catalog/kubedb/raw/postgres/postgres-12.17-official.yaml b/catalog/kubedb/raw/postgres/postgres-12.17-official.yaml index 731b04662..acfd4dc27 100644 --- a/catalog/kubedb/raw/postgres/postgres-12.17-official.yaml +++ b/catalog/kubedb/raw/postgres/postgres-12.17-official.yaml @@ -14,7 +14,7 @@ spec: volumeSnapshot: name: VolumeSnapshot walg: - image: ghcr.io/kubedb/postgres-archiver:v0.0.1_12.17-alpine + image: ghcr.io/kubedb/postgres-archiver:(v0.0.1)_12.17-alpine coordinator: image: ghcr.io/kubedb/pg-coordinator:v0.23.0 db: @@ -59,7 +59,7 @@ spec: volumeSnapshot: name: VolumeSnapshot walg: - image: ghcr.io/kubedb/postgres-archiver:v0.0.1_12.17-bookworm + image: ghcr.io/kubedb/postgres-archiver:(v0.0.1)_12.17-bookworm coordinator: image: ghcr.io/kubedb/pg-coordinator:v0.23.0 db: diff --git a/catalog/kubedb/raw/postgres/postgres-12.6-timescaledb.yaml b/catalog/kubedb/raw/postgres/postgres-12.6-timescaledb.yaml index c8154df91..b26d65048 100644 --- a/catalog/kubedb/raw/postgres/postgres-12.6-timescaledb.yaml +++ b/catalog/kubedb/raw/postgres/postgres-12.6-timescaledb.yaml @@ -3,6 +3,18 @@ kind: PostgresVersion metadata: name: timescaledb-2.1.0-pg12 spec: + archiver: + addon: + name: postgres-addon + tasks: + manifestBackup: + name: ManifestBackup + manifestRestore: + name: ManifestRestore + volumeSnapshot: + name: VolumeSnapshot + walg: + image: ghcr.io/kubedb/postgres-archiver:(v0.0.1)_12.17-alpine coordinator: image: ghcr.io/kubedb/pg-coordinator:v0.23.0 db: diff --git a/catalog/kubedb/raw/postgres/postgres-12.9-postgis.yaml b/catalog/kubedb/raw/postgres/postgres-12.9-postgis.yaml index 5e602f12e..65e050bf8 100644 --- a/catalog/kubedb/raw/postgres/postgres-12.9-postgis.yaml +++ b/catalog/kubedb/raw/postgres/postgres-12.9-postgis.yaml @@ -14,7 +14,7 @@ spec: volumeSnapshot: name: VolumeSnapshot walg: - image: ghcr.io/kubedb/postgres-archiver:v0.0.1_12.17-bookworm + image: ghcr.io/kubedb/postgres-archiver:(v0.0.1)_12.17-bookworm coordinator: image: ghcr.io/kubedb/pg-coordinator:v0.23.0 db: diff --git a/catalog/kubedb/raw/postgres/postgres-13.13-official.yaml b/catalog/kubedb/raw/postgres/postgres-13.13-official.yaml index 692237ee1..e471847f2 100644 --- a/catalog/kubedb/raw/postgres/postgres-13.13-official.yaml +++ b/catalog/kubedb/raw/postgres/postgres-13.13-official.yaml @@ -14,7 +14,7 @@ spec: volumeSnapshot: name: VolumeSnapshot walg: - image: ghcr.io/kubedb/postgres-archiver:v0.0.1_13.13-alpine + image: ghcr.io/kubedb/postgres-archiver:(v0.0.1)_13.13-alpine coordinator: image: ghcr.io/kubedb/pg-coordinator:v0.23.0 db: @@ -58,7 +58,7 @@ spec: volumeSnapshot: name: VolumeSnapshot walg: - image: ghcr.io/kubedb/postgres-archiver:v0.0.1_13.13-bookworm + image: ghcr.io/kubedb/postgres-archiver:(v0.0.1)_13.13-bookworm coordinator: image: ghcr.io/kubedb/pg-coordinator:v0.23.0 db: diff --git a/catalog/kubedb/raw/postgres/postgres-13.2-timescaledb.yaml b/catalog/kubedb/raw/postgres/postgres-13.2-timescaledb.yaml index c428e23d8..0d98f2e5b 100644 --- a/catalog/kubedb/raw/postgres/postgres-13.2-timescaledb.yaml +++ b/catalog/kubedb/raw/postgres/postgres-13.2-timescaledb.yaml @@ -3,6 +3,18 @@ kind: PostgresVersion metadata: name: timescaledb-2.1.0-pg13 spec: + archiver: + addon: + name: postgres-addon + tasks: + manifestBackup: + name: ManifestBackup + manifestRestore: + name: ManifestRestore + volumeSnapshot: + name: VolumeSnapshot + walg: + image: ghcr.io/kubedb/postgres-archiver:(v0.0.1)_13.13-alpine coordinator: image: ghcr.io/kubedb/pg-coordinator:v0.23.0 db: diff --git a/catalog/kubedb/raw/postgres/postgres-13.5-postgis.yaml b/catalog/kubedb/raw/postgres/postgres-13.5-postgis.yaml index 1d59a6d92..f4b41ae98 100644 --- a/catalog/kubedb/raw/postgres/postgres-13.5-postgis.yaml +++ b/catalog/kubedb/raw/postgres/postgres-13.5-postgis.yaml @@ -14,7 +14,7 @@ spec: volumeSnapshot: name: VolumeSnapshot walg: - image: ghcr.io/kubedb/postgres-archiver:v0.0.1_13.13-bookworm + image: ghcr.io/kubedb/postgres-archiver:(v0.0.1)_13.13-bookworm coordinator: image: ghcr.io/kubedb/pg-coordinator:v0.23.0 db: diff --git a/catalog/kubedb/raw/postgres/postgres-14.1-postgis.yaml b/catalog/kubedb/raw/postgres/postgres-14.1-postgis.yaml index cfc4bf008..7a5ab1949 100644 --- a/catalog/kubedb/raw/postgres/postgres-14.1-postgis.yaml +++ b/catalog/kubedb/raw/postgres/postgres-14.1-postgis.yaml @@ -14,7 +14,7 @@ spec: volumeSnapshot: name: VolumeSnapshot walg: - image: ghcr.io/kubedb/postgres-archiver:v0.0.1_14.10-bookworm + image: ghcr.io/kubedb/postgres-archiver:(v0.0.1)_14.10-bookworm coordinator: image: ghcr.io/kubedb/pg-coordinator:v0.23.0 db: diff --git a/catalog/kubedb/raw/postgres/postgres-14.1-timescaledb.yaml b/catalog/kubedb/raw/postgres/postgres-14.1-timescaledb.yaml index 3fc5c4726..77c1aaaa2 100644 --- a/catalog/kubedb/raw/postgres/postgres-14.1-timescaledb.yaml +++ b/catalog/kubedb/raw/postgres/postgres-14.1-timescaledb.yaml @@ -3,6 +3,18 @@ kind: PostgresVersion metadata: name: timescaledb-2.5.0-pg14.1 spec: + archiver: + addon: + name: postgres-addon + tasks: + manifestBackup: + name: ManifestBackup + manifestRestore: + name: ManifestRestore + volumeSnapshot: + name: VolumeSnapshot + walg: + image: ghcr.io/kubedb/postgres-archiver:(v0.0.1)_14.10-alpine coordinator: image: ghcr.io/kubedb/pg-coordinator:v0.23.0 db: diff --git a/catalog/kubedb/raw/postgres/postgres-14.10-official.yaml b/catalog/kubedb/raw/postgres/postgres-14.10-official.yaml index 20bfca3dc..2dc469b99 100644 --- a/catalog/kubedb/raw/postgres/postgres-14.10-official.yaml +++ b/catalog/kubedb/raw/postgres/postgres-14.10-official.yaml @@ -14,7 +14,7 @@ spec: volumeSnapshot: name: VolumeSnapshot walg: - image: ghcr.io/kubedb/postgres-archiver:v0.0.1_14.10-alpine + image: ghcr.io/kubedb/postgres-archiver:(v0.0.1)_14.10-alpine coordinator: image: ghcr.io/kubedb/pg-coordinator:v0.23.0 db: @@ -55,7 +55,7 @@ spec: volumeSnapshot: name: VolumeSnapshot walg: - image: ghcr.io/kubedb/postgres-archiver:v0.0.1_14.10-bookworm + image: ghcr.io/kubedb/postgres-archiver:(v0.0.1)_14.10-bookworm coordinator: image: ghcr.io/kubedb/pg-coordinator:v0.23.0 db: diff --git a/catalog/kubedb/raw/postgres/postgres-15.5-official.yaml b/catalog/kubedb/raw/postgres/postgres-15.5-official.yaml index 47e0caebc..6e82078a5 100644 --- a/catalog/kubedb/raw/postgres/postgres-15.5-official.yaml +++ b/catalog/kubedb/raw/postgres/postgres-15.5-official.yaml @@ -14,7 +14,7 @@ spec: volumeSnapshot: name: VolumeSnapshot walg: - image: ghcr.io/kubedb/postgres-archiver:v0.0.1_15.5-alpine + image: ghcr.io/kubedb/postgres-archiver:(v0.0.1)_15.5-alpine coordinator: image: ghcr.io/kubedb/pg-coordinator:v0.23.0 db: @@ -58,7 +58,7 @@ spec: volumeSnapshot: name: VolumeSnapshot walg: - image: ghcr.io/kubedb/postgres-archiver:v0.0.1_15.5-bookworm + image: ghcr.io/kubedb/postgres-archiver:(v0.0.1)_15.5-bookworm coordinator: image: ghcr.io/kubedb/pg-coordinator:v0.23.0 db: diff --git a/catalog/kubedb/raw/postgres/postgres-16.1-official.yaml b/catalog/kubedb/raw/postgres/postgres-16.1-official.yaml index ac308071f..d6452cc67 100644 --- a/catalog/kubedb/raw/postgres/postgres-16.1-official.yaml +++ b/catalog/kubedb/raw/postgres/postgres-16.1-official.yaml @@ -14,7 +14,7 @@ spec: volumeSnapshot: name: VolumeSnapshot walg: - image: ghcr.io/kubedb/postgres-archiver:v0.0.1_16.1-alpine + image: ghcr.io/kubedb/postgres-archiver:(v0.0.1)_16.1-alpine coordinator: image: ghcr.io/kubedb/pg-coordinator:v0.23.0 db: @@ -58,7 +58,7 @@ spec: volumeSnapshot: name: VolumeSnapshot walg: - image: ghcr.io/kubedb/postgres-archiver:v0.0.1_16.1-bookworm + image: ghcr.io/kubedb/postgres-archiver:(v0.0.1)_16.1-bookworm coordinator: image: ghcr.io/kubedb/pg-coordinator:v0.23.0 db: diff --git a/charts/kubedb-catalog/templates/postgres/postgres-11.11-timescaledb.yaml b/charts/kubedb-catalog/templates/postgres/postgres-11.11-timescaledb.yaml index 5f3dee776..7f87975df 100644 --- a/charts/kubedb-catalog/templates/postgres/postgres-11.11-timescaledb.yaml +++ b/charts/kubedb-catalog/templates/postgres/postgres-11.11-timescaledb.yaml @@ -6,6 +6,18 @@ metadata: labels: {{- include "kubedb-catalog.labels" . | nindent 4 }} spec: + archiver: + addon: + name: postgres-addon + tasks: + manifestBackup: + name: ManifestBackup + manifestRestore: + name: ManifestRestore + volumeSnapshot: + name: VolumeSnapshot + walg: + image: '{{ include "image.ghcr" (merge (dict "_repo" "kubedb/postgres-archiver") $) }}:v0.0.1_11.22-alpine' coordinator: image: '{{ include "image.ghcr" (merge (dict "_repo" "kubedb/pg-coordinator") $) }}:v0.23.0' db: diff --git a/charts/kubedb-catalog/templates/postgres/postgres-12.6-timescaledb.yaml b/charts/kubedb-catalog/templates/postgres/postgres-12.6-timescaledb.yaml index 69e7edfd3..436b7525c 100644 --- a/charts/kubedb-catalog/templates/postgres/postgres-12.6-timescaledb.yaml +++ b/charts/kubedb-catalog/templates/postgres/postgres-12.6-timescaledb.yaml @@ -6,6 +6,18 @@ metadata: labels: {{- include "kubedb-catalog.labels" . | nindent 4 }} spec: + archiver: + addon: + name: postgres-addon + tasks: + manifestBackup: + name: ManifestBackup + manifestRestore: + name: ManifestRestore + volumeSnapshot: + name: VolumeSnapshot + walg: + image: '{{ include "image.ghcr" (merge (dict "_repo" "kubedb/postgres-archiver") $) }}:v0.0.1_12.17-alpine' coordinator: image: '{{ include "image.ghcr" (merge (dict "_repo" "kubedb/pg-coordinator") $) }}:v0.23.0' db: diff --git a/charts/kubedb-catalog/templates/postgres/postgres-13.2-timescaledb.yaml b/charts/kubedb-catalog/templates/postgres/postgres-13.2-timescaledb.yaml index 1eb756172..b95b2cc7d 100644 --- a/charts/kubedb-catalog/templates/postgres/postgres-13.2-timescaledb.yaml +++ b/charts/kubedb-catalog/templates/postgres/postgres-13.2-timescaledb.yaml @@ -6,6 +6,18 @@ metadata: labels: {{- include "kubedb-catalog.labels" . | nindent 4 }} spec: + archiver: + addon: + name: postgres-addon + tasks: + manifestBackup: + name: ManifestBackup + manifestRestore: + name: ManifestRestore + volumeSnapshot: + name: VolumeSnapshot + walg: + image: '{{ include "image.ghcr" (merge (dict "_repo" "kubedb/postgres-archiver") $) }}:v0.0.1_13.13-alpine' coordinator: image: '{{ include "image.ghcr" (merge (dict "_repo" "kubedb/pg-coordinator") $) }}:v0.23.0' db: diff --git a/charts/kubedb-catalog/templates/postgres/postgres-14.1-timescaledb.yaml b/charts/kubedb-catalog/templates/postgres/postgres-14.1-timescaledb.yaml index 395430267..4b420fa78 100644 --- a/charts/kubedb-catalog/templates/postgres/postgres-14.1-timescaledb.yaml +++ b/charts/kubedb-catalog/templates/postgres/postgres-14.1-timescaledb.yaml @@ -6,6 +6,18 @@ metadata: labels: {{- include "kubedb-catalog.labels" . | nindent 4 }} spec: + archiver: + addon: + name: postgres-addon + tasks: + manifestBackup: + name: ManifestBackup + manifestRestore: + name: ManifestRestore + volumeSnapshot: + name: VolumeSnapshot + walg: + image: '{{ include "image.ghcr" (merge (dict "_repo" "kubedb/postgres-archiver") $) }}:v0.0.1_14.10-alpine' coordinator: image: '{{ include "image.ghcr" (merge (dict "_repo" "kubedb/pg-coordinator") $) }}:v0.23.0' db: