-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replacements should throw errors on invalid targets #4789
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ package krusty_test | |
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" | ||
) | ||
|
||
|
@@ -546,3 +547,103 @@ metadata: | |
name: red-dc6gc5btkc | ||
`) | ||
} | ||
|
||
func TestIssue4761_path_not_in_target_with_create_true(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we have these two tests as tests for the replacements filter in The tests here in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, will move them! |
||
th := kusttest_test.MakeEnhancedHarness(t) | ||
defer th.Reset() | ||
|
||
th.WriteF("resources.yaml", ` | ||
--- | ||
apiVersion: networking.istio.io/v1alpha3 | ||
kind: EnvoyFilter | ||
metadata: | ||
name: request-id | ||
spec: | ||
configPatches: | ||
- applyTo: NETWORK_FILTER | ||
- applyTo: NETWORK_FILTER | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: istio-version | ||
annotations: | ||
config.kubernetes.io/local-config: true | ||
data: | ||
ISTIO_REGEX: '^1\.14.*' | ||
`) | ||
|
||
th.WriteK(".", ` | ||
resources: | ||
- resources.yaml | ||
|
||
replacements: | ||
- source: | ||
kind: ConfigMap | ||
name: istio-version | ||
fieldPath: data.ISTIO_REGEX | ||
targets: | ||
- select: | ||
kind: EnvoyFilter | ||
fieldPaths: | ||
- spec.configPatches.0.match.proxy.proxyVersion | ||
- spec.configPatches.1.match.proxy.proxyVersion | ||
- spec.configPatches.2.match.proxy.proxyVersion | ||
- spec.configPatches.3.match.proxy.proxyVersion | ||
options: | ||
create: true | ||
`) | ||
|
||
err := th.RunWithErr(".", th.MakeDefaultOptions()) | ||
require.EqualError(t, err, "unable to find or create field spec.configPatches.2.match.proxy.proxyVersion in replacement target") | ||
} | ||
|
||
func TestIssue4761_path_not_in_target_with_create_false(t *testing.T) { | ||
th := kusttest_test.MakeEnhancedHarness(t) | ||
defer th.Reset() | ||
|
||
th.WriteF("resources.yaml", ` | ||
--- | ||
apiVersion: networking.istio.io/v1alpha3 | ||
kind: EnvoyFilter | ||
metadata: | ||
name: request-id | ||
spec: | ||
configPatches: | ||
- applyTo: NETWORK_FILTER | ||
- applyTo: NETWORK_FILTER | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: istio-version | ||
annotations: | ||
config.kubernetes.io/local-config: true | ||
data: | ||
ISTIO_REGEX: '^1\.14.*' | ||
`) | ||
|
||
th.WriteK(".", ` | ||
resources: | ||
- resources.yaml | ||
|
||
replacements: | ||
- source: | ||
kind: ConfigMap | ||
name: istio-version | ||
fieldPath: data.ISTIO_REGEX | ||
targets: | ||
- select: | ||
kind: EnvoyFilter | ||
fieldPaths: | ||
- spec.configPatches.0.match.proxy.proxyVersion | ||
- spec.configPatches.1.match.proxy.proxyVersion | ||
- spec.configPatches.2.match.proxy.proxyVersion | ||
- spec.configPatches.3.match.proxy.proxyVersion | ||
options: | ||
create: false | ||
`) | ||
|
||
err := th.RunWithErr(".", th.MakeDefaultOptions()) | ||
require.EqualError(t, err, "unable to find field spec.configPatches.0.match.proxy.proxyVersion in replacement target") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was testing that when given a fieldspec that we cannot satisfy, we do nothing. This PR proposes that we should be throwing an error in this exact case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't recall if this was intentional or an oversight when this was introduced. But I agree with you that it is odd behavior to silently do nothing, and that it is more intuitive to throw an error instead.