Skip to content

Commit bfa68a5

Browse files
committed
fixup! Certificate support for image registry
Signed-off-by: Todd Short <tshort@redhat.com>
1 parent c3aff36 commit bfa68a5

File tree

2 files changed

+33
-43
lines changed

2 files changed

+33
-43
lines changed

internal/controllers/clusterextension_controller.go

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ import (
2222
"errors"
2323
"fmt"
2424
"io"
25-
"os"
26-
"path/filepath"
2725
"sort"
2826
"strings"
2927
"sync"
@@ -75,6 +73,7 @@ import (
7573
catalogfilter "github.com/operator-framework/operator-controller/internal/catalogmetadata/filter"
7674
catalogsort "github.com/operator-framework/operator-controller/internal/catalogmetadata/sort"
7775
"github.com/operator-framework/operator-controller/internal/conditionsets"
76+
"github.com/operator-framework/operator-controller/internal/httputil"
7877
"github.com/operator-framework/operator-controller/internal/labels"
7978
)
8079

@@ -533,7 +532,7 @@ func SetDeprecationStatus(ext *ocv1alpha1.ClusterExtension, bundle *catalogmetad
533532
}
534533

535534
func (r *ClusterExtensionReconciler) generateBundleDeploymentForUnpack(ctx context.Context, bundlePath string, ce *ocv1alpha1.ClusterExtension) *rukpakv1alpha2.BundleDeployment {
536-
certData, err := r.getCertificateData(ce)
535+
certData, err := httputil.LoadCerts(r.CaCertDir)
537536
if err != nil {
538537
log.FromContext(ctx).WithName("operator-controller").WithValues("cluster-extension", ce.GetName()).Error(err, "unable to get TLS certificate")
539538
}
@@ -560,29 +559,6 @@ func (r *ClusterExtensionReconciler) generateBundleDeploymentForUnpack(ctx conte
560559
}
561560
}
562561

563-
func (r *ClusterExtensionReconciler) getCertificateData(ce *ocv1alpha1.ClusterExtension) (string, error) {
564-
if r.CaCertDir == "" {
565-
return "", nil
566-
}
567-
568-
var certs []string
569-
err := filepath.Walk(r.CaCertDir, func(path string, info os.FileInfo, err error) error {
570-
if info.IsDir() {
571-
return nil
572-
}
573-
data, err := os.ReadFile(path)
574-
if err != nil {
575-
return err
576-
}
577-
certs = append(certs, string(data))
578-
return nil
579-
})
580-
if err != nil {
581-
return "", err
582-
}
583-
return strings.Join(certs, "\n"), nil
584-
}
585-
586562
// SetupWithManager sets up the controller with the Manager.
587563
func (r *ClusterExtensionReconciler) SetupWithManager(mgr ctrl.Manager) error {
588564
controller, err := ctrl.NewControllerManagedBy(mgr).

internal/httputil/httputil.go

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,32 @@ import (
1010
"time"
1111
)
1212

13+
func LoadCerts(caDir string) (string, error) {
14+
if caDir == "" {
15+
return "", nil
16+
}
17+
18+
var certs []string
19+
err := filepath.Walk(caDir, func(path string, info os.FileInfo, err error) error {
20+
if err != nil {
21+
return err
22+
}
23+
if info.IsDir() {
24+
return nil
25+
}
26+
data, err := os.ReadFile(path)
27+
if err != nil {
28+
return err
29+
}
30+
certs = append(certs, string(data))
31+
return nil
32+
})
33+
if err != nil {
34+
return "", err
35+
}
36+
return strings.Join(certs, "\n"), nil
37+
}
38+
1339
func BuildHTTPClient(caDir string) (*http.Client, error) {
1440
httpClient := &http.Client{Timeout: 10 * time.Second}
1541

@@ -19,24 +45,12 @@ func BuildHTTPClient(caDir string) (*http.Client, error) {
1945
return nil, err
2046
}
2147

22-
if caDir != "" {
23-
var certs []string
24-
err := filepath.Walk(caDir, func(path string, info os.FileInfo, err error) error {
25-
if info.IsDir() {
26-
return nil
27-
}
28-
data, err := os.ReadFile(path)
29-
if err != nil {
30-
return err
31-
}
32-
certs = append(certs, string(data))
33-
return nil
34-
})
35-
if err != nil {
36-
return nil, err
37-
}
38-
caCertPool.AppendCertsFromPEM([]byte(strings.Join(certs, "\n")))
48+
certs, err := LoadCerts(caDir)
49+
if err != nil {
50+
return nil, err
3951
}
52+
53+
caCertPool.AppendCertsFromPEM([]byte(certs))
4054
tlsConfig := &tls.Config{
4155
RootCAs: caCertPool,
4256
MinVersion: tls.VersionTLS12,

0 commit comments

Comments
 (0)