Skip to content

Commit

Permalink
🐛 (kustomize/v2, go/v4): Stop scafold CA injection
Browse files Browse the repository at this point in the history
The CA injection annotation is now unnecessary since switching from vars
to replacements in the kustomization. The replacements have "create:
true" which means that they will add the annotation if it is not already
there, hence the patch is not needed.
  • Loading branch information
lentzi90 committed Aug 28, 2023
1 parent 8824c0a commit 244c496
Show file tree
Hide file tree
Showing 35 changed files with 4 additions and 287 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ patches:
#- path: patches/webhook_in_projectconfigs.yaml
#+kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
# patches here are for enabling the CA injection for each CRD
#- path: patches/cainjection_in_projectconfigs.yaml
#+kubebuilder:scaffold:crdkustomizecainjectionpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
configurations:
- kustomizeconfig.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ patches:
- path: patches/webhook_in_cronjobs.yaml
#+kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
# patches here are for enabling the CA injection for each CRD
- path: patches/cainjection_in_cronjobs.yaml
#+kubebuilder:scaffold:crdkustomizecainjectionpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
configurations:
- kustomizeconfig.yaml

This file was deleted.

5 changes: 0 additions & 5 deletions hack/docs/internal/cronjob-tutorial/generate_cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,11 +586,6 @@ func updateKustomization(sp *Sample) {
filepath.Join(sp.ctx.Dir, "config/crd/kustomization.yaml"),
`#- path: patches/webhook_in_cronjobs.yaml`, `#`)
CheckError("fixing crd/kustomization", err)

err = pluginutil.UncommentCode(
filepath.Join(sp.ctx.Dir, "config/crd/kustomization.yaml"),
`#- path: patches/cainjection_in_cronjobs.yaml`, `#`)
CheckError("fixing crd/kustomization", err)
}

func updateExample(sp *Sample) {
Expand Down
1 change: 0 additions & 1 deletion pkg/plugins/common/kustomize/v2/scaffolds/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ func (s *apiScaffolder) Scaffold() error {
&rbac.CRDEditorRole{},
&rbac.CRDViewerRole{},
&patches.EnableWebhookPatch{},
&patches.EnableCAInjectionPatch{},
&crd.Kustomization{},
&crd.KustomizeConfig{},
); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,33 +44,28 @@ func (f *Kustomization) SetTemplateDefaults() error {
f.TemplateBody = fmt.Sprintf(kustomizationTemplate,
machinery.NewMarkerFor(f.Path, resourceMarker),
machinery.NewMarkerFor(f.Path, webhookPatchMarker),
machinery.NewMarkerFor(f.Path, caInjectionPatchMarker),
)

return nil
}

const (
resourceMarker = "crdkustomizeresource"
webhookPatchMarker = "crdkustomizewebhookpatch"
caInjectionPatchMarker = "crdkustomizecainjectionpatch"
resourceMarker = "crdkustomizeresource"
webhookPatchMarker = "crdkustomizewebhookpatch"
)

// GetMarkers implements file.Inserter
func (f *Kustomization) GetMarkers() []machinery.Marker {
return []machinery.Marker{
machinery.NewMarkerFor(f.Path, resourceMarker),
machinery.NewMarkerFor(f.Path, webhookPatchMarker),
machinery.NewMarkerFor(f.Path, caInjectionPatchMarker),
}
}

const (
resourceCodeFragment = `- bases/%s_%s.yaml
`
webhookPatchCodeFragment = `#- path: patches/webhook_in_%s.yaml
`
caInjectionPatchCodeFragment = `#- path: patches/cainjection_in_%s.yaml
`
)

Expand All @@ -86,20 +81,13 @@ func (f *Kustomization) GetCodeFragments() machinery.CodeFragmentsMap {
webhookPatch := make([]string, 0)
webhookPatch = append(webhookPatch, fmt.Sprintf(webhookPatchCodeFragment, f.Resource.Plural))

// Generate resource code fragments
caInjectionPatch := make([]string, 0)
caInjectionPatch = append(caInjectionPatch, fmt.Sprintf(caInjectionPatchCodeFragment, f.Resource.Plural))

// Only store code fragments in the map if the slices are non-empty
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
}

return fragments
}
Expand All @@ -115,10 +103,6 @@ patches:
# patches here are for enabling the conversion webhook for each CRD
%s
# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
# patches here are for enabling the CA injection for each CRD
%s
# the following config is for teaching kustomize how to do kustomization for CRDs.
configurations:
- kustomizeconfig.yaml
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ patches:
#- path: patches/webhook_in_admirals.yaml
#+kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
# patches here are for enabling the CA injection for each CRD
#- path: patches/cainjection_in_captains.yaml
#- path: patches/cainjection_in_firstmates.yaml
#- path: patches/cainjection_in_admirals.yaml
#+kubebuilder:scaffold:crdkustomizecainjectionpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
configurations:
- kustomizeconfig.yaml

This file was deleted.

This file was deleted.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.12.0
controller-gen.kubebuilder.io/version: v0.13.0
name: busyboxes.example.com.testproject.org
spec:
group: example.com.testproject.org
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.12.0
controller-gen.kubebuilder.io/version: v0.13.0
name: memcacheds.example.com.testproject.org
spec:
group: example.com.testproject.org
Expand Down
15 changes: 0 additions & 15 deletions testdata/project-v4-multigroup/config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,6 @@ patches:
#- path: patches/webhook_in_busyboxes.yaml
#+kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
# patches here are for enabling the CA injection for each CRD
#- path: patches/cainjection_in_captains.yaml
#- path: patches/cainjection_in_frigates.yaml
#- path: patches/cainjection_in_destroyers.yaml
#- path: patches/cainjection_in_cruisers.yaml
#- path: patches/cainjection_in_krakens.yaml
#- path: patches/cainjection_in_leviathans.yaml
#- path: patches/cainjection_in_healthcheckpolicies.yaml
#- path: patches/cainjection_in_bars.yaml
#- path: patches/cainjection_in_lakers.yaml
#- path: patches/cainjection_in_memcacheds.yaml
#- path: patches/cainjection_in_busyboxes.yaml
#+kubebuilder:scaffold:crdkustomizecainjectionpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
configurations:
- kustomizeconfig.yaml

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ patches:
#- path: patches/webhook_in_busyboxes.yaml
#+kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
# patches here are for enabling the CA injection for each CRD
#- path: patches/cainjection_in_memcacheds.yaml
#- path: patches/cainjection_in_busyboxes.yaml
#+kubebuilder:scaffold:crdkustomizecainjectionpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
configurations:
- kustomizeconfig.yaml

This file was deleted.

This file was deleted.

Loading

0 comments on commit 244c496

Please sign in to comment.