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
19 changes: 16 additions & 3 deletions pkg/cincinnati/cincinnati.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,20 @@ const (
type Client struct {
id uuid.UUID
transport *http.Transport

// userAgent configures the User-Agent header for upstream
// requests. If empty, the User-Agent header will not be
// populated.
userAgent string
}

// NewClient creates a new Cincinnati client with the given client identifier.
func NewClient(id uuid.UUID, transport *http.Transport) Client {
return Client{id: id, transport: transport}
func NewClient(id uuid.UUID, transport *http.Transport, userAgent string) Client {
return Client{
id: id,
transport: transport,
userAgent: userAgent,
}
}

// Error is returned when are unable to get updates.
Expand Down Expand Up @@ -92,7 +101,11 @@ func (c Client) GetUpdates(ctx context.Context, uri *url.URL, desiredArch, curre
if err != nil {
return current, nil, nil, &Error{Reason: "InvalidRequest", Message: err.Error(), cause: err}
}
req.Header.Add("Accept", GraphMediaType)

if c.userAgent != "" {
req.Header.Set("User-Agent", c.userAgent)
}
req.Header.Set("Accept", GraphMediaType)
if c.transport != nil && c.transport.TLSClientConfig != nil {
if c.transport.TLSClientConfig.ClientCAs == nil {
klog.V(2).Infof("Using a root CA pool with 0 root CA subjects to request updates from %s", uri)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cincinnati/cincinnati_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ func TestGetUpdates(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(handler))
defer ts.Close()

c := NewClient(clientID, nil)
c := NewClient(clientID, nil, "")

uri, err := url.Parse(ts.URL)
if err != nil {
Expand Down
8 changes: 5 additions & 3 deletions pkg/cvo/availableupdates.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ func (optr *Operator) syncAvailableUpdates(ctx context.Context, config *configv1
return err
}

userAgent := optr.getUserAgent()

current, updates, conditionalUpdates, condition := calculateAvailableUpdatesStatus(ctx, string(config.Spec.ClusterID),
transport, upstream, desiredArch, currentArch, channel, optr.release.Version)
transport, userAgent, upstream, desiredArch, currentArch, channel, optr.release.Version)

if usedDefaultUpstream {
upstream = ""
Expand Down Expand Up @@ -211,7 +213,7 @@ func (optr *Operator) getDesiredArchitecture(update *configv1.Update) string {
return ""
}

func calculateAvailableUpdatesStatus(ctx context.Context, clusterID string, transport *http.Transport, upstream, desiredArch,
func calculateAvailableUpdatesStatus(ctx context.Context, clusterID string, transport *http.Transport, userAgent, upstream, desiredArch,
currentArch, channel, version string) (configv1.Release, []configv1.Release, []configv1.ConditionalUpdate,
configv1.ClusterOperatorStatusCondition) {

Expand Down Expand Up @@ -269,7 +271,7 @@ func calculateAvailableUpdatesStatus(ctx context.Context, clusterID string, tran
}
}

current, updates, conditionalUpdates, err := cincinnati.NewClient(uuid, transport).GetUpdates(ctx, upstreamURI, desiredArch,
current, updates, conditionalUpdates, err := cincinnati.NewClient(uuid, transport, userAgent).GetUpdates(ctx, upstreamURI, desiredArch,
currentArch, channel, currentVersion)

if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions pkg/cvo/egress.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,19 @@ import (

"golang.org/x/net/http/httpproxy"
apierrors "k8s.io/apimachinery/pkg/api/errors"

"github.com/openshift/cluster-version-operator/pkg/version"
)

// Returns a User-Agent to be used for outgoing HTTP requests.
//
// https://www.rfc-editor.org/rfc/rfc7231#section-5.5.3
func (optr *Operator) getUserAgent() string {
token := "ClusterVersionOperator"
productVersion := version.Version
return fmt.Sprintf("%s/%s", token, productVersion)
}

// getTransport constructs an HTTP transport configuration, including
// any custom proxy configuration.
func (optr *Operator) getTransport() (*http.Transport, error) {
Expand Down