Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/prometheus/client_golang v1.7.1
github.com/prometheus/client_model v0.2.0
github.com/spf13/cobra v1.1.1
golang.org/x/net v0.0.0-20210224082022-3d97a244fca7
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba
k8s.io/api v0.21.1
k8s.io/apiextensions-apiserver v0.21.1
Expand Down
89 changes: 0 additions & 89 deletions go.sum

Large diffs are not rendered by default.

30 changes: 19 additions & 11 deletions pkg/cincinnati/cincinnati.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cincinnati

import (
"context"
"crypto/tls"
"encoding/json"
"fmt"
"io/ioutil"
Expand All @@ -12,6 +11,7 @@ import (

"github.com/blang/semver/v4"
"github.com/google/uuid"
"k8s.io/klog/v2"
)

const (
Expand All @@ -27,13 +27,12 @@ const (
// an upstream Cincinnati stack.
type Client struct {
id uuid.UUID
proxyURL *url.URL
tlsConfig *tls.Config
transport *http.Transport
}

// NewClient creates a new Cincinnati client with the given client identifier.
func NewClient(id uuid.UUID, proxyURL *url.URL, tlsConfig *tls.Config) Client {
return Client{id: id, proxyURL: proxyURL, tlsConfig: tlsConfig}
func NewClient(id uuid.UUID, transport *http.Transport) Client {
return Client{id: id, transport: transport}
}

// Update is a single node from the update graph.
Expand Down Expand Up @@ -65,7 +64,6 @@ func (err *Error) Error() string {
// image can be downloaded.
func (c Client) GetUpdates(ctx context.Context, uri *url.URL, arch string, channel string, version semver.Version) (Update, []Update, error) {
var current Update
transport := http.Transport{}
// Prepare parametrized cincinnati query.
queryParams := uri.Query()
queryParams.Add("arch", arch)
Expand All @@ -80,15 +78,25 @@ func (c Client) GetUpdates(ctx context.Context, uri *url.URL, arch string, chann
return current, nil, &Error{Reason: "InvalidRequest", Message: err.Error(), cause: err}
}
req.Header.Add("Accept", GraphMediaType)
if c.tlsConfig != nil {
transport.TLSClientConfig = c.tlsConfig
if c.transport != nil && c.transport.TLSClientConfig != nil {
if c.transport.TLSClientConfig.ClientCAs == nil {
klog.V(5).Infof("Using a root CA pool with 0 root CA subjects to request updates from %s", uri)
} else {
klog.V(5).Infof("Using a root CA pool with %n root CA subjects to request updates from %s", len(c.transport.TLSClientConfig.RootCAs.Subjects()), uri)
}
}

if c.proxyURL != nil {
transport.Proxy = http.ProxyURL(c.proxyURL)
if c.transport != nil && c.transport.Proxy != nil {
proxy, err := c.transport.Proxy(req)
if err == nil && proxy != nil {
klog.V(5).Infof("Using proxy %s to request updates from %s", proxy.Host, uri)
}
}

client := http.Client{Transport: &transport}
client := http.Client{}
if c.transport != nil {
client.Transport = c.transport
}
timeoutCtx, cancel := context.WithTimeout(ctx, getUpdatesTimeout)
defer cancel()
resp, err := client.Do(req.WithContext(timeoutCtx))
Expand Down
5 changes: 1 addition & 4 deletions pkg/cincinnati/cincinnati_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cincinnati

import (
"context"
"crypto/tls"
"encoding/json"
"fmt"
"net/http"
Expand Down Expand Up @@ -120,10 +119,8 @@ func TestGetUpdates(t *testing.T) {

ts := httptest.NewServer(http.HandlerFunc(handler))
defer ts.Close()
var proxyURL *url.URL
var tlsConfig *tls.Config

c := NewClient(clientID, proxyURL, tlsConfig)
c := NewClient(clientID, nil)

uri, err := url.Parse(ts.URL)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions pkg/cvo/availableupdates.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package cvo

import (
"context"
"crypto/tls"
"fmt"
"net/http"
"net/url"
"runtime"
"sort"
Expand Down Expand Up @@ -43,12 +43,12 @@ func (optr *Operator) syncAvailableUpdates(ctx context.Context, config *configv1
return nil
}

proxyURL, tlsConfig, err := optr.getTransportOpts()
transport, err := optr.getTransport()
if err != nil {
return err
}

current, updates, condition := calculateAvailableUpdatesStatus(ctx, string(config.Spec.ClusterID), proxyURL, tlsConfig, upstream, arch, channel, optr.release.Version)
current, updates, condition := calculateAvailableUpdatesStatus(ctx, string(config.Spec.ClusterID), transport, upstream, arch, channel, optr.release.Version)

if usedDefaultUpstream {
upstream = ""
Expand Down Expand Up @@ -144,7 +144,7 @@ func (optr *Operator) getAvailableUpdates() *availableUpdates {
return optr.availableUpdates
}

func calculateAvailableUpdatesStatus(ctx context.Context, clusterID string, proxyURL *url.URL, tlsConfig *tls.Config, upstream, arch, channel, version string) (configv1.Release, []configv1.Release, configv1.ClusterOperatorStatusCondition) {
func calculateAvailableUpdatesStatus(ctx context.Context, clusterID string, transport *http.Transport, upstream, arch, channel, version string) (configv1.Release, []configv1.Release, configv1.ClusterOperatorStatusCondition) {
var cvoCurrent configv1.Release
if len(upstream) == 0 {
return cvoCurrent, nil, configv1.ClusterOperatorStatusCondition{
Expand Down Expand Up @@ -199,7 +199,7 @@ func calculateAvailableUpdatesStatus(ctx context.Context, clusterID string, prox
}
}

current, updates, err := cincinnati.NewClient(uuid, proxyURL, tlsConfig).GetUpdates(ctx, upstreamURI, arch, channel, currentVersion)
current, updates, err := cincinnati.NewClient(uuid, transport).GetUpdates(ctx, upstreamURI, arch, channel, currentVersion)
if err != nil {
klog.V(2).Infof("Upstream server %s could not return available updates: %v", upstream, err)
if updateError, ok := err.(*cincinnati.Error); ok {
Expand Down
24 changes: 1 addition & 23 deletions pkg/cvo/cvo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package cvo

import (
"context"
"crypto/tls"
"fmt"
"net/http"
"net/url"
"strconv"
"sync"
"time"
Expand Down Expand Up @@ -832,14 +830,10 @@ func (optr *Operator) defaultPreconditionChecks() precondition.List {
// HTTPClient provides a method for generating an HTTP client
// with the proxy and trust settings, if set in the cluster.
func (optr *Operator) HTTPClient() (*http.Client, error) {
proxyURL, tlsConfig, err := optr.getTransportOpts()
transportOption, err := optr.getTransport()
if err != nil {
return nil, err
}
transportOption := &http.Transport{
Proxy: http.ProxyURL(proxyURL),
TLSClientConfig: tlsConfig,
}
transportConfig := &transport.Config{Transport: transportOption}
transport, err := transport.New(transportConfig)
if err != nil {
Expand All @@ -849,19 +843,3 @@ func (optr *Operator) HTTPClient() (*http.Client, error) {
Transport: transport,
}, nil
}

// getTransportOpts retrieves the URL of the cluster proxy and the CA
// trust, if they exist.
func (optr *Operator) getTransportOpts() (*url.URL, *tls.Config, error) {
proxyURL, err := optr.getHTTPSProxyURL()
if err != nil {
return nil, nil, err
}

var tlsConfig *tls.Config
tlsConfig, err = optr.getTLSConfig()
if err != nil {
return nil, nil, err
}
return proxyURL, tlsConfig, nil
}
Loading