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
32 changes: 27 additions & 5 deletions pkg/cvo/availableupdates.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"net/http"
"net/url"
"runtime"
"sort"
"strings"
"time"
Expand All @@ -23,6 +22,7 @@ import (
"github.com/openshift/cluster-version-operator/pkg/clusterconditions"
)

const noArchitecture string = "NoArchitecture"
const noChannel string = "NoChannel"

// syncAvailableUpdates attempts to retrieve the latest updates and update the status of the ClusterVersion
Expand All @@ -35,8 +35,9 @@ func (optr *Operator) syncAvailableUpdates(ctx context.Context, config *configv1
usedDefaultUpstream = true
upstream = optr.defaultUpstreamServer
}
arch := runtime.GOARCH

channel := config.Spec.Channel
arch := optr.getArchitecture()

// updates are only checked at most once per minimumUpdateCheckInterval or if the generation changes
u := optr.getAvailableUpdates()
Expand All @@ -46,6 +47,9 @@ func (optr *Operator) syncAvailableUpdates(ctx context.Context, config *configv1
klog.V(2).Infof("Retrieving available updates again, because more than %s has elapsed since %s", optr.minimumUpdateCheckInterval, u.LastAttempt)
} else if channel != u.Channel {
klog.V(2).Infof("Retrieving available updates again, because the channel has changed from %q to %q", u.Channel, channel)
} else if arch != u.Architecture {
klog.V(2).Infof("Retrieving available updates again, because the architecture has changed from %q to %q",
u.Architecture, arch)
} else if upstream == u.Upstream || (upstream == optr.defaultUpstreamServer && u.Upstream == "") {
klog.V(2).Infof("Available updates were recently retrieved, with less than %s elapsed since %s, will try later.", optr.minimumUpdateCheckInterval, u.LastAttempt)
return nil
Expand All @@ -67,6 +71,7 @@ func (optr *Operator) syncAvailableUpdates(ctx context.Context, config *configv1
au := &availableUpdates{
Upstream: upstream,
Channel: config.Spec.Channel,
Architecture: arch,
Current: current,
Updates: updates,
ConditionalUpdates: conditionalUpdates,
Expand All @@ -82,8 +87,9 @@ func (optr *Operator) syncAvailableUpdates(ctx context.Context, config *configv1
}

type availableUpdates struct {
Upstream string
Channel string
Upstream string
Channel string
Architecture string

// LastAttempt records the time of the most recent attempt at update
// retrieval, regardless of whether it was successful.
Expand Down Expand Up @@ -115,6 +121,7 @@ func (u *availableUpdates) NeedsUpdate(original *configv1.ClusterVersion) *confi
if u == nil {
return nil
}
// Architecture could change but does not reside in ClusterVersion
if u.Upstream != string(original.Spec.Upstream) || u.Channel != original.Spec.Channel {
return nil
}
Expand Down Expand Up @@ -160,6 +167,7 @@ func (optr *Operator) setAvailableUpdates(u *availableUpdates) {
if u != nil && (optr.availableUpdates == nil ||
optr.availableUpdates.Upstream != u.Upstream ||
optr.availableUpdates.Channel != u.Channel ||
optr.availableUpdates.Architecture != u.Architecture ||
success) {
u.LastSyncOrConfigChange = u.LastAttempt
} else if optr.availableUpdates != nil {
Expand All @@ -176,6 +184,20 @@ func (optr *Operator) getAvailableUpdates() *availableUpdates {
return optr.availableUpdates
}

// getArchitecture returns the currently determined cluster architecture.
func (optr *Operator) getArchitecture() string {
optr.statusLock.Lock()
defer optr.statusLock.Unlock()
return optr.architecture
}

// SetArchitecture sets the cluster architecture.
func (optr *Operator) SetArchitecture(architecture string) {
optr.statusLock.Lock()
defer optr.statusLock.Unlock()
optr.architecture = architecture
}

func calculateAvailableUpdatesStatus(ctx context.Context, clusterID string, transport *http.Transport, upstream, arch, channel, version string) (configv1.Release, []configv1.Release, []configv1.ConditionalUpdate, configv1.ClusterOperatorStatusCondition) {
var cvoCurrent configv1.Release
if len(upstream) == 0 {
Expand Down Expand Up @@ -203,7 +225,7 @@ func calculateAvailableUpdatesStatus(ctx context.Context, clusterID string, tran

if len(arch) == 0 {
return cvoCurrent, nil, nil, configv1.ClusterOperatorStatusCondition{
Type: configv1.RetrievedUpdates, Status: configv1.ConditionFalse, Reason: "NoArchitecture",
Type: configv1.RetrievedUpdates, Status: configv1.ConditionFalse, Reason: noArchitecture,
Message: "The set of architectures has not been configured.",
}
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/cvo/cvo.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ type Operator struct {
// minimumUpdateCheckInterval is the minimum duration to check for updates from
// the upstream.
minimumUpdateCheckInterval time.Duration
// architecture identifies the current architecture being used to retrieve available updates
// from OSUS. It's possible values and how it's set are defined by the OSUS Cincinnati API's
// "arch" property.
architecture string
// payloadDir is intended for testing. If unset it will default to '/'
payloadDir string
// defaultUpstreamServer is intended for testing.
Expand Down Expand Up @@ -249,6 +253,7 @@ func (optr *Operator) InitializeFromPayload(ctx context.Context, restConfig *res

optr.release = update.Release
optr.releaseCreated = update.ImageRef.CreationTimestamp.Time
optr.SetArchitecture(update.Architecture)

httpClientConstructor := sigstore.NewCachedHTTPClientConstructor(optr.HTTPClient, nil)
configClient, err := coreclientsetv1.NewForConfig(restConfig)
Expand Down Expand Up @@ -584,6 +589,8 @@ func (optr *Operator) sync(ctx context.Context, key string) error {
// inform the config sync loop about our desired state
status := optr.configSync.Update(ctx, config.Generation, desired, config, state, optr.name)

optr.SetArchitecture(status.Architecture)

// write cluster version status
return optr.syncStatus(ctx, original, config, status, errs)
}
Expand Down
Loading