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