Skip to content

Commit

Permalink
fix(upgrade): add support for images having more than one ":" (openeb…
Browse files Browse the repository at this point in the history
…s-archive#1557)

* fix(upgarde): add support for images having more than one ":"

Signed-off-by: shubham <[email protected]>
  • Loading branch information
shubham14bajpai committed Dec 27, 2019
1 parent a8602c9 commit 071e801
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/upgrade/upgrader/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ func getContainerName(d *appsv1.Deployment) (string, error) {
func getBaseImage(deployObj *appsv1.Deployment, name string) (string, error) {
for _, con := range deployObj.Spec.Template.Spec.Containers {
if con.Name == name {
baseImage := strings.Split(con.Image, ":")[0]
lastIndex := strings.LastIndex(con.Image, ":")
if lastIndex == -1 {
return "", errors.Errorf("no version tag found on image %s", con.Image)
}
baseImage := con.Image[:lastIndex]
if urlPrefix != "" {
// urlPrefix is the url to the directory where the images are present
// the below logic takes the image name from current baseImage and
Expand Down
118 changes: 118 additions & 0 deletions pkg/upgrade/upgrader/helper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
Copyright 2019 The OpenEBS Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
"testing"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
)

func Test_getBaseImage(t *testing.T) {
type args struct {
deployObj *appsv1.Deployment
name string
}
tests := []struct {
name string
args args
want string
wantErr bool
}{
// TODO: Add test cases.
{
name: "Without proxy",
want: "quay.io/openebs/cstor-pool",
wantErr: false,
args: args{
deployObj: &appsv1.Deployment{
Spec: appsv1.DeploymentSpec{
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
corev1.Container{
Name: "cstor-pool",
Image: "quay.io/openebs/cstor-pool:1.4.0",
},
},
},
},
},
},
name: "cstor-pool",
},
},
{
name: "With proxy",
want: "fsdepot.evry.com:8085/openebs/cstor-pool",
wantErr: false,
args: args{
deployObj: &appsv1.Deployment{
Spec: appsv1.DeploymentSpec{
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
corev1.Container{
Name: "cstor-pool",
Image: "fsdepot.evry.com:8085/openebs/cstor-pool:1.4.0",
},
},
},
},
},
},
name: "cstor-pool",
},
},
{
name: "With no image tag",
want: "",
wantErr: true,
args: args{
deployObj: &appsv1.Deployment{
Spec: appsv1.DeploymentSpec{
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
corev1.Container{
Name: "cstor-pool",
Image: "quay.io/openebs/cstor-pool",
},
},
},
},
},
},
name: "cstor-pool",
},
},
}
for _, tt := range tests {
tt := tt // pin it
t.Run(tt.name, func(t *testing.T) {
got, err := getBaseImage(tt.args.deployObj, tt.args.name)
if (err != nil) != tt.wantErr {
t.Errorf("getBaseImage() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("getBaseImage() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 071e801

Please sign in to comment.