Skip to content

Commit 16a677b

Browse files
authored
Deployment was broken when using a pinned tag (#401)
instead of only a tag or only a digest. Fixes #389
1 parent 2c943af commit 16a677b

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

apis/mattermost/v1alpha1/clusterinstallation_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@ func TestClusterInstallation(t *testing.T) {
163163
assert.Contains(t, ci.GetImageName(), ci.Spec.Version)
164164
assert.Equal(t, ci.GetImageName(), fmt.Sprintf("%s@%s", ci.Spec.Image, ci.Spec.Version))
165165
})
166+
167+
t.Run("using tag and digest", func(t *testing.T) {
168+
ci.Spec.Version = "10.6.1@sha256:dd15a51ac7dafd213744d1ef23394e7532f71a90f477c969b94600e46da5a0cf"
169+
assert.Contains(t, ci.GetImageName(), ci.Spec.Image)
170+
assert.Contains(t, ci.GetImageName(), ci.Spec.Version)
171+
assert.Equal(t, ci.GetImageName(), fmt.Sprintf("%s:%s", ci.Spec.Image, ci.Spec.Version))
172+
})
166173
}
167174

168175
func TestGetDeploymentImageName(t *testing.T) {

apis/mattermost/v1alpha1/clusterinstallation_utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,10 @@ func (mattermost *ClusterInstallation) GetMattermostAppContainer(containers []co
189189
// GetImageName returns the container image name that matches the spec of the
190190
// ClusterInstallation.
191191
func (mattermost *ClusterInstallation) GetImageName() string {
192-
// if user set the version using the Digest instead of tag like
192+
// if user set the version using only the Digest instead of tag or tag@digest like
193193
// sha256:dd15a51ac7dafd213744d1ef23394e7532f71a90f477c969b94600e46da5a0cf
194194
// we need to set the @ instead of : to split the image name and "tag"
195-
if strings.Contains(mattermost.Spec.Version, "sha256:") {
195+
if strings.HasPrefix(mattermost.Spec.Version, "sha256:") {
196196
return fmt.Sprintf("%s@%s", mattermost.Spec.Image, mattermost.Spec.Version)
197197
}
198198
return fmt.Sprintf("%s:%s", mattermost.Spec.Image, mattermost.Spec.Version)

apis/mattermost/v1beta1/mattermost_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,13 @@ func TestMattermost(t *testing.T) {
157157
assert.Contains(t, mm.GetImageName(), mm.Spec.Version)
158158
assert.Equal(t, mm.GetImageName(), fmt.Sprintf("%s@%s", mm.Spec.Image, mm.Spec.Version))
159159
})
160+
161+
t.Run("using tag and digest", func(t *testing.T) {
162+
mm.Spec.Version = "10.6.1@sha256:dd15a51ac7dafd213744d1ef23394e7532f71a90f477c969b94600e46da5a0cf"
163+
assert.Contains(t, mm.GetImageName(), mm.Spec.Image)
164+
assert.Contains(t, mm.GetImageName(), mm.Spec.Version)
165+
assert.Equal(t, mm.GetImageName(), fmt.Sprintf("%s:%s", mm.Spec.Image, mm.Spec.Version))
166+
})
160167
}
161168

162169
func TestOtherUtils(t *testing.T) {

apis/mattermost/v1beta1/mattermost_utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,10 @@ func getContainerByName(containers []corev1.Container, containerName string) *co
210210
// GetImageName returns the container image name that matches the spec of the
211211
// ClusterInstallation.
212212
func (mm *Mattermost) GetImageName() string {
213-
// if user set the version using the Digest instead of tag like
213+
// if user set the version using only the Digest instead of tag or tag@digest like
214214
// sha256:dd15a51ac7dafd213744d1ef23394e7532f71a90f477c969b94600e46da5a0cf
215215
// we need to set the @ instead of : to split the image name and "tag"
216-
if strings.Contains(mm.Spec.Version, "sha256:") {
216+
if strings.HasPrefix(mm.Spec.Version, "sha256:") {
217217
return fmt.Sprintf("%s@%s", mm.Spec.Image, mm.Spec.Version)
218218
}
219219
return fmt.Sprintf("%s:%s", mm.Spec.Image, mm.Spec.Version)

0 commit comments

Comments
 (0)