@@ -20,9 +20,11 @@ import (
2020 "context"
2121 "fmt"
2222
23+ trustmanagerapi "github.com/cert-manager/trust-manager/pkg/apis/trustmanager/v1alpha2"
2324 corev1 "k8s.io/api/core/v1"
2425 apierrors "k8s.io/apimachinery/pkg/api/errors"
2526 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27+ "k8s.io/utils/ptr"
2628 "sigs.k8s.io/controller-runtime/pkg/client"
2729 logf "sigs.k8s.io/controller-runtime/pkg/log"
2830
@@ -66,32 +68,38 @@ func (b *BundleBuilder) BuildBundle(ctx context.Context, sources []trustapi.Bund
6668 util .WithLogger (logf .FromContext (ctx ).WithName ("cert-pool" )),
6769 )
6870
69- for _ , source := range sources {
71+ for _ , source := range spec . Sources {
7072 var certSource bundleSource
7173
72- switch {
73- case source . ConfigMap != nil :
74- certSource = & configMapBundleSource {b .Reader , b .Namespace , source . ConfigMap }
74+ switch source . Kind {
75+ case " ConfigMap" :
76+ certSource = & configMapBundleSource {b .Reader , b .Namespace , source }
7577
76- case source . Secret != nil :
77- certSource = & secretBundleSource {b .Reader , b .Namespace , source . Secret }
78+ case " Secret" :
79+ certSource = & secretBundleSource {b .Reader , b .Namespace , source }
7880
79- case source .InLine != nil :
80- certSource = & inlineBundleSource {* source .InLine }
81-
82- case source .UseDefaultCAs != nil :
83- if ! * source .UseDefaultCAs {
84- continue
85- }
86- if b .DefaultPackage == nil {
87- return BundleData {}, NotFoundError {fmt .Errorf ("no default package was specified when trust-manager was started; default CAs not available" )}
88- }
89- certSource = & defaultCAsBundleSource {b .DefaultPackage .Bundle }
90- resolvedBundle .DefaultCAPackageStringID = b .DefaultPackage .StringID ()
9181 default :
92- panic (fmt .Sprintf ("don't know how to process source: %+v" , source ))
82+ panic (fmt .Sprintf ("don't know how to process source of kind: %q" , source .Kind ))
83+ }
84+
85+ if err := certSource .addToCertPool (ctx , certPool ); err != nil {
86+ return BundleData {}, err
9387 }
88+ }
89+
90+ if spec .InLineCAs != nil {
91+ certSource := & inlineBundleSource {* spec .InLineCAs }
92+ if err := certSource .addToCertPool (ctx , certPool ); err != nil {
93+ return BundleData {}, err
94+ }
95+ }
9496
97+ if ptr .Deref (spec .IncludeDefaultCAs , false ) {
98+ if b .DefaultPackage == nil {
99+ return BundleData {}, NotFoundError {fmt .Errorf ("no default package was specified when trust-manager was started; default CAs not available" )}
100+ }
101+ certSource := & defaultCAsBundleSource {b .DefaultPackage .Bundle }
102+ resolvedBundle .DefaultCAPackageStringID = b .DefaultPackage .StringID ()
95103 if err := certSource .addToCertPool (ctx , resolvedBundle .CertPool ); err != nil {
96104 return BundleData {}, err
97105 }
@@ -134,7 +142,7 @@ func (s defaultCAsBundleSource) addToCertPool(_ context.Context, pool *util.Cert
134142type configMapBundleSource struct {
135143 client.Reader
136144 Namespace string
137- ref * trustapi. SourceObjectKeySelector
145+ ref trustmanagerapi. BundleSource
138146}
139147
140148func (b configMapBundleSource ) addToCertPool (ctx context.Context , pool * util.CertPool ) error {
@@ -197,7 +205,7 @@ func (b configMapBundleSource) addToCertPool(ctx context.Context, pool *util.Cer
197205type secretBundleSource struct {
198206 client.Reader
199207 Namespace string
200- ref * trustapi. SourceObjectKeySelector
208+ ref trustmanagerapi. BundleSource
201209}
202210
203211func (b secretBundleSource ) addToCertPool (ctx context.Context , pool * util.CertPool ) error {
0 commit comments