Skip to content

Commit

Permalink
Merge pull request yunionio#34 from zexi/hotfix/get-image-info
Browse files Browse the repository at this point in the history
fix getRepoImageName parse sha256 tag
  • Loading branch information
yousong authored Mar 9, 2020
2 parents 74dcb73 + 1a6fac5 commit 4ec9b5a
Show file tree
Hide file tree
Showing 20 changed files with 1,088 additions and 542 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ require (
sigs.k8s.io/testing_frameworks v0.1.1 // indirect
yunion.io/x/jsonutils v0.0.0-20200303051356-aa609aba0cda
yunion.io/x/log v0.0.0-20190629062853-9f6483a7103d
yunion.io/x/onecloud v0.0.0-20200303051418-112eb0d7ae22
yunion.io/x/onecloud-operator v0.0.2-0.20200302130241-cb99d44a51a5
yunion.io/x/pkg v0.0.0-20200302034534-fdf44d54b070
yunion.io/x/onecloud v0.0.0-20200309043639-7b0ceddd6b80
yunion.io/x/onecloud-operator v0.0.2-0.20200309080407-e89871b996c7
yunion.io/x/pkg v0.0.0-20200304112442-9dae9351325e
)

replace (
Expand Down
11 changes: 6 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1042,17 +1042,18 @@ yunion.io/x/log v0.0.0-20190514041436-04ce53b17c6b h1:Z9z+7iegu0HXuL+S8taVWRd1P4
yunion.io/x/log v0.0.0-20190514041436-04ce53b17c6b/go.mod h1:+gauLs73omeJAPlsXcevLsJLKixV+sR/E7WSYTSx1fE=
yunion.io/x/log v0.0.0-20190629062853-9f6483a7103d h1:59zrDL7Ft+hDukguJRmLr/Gdu/9V75x+yX99ovZwfaA=
yunion.io/x/log v0.0.0-20190629062853-9f6483a7103d/go.mod h1:LC6f/4FozL0iaAbnFt2eDX9jlsyo3WiOUPm03d7+U4U=
yunion.io/x/onecloud v0.0.0-20200302125143-da235de89624/go.mod h1:Bwwm854tfC0eoMiEKX0NlEcqPBE+F+mDM/YR3x7V4OY=
yunion.io/x/onecloud v0.0.0-20200303051418-112eb0d7ae22 h1:Bu9h+mJTXfpmAVkALHfdqUcJnZEItEHkmXDlGpnFIVY=
yunion.io/x/onecloud v0.0.0-20200303051418-112eb0d7ae22/go.mod h1:Bwwm854tfC0eoMiEKX0NlEcqPBE+F+mDM/YR3x7V4OY=
yunion.io/x/onecloud-operator v0.0.2-0.20200302130241-cb99d44a51a5 h1:q9ds3CBwhu59VHA8Wyf319AG5zQCYV17UIpjnRyFdbI=
yunion.io/x/onecloud-operator v0.0.2-0.20200302130241-cb99d44a51a5/go.mod h1:RfLY9fAuxLMiFue3SfP2W9R3ogSqk6QXFOOD6PCeTMw=
yunion.io/x/onecloud v0.0.0-20200309043639-7b0ceddd6b80 h1:BI92GsdkEZfF7zFyayg1JPBJp3PUjESPpMgwL6o0W/Y=
yunion.io/x/onecloud v0.0.0-20200309043639-7b0ceddd6b80/go.mod h1:Bwwm854tfC0eoMiEKX0NlEcqPBE+F+mDM/YR3x7V4OY=
yunion.io/x/onecloud-operator v0.0.2-0.20200309080407-e89871b996c7 h1:aQi/ePISrHtaKTUzNzV1Gq9OzFUEbmKrL9DxIE2wezw=
yunion.io/x/onecloud-operator v0.0.2-0.20200309080407-e89871b996c7/go.mod h1:hqFcli7owdcepv3tOEl2AnVRFaXpTZiYnXlKfZUqDu4=
yunion.io/x/pkg v0.0.0-20190620104149-945c25821dbf h1:OsKC+2ghZHwp+Ztm/MwKlLKKRiE7QcPG8eTp0GmsHbg=
yunion.io/x/pkg v0.0.0-20190620104149-945c25821dbf/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
yunion.io/x/pkg v0.0.0-20190628082551-f4033ba2ea30/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
yunion.io/x/pkg v0.0.0-20200103043034-27c6f82160fa/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
yunion.io/x/pkg v0.0.0-20200302034534-fdf44d54b070 h1:rKnYgtvMHKmzPEUTkyNjyKOG7wzjpUvI7fcZwLNGQXw=
yunion.io/x/pkg v0.0.0-20200302034534-fdf44d54b070/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
yunion.io/x/pkg v0.0.0-20200304112442-9dae9351325e h1:rBfX77+VEBVpe6Xxy2gDa4WB7qbtndWvXcrVKzleF84=
yunion.io/x/pkg v0.0.0-20200304112442-9dae9351325e/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e h1:v+EzIadodSwkdZ/7bremd7J8J50Cise/HCylsOJngmo=
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e/go.mod h1:0iFKpOs1y4lbCxeOmq3Xx/0AcQoewVPwj62eRluioEo=
yunion.io/x/sqlchemy v0.0.0-20200221103553-6a98f7f8ab92 h1:Iz70/alKMAW3KeePhmExuhWsYw1MGTcMr5ewAL5lj1I=
Expand Down
46 changes: 10 additions & 36 deletions pkg/phases/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
"time"

Expand All @@ -25,6 +24,7 @@ import (
"yunion.io/x/onecloud-operator/pkg/apis/onecloud/v1alpha1"
"yunion.io/x/onecloud-operator/pkg/client/clientset/versioned"
occonfig "yunion.io/x/onecloud-operator/pkg/manager/config"
"yunion.io/x/onecloud-operator/pkg/util/image"

"yunion.io/x/ocadm/pkg/apis/constants"
apiv1 "yunion.io/x/ocadm/pkg/apis/v1"
Expand Down Expand Up @@ -381,46 +381,20 @@ func updateCluster(data *clusterData, opt *updateOptions) error {
return nil
}

func getRepoImageName(img string) (string, string, string) {
parts := strings.Split(img, "/")
var (
repo string
imageName string
tag string
)
getImageTag := func(img string) (string, string) {
parts := strings.Split(img, ":")
if len(parts) == 0 {
return "", ""
}
if len(parts) == 1 {
tag := "latest"
img := parts[0]
return img, tag
} else {
img = parts[0]
tag = parts[len(parts)-1]
return img, tag
}
}
getRepo := func(parts []string) string {
return filepath.Join(parts...)
}
if len(parts) == 0 {
return "", "", ""
}
if len(parts) == 1 {
imageName, tag = getImageTag(parts[0])
} else {
imageName, tag = getImageTag(parts[len(parts)-1])
repo = getRepo(parts[0 : len(parts)-1])
func getRepoImageName(img string) (string, string, string, error) {
ret, err := image.ParseImageReference(img)
if err != nil {
return "", "", "", err
}
return repo, imageName, tag
return ret.Repository, ret.Image, ret.Tag, nil
}

func getOperatorVersion(operator *appv1.Deployment) (string, string, string, error) {
img := operator.Spec.Template.Spec.Containers[0].Image
repo, imageName, tag := getRepoImageName(img)
repo, imageName, tag, err := getRepoImageName(img)
if err != nil {
return "", "", "", err
}
if repo == "" {
return "", "", "", errors.Errorf("Failed to get %q repo", img)
}
Expand Down
66 changes: 66 additions & 0 deletions pkg/phases/cluster/cluster_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package cluster

import "testing"

func Test_getRepoImageName(t *testing.T) {
type args struct {
img string
}
tests := []struct {
name string
args args
want string
want1 string
want2 string
}{
{
"yunion/image",
args{"yunion/image"},
"yunion",
"image",
"latest",
},
{
"hub.docker.io/yunion/image:v2",
args{"hub.docker.io/yunion/image:v2"},
"hub.docker.io/yunion",
"image",
"v2",
},
{
"hub.docker.io/yunion/image:v2",
args{"hub.docker.io/yunion/image:v2"},
"hub.docker.io/yunion",
"image",
"v2",
},
{
"10.168.222.173:8082/yunion/image:v2",
args{"10.168.222.173:8082/yunion/image:v2"},
"10.168.222.173:8082/yunion",
"image",
"v2",
},
{
"registry.cn-beijing.aliyuncs.com/yunionio/climc@sha256:32dcddaa6271b8c752bd6574c789771d38315076ce300c4a1d4618496e359f2d",
args{"registry.cn-beijing.aliyuncs.com/yunionio/climc@sha256:32dcddaa6271b8c752bd6574c789771d38315076ce300c4a1d4618496e359f2d"},
"registry.cn-beijing.aliyuncs.com/yunionio",
"climc",
"",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, got1, got2, _ := getRepoImageName(tt.args.img)
if got != tt.want {
t.Errorf("getRepoImageName() got = %v, want %v", got, tt.want)
}
if got1 != tt.want1 {
t.Errorf("getRepoImageName() got1 = %v, want %v", got1, tt.want1)
}
if got2 != tt.want2 {
t.Errorf("getRepoImageName() got2 = %v, want %v", got2, tt.want2)
}
})
}
}
7 changes: 4 additions & 3 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ yunion.io/x/jsonutils
# yunion.io/x/log v0.0.0-20190629062853-9f6483a7103d
yunion.io/x/log
yunion.io/x/log/hooks
# yunion.io/x/onecloud v0.0.0-20200303051418-112eb0d7ae22
# yunion.io/x/onecloud v0.0.0-20200309043639-7b0ceddd6b80
yunion.io/x/onecloud/pkg/ansibleserver/options
yunion.io/x/onecloud/pkg/apis
yunion.io/x/onecloud/pkg/apis/ansible
Expand Down Expand Up @@ -922,7 +922,7 @@ yunion.io/x/onecloud/pkg/util/stringutils2
yunion.io/x/onecloud/pkg/vpcagent/options
yunion.io/x/onecloud/pkg/webconsole/options
yunion.io/x/onecloud/pkg/yunionconf/options
# yunion.io/x/onecloud-operator v0.0.2-0.20200302130241-cb99d44a51a5
# yunion.io/x/onecloud-operator v0.0.2-0.20200309080407-e89871b996c7
yunion.io/x/onecloud-operator/pkg/apis/constants
yunion.io/x/onecloud-operator/pkg/apis/onecloud/scheme
yunion.io/x/onecloud-operator/pkg/apis/onecloud/v1alpha1
Expand All @@ -935,13 +935,14 @@ yunion.io/x/onecloud-operator/pkg/label
yunion.io/x/onecloud-operator/pkg/manager
yunion.io/x/onecloud-operator/pkg/manager/component
yunion.io/x/onecloud-operator/pkg/manager/config
yunion.io/x/onecloud-operator/pkg/util/image
yunion.io/x/onecloud-operator/pkg/util/k8s
yunion.io/x/onecloud-operator/pkg/util/mysql
yunion.io/x/onecloud-operator/pkg/util/onecloud
yunion.io/x/onecloud-operator/pkg/util/passwd
yunion.io/x/onecloud-operator/pkg/util/pkiutil
yunion.io/x/onecloud-operator/pkg/util/retry
# yunion.io/x/pkg v0.0.0-20200302034534-fdf44d54b070
# yunion.io/x/pkg v0.0.0-20200304112442-9dae9351325e
yunion.io/x/pkg/errors
yunion.io/x/pkg/gotypes
yunion.io/x/pkg/trace
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions vendor/yunion.io/x/onecloud-operator/pkg/manager/component/host.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 9 additions & 34 deletions vendor/yunion.io/x/onecloud-operator/pkg/manager/component/sync.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions vendor/yunion.io/x/onecloud-operator/pkg/util/image/reference.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4ec9b5a

Please sign in to comment.