Skip updating empty containers in image tranformer

This commit is contained in:
Haiyan Meng
2019-11-21 11:53:21 -08:00
parent 964a5082b1
commit 752ca4b37c
5 changed files with 17 additions and 15 deletions

View File

@@ -82,7 +82,7 @@ func (p *ImageTagTransformerPlugin) findAndReplaceImage(obj map[string]interface
updated := false
for _, path := range paths {
containers, found := obj[path]
if found {
if found && containers != nil {
if _, err := p.updateContainers(containers); err != nil {
return err
}

View File

@@ -6,7 +6,7 @@ package builtins
import (
"fmt"
jsonpatch "github.com/evanphx/json-patch"
"github.com/evanphx/json-patch"
"github.com/pkg/errors"
"sigs.k8s.io/kustomize/api/ifc"
"sigs.k8s.io/kustomize/api/resid"

View File

@@ -6,7 +6,7 @@ package builtins
import (
"fmt"
jsonpatch "github.com/evanphx/json-patch"
"github.com/evanphx/json-patch"
"github.com/pkg/errors"
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/api/resource"

View File

@@ -86,7 +86,7 @@ func (p *plugin) findAndReplaceImage(obj map[string]interface{}) error {
updated := false
for _, path := range paths {
containers, found := obj[path]
if found {
if found && containers != nil {
if _, err := p.updateContainers(containers); err != nil {
return err
}

View File

@@ -4,7 +4,6 @@
package main_test
import (
"strings"
"testing"
"sigs.k8s.io/kustomize/api/testutils/kusttest"
@@ -379,7 +378,7 @@ func TestImageTagTransformerEmptyContainers(t *testing.T) {
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
err := th.ErrorFromLoadAndRunTransformer(`
rm := th.LoadAndRunTransformer(`
apiVersion: builtin
kind: ImageTagTransformer
metadata:
@@ -399,13 +398,16 @@ spec:
containers:
initContainers:
`)
expectedErrMsg := "containers path is not of type []interface{} but <nil>"
if err == nil {
t.Fatalf("expected error: %s; got nothing", expectedErrMsg)
}
if !strings.Contains(err.Error(), expectedErrMsg) {
t.Fatalf("expected error: %s; got error: %s", expectedErrMsg, err.Error())
}
th.AssertActualEqualsExpected(rm, `
apiVersion: v1
group: apps
kind: Deployment
metadata:
name: deploy1
spec:
template:
spec:
containers: null
initContainers: null
`)
}