Skip to content

Commit 06cb138

Browse files
committed
pkg/cvo/egress: Pull HTTPS/Proxy egress into separate file
These are not just for available updates, they're also for downloading signatures. Placing them in a separate file makes it easier to focus on the code that is specific to available updates.
1 parent 53566c0 commit 06cb138

File tree

2 files changed

+61
-53
lines changed

2 files changed

+61
-53
lines changed

pkg/cvo/availableupdates.go

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cvo
22

33
import (
44
"crypto/tls"
5-
"crypto/x509"
65
"fmt"
76
"net/url"
87
"runtime"
@@ -11,7 +10,6 @@ import (
1110
"github.com/blang/semver"
1211
"github.com/google/uuid"
1312
"k8s.io/apimachinery/pkg/api/equality"
14-
"k8s.io/apimachinery/pkg/api/errors"
1513
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1614
"k8s.io/klog"
1715

@@ -224,54 +222,3 @@ func calculateAvailableUpdatesStatus(clusterID string, proxyURL *url.URL, tlsCon
224222
LastTransitionTime: metav1.Now(),
225223
}
226224
}
227-
228-
// getHTTPSProxyURL returns a url.URL object for the configured
229-
// https proxy only. It can be nil if does not exist or there is an error.
230-
func (optr *Operator) getHTTPSProxyURL() (*url.URL, string, error) {
231-
proxy, err := optr.proxyLister.Get("cluster")
232-
233-
if errors.IsNotFound(err) {
234-
return nil, "", nil
235-
}
236-
if err != nil {
237-
return nil, "", err
238-
}
239-
240-
if &proxy.Spec != nil {
241-
if proxy.Spec.HTTPSProxy != "" {
242-
proxyURL, err := url.Parse(proxy.Spec.HTTPSProxy)
243-
if err != nil {
244-
return nil, "", err
245-
}
246-
return proxyURL, proxy.Spec.TrustedCA.Name, nil
247-
}
248-
}
249-
return nil, "", nil
250-
}
251-
252-
func (optr *Operator) getTLSConfig(cmNameRef string) (*tls.Config, error) {
253-
cm, err := optr.cmConfigLister.Get(cmNameRef)
254-
255-
if err != nil {
256-
return nil, err
257-
}
258-
259-
certPool, _ := x509.SystemCertPool()
260-
if certPool == nil {
261-
certPool = x509.NewCertPool()
262-
}
263-
264-
if cm.Data["ca-bundle.crt"] != "" {
265-
if ok := certPool.AppendCertsFromPEM([]byte(cm.Data["ca-bundle.crt"])); !ok {
266-
return nil, fmt.Errorf("unable to add ca-bundle.crt certificates")
267-
}
268-
} else {
269-
return nil, nil
270-
}
271-
272-
config := &tls.Config{
273-
RootCAs: certPool,
274-
}
275-
276-
return config, nil
277-
}

pkg/cvo/egress.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package cvo
2+
3+
import (
4+
"crypto/tls"
5+
"crypto/x509"
6+
"fmt"
7+
"net/url"
8+
9+
"k8s.io/apimachinery/pkg/api/errors"
10+
)
11+
12+
// getHTTPSProxyURL returns a url.URL object for the configured
13+
// https proxy only. It can be nil if does not exist or there is an error.
14+
func (optr *Operator) getHTTPSProxyURL() (*url.URL, string, error) {
15+
proxy, err := optr.proxyLister.Get("cluster")
16+
17+
if errors.IsNotFound(err) {
18+
return nil, "", nil
19+
}
20+
if err != nil {
21+
return nil, "", err
22+
}
23+
24+
if &proxy.Spec != nil {
25+
if proxy.Spec.HTTPSProxy != "" {
26+
proxyURL, err := url.Parse(proxy.Spec.HTTPSProxy)
27+
if err != nil {
28+
return nil, "", err
29+
}
30+
return proxyURL, proxy.Spec.TrustedCA.Name, nil
31+
}
32+
}
33+
return nil, "", nil
34+
}
35+
36+
func (optr *Operator) getTLSConfig(cmNameRef string) (*tls.Config, error) {
37+
cm, err := optr.cmConfigLister.Get(cmNameRef)
38+
39+
if err != nil {
40+
return nil, err
41+
}
42+
43+
certPool, _ := x509.SystemCertPool()
44+
if certPool == nil {
45+
certPool = x509.NewCertPool()
46+
}
47+
48+
if cm.Data["ca-bundle.crt"] != "" {
49+
if ok := certPool.AppendCertsFromPEM([]byte(cm.Data["ca-bundle.crt"])); !ok {
50+
return nil, fmt.Errorf("unable to add ca-bundle.crt certificates")
51+
}
52+
} else {
53+
return nil, nil
54+
}
55+
56+
config := &tls.Config{
57+
RootCAs: certPool,
58+
}
59+
60+
return config, nil
61+
}

0 commit comments

Comments
 (0)