mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Skip updating empty containers in image tranformer
This commit is contained in:
@@ -82,7 +82,7 @@ func (p *ImageTagTransformerPlugin) findAndReplaceImage(obj map[string]interface
|
|||||||
updated := false
|
updated := false
|
||||||
for _, path := range paths {
|
for _, path := range paths {
|
||||||
containers, found := obj[path]
|
containers, found := obj[path]
|
||||||
if found {
|
if found && containers != nil {
|
||||||
if _, err := p.updateContainers(containers); err != nil {
|
if _, err := p.updateContainers(containers); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ package builtins
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
jsonpatch "github.com/evanphx/json-patch"
|
"github.com/evanphx/json-patch"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"sigs.k8s.io/kustomize/api/ifc"
|
"sigs.k8s.io/kustomize/api/ifc"
|
||||||
"sigs.k8s.io/kustomize/api/resid"
|
"sigs.k8s.io/kustomize/api/resid"
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ package builtins
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
jsonpatch "github.com/evanphx/json-patch"
|
"github.com/evanphx/json-patch"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
"sigs.k8s.io/kustomize/api/resource"
|
"sigs.k8s.io/kustomize/api/resource"
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ func (p *plugin) findAndReplaceImage(obj map[string]interface{}) error {
|
|||||||
updated := false
|
updated := false
|
||||||
for _, path := range paths {
|
for _, path := range paths {
|
||||||
containers, found := obj[path]
|
containers, found := obj[path]
|
||||||
if found {
|
if found && containers != nil {
|
||||||
if _, err := p.updateContainers(containers); err != nil {
|
if _, err := p.updateContainers(containers); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
package main_test
|
package main_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/testutils/kusttest"
|
"sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
@@ -379,7 +378,7 @@ func TestImageTagTransformerEmptyContainers(t *testing.T) {
|
|||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
||||||
|
|
||||||
err := th.ErrorFromLoadAndRunTransformer(`
|
rm := th.LoadAndRunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
kind: ImageTagTransformer
|
kind: ImageTagTransformer
|
||||||
metadata:
|
metadata:
|
||||||
@@ -399,13 +398,16 @@ spec:
|
|||||||
containers:
|
containers:
|
||||||
initContainers:
|
initContainers:
|
||||||
`)
|
`)
|
||||||
|
th.AssertActualEqualsExpected(rm, `
|
||||||
expectedErrMsg := "containers path is not of type []interface{} but <nil>"
|
apiVersion: v1
|
||||||
if err == nil {
|
group: apps
|
||||||
t.Fatalf("expected error: %s; got nothing", expectedErrMsg)
|
kind: Deployment
|
||||||
}
|
metadata:
|
||||||
|
name: deploy1
|
||||||
if !strings.Contains(err.Error(), expectedErrMsg) {
|
spec:
|
||||||
t.Fatalf("expected error: %s; got error: %s", expectedErrMsg, err.Error())
|
template:
|
||||||
}
|
spec:
|
||||||
|
containers: null
|
||||||
|
initContainers: null
|
||||||
|
`)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user