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