Skip to content

Commit

Permalink
Templatize wal-g images
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha committed Dec 27, 2023
1 parent 74e57f6 commit 51b6b11
Show file tree
Hide file tree
Showing 19 changed files with 154 additions and 24 deletions.
50 changes: 42 additions & 8 deletions catalog/kubedb/fmt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}
Expand Down Expand Up @@ -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":
Expand All @@ -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)
}
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
12 changes: 12 additions & 0 deletions catalog/kubedb/raw/postgres/postgres-11.11-timescaledb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion catalog/kubedb/raw/postgres/postgres-11.14-postgis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions catalog/kubedb/raw/postgres/postgres-11.22-official.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions catalog/kubedb/raw/postgres/postgres-12.17-official.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions catalog/kubedb/raw/postgres/postgres-12.6-timescaledb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion catalog/kubedb/raw/postgres/postgres-12.9-postgis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions catalog/kubedb/raw/postgres/postgres-13.13-official.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions catalog/kubedb/raw/postgres/postgres-13.2-timescaledb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion catalog/kubedb/raw/postgres/postgres-13.5-postgis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion catalog/kubedb/raw/postgres/postgres-14.1-postgis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions catalog/kubedb/raw/postgres/postgres-14.1-timescaledb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions catalog/kubedb/raw/postgres/postgres-14.10-official.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions catalog/kubedb/raw/postgres/postgres-15.5-official.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions catalog/kubedb/raw/postgres/postgres-16.1-official.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 51b6b11

Please sign in to comment.