Repository: kubernetes-sigs/kubebuilder (language: go)

Issue:
Duplicate Webhook Patch Entries in config/crd/kustomization.yaml When Creating Multiple Versions of the Same Kind
### What broke? What's expected?

When creating multiple versions for the same kind, in the config/crd/kustomization.yaml, there are duplicate entries for the webhook patch path:

```
- path: patches/webhook_in_cronjobs.yaml
- path: patches/webhook_in_cronjobs.yaml
- path: patches/webhook_in_cronjobs.yaml
- path: patches/webhook_in_cronjobs.yaml
```

The config/crd/kustomization.yaml file should contain only one entry for the webhook patch, regardless of the number of versions for the same kind. The path should only be added if it is not already present.

The implementation to add the value with the marker is here:

https://github.com/kubernetes-sigs/kubebuilder/blob/e3ebfafde3b7ac81588ee7c30c93b75494334dec/pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/crd/kustomization.go#L92-L95

### Reproducing this issue

```shell
kubebuilder init
kubebuilder create api --group batch --version v1 --kind CronJob
kubebuilder create webhook --group batch --version v1 --kind CronJob --defaulting --programmatic-validation --conversion
kubebuilder create api --group batch --version v2 --kind CronJob
kubebuilder create webhook --group batch --version v2 --kind CronJob --defaulting --programmatic-validation --conversion
```


### KubeBuilder (CLI) Version

master

### PROJECT version

_No response_

### Plugin versions

```yaml
go/v4
```


### Other versions

_No response_

### Extra Labels

_No response_


Discussion / hints:
/assign
Hi @TAM360, are you still resolving this ?
@ansh-devs yup, working on it.
/assign

Fix patch:
diff --git a/pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/crd/kustomization.go b/pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/crd/kustomization.go
index b77d2137b97..2da3a06a8cb 100644
--- a/pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/crd/kustomization.go
+++ b/pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/crd/kustomization.go
@@ -91,7 +91,11 @@ func (f *Kustomization) GetCodeFragments() machinery.CodeFragmentsMap {
 
 	if !f.Resource.Webhooks.IsEmpty() {
 		webhookPatch := fmt.Sprintf(webhookPatchCodeFragment, suffix)
-		fragments[machinery.NewMarkerFor(f.Path, webhookPatchMarker)] = []string{webhookPatch}
+
+		marker := machinery.NewMarkerFor(f.Path, webhookPatchMarker)
+		if _, exists := fragments[marker]; !exists {
+			fragments[marker] = []string{webhookPatch}
+		}
 	}
 
 	// Generate resource code fragments


Test patch: