mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
fix issues from code review
This commit is contained in:
@@ -29,7 +29,7 @@ import (
|
||||
)
|
||||
|
||||
type setImageTagOptions struct {
|
||||
imageTagMap map[string]image.Tag
|
||||
imageTagMap map[string]image.ImageTag
|
||||
}
|
||||
|
||||
var pattern = regexp.MustCompile("^(.*):([a-zA-Z0-9._-]*)$")
|
||||
@@ -74,11 +74,11 @@ func (o *setImageTagOptions) Validate(args []string) error {
|
||||
return errors.New("no image specified")
|
||||
}
|
||||
|
||||
o.imageTagMap = make(map[string]image.Tag)
|
||||
o.imageTagMap = make(map[string]image.ImageTag)
|
||||
|
||||
for _, arg := range args {
|
||||
if s := strings.Split(arg, "@"); len(s) > 1 {
|
||||
o.imageTagMap[s[0]] = image.Tag{
|
||||
o.imageTagMap[s[0]] = image.ImageTag{
|
||||
Name: s[0],
|
||||
Digest: s[1],
|
||||
}
|
||||
@@ -89,7 +89,7 @@ func (o *setImageTagOptions) Validate(args []string) error {
|
||||
if len(s) != 3 {
|
||||
return errors.New("invalid format of imagetag, must specify it as <image>:<newtag> or <image>@<digest>")
|
||||
}
|
||||
o.imageTagMap[s[1]] = image.Tag{
|
||||
o.imageTagMap[s[1]] = image.ImageTag{
|
||||
Name: s[1],
|
||||
NewTag: s[2],
|
||||
}
|
||||
@@ -116,7 +116,7 @@ func (o *setImageTagOptions) RunSetImageTags(fSys fs.FileSystem) error {
|
||||
o.imageTagMap[it.Name] = it
|
||||
}
|
||||
|
||||
var imageTags []image.Tag
|
||||
var imageTags []image.ImageTag
|
||||
for _, v := range o.imageTagMap {
|
||||
imageTags = append(imageTags, v)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
Copyright 2019 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -17,14 +17,14 @@ limitations under the License.
|
||||
package image
|
||||
|
||||
// Append appends a slice of type Tag to slice of type Image
|
||||
func Append(images []Image, tags ...Tag) []Image {
|
||||
func Append(images []Image, tags ...ImageTag) []Image {
|
||||
for _, tag := range tags {
|
||||
images = append(images, toImage(tag))
|
||||
}
|
||||
return images
|
||||
}
|
||||
|
||||
func toImage(tag Tag) Image {
|
||||
func toImage(tag ImageTag) Image {
|
||||
return Image{
|
||||
Name: tag.Name,
|
||||
NewTag: tag.NewTag,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
Copyright 2019 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Package image provides struct definitions and libraries
|
||||
// for image overwriting of names, tags and digest.
|
||||
package image
|
||||
|
||||
// Image contains an image name, a new name, a new tag or digest,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
Copyright 2019 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -16,9 +16,9 @@ limitations under the License.
|
||||
|
||||
package image
|
||||
|
||||
// Tag contains an image and a new tag, which will replace the original tag.
|
||||
// Tag usage is deprecated, instead use ImageTag.
|
||||
type Tag struct {
|
||||
// ImageTag contains an image and a new tag, which will replace the original tag.
|
||||
// Deprecated, instead use Image.
|
||||
type ImageTag struct {
|
||||
// Name is a tag-less image name.
|
||||
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
||||
|
||||
|
||||
@@ -302,7 +302,7 @@ func (kt *KustTarget) newTransformer(
|
||||
return nil, err
|
||||
}
|
||||
r = append(r, t)
|
||||
t, err = transformers.NewImageTransformer(kt.kustomization.Image)
|
||||
t, err = transformers.NewImageTransformer(kt.kustomization.Images)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
Copyright 2019 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -36,7 +36,7 @@ func NewImageTransformer(slice []image.Image) (Transformer, error) {
|
||||
return &imageTransformer{slice}, nil
|
||||
}
|
||||
|
||||
// Transform finds the matching images and replaces name and/or tag
|
||||
// Transform finds the matching images and replaces name, tag and/or digest
|
||||
func (pt *imageTransformer) Transform(resources resmap.ResMap) error {
|
||||
if len(pt.images) == 0 {
|
||||
return nil
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
Copyright 2019 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -82,10 +82,6 @@ func TestImageTransformer(t *testing.T) {
|
||||
"name": "nginx1",
|
||||
"image": "nginx",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"name": "myimage",
|
||||
"image": "myprivaterepohostname:1234/my/image:latest",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -118,6 +114,18 @@ func TestImageTransformer(t *testing.T) {
|
||||
"name": "init-docker",
|
||||
"image": "docker:17-git",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"name": "myimage",
|
||||
"image": "myprivaterepohostname:1234/my/image:latest",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"name": "my-app",
|
||||
"image": "my-app-image:v1",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"name": "my-cool-app",
|
||||
"image": "gcr.io:8080/my-project/my-cool-app:latest",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -174,10 +182,6 @@ func TestImageTransformer(t *testing.T) {
|
||||
"name": "nginx1",
|
||||
"image": "nginx:v2",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"name": "myimage",
|
||||
"image": "myprivaterepohostname:1234/my/image:v1.0.1",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -210,6 +214,18 @@ func TestImageTransformer(t *testing.T) {
|
||||
"name": "init-docker",
|
||||
"image": "my-docker@sha256:25a0d4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d3",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"name": "myimage",
|
||||
"image": "myprivaterepohostname:1234/my/image:v1.0.1",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"name": "my-app",
|
||||
"image": "gcr.io/my-project/my-app-image:v1",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"name": "my-cool-app",
|
||||
"image": "my-cool-app:latest",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -223,6 +239,8 @@ func TestImageTransformer(t *testing.T) {
|
||||
{Name: "myprivaterepohostname:1234/my/image", NewTag: "v1.0.1"},
|
||||
{Name: "foobar", Digest: "sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d3"},
|
||||
{Name: "alpine", NewName: "myprivaterepohostname:1234/my/cool-alpine"},
|
||||
{Name: "my-app-image", NewName: "gcr.io/my-project/my-app-image"},
|
||||
{Name: "gcr.io:8080/my-project/my-cool-app", NewName: "my-cool-app"},
|
||||
{Name: "postgres", NewName: "my-postgres", NewTag: "v3"},
|
||||
{Name: "docker", NewName: "my-docker", Digest: "sha256:25a0d4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d3"},
|
||||
})
|
||||
|
||||
@@ -72,10 +72,10 @@ type Kustomization struct {
|
||||
// and http://jsonpatch.com
|
||||
PatchesJson6902 []patch.Json6902 `json:"patchesJson6902,omitempty" yaml:"patchesJson6902,omitempty"`
|
||||
|
||||
// Image is a list of (image name, new name, new tag or digest)
|
||||
// Images is a list of (image name, new name, new tag or digest)
|
||||
// for changing image names, tags or digests. This can also be achieved with a
|
||||
// patch, but this operator is simpler to specify.
|
||||
Image []image.Image `json:"images,omitempty" yaml:"images,omitempty"`
|
||||
Images []image.Image `json:"images,omitempty" yaml:"images,omitempty"`
|
||||
|
||||
// Vars allow things modified by kustomize to be injected into a
|
||||
// container specification. A var is a name (e.g. FOO) associated
|
||||
@@ -137,7 +137,7 @@ type Kustomization struct {
|
||||
Patches []string `json:"patches,omitempty" yaml:"patches,omitempty"`
|
||||
|
||||
// Deprecated. Use `Image`
|
||||
ImageTags []image.Tag `json:"imageTags,omitempty" yaml:"imageTags,omitempty"`
|
||||
ImageTags []image.ImageTag `json:"imageTags,omitempty" yaml:"imageTags,omitempty"`
|
||||
}
|
||||
|
||||
// DealWithDeprecatedFields should be called immediately after
|
||||
@@ -157,8 +157,8 @@ func (k *Kustomization) DealWithDeprecatedFields() {
|
||||
if len(k.ImageTags) > 0 {
|
||||
// Transform `image.Tag` to `image.Image`
|
||||
// for backwards compatibility
|
||||
k.Image = image.Append(
|
||||
k.Image, k.ImageTags...)
|
||||
k.Images = image.Append(
|
||||
k.Images, k.ImageTags...)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user