Skip to content

Commit b18814e

Browse files
committed
User-facing migration to ClusterBundle
Signed-off-by: Erik Godding Boye <egboye@gmail.com>
1 parent 21824c2 commit b18814e

31 files changed

Lines changed: 1135 additions & 540 deletions

File tree

cmd/trust-manager/app/app.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333

3434
"github.com/cert-manager/trust-manager/cmd/trust-manager/app/options"
3535
trustapi "github.com/cert-manager/trust-manager/pkg/apis/trust/v1alpha1"
36+
trustmanagerapi "github.com/cert-manager/trust-manager/pkg/apis/trustmanager/v1alpha2"
3637
"github.com/cert-manager/trust-manager/pkg/bundle"
3738
"github.com/cert-manager/trust-manager/pkg/webhook"
3839
)
@@ -70,6 +71,7 @@ func NewCommand() *cobra.Command {
7071
scheme := runtime.NewScheme()
7172
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
7273
utilruntime.Must(trustapi.AddToScheme(scheme))
74+
utilruntime.Must(trustmanagerapi.AddToScheme(scheme))
7375

7476
mgr, err := ctrl.NewManager(opts.RestConfig, ctrl.Options{
7577
Scheme: scheme,
@@ -113,7 +115,10 @@ func NewCommand() *cobra.Command {
113115
// Register webhook handlers with manager.
114116
log.Info("registering webhook endpoints")
115117
if err := webhook.SetupWebhookWithManager(mgr); err != nil {
116-
return fmt.Errorf("failed to register webhook: %w", err)
118+
return fmt.Errorf("failed to register Bundle webhook: %w", err)
119+
}
120+
if err := (&webhook.ClusterBundle{}).SetupWebhookWithManager(mgr); err != nil {
121+
return fmt.Errorf("failed to register ClusterBundle webhook: %w", err)
117122
}
118123

119124
// Start all runnables and controller

deploy/charts/trust-manager/templates/clusterrole.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,27 @@ rules:
3636
- "namespaces"
3737
verbs: ["get", "list", "watch"]
3838

39+
- apiGroups:
40+
- "trust-manager.io"
41+
resources:
42+
- "clusterbundles"
43+
# The create and patch verbs are required as long as the migration controller is operating.
44+
verbs: ["get", "list", "watch", "create", "patch"]
45+
46+
# Permissions to update finalizers are required for trust-manager to work correctly
47+
# on OpenShift, even though we don't directly use finalizers at the time of writing
48+
- apiGroups:
49+
- "trust-manager.io"
50+
resources:
51+
- "clusterbundles/finalizers"
52+
verbs: ["update"]
53+
54+
- apiGroups:
55+
- "trust-manager.io"
56+
resources:
57+
- "clusterbundles/status"
58+
verbs: ["patch"]
59+
3960
{{- if not .Values.app.targetNamespaces }}
4061
{{ include "trust-manager.rbac.namespacedResourcesRules" . }}
4162
{{- end -}}

deploy/charts/trust-manager/templates/crd-trust-manager.io_clusterbundles.yaml

Lines changed: 489 additions & 0 deletions
Large diffs are not rendered by default.

deploy/charts/trust-manager/templates/crd-trust.cert-manager.io_bundles.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@ spec:
3939
jsonPath: .metadata.creationTimestamp
4040
name: Age
4141
type: date
42+
deprecated: true
43+
deprecationWarning: trust.cert-manager.io/v1alpha1 Bundle is deprecated, please migrate to trust-manager.io/v1alpha2 ClusterBundle
4244
name: v1alpha1
4345
schema:
4446
openAPIV3Schema:
47+
description: 'Deprecated: v1alpha1.Bundle will be removed in a future release. Migrate to v1alpha2.ClusterBundle instead.'
4548
properties:
4649
apiVersion:
4750
description: |-

deploy/charts/trust-manager/templates/webhook.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,26 @@ webhooks:
124124
name: {{ include "trust-manager.name" . }}
125125
namespace: {{ include "trust-manager.namespace" . }}
126126
path: /validate-trust-cert-manager-io-v1alpha1-bundle
127+
- name: vclusterbundle-v1alpha2.trust-manager.io
128+
rules:
129+
- apiGroups:
130+
- "trust-manager.io"
131+
apiVersions:
132+
- v1alpha2
133+
operations:
134+
- CREATE
135+
- UPDATE
136+
resources:
137+
- clusterbundles
138+
admissionReviewVersions: ["v1"]
139+
timeoutSeconds: {{ .Values.app.webhook.timeoutSeconds }}
140+
failurePolicy: Fail
141+
sideEffects: None
142+
clientConfig:
143+
{{ if .Values.app.webhook.tls.helmCert.enabled }}
144+
caBundle: "{{ $ca.Cert | b64enc }}"
145+
{{ end }}
146+
service:
147+
name: {{ include "trust-manager.name" . }}
148+
namespace: {{ include "trust-manager.namespace" . }}
149+
path: /validate-trust-manager-io-v1alpha2-clusterbundle

deploy/crds/trust.cert-manager.io_bundles.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,14 @@ spec:
3535
jsonPath: .metadata.creationTimestamp
3636
name: Age
3737
type: date
38+
deprecated: true
39+
deprecationWarning: trust.cert-manager.io/v1alpha1 Bundle is deprecated, please
40+
migrate to trust-manager.io/v1alpha2 ClusterBundle
3841
name: v1alpha1
3942
schema:
4043
openAPIV3Schema:
44+
description: 'Deprecated: v1alpha1.Bundle will be removed in a future release.
45+
Migrate to v1alpha2.ClusterBundle instead.'
4146
properties:
4247
apiVersion:
4348
description: |-

make/00_mod.mk

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ oci_package_debian_bookworm_additional_layers += $(debian_bookworm_package_layer
5858
deploy_name := trust-manager
5959
deploy_namespace := cert-manager
6060

61-
# Exclude new ClusterBundle API from Helm chart for now.
62-
crds_template_exclude_pattern := trust-manager.io_clusterbundles.yaml
6361
helm_chart_source_dir := deploy/charts/trust-manager
6462
helm_chart_image_name := quay.io/jetstack/charts/trust-manager
6563
helm_chart_version := $(VERSION)

pkg/apis/trust/v1alpha1/types_bundle.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var BundleLabelKey = "trust.cert-manager.io/bundle"
2626
var BundleHashAnnotationKey = "trust.cert-manager.io/hash"
2727

2828
// +kubebuilder:object:root=true
29+
// +kubebuilder:deprecatedversion:warning="trust.cert-manager.io/v1alpha1 Bundle is deprecated, please migrate to trust-manager.io/v1alpha2 ClusterBundle"
2930
// +kubebuilder:printcolumn:name="ConfigMap Target",type="string",JSONPath=".spec.target.configMap.key",description="Bundle ConfigMap Target Key"
3031
// +kubebuilder:printcolumn:name="Secret Target",type="string",JSONPath=".spec.target.secret.key",description="Bundle Secret Target Key"
3132
// +kubebuilder:printcolumn:name="Synced",type="string",JSONPath=`.status.conditions[?(@.type == "Synced")].status`,description="Bundle has been synced"
@@ -36,6 +37,7 @@ var BundleHashAnnotationKey = "trust.cert-manager.io/hash"
3637
// +genclient
3738
// +genclient:nonNamespaced
3839

40+
// Deprecated: v1alpha1.Bundle will be removed in a future release. Migrate to v1alpha2.ClusterBundle instead.
3941
type Bundle struct {
4042
metav1.TypeMeta `json:",inline"`
4143

@@ -54,6 +56,8 @@ type Bundle struct {
5456
}
5557

5658
// +kubebuilder:object:root=true
59+
60+
// Deprecated: v1alpha1.BundleList will be removed in one of the next releases. Migrate to v1alpha2.ClusterBundleList instead.
5761
type BundleList struct {
5862
metav1.TypeMeta `json:",inline"`
5963
metav1.ListMeta `json:"metadata"`

pkg/applyconfigurations/trust/v1alpha1/bundle.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/bundle/bundle.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
logf "sigs.k8s.io/controller-runtime/pkg/log"
3737

3838
trustapi "github.com/cert-manager/trust-manager/pkg/apis/trust/v1alpha1"
39+
trustmanagerapi "github.com/cert-manager/trust-manager/pkg/apis/trustmanager/v1alpha2"
3940
"github.com/cert-manager/trust-manager/pkg/bundle/controller"
4041
"github.com/cert-manager/trust-manager/pkg/bundle/internal/source"
4142
"github.com/cert-manager/trust-manager/pkg/bundle/internal/ssa_client"
@@ -83,12 +84,12 @@ func (b *bundle) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result,
8384
return ctrl.Result{}, resultErr
8485
}
8586

86-
func (b *bundle) reconcileBundle(ctx context.Context, req ctrl.Request) (statusPatch *trustapi.BundleStatus, returnedErr error) {
87+
func (b *bundle) reconcileBundle(ctx context.Context, req ctrl.Request) (statusPatch *trustmanagerapi.BundleStatus, returnedErr error) {
8788
log := logf.FromContext(ctx).WithValues("bundle", req.NamespacedName.Name)
8889
ctx = logf.IntoContext(ctx, log)
8990
log.V(2).Info("syncing bundle")
9091

91-
var bundle trustapi.Bundle
92+
var bundle trustmanagerapi.ClusterBundle
9293
err := b.client.Get(ctx, req.NamespacedName, &bundle)
9394
if apierrors.IsNotFound(err) {
9495
log.V(2).Info("bundle no longer exists, ignoring")
@@ -102,10 +103,10 @@ func (b *bundle) reconcileBundle(ctx context.Context, req ctrl.Request) (statusP
102103

103104
// Initialize patch with current status field values, except conditions.
104105
// This is done to ensure information is not lost in patch if exiting early.
105-
statusPatch = &trustapi.BundleStatus{
106+
statusPatch = &trustmanagerapi.BundleStatus{
106107
DefaultCAPackageVersion: bundle.Status.DefaultCAPackageVersion,
107108
}
108-
resolvedBundle, err := b.bundleBuilder.BuildBundle(ctx, bundle.Spec.Sources)
109+
resolvedBundle, err := b.bundleBuilder.BuildBundle(ctx, bundle.Spec)
109110

110111
if err != nil {
111112
var reason, message string
@@ -222,7 +223,7 @@ func (b *bundle) reconcileBundle(ctx context.Context, req ctrl.Request) (statusP
222223
}
223224
err := b.targetReconciler.Cache.List(ctx, targetList, &client.ListOptions{
224225
LabelSelector: labels.SelectorFromSet(map[string]string{
225-
trustapi.BundleLabelKey: bundle.Name,
226+
trustmanagerapi.BundleLabelKey: bundle.Name,
226227
}),
227228
})
228229
if err != nil {
@@ -338,7 +339,7 @@ func (b *bundle) reconcileBundle(ctx context.Context, req ctrl.Request) (statusP
338339
return statusPatch, nil
339340
}
340341

341-
func (b *bundle) bundleTargetNamespaceSelector(bundleTarget trustapi.BundleTarget) (labels.Selector, error) {
342+
func (b *bundle) bundleTargetNamespaceSelector(bundleTarget trustmanagerapi.BundleTarget) (labels.Selector, error) {
342343
nsSelector := bundleTarget.NamespaceSelector
343344

344345
// LabelSelectorAsSelector returns a Selector selecting nothing if LabelSelector is nil,

0 commit comments

Comments
 (0)