🎨优化一下取tag的时候可能带有v字符,干掉他
All checks were successful
continuous-integration/drone/tag Build is passing
All checks were successful
continuous-integration/drone/tag Build is passing
This commit is contained in:
parent
eafe8fab8d
commit
d78b079290
@ -44,12 +44,6 @@ func (c *config) Client() (*client, error) {
|
|||||||
// @return err
|
// @return err
|
||||||
func (c client) Do(namespace, kind, resourceName, actionMethod, repo string) (err error) {
|
func (c client) Do(namespace, kind, resourceName, actionMethod, repo string) (err error) {
|
||||||
|
|
||||||
fmt.Println("命名空间: ", namespace)
|
|
||||||
fmt.Println("资源类型: ", kind)
|
|
||||||
fmt.Println("资源名称: ", resourceName)
|
|
||||||
fmt.Println("操作类型: ", actionMethod)
|
|
||||||
fmt.Println("镜像地址: ", repo)
|
|
||||||
|
|
||||||
var kindType any // 应用类型
|
var kindType any // 应用类型
|
||||||
var resource any // 资源详情
|
var resource any // 资源详情
|
||||||
|
|
||||||
@ -78,8 +72,31 @@ func (c client) Do(namespace, kind, resourceName, actionMethod, repo string) (er
|
|||||||
|
|
||||||
// 解析规则,判断是只单独变更tag还是镜像整个替换
|
// 解析规则,判断是只单独变更tag还是镜像整个替换
|
||||||
if !strings.Contains(repo, ":") {
|
if !strings.Contains(repo, ":") {
|
||||||
|
|
||||||
|
// 判断是镜像地址还是tag标签
|
||||||
|
if strings.Contains(repo, "/") {
|
||||||
|
// 镜像地址,默认tag为 latest
|
||||||
|
repo = fmt.Sprintf("%s:latest", repo)
|
||||||
|
} else {
|
||||||
|
// 只是tag标签,判断tag标签是否带有v开头的字符
|
||||||
|
if strings.HasPrefix(repo, "v") {
|
||||||
|
repo = strings.ReplaceAll(repo, "v", "")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
resource.(*appv1.Deployment).Spec.Template.Spec.Containers[0].Image = fmt.Sprintf("%s:%s", strings.Split(resource.(*appv1.Deployment).Spec.Template.Spec.Containers[0].Image, ":")[0], repo)
|
resource.(*appv1.Deployment).Spec.Template.Spec.Containers[0].Image = fmt.Sprintf("%s:%s", strings.Split(resource.(*appv1.Deployment).Spec.Template.Spec.Containers[0].Image, ":")[0], repo)
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
// 获取tag
|
||||||
|
image := strings.Split(repo, ":")[0]
|
||||||
|
tag := strings.Split(repo, ":")[1]
|
||||||
|
|
||||||
|
if strings.Contains(tag, "v") {
|
||||||
|
tag = strings.ReplaceAll(tag, "v", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
repo = fmt.Sprintf("%s:%s", image, tag)
|
||||||
|
|
||||||
resource.(*appv1.Deployment).Spec.Template.Spec.Containers[0].Image = repo
|
resource.(*appv1.Deployment).Spec.Template.Spec.Containers[0].Image = repo
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,10 +134,15 @@ func (c client) Do(namespace, kind, resourceName, actionMethod, repo string) (er
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
kindType = c.AppsV1().Deployments(namespace)
|
|
||||||
default:
|
default:
|
||||||
return errors.New("not support")
|
return errors.New("not support")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println("命名空间: ", namespace)
|
||||||
|
fmt.Println("资源类型: ", kind)
|
||||||
|
fmt.Println("资源名称: ", resourceName)
|
||||||
|
fmt.Println("操作类型: ", actionMethod)
|
||||||
|
fmt.Println("镜像地址: ", repo)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user