Skip to content

Commit 00abef6

Browse files
committed
Centralize reading cluster proxy settings and adapt available updates code to use helper function for getting proxy URL and CA trust.
1 parent 99d1d5e commit 00abef6

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

pkg/cvo/availableupdates.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
// object. It will set the RetrievedUpdates condition. Updates are only checked if it has been more than
2525
// the minimumUpdateCheckInterval since the last check.
2626
func (optr *Operator) syncAvailableUpdates(config *configv1.ClusterVersion) error {
27-
var tlsConfig *tls.Config
2827
usedDefaultUpstream := false
2928
upstream := string(config.Spec.Upstream)
3029
if len(upstream) == 0 {
@@ -41,16 +40,10 @@ func (optr *Operator) syncAvailableUpdates(config *configv1.ClusterVersion) erro
4140
return nil
4241
}
4342

44-
proxyURL, cmNameRef, err := optr.getHTTPSProxyURL()
43+
proxyURL, tlsConfig, err := optr.getTransportOpts()
4544
if err != nil {
4645
return err
4746
}
48-
if cmNameRef != "" {
49-
tlsConfig, err = optr.getTLSConfig(cmNameRef)
50-
if err != nil {
51-
return err
52-
}
53-
}
5447

5548
updates, condition := calculateAvailableUpdatesStatus(string(config.Spec.ClusterID), proxyURL, tlsConfig, upstream, arch, channel, optr.releaseVersion)
5649

pkg/cvo/cvo.go

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

33
import (
44
"context"
5+
"crypto/tls"
56
"fmt"
7+
"net/url"
68
"strconv"
79
"sync"
810
"time"
@@ -652,3 +654,21 @@ func (optr *Operator) defaultPreconditionChecks() precondition.List {
652654
preconditioncv.NewUpgradeable(optr.cvLister),
653655
}
654656
}
657+
658+
// getTransportOpts retrieves the URL of the cluster proxy and the CA
659+
// trust, if they exist.
660+
func (optr *Operator) getTransportOpts() (*url.URL, *tls.Config, error) {
661+
proxyURL, cmNameRef, err := optr.getHTTPSProxyURL()
662+
if err != nil {
663+
return nil, nil, err
664+
}
665+
666+
var tlsConfig *tls.Config
667+
if cmNameRef != "" {
668+
tlsConfig, err = optr.getTLSConfig(cmNameRef)
669+
if err != nil {
670+
return nil, nil, err
671+
}
672+
}
673+
return proxyURL, tlsConfig, nil
674+
}

0 commit comments

Comments
 (0)