Skip to content

Commit c66f936

Browse files
committed
Eliminate use of naked bool (includeDefaultCAs) in ClusterBundle API
Signed-off-by: Erik Godding Boye <egboye@gmail.com>
1 parent 9abd57e commit c66f936

File tree

9 files changed

+148
-41
lines changed

9 files changed

+148
-41
lines changed

deploy/crds/trust-manager.io_clusterbundles.yaml

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,32 @@ spec:
5959
spec:
6060
description: Desired state of the Bundle resource.
6161
properties:
62+
defaultCAs:
63+
description: DefaultCAs configures the use of a default CA bundle
64+
as a trust source.
65+
properties:
66+
provider:
67+
description: "Provider identifies the provider of the default
68+
CA bundle.\n\nValid values:\n- System: Uses the default CA package
69+
made available to trust-manager at\n\t\tstartup. This package
70+
is typically provided when trust-manager is installed\n\t\tvia
71+
Helm, or when the controller is started with the\n\t\t\"--default-package-location\"
72+
flag, which enables a package-injecting init\n\t\tcontainer.\n\n\t\tIf
73+
no default CA package was configured at startup, specifying
74+
this source\n\t\twill result in reconciliation failure.\n\n\t\tThe
75+
version of the default CA package used for a Bundle is reported
76+
in\n\t\tstatus.defaultCAPackageVersion.\n- Disabled: No default
77+
CAs are used as sources."
78+
enum:
79+
- System
80+
- Disabled
81+
type: string
82+
required:
83+
- provider
84+
type: object
6285
inLineCAs:
6386
description: InLine is a simple string to append as the source data.
6487
type: string
65-
includeDefaultCAs:
66-
description: |-
67-
IncludeDefaultCAs, when true, requests the default CA bundle to be used as a source.
68-
Default CAs are available if trust-manager was installed via Helm
69-
or was otherwise set up to include a package-injecting init container by using the
70-
"--default-package-location" flag when starting the trust-manager controller.
71-
If default CAs were not configured at start-up, any request to use the default
72-
CAs will fail.
73-
The version of the default CA package which is used for a Bundle is stored in the
74-
defaultCAPackageVersion field of the Bundle's status field.
75-
type: boolean
7688
sources:
7789
description: Sources is a set of references to data whose data will
7890
sync to the target.

pkg/apis/trust/v1alpha1/conversion.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2525
apimachineryconversion "k8s.io/apimachinery/pkg/conversion"
2626
"k8s.io/apimachinery/pkg/runtime"
27+
"k8s.io/utils/ptr"
2728
"sigs.k8s.io/controller-runtime/pkg/conversion"
2829

2930
trustv1alpha2 "github.com/cert-manager/trust-manager/pkg/apis/trustmanager/v1alpha2"
@@ -105,7 +106,11 @@ func Convert_v1alpha1_BundleSource_To_v1alpha2_BundleSource(in *BundleSource, ou
105106
}
106107
if in.UseDefaultCAs != nil {
107108
obj := scope.Meta().Context.(*trustv1alpha2.ClusterBundle)
108-
obj.Spec.IncludeDefaultCAs = in.UseDefaultCAs
109+
provider := trustv1alpha2.DefaultCAsProviderDisabled
110+
if *in.UseDefaultCAs {
111+
provider = trustv1alpha2.DefaultCAsProviderSystem
112+
}
113+
obj.Spec.DefaultCAs = &trustv1alpha2.DefaultCAsSource{Provider: provider}
109114
}
110115

111116
return nil
@@ -221,8 +226,8 @@ func Convert_v1alpha2_BundleSpec_To_v1alpha1_BundleSpec(in *trustv1alpha2.Bundle
221226
if in.InLineCAs != nil {
222227
out.Sources = append(out.Sources, BundleSource{InLine: in.InLineCAs})
223228
}
224-
if in.IncludeDefaultCAs != nil {
225-
out.Sources = append(out.Sources, BundleSource{UseDefaultCAs: in.IncludeDefaultCAs})
229+
if in.DefaultCAs != nil {
230+
out.Sources = append(out.Sources, BundleSource{UseDefaultCAs: ptr.To(in.DefaultCAs.Provider == trustv1alpha2.DefaultCAsProviderSystem)})
226231
}
227232

228233
return nil

pkg/apis/trust/v1alpha1/conversion_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ func fuzzFuncs(_ runtimeserializer.CodecFactory) []any {
9393
spokeSourceObjectKeySelectorFuzzer,
9494
spokeBundleTargetFuzzer,
9595
hubBundleSourceFuzzer,
96+
hubDefaultCAsFuzzer,
9697
hubBundleTargetFuzzer,
9798
}
9899
}
@@ -165,6 +166,14 @@ func hubBundleSourceFuzzer(obj *trustmanagerapi.BundleSource, c randfill.Continu
165166
obj.Kind = kindSet[rand.Intn(len(kindSet))] //nolint:gosec
166167
}
167168

169+
func hubDefaultCAsFuzzer(obj *trustmanagerapi.DefaultCAsSource, c randfill.Continue) {
170+
c.FillNoCustom(obj)
171+
172+
// We only allow known providers, so must normalize the provider
173+
providerSet := []string{trustmanagerapi.DefaultCAsProviderDisabled, trustmanagerapi.DefaultCAsProviderSystem}
174+
obj.Provider = providerSet[rand.Intn(len(providerSet))] //nolint:gosec
175+
}
176+
168177
func hubBundleTargetFuzzer(obj *trustmanagerapi.BundleTarget, c randfill.Continue) {
169178
c.FillNoCustom(obj)
170179

pkg/apis/trust/v1alpha1/zz_generated.conversion.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/trustmanager/v1alpha2/types_cluster_bundle.go

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,9 @@ type BundleSpec struct {
6666
// +kubebuilder:validation:MaxItems=100
6767
Sources []BundleSource `json:"sources,omitempty"`
6868

69-
// IncludeDefaultCAs, when true, requests the default CA bundle to be used as a source.
70-
// Default CAs are available if trust-manager was installed via Helm
71-
// or was otherwise set up to include a package-injecting init container by using the
72-
// "--default-package-location" flag when starting the trust-manager controller.
73-
// If default CAs were not configured at start-up, any request to use the default
74-
// CAs will fail.
75-
// The version of the default CA package which is used for a Bundle is stored in the
76-
// defaultCAPackageVersion field of the Bundle's status field.
69+
// DefaultCAs configures the use of a default CA bundle as a trust source.
7770
// +optional
78-
IncludeDefaultCAs *bool `json:"includeDefaultCAs,omitempty"`
71+
DefaultCAs *DefaultCAsSource `json:"defaultCAs,omitempty"`
7972

8073
// InLine is a simple string to append as the source data.
8174
// +optional
@@ -100,6 +93,28 @@ type BundleSource struct {
10093
Key string `json:"key"`
10194
}
10295

96+
// DefaultCAsSource configures the use of a default CA bundle as a trust source.
97+
type DefaultCAsSource struct {
98+
// Provider identifies the provider of the default CA bundle.
99+
//
100+
// Valid values:
101+
// - System: Uses the default CA package made available to trust-manager at
102+
// startup. This package is typically provided when trust-manager is installed
103+
// via Helm, or when the controller is started with the
104+
// "--default-package-location" flag, which enables a package-injecting init
105+
// container.
106+
//
107+
// If no default CA package was configured at startup, specifying this source
108+
// will result in reconciliation failure.
109+
//
110+
// The version of the default CA package used for a Bundle is reported in
111+
// status.defaultCAPackageVersion.
112+
// - Disabled: No default CAs are used as sources.
113+
// +required
114+
// +kubebuilder:validation:Enum=System;Disabled
115+
Provider string `json:"provider"`
116+
}
117+
103118
// BundleTarget is the target resource that the Bundle will sync all source
104119
// data to.
105120
// +kubebuilder:validation:XValidation:rule="[has(self.configMap), has(self.secret)].exists(x,x)", message="any of the following fields must be provided: [configMap, secret]"
@@ -156,6 +171,9 @@ const (
156171
ConfigMapKind string = "ConfigMap"
157172

158173
SecretKind string = "Secret"
174+
175+
DefaultCAsProviderDisabled string = "Disabled"
176+
DefaultCAsProviderSystem string = "System"
159177
)
160178

161179
// SourceReference is a reference to a source object.

pkg/apis/trustmanager/v1alpha2/zz_generated.deepcopy.go

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

pkg/applyconfigurations/trustmanager/v1alpha2/bundlespec.go

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

pkg/applyconfigurations/trustmanager/v1alpha2/defaultcassource.go

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

test/integration/clusterbundle/migration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ var _ = Describe("ClusterBundle Migration", func() {
119119
clusterBundle.Annotations = map[string]string{
120120
trustmanagerapi.BundleMigratedAnnotation: "true",
121121
}
122-
clusterBundle.Spec.IncludeDefaultCAs = ptr.To(true)
122+
clusterBundle.Spec.DefaultCAs = &trustmanagerapi.DefaultCAsSource{Provider: trustmanagerapi.DefaultCAsProviderSystem}
123123
Expect(cl.Update(ctx, clusterBundle)).To(Succeed())
124124

125125
Eventually(func() (string, error) {

0 commit comments

Comments
 (0)