-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Name in a configMapRef is not updated to include the hash as a suffix (nor a prefix) #5047
Comments
/assign |
A note for self and also anyone else who tries to reproduce. The patch included does not affect the outcome and can thus be removed and "-example-configmap" directly added to the deployment manifest. It is important to use the most minimalistic manifest as this simplifies the code path to debug as well 😉 Please let me know if I'm wrong @jonathanlking and the patch does actually matter for the issue! |
This comment was marked as outdated.
This comment was marked as outdated.
@Serializator Ah, yes I did misunderstand! 🤦♂️ You're saying that the patch could be replace and instead the deployment could be changed to:
I agree, you're right, the patch included does not affect the outcome. |
Though this is not yet conclusive, I was able to pinpoint the PR in which the regression was introduced. Gotta ❤️ Git with its bisect command! I will go through the changes in this PR and try to identify which specific change is causing this behaviour. @jonathanlking, thanks for the specific versions in the description, this helped a lot! |
/triage accepted I can reproduce the regression between v3.9.2 and v3.9.3, though enabling/disabling the |
@natasha41575 Apologies (for the second time today!), you're right about the I'm not sure why I originally thought it did 🤔 |
Appendix 1. below is taken from In the original code (before the change from #3529) Right now this results in What my suggestion would be to bring this OR logic into @natasha41575, what do you think of this suggestion? Appendix 1.
Appendix 2. func SameEndingSubarray(shortest, longest []string) bool {
if len(shortest) > len(longest) {
longest, shortest = shortest, longest
}
diff := len(longest) - len(shortest)
if len(shortest) == 0 {
return diff == 0
}
for i := len(shortest) - 1; i >= 0; i-- {
if longest[i+diff] != shortest[i] {
return false
}
}
return true
} |
I'm facing the same issue even in kustomize v5.0.1 |
@Serializator thanks again for your investigation! I've had a go at trying what I believe you suggested: diff --git i/api/resource/resource.go w/api/resource/resource.go
index 53a62dffd..3585593d3 100644
--- i/api/resource/resource.go
+++ w/api/resource/resource.go
@@ -321,7 +321,7 @@ func (r *Resource) getCsvAnnotation(name string) []string {
// as OutermostPrefixSuffix but performs a deeper comparison
// of the suffix and prefix slices.
func (r *Resource) PrefixesSuffixesEquals(o ResCtx) bool {
- return SameEndingSubarray(r.GetNamePrefixes(), o.GetNamePrefixes()) && SameEndingSubarray(r.GetNameSuffixes(), o.GetNameSuffixes())
+ return SameEndingSubarray(r.GetNamePrefixes(), o.GetNamePrefixes()) || SameEndingSubarray(r.GetNameSuffixes(), o.GetNameSuffixes())
}
// RemoveBuildAnnotations removes annotations created by the build process. This does seem to fix the issue reported! 🎉 # kustomization.yaml
resources:
- a
- b # a/kustomization.yaml
resources:
- ../common
namePrefix: a # b/kustomization.yaml
resources:
- ../common
namePrefix: b # common/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: "-example"
spec:
template:
spec:
containers:
- name: app
envFrom:
- configMapRef:
name: "-example-configmap" # common/kustomization.yaml
resources:
- deployment.yaml
configMapGenerator:
- name: "-example-configmap" Prior to this change we get (tested on v3.9.3-4.5.7): apiVersion: v1
kind: ConfigMap
metadata:
name: a-example-configmap-6ct58987ht
---
apiVersion: v1
kind: ConfigMap
metadata:
name: b-example-configmap-6ct58987ht
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: a-example
spec:
template:
spec:
containers:
- envFrom:
- configMapRef:
name: a-example-configmap-6ct58987ht
name: app
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: b-example
spec:
template:
spec:
containers:
- envFrom:
- configMapRef:
name: b-example-configmap-6ct58987ht
name: app However after the change we now get: **** Too many possible referral targets to referrer:
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
config.kubernetes.io/prefixes: a
config.kubernetes.io/previousNames: -example
config.kubernetes.io/previousNamespaces: default
name: a-example
spec:
template:
spec:
containers:
- envFrom:
- configMapRef:
name: -example-configmap
name: app
--- possible referral 0:
apiVersion: v1
kind: ConfigMap
metadata:
annotations:
config.kubernetes.io/prefixes: a
config.kubernetes.io/previousNames: -example-configmap,a-example-configmap
config.kubernetes.io/previousNamespaces: default,default
name: a-example-configmap-6ct58987ht
------
--- possible referral 1:
apiVersion: v1
kind: ConfigMap
metadata:
annotations:
config.kubernetes.io/prefixes: b
config.kubernetes.io/previousNames: -example-configmap,b-example-configmap
config.kubernetes.io/previousNamespaces: default,default
name: b-example-configmap-6ct58987ht
------
Error: updating name reference in 'spec/template/spec/containers/envFrom/configMapRef/name' field of 'apps_v1_Deployment|~X|a-example': considering field 'spec/template/spec/containers/envFrom/configMapRef/name' of object
apiVersion: apps/v1
kind: Deployment
metadata:
name: "a-example"
annotations:
config.kubernetes.io/prefixes: a
config.kubernetes.io/previousNames: -example
config.kubernetes.io/previousNamespaces: default
spec:
template:
spec:
containers:
- name: app
envFrom:
- configMapRef:
name: "-example-configmap"
: visit traversal on path: [envFrom configMapRef name]: visit traversal on path: [configMapRef name]: found multiple possible referrals: ~G_v1_ConfigMap|~X|a-example-configmap-6ct58987ht, ~G_v1_ConfigMap|~X|b-example-configmap-6ct58987ht I've added this new example and also the patched version of Any ideas/suggestions would be greatly appreciated! (and please say if I've misunderstood something/made a silly error again 😅) |
I re-read your comment and I think this patch might work (it still fixes the original issue, but doesn't introduce the new one): diff --git i/api/resource/resource.go w/api/resource/resource.go
index 53a62dffd..3d471e6d9 100644
--- i/api/resource/resource.go
+++ w/api/resource/resource.go
@@ -320,8 +320,8 @@ func (r *Resource) getCsvAnnotation(name string) []string {
// PrefixesSuffixesEquals is conceptually doing the same task
// as OutermostPrefixSuffix but performs a deeper comparison
// of the suffix and prefix slices.
-func (r *Resource) PrefixesSuffixesEquals(o ResCtx) bool {
- return SameEndingSubarray(r.GetNamePrefixes(), o.GetNamePrefixes()) && SameEndingSubarray(r.GetNameSuffixes(), o.GetNameSuffixes())
+func(r * Resource) PrefixesSuffixesEquals(o ResCtx) bool {
+ return (len(r.GetNamePrefixes()) == 0 || len(o.GetNamePrefixes()) == 0 || SameEndingSubarray(r.GetNamePrefixes(), o.GetNamePrefixes())) && (len(r.GetNameSuffixes()) == 0 || len(o.GetNameSuffixes()) == 0 || SameEndingSubarray(r.GetNameSuffixes(), o.GetNameSuffixes()))
}
// RemoveBuildAnnotations removes annotations created by the build process. If either of the prefixes/suffixes are empty then it treats that prefix/suffix as equal, which is what the previous behaviour was (I think?). |
While trying to implement a fix, I think I’m getting a better understanding of the problem. kustomize/api/filters/nameref/nameref.go Line 328 in da4e881
[
{
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": {
"annotations": {
"internal.config.kubernetes.io/generatorBehavior": "unspecified",
"internal.config.kubernetes.io/needsHashSuffix": "enabled",
"internal.config.kubernetes.io/prefixes": "a",
"internal.config.kubernetes.io/previousKinds": "ConfigMap,ConfigMap",
"internal.config.kubernetes.io/previousNames": "-example-configmap,a-example-configmap",
"internal.config.kubernetes.io/previousNamespaces": "default,default"
},
"name": "a-example-configmap-6ct58987ht"
}
},
{
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": {
"annotations": {
"internal.config.kubernetes.io/generatorBehavior": "unspecified",
"internal.config.kubernetes.io/needsHashSuffix": "enabled",
"internal.config.kubernetes.io/prefixes": "b",
"internal.config.kubernetes.io/previousKinds": "ConfigMap,ConfigMap",
"internal.config.kubernetes.io/previousNames": "-example-configmap,b-example-configmap",
"internal.config.kubernetes.io/previousNamespaces": "default,default"
},
"name": "b-example-configmap-6ct58987ht"
}
}
] and the resource is: {
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"annotations": {
"internal.config.kubernetes.io/prefixes": "b",
"internal.config.kubernetes.io/previousKinds": "Deployment,Deployment",
"internal.config.kubernetes.io/previousNames": "-,-api",
"internal.config.kubernetes.io/previousNamespaces": "default,default",
"internal.config.kubernetes.io/suffixes": "api"
},
"name": "b-api"
},
"spec": {
"template": {
"spec": {
"containers": [
{
"envFrom": [
{
"configMapRef": {
"name": "-example-configmap"
}
}
],
"name": "app"
}
]
}
}
}
} The second candidate is what I would like to get picked, however while it has the prefix
as this is exactly that scenario. |
If we change the logic to “OR” as @Serializator suggested, we run into the same issue that #3529 was trying to fix, which is that we're left with more than one candidate in some scenarios (which is caught by some existing unit tests, e.g. If we break the I think there are a few different heuristics you could use, e.g. initially
This approach does feel a bit hacky to me, however if we’re only searching for the best, rather than an exact match (which I get the impression we are) I'm more comfortable. My branch in #5236 does seem to pass the I'd really appreciate feedback on whether this approach makes sense/if you think I've misunderstood the problem/have any other suggestions! 🙏 |
Any fix on v5.1.1, still facing the issue |
@BishuSinha I'm waiting for feedback on whether my suggested approach makes sense/would be accepted. We've been using a patched version of Kustomize at work (based on #5236) and not had any issues, which is promising. |
Thanks mate , will use the patch for now , cheers |
What happened?
While upgrading from an older version kustomize I discovered a breaking change in output between v3.9.2 and v3.9.3, where a
configMapRef
is no longer valid.While this behaviour appeared in v3.9.3, it can be reverted by applying the(I was wrong about this!)--enable_kyaml=false
flag and from looking at the release notes for v3.9.3 I believe the difference is actually due to the switch to thekyaml
library.I think it’s different to other GitHub issues I’ve found (e.g. #1301 or #2609) as I can still replicate this on v5.0.0.
What did you expect to happen?
A hash and suffix to still be included in the
configMapRef
, i.e.a-example-configmap-6ct58987ht
rather than-example-configmap
.Interestingly building
a
orb
independently (or removing either- a
or- b
from thekustomization.yaml
) still gives the expected behaviour. It's only when there are multiple resources that this unexpected behaviour occurs.Perhaps I was previously relying on undefined/buggy behaviour?
How can we reproduce it (as minimally and precisely as possible)?
I also have a copy of these files here https://github.com/jonathanlking/kustomize-example.
Expected output
Actual output
Kustomize version
v3.9.3 onwards (including v5.0.0)
Operating system
Linux
The text was updated successfully, but these errors were encountered: