Skip to content

Commit dca2686

Browse files
committed
pkg/cvo/avialableupdates: Pull URI parsing out of GetUpdates
Moving it up one level into calculateAvailableUpdatesStatus places it right next to the existing len(upstream) check, so now both "is the upstream URI valid?" checks are in the same place.
1 parent 0708065 commit dca2686

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

pkg/cincinnati/cincinnati.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,18 @@ func (err *Error) Error() string {
5858
// finding all of the children. These children are the available updates for
5959
// the current version and their payloads indicate from where the actual update
6060
// image can be downloaded.
61-
func (c Client) GetUpdates(upstream string, arch string, channel string, version semver.Version) ([]Update, error) {
61+
func (c Client) GetUpdates(uri *url.URL, arch string, channel string, version semver.Version) ([]Update, error) {
6262
transport := http.Transport{}
6363
// Prepare parametrized cincinnati query.
64-
cincinnatiURL, err := url.Parse(upstream)
65-
if err != nil {
66-
return nil, &Error{Reason: "InvalidURI", Message: fmt.Sprintf("failed to parse upstream URL: %s", err)}
67-
}
68-
queryParams := cincinnatiURL.Query()
64+
queryParams := uri.Query()
6965
queryParams.Add("arch", arch)
7066
queryParams.Add("channel", channel)
7167
queryParams.Add("id", c.id.String())
7268
queryParams.Add("version", version.String())
73-
cincinnatiURL.RawQuery = queryParams.Encode()
69+
uri.RawQuery = queryParams.Encode()
7470

7571
// Download the update graph.
76-
req, err := http.NewRequest("GET", cincinnatiURL.String(), nil)
72+
req, err := http.NewRequest("GET", uri.String(), nil)
7773
if err != nil {
7874
return nil, &Error{Reason: "InvalidRequest", Message: err.Error(), cause: err}
7975
}

pkg/cincinnati/cincinnati_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,12 @@ func TestGetUpdates(t *testing.T) {
127127

128128
c := NewClient(clientID, proxyURL, tlsConfig)
129129

130-
updates, err := c.GetUpdates(ts.URL, arch, channelName, semver.MustParse(test.version))
130+
uri, err := url.Parse(ts.URL)
131+
if err != nil {
132+
t.Fatal(err)
133+
}
134+
135+
updates, err := c.GetUpdates(uri, arch, channelName, semver.MustParse(test.version))
131136
if test.err == "" {
132137
if err != nil {
133138
t.Fatalf("expected nil error, got: %v", err)

pkg/cvo/availableupdates.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ func calculateAvailableUpdatesStatus(clusterID string, proxyURL *url.URL, tlsCon
127127
}
128128
}
129129

130+
upstreamURI, err := url.Parse(upstream)
131+
if err != nil {
132+
return nil, configv1.ClusterOperatorStatusCondition{
133+
Type: configv1.RetrievedUpdates, Status: configv1.ConditionFalse, Reason: "InvalidURI",
134+
Message: fmt.Sprintf("failed to parse upstream URL: %s", err),
135+
}
136+
}
137+
130138
uuid, err := uuid.Parse(string(clusterID))
131139
if err != nil {
132140
return nil, configv1.ClusterOperatorStatusCondition{
@@ -165,7 +173,7 @@ func calculateAvailableUpdatesStatus(clusterID string, proxyURL *url.URL, tlsCon
165173
}
166174
}
167175

168-
updates, err := cincinnati.NewClient(uuid, proxyURL, tlsConfig).GetUpdates(upstream, arch, channel, currentVersion)
176+
updates, err := cincinnati.NewClient(uuid, proxyURL, tlsConfig).GetUpdates(upstreamURI, arch, channel, currentVersion)
169177
if err != nil {
170178
klog.V(2).Infof("Upstream server %s could not return available updates: %v", upstream, err)
171179
if updateError, ok := err.(*cincinnati.Error); ok {

0 commit comments

Comments
 (0)