Skip to content

Commit d98a354

Browse files
tjmoore4Jonathan S. Katz
authored andcommitted
Update standard image tag when using a GIS enabled cluster
Currently, the image tag value used by GIS enabled pgclusters is being used when creating sidecontainers. Since the standard and GIS enable PostgreSQL containers use different tags, this causes an image pull error. This update takes the current image name and the image tag value stored in the pgcluster CRD and, if the image being used is the crunchy-postgres-gis-ha container with the corresponding tag, it uses an updated tag without the addition of the GIS version when provisioning sidecars containers for the cluster. Issue: [ch9393] Issue: #1749
1 parent fbe152c commit d98a354

File tree

5 files changed

+97
-3
lines changed

5 files changed

+97
-3
lines changed

internal/operator/cluster/pgadmin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ func createPgAdminDeployment(clientset kubernetes.Interface, cluster *crv1.Pgclu
348348
Name: pgAdminDeploymentName,
349349
ClusterName: cluster.Name,
350350
CCPImagePrefix: operator.Pgo.Cluster.CCPImagePrefix,
351-
CCPImageTag: cluster.Spec.CCPImageTag,
351+
CCPImageTag: util.GetStandardImageTag(cluster.Spec.CCPImage, cluster.Spec.CCPImageTag),
352352
DisableFSGroup: operator.Pgo.Cluster.DisableFSGroup,
353353
Port: defPgAdminPort,
354354
InitUser: defSetupUsername,

internal/operator/cluster/pgbouncer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ func createPgBouncerDeployment(clientset kubernetes.Interface, cluster *crv1.Pgc
554554
Name: pgbouncerDeploymentName,
555555
ClusterName: cluster.Name,
556556
CCPImagePrefix: util.GetValueOrDefault(cluster.Spec.CCPImagePrefix, operator.Pgo.Cluster.CCPImagePrefix),
557-
CCPImageTag: cluster.Spec.CCPImageTag,
557+
CCPImageTag: util.GetStandardImageTag(cluster.Spec.CCPImage, cluster.Spec.CCPImageTag),
558558
Port: cluster.Spec.Port,
559559
PGBouncerConfigMap: util.GeneratePgBouncerConfigMapName(cluster.Name),
560560
PGBouncerSecret: util.GeneratePgBouncerSecretName(cluster.Name),

internal/operator/clusterutilities.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ func GetBadgerAddon(clientset kubernetes.Interface, namespace string, cluster *c
335335
if cluster.Labels[config.LABEL_BADGER] == "true" {
336336
log.Debug("crunchy_badger was found as a label on cluster create")
337337
badgerTemplateFields := badgerTemplateFields{}
338-
badgerTemplateFields.CCPImageTag = spec.CCPImageTag
338+
badgerTemplateFields.CCPImageTag = util.GetStandardImageTag(spec.CCPImage, spec.CCPImageTag)
339339
badgerTemplateFields.BadgerTarget = pgbadger_target
340340
badgerTemplateFields.PGBadgerPort = spec.PGBadgerPort
341341
badgerTemplateFields.CCPImagePrefix = util.GetValueOrDefault(spec.CCPImagePrefix, Pgo.Cluster.CCPImagePrefix)

internal/util/util.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"errors"
2121
"fmt"
2222
"math/rand"
23+
"regexp"
2324
"strings"
2425
"time"
2526

@@ -45,6 +46,10 @@ type JSONPatchOperation struct {
4546
Value interface{} `json:"value"`
4647
}
4748

49+
// gisImageTagRegex is a regular expression designed to match the standard image tag for
50+
// the crunchy-postgres-gis-ha container
51+
var gisImageTagRegex = regexp.MustCompile(`(.+-[\d|\.]+)-[\d|\.]+?(-[\d|\.]+.*)`)
52+
4853
func init() {
4954
rand.Seed(time.Now().UnixNano())
5055

@@ -203,6 +208,20 @@ func GetSecretPassword(clientset kubernetes.Interface, db, suffix, Namespace str
203208

204209
}
205210

211+
// GetStandardImageTag takes the current image name and the image tag value
212+
// stored in the pgcluster CRD and, if the image being used is the
213+
// crunchy-postgres-gis-ha container with the corresponding tag, it returns
214+
// the tag without the addition of the GIS version. This tag value can then
215+
// be used when provisioning containers using the standard containers tag.
216+
func GetStandardImageTag(imageName, imageTag string) string {
217+
218+
if imageName == "crunchy-postgres-gis-ha" && strings.Count(imageTag, "-") > 2 {
219+
return gisImageTagRegex.ReplaceAllString(imageTag, "$1$2")
220+
}
221+
222+
return imageTag
223+
}
224+
206225
// RandStringBytesRmndr ...
207226
func RandStringBytesRmndr(n int) string {
208227
b := make([]byte, n)

internal/util/util_test.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package util
2+
3+
import "testing"
4+
5+
func TestGetStandardImageTag(t *testing.T) {
6+
7+
assertCorrectMessage := func(t testing.TB, got, want string) {
8+
t.Helper()
9+
if got != want {
10+
t.Errorf("got %q want %q", got, want)
11+
}
12+
}
13+
14+
imageTagTests := []struct {
15+
description string
16+
imageName string
17+
imageTag string
18+
expected string
19+
}{
20+
{
21+
"image: crunchy-postgres-ha, tag: centos7-12.4-4.5.0",
22+
"crunchy-postgres-ha",
23+
"centos7-12.4-4.5.0",
24+
"centos7-12.4-4.5.0",
25+
}, {
26+
"image: crunchy-postgres-gis-ha, tag: centos7-12.4-3.0-4.5.0",
27+
"crunchy-postgres-gis-ha",
28+
"centos7-12.4-3.0-4.5.0",
29+
"centos7-12.4-4.5.0",
30+
}, {
31+
"image: crunchy-postgres-ha, tag: centos7-12.4-4.5.0-beta.1",
32+
"crunchy-postgres-ha",
33+
"centos7-12.4-4.5.0-beta.1",
34+
"centos7-12.4-4.5.0-beta.1",
35+
}, {
36+
"image: crunchy-postgres-gis-ha, tag: centos7-12.4-3.0-4.5.0-beta.2",
37+
"crunchy-postgres-gis-ha",
38+
"centos7-12.4-3.0-4.5.0-beta.2",
39+
"centos7-12.4-4.5.0-beta.2",
40+
}, {
41+
"image: crunchy-postgres-ha, tag: centos8-9.5.23-4.5.0-rc.1",
42+
"crunchy-postgres-ha",
43+
"centos8-9.5.23-4.5.0-rc.1",
44+
"centos8-9.5.23-4.5.0-rc.1",
45+
}, {
46+
"image: crunchy-postgres-gis-ha, tag: centos8-9.5.23-2.4-4.5.0-rc.1",
47+
"crunchy-postgres-gis-ha",
48+
"centos8-9.5.23-2.4-4.5.0-rc.1",
49+
"centos8-9.5.23-4.5.0-rc.1",
50+
}, {
51+
"image: crunchy-postgres-gis-ha, tag: centos8-13.0-3.0-4.5.0-rc.1",
52+
"crunchy-postgres-gis-ha",
53+
"centos8-13.0-3.0-4.5.0-rc.1",
54+
"centos8-13.0-4.5.0-rc.1",
55+
}, {
56+
"image: crunchy-postgres-gis-ha, tag: centos8-custom123",
57+
"crunchy-postgres-gis-ha",
58+
"centos8-custom123",
59+
"centos8-custom123",
60+
}, {
61+
"image: crunchy-postgres-gis-ha, tag: centos8-custom123-moreinfo-789",
62+
"crunchy-postgres-gis-ha",
63+
"centos8-custom123-moreinfo-789",
64+
"centos8-custom123-moreinfo-789",
65+
},
66+
}
67+
68+
for _, itt := range imageTagTests {
69+
t.Run(itt.description, func(t *testing.T) {
70+
got := GetStandardImageTag(itt.imageName, itt.imageTag)
71+
want := itt.expected
72+
assertCorrectMessage(t, got, want)
73+
})
74+
}
75+
}

0 commit comments

Comments
 (0)