Skip to content

Commit

Permalink
fix(admintools): add default image tag if left empty
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrevilain committed Oct 2, 2024
1 parent 4afb5fe commit 4f19690
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 18 deletions.
4 changes: 4 additions & 0 deletions api/v1beta1/temporalcluster_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ func (c *TemporalCluster) Default() {
c.Spec.AdminTools.Image = defaultTemporalAdmintoolsImage
}

if c.Spec.AdminTools.Version == "" {
c.Spec.AdminTools.Version = version.DefaultAdminToolTag(c.Spec.Version)
}

if c.Spec.MTLS != nil {
if c.Spec.MTLS.RefreshInterval == nil {
c.Spec.MTLS.RefreshInterval = &metav1.Duration{Duration: time.Hour}
Expand Down
7 changes: 1 addition & 6 deletions internal/resource/persistence/schema_setup_job_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,6 @@ func (b *SchemaJobBuilder) Build() client.Object {

volumes = append(volumes, GetDatastoresVolumes(datastores)...)

tag := b.instance.Spec.AdminTools.Version
if tag == "" {
tag = version.PersistenceJobTag(b.instance.Spec.Version)
}

return &batchv1.Job{
ObjectMeta: metav1.ObjectMeta{
Name: b.instance.ChildResourceName(b.name),
Expand Down Expand Up @@ -129,7 +124,7 @@ func (b *SchemaJobBuilder) Build() client.Object {
Containers: []corev1.Container{
{
Name: "schema-script-runner",
Image: fmt.Sprintf("%s:%s", b.instance.Spec.AdminTools.Image, tag),
Image: fmt.Sprintf("%s:%s", b.instance.Spec.AdminTools.Image, version.DefaultAdminToolTag(b.instance.Spec.Version)),
ImagePullPolicy: corev1.PullIfNotPresent,
Resources: b.instance.Spec.JobResources,
TerminationMessagePath: corev1.TerminationMessagePathDefault,
Expand Down
20 changes: 20 additions & 0 deletions pkg/version/admintools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package version

import "fmt"

// DefaultAdminToolTag returns the tag of the admin tools image for the given version.
// It's required as 1.24.x had really bad image tagging.
func DefaultAdminToolTag(version *Version) string {
// Particular case for >= 1.24.0 but < 1.25.0
if version.GreaterOrEqual(V1_24_0) && version.LessThan(V1_25_0) {
return "1.24.2-tctl-1.18.1-cli-0.13.2"
}

// Particular case for >= 1.25 because the admin tools image tag doesn't
// contains patch version (or it has the same bad naming as for 1.24.x).
if version.GreaterOrEqual(V1_25_0) {
return fmt.Sprintf("%d.%d", version.Major(), version.Minor())
}

return version.String()
}
53 changes: 53 additions & 0 deletions pkg/version/admintools_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package version_test

import (
"testing"

"github.com/alexandrevilain/temporal-operator/pkg/version"
"github.com/stretchr/testify/assert"
)

func TestDefaultAdminToolTag(t *testing.T) {
tests := []struct {
name string
version *version.Version
expected string
}{
{
name: "Version 1.24.1",
version: version.MustNewVersionFromString("1.24.1"),
expected: "1.24.2-tctl-1.18.1-cli-0.13.2",
},
{
name: "Version 1.24.9",
version: version.MustNewVersionFromString("1.24.9"),
expected: "1.24.2-tctl-1.18.1-cli-0.13.2",
},
{
name: "Version 1.25.0",
version: version.MustNewVersionFromString("1.25.0"),
expected: "1.25",
},
{
name: "Version 1.25.5",
version: version.MustNewVersionFromString("1.25.5"),
expected: "1.25",
},
{
name: "Version 1.26.0",
version: version.MustNewVersionFromString("1.26.0"),
expected: "1.26",
},
{
name: "Version 1.10.0",
version: version.MustNewVersionFromString("1.10.0"),
expected: "1.10.0",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.expected, version.DefaultAdminToolTag(tt.version))
})
}
}
12 changes: 0 additions & 12 deletions pkg/version/persistence_jobs.go

This file was deleted.

0 comments on commit 4f19690

Please sign in to comment.