mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-10 08:20:59 +00:00
use regexp to determin if the image matched in imagetag transformer
This commit is contained in:
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package transformers
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/kubernetes-sigs/kustomize/pkg/resmap"
|
||||
@@ -115,6 +116,7 @@ func (pt *imageTagTransformer) findContainers(obj map[string]interface{}) error
|
||||
}
|
||||
|
||||
func isImageMatched(s, t string) bool {
|
||||
imagetag := strings.Split(s, ":")
|
||||
return len(imagetag) >= 1 && imagetag[0] == t
|
||||
// Tag values are limited to [a-zA-Z0-9_.-].
|
||||
pattern, _ := regexp.Compile("^" + t + "(:[a-zA-Z0-9_.-]*)?$")
|
||||
return pattern.MatchString(s)
|
||||
}
|
||||
|
||||
@@ -66,8 +66,8 @@ func TestImageTagTransformer(t *testing.T) {
|
||||
"image": "nginx",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"name": "nginx2",
|
||||
"image": "my-nginx:random",
|
||||
"name": "myimage",
|
||||
"image": "myprivaterepohostname:1234/my/image:latest",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -78,7 +78,7 @@ func TestImageTagTransformer(t *testing.T) {
|
||||
"spec": map[string]interface{}{
|
||||
"containers": []interface{}{
|
||||
map[string]interface{}{
|
||||
"name": "ngin3",
|
||||
"name": "nginx3",
|
||||
"image": "nginx:v1",
|
||||
},
|
||||
map[string]interface{}{
|
||||
@@ -130,8 +130,8 @@ func TestImageTagTransformer(t *testing.T) {
|
||||
"image": "nginx:v2",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"name": "nginx2",
|
||||
"image": "my-nginx:previous",
|
||||
"name": "myimage",
|
||||
"image": "myprivaterepohostname:1234/my/image:v1.0.1",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -142,7 +142,7 @@ func TestImageTagTransformer(t *testing.T) {
|
||||
"spec": map[string]interface{}{
|
||||
"containers": []interface{}{
|
||||
map[string]interface{}{
|
||||
"name": "ngin3",
|
||||
"name": "nginx3",
|
||||
"image": "nginx:v2",
|
||||
},
|
||||
map[string]interface{}{
|
||||
@@ -159,6 +159,7 @@ func TestImageTagTransformer(t *testing.T) {
|
||||
it, err := NewImageTagTransformer([]types.ImageTag{
|
||||
{Name: "nginx", NewTag: "v2"},
|
||||
{Name: "my-nginx", NewTag: "previous"},
|
||||
{Name: "myprivaterepohostname:1234/my/image", NewTag: "v1.0.1"},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user