Skip to content

Commit

Permalink
Merge pull request #3838 from camilamacedo86/fix-dist-g
Browse files Browse the repository at this point in the history
🐛 Fix the CRD kustomization path logic to ensure webhook patches are generated exclusively for resources that are configured with webhooks
  • Loading branch information
k8s-ci-robot committed Apr 2, 2024
2 parents 0218ad7 + 8372976 commit 4e206d8
Show file tree
Hide file tree
Showing 12 changed files with 2,663 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ resources:
patches:
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
# patches here are for enabling the conversion webhook for each CRD
#- path: patches/webhook_in_projectconfigs.yaml
#+kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ resources:
patches:
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
# patches here are for enabling the conversion webhook for each CRD
#- path: patches/webhook_in_memcacheds.yaml
#+kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ func (f *Kustomization) GetCodeFragments() machinery.CodeFragmentsMap {
if f.MultiGroup && f.Resource.Group != "" {
suffix = f.Resource.Group + "_" + f.Resource.Plural
}
// Generate resource code fragments
webhookPatch := make([]string, 0)
webhookPatch = append(webhookPatch, fmt.Sprintf(webhookPatchCodeFragment, suffix))

if !f.Resource.Webhooks.IsEmpty() {
webhookPatch := fmt.Sprintf(webhookPatchCodeFragment, suffix)
fragments[machinery.NewMarkerFor(f.Path, webhookPatchMarker)] = []string{webhookPatch}
}

// Generate resource code fragments
caInjectionPatch := make([]string, 0)
Expand All @@ -100,9 +102,7 @@ func (f *Kustomization) GetCodeFragments() machinery.CodeFragmentsMap {
if len(res) != 0 {
fragments[machinery.NewMarkerFor(f.Path, resourceMarker)] = res
}
if len(webhookPatch) != 0 {
fragments[machinery.NewMarkerFor(f.Path, webhookPatchMarker)] = webhookPatch
}

if len(caInjectionPatch) != 0 {
fragments[machinery.NewMarkerFor(f.Path, caInjectionPatchMarker)] = caInjectionPatch
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/plugins/common/kustomize/v2/scaffolds/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

log "github.com/sirupsen/logrus"
pluginutil "sigs.k8s.io/kubebuilder/v3/pkg/plugin/util"
"sigs.k8s.io/kubebuilder/v3/pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/crd"
"sigs.k8s.io/kubebuilder/v3/pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/crd/patches"

"sigs.k8s.io/kubebuilder/v3/pkg/config"
Expand Down Expand Up @@ -82,6 +83,7 @@ func (s *webhookScaffolder) Scaffold() error {
&certmanager.KustomizeConfig{},
&patches.EnableWebhookPatch{},
&patches.EnableCAInjectionPatch{},
&crd.Kustomization{},
); err != nil {
return fmt.Errorf("error scaffolding kustomize webhook manifests: %v", err)
}
Expand Down
7 changes: 1 addition & 6 deletions test/testdata/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,7 @@ function scaffold_test_project {
fi

make generate manifests
# TODO fix the error with multigroup layout and allow it be generated
# with this one.
# Error: trouble configuring builtin PatchTransformer with config: `
# path: patches/webhook_in_sea-creatures_krakens.yaml
# `: failed to get the patch file from path(patches/webhook_in_sea-creatures_krakens.yaml): evalsymlink failure on '/Users/camiladeomacedo/go/src/sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/config/crd/patches/webhook_in_sea-creatures_krakens.yaml' : lstat go/src/sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/config/crd/patches/webhook_in_sea-creatures_krakens.yaml: no such file or directory
if [[ $project =~ v4 && ! $project =~ multigroup ]]; then
if [[ $project =~ v4 ]]; then
make build-installer
fi

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ patches:
- path: patches/webhook_in_ship_frigates.yaml
- path: patches/webhook_in_ship_destroyers.yaml
- path: patches/webhook_in_ship_cruisers.yaml
- path: patches/webhook_in_sea-creatures_krakens.yaml
#- path: patches/webhook_in_sea-creatures_leviathans.yaml
#- path: patches/webhook_in_foo.policy_healthcheckpolicies.yaml
#- path: patches/webhook_in_foo_bars.yaml
#- path: patches/webhook_in_fiz_bars.yaml
#- path: patches/webhook_in_lakers.yaml
- path: patches/webhook_in_lakers.yaml
#+kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
resources:
- manager.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: controller
newName: controller
newTag: latest
Loading

0 comments on commit 4e206d8

Please sign in to comment.