@@ -17,15 +17,11 @@ limitations under the License.
1717package main
1818
1919import (
20- "crypto/tls"
2120 "crypto/x509"
2221 "flag"
2322 "fmt"
24- "log"
25- "net/http"
2623 "net/url"
2724 "os"
28- "time"
2925
3026 "github.com/spf13/pflag"
3127 "go.uber.org/zap/zapcore"
@@ -48,6 +44,7 @@ import (
4844 catalogclient "github.com/operator-framework/operator-controller/internal/catalogmetadata/client"
4945 "github.com/operator-framework/operator-controller/internal/controllers"
5046 "github.com/operator-framework/operator-controller/internal/handler"
47+ "github.com/operator-framework/operator-controller/internal/httputil"
5148 "github.com/operator-framework/operator-controller/internal/labels"
5249 "github.com/operator-framework/operator-controller/internal/version"
5350 "github.com/operator-framework/operator-controller/pkg/features"
@@ -82,11 +79,11 @@ func main() {
8279 systemNamespace string
8380 unpackImage string
8481 provisionerStorageDirectory string
85- tlsCert string
82+ caCert string
8683 )
8784 flag .StringVar (& metricsAddr , "metrics-bind-address" , ":8080" , "The address the metric endpoint binds to." )
8885 flag .StringVar (& probeAddr , "health-probe-bind-address" , ":8081" , "The address the probe endpoint binds to." )
89- flag .StringVar (& tlsCert , "tls -cert" , "" , "The TLS certificate to use for verifying HTTPS connections to the Catalogd web server." )
86+ flag .StringVar (& caCert , "ca -cert" , "" , "The TLS certificate to use for verifying HTTPS connections to the Catalogd web server." )
9087 flag .BoolVar (& enableLeaderElection , "leader-elect" , false ,
9188 "Enable leader election for controller manager. " +
9289 "Enabling this will ensure there is only one active controller manager." )
@@ -156,23 +153,9 @@ func main() {
156153 os .Exit (1 )
157154 }
158155
159- httpClient := & http.Client {Timeout : 10 * time .Second }
160-
161- if tlsCert != "" {
162- cert , err := os .ReadFile (tlsCert )
163- if err != nil {
164- log .Fatalf ("Failed to read certificate file: %v" , err )
165- }
166- caCertPool := x509 .NewCertPool ()
167- caCertPool .AppendCertsFromPEM (cert )
168- tlsConfig := & tls.Config {
169- RootCAs : caCertPool ,
170- MinVersion : tls .VersionTLS12 ,
171- }
172- tlsTransport := & http.Transport {
173- TLSClientConfig : tlsConfig ,
174- }
175- httpClient .Transport = tlsTransport
156+ httpClient , err := httputil .BuildHTTPClient (caCert )
157+ if err != nil {
158+ setupLog .Error (err , "unable to create catalogd http client" )
176159 }
177160
178161 cl := mgr .GetClient ()
0 commit comments