Given I have these in test/base:
# test/base/crd.yaml
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: nginx
# test/base/service.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx
md5-ef4e0878d33501b4f1b88a19709fb8d7
# test/base/kustomization.yaml
namePrefix: base--
resources:
- crd.yaml
- service.yaml
md5-79d2498025a5a108c201de6a76ab9d04
# test/overlay/crd.yaml
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: nginx
md5-ef4e0878d33501b4f1b88a19709fb8d7
# test/overlay/service.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx
md5-ef4e0878d33501b4f1b88a19709fb8d7
# test/overlay/kustomization.yalm
namePrefix: overlay--
bases:
- ../base
patches:
- crd.yaml
- service.yaml
md5-6dc5b86045becfddd8113fba3b0ab422
apiVersion: v1
kind: Service
metadata:
name: overlay--base--nginx
---
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: overlay--nginx
It seems like this is what's causing it to reset the name after the base has already run:
// k8sdeps/transformer/patch/patch.go:76-93
case runtime.IsNotRegisteredError(err):
// Use JSON merge patch to handle types w/o schema
baseBytes, err := json.Marshal(base.Map())
if err != nil {
return err
}
patchBytes, err := json.Marshal(patch.Map())
if err != nil {
return err
}
mergedBytes, err := jsonpatch.MergePatch(baseBytes, patchBytes)
if err != nil {
return err
}
err = json.Unmarshal(mergedBytes, &merged)
if err != nil {
return err
}
where known objects get a strategic merge:
// k8sdeps/transformer/patch/patch.go:96-111
default:
// Use Strategic-Merge-Patch to handle types w/ schema
// TODO: Change this to use the new Merge package.
// Store the name of the base object, because this name may have been munged.
// Apply this name to the patched object.
lookupPatchMeta, err := strategicpatch.NewPatchMetaFromStruct(versionedObj)
if err != nil {
return err
}
merged, err = strategicpatch.StrategicMergeMapPatchUsingLookupPatchMeta(
base.Map(),
patch.Map(),
lookupPatchMeta)
if err != nil {
return err
}
What's the reason to make a distinction between custom resources and known resources? I'm guessing metadata should be fairly straight forward to handle in a same way for custom resources?
Same issue as #669
Especially annoying if you are working with e.g. OpenShift because this fails for
apiVersion: v1
kind: DeploymentConfig
Why was this closed? Was it fixed? It doesn't appear to be.
I've got
# overlays/staging/kustomization.yaml
commonLabels:
env: staging
nameSuffix: -staging
resources:
- ../../base
# base/kustomization.yaml
commonLabels:
svc: app
resources:
- ../shared
- app-deployment.yaml
- app-service.yaml
- artisan-cron.yaml
- database-backup.yaml
- artisan-worker.yaml
# shared/kustomization
commonLabels:
app: kmbookings
owner: mpen
namespace: kymark
namePrefix: kmb-
And when I build:
โฏ kustomize build kubernetes/overlays/staging | grep app-deployment
name: app-deployment-staging
The namePrefix from shared/kustomization.yaml is missing. My namespace is missing too.
โฏ kustomize version
{Version:kustomize/v3.6.1 GitCommit:c97fa946d576eb6ed559f17f2ac43b3b5a8d5dbd BuildDate:2020-05-27T20:47:35Z GoOs:linux GoArch:amd64}
@Liujingfang1
Did your PR fix the issue for CRDs in general or just for namePrefixes? In my case it's a DeploymentConfig CRD from OpenShift and applying patchesStrategicMerge would replace the whole block instead of only the affected attribute(s).
I have the latest version of kustomize (3.18) and am experiencing the same issue that @takahser is.
Attempting to use patchesStrategicMerge on an openshift CRD does not merge, it replaces.
If you include multiple patch files, only the last patch appears in the resulting yaml and the original yaml is gone.
Most helpful comment
@Liujingfang1
Did your PR fix the issue for CRDs in general or just for
namePrefixes? In my case it's aDeploymentConfigCRD from OpenShift and applyingpatchesStrategicMergewould replace the whole block instead of only the affected attribute(s).