Skip to content

Commit

Permalink
pkg: Migrate to (*Manifest).Include(..., overrides)
Browse files Browse the repository at this point in the history
Shifting to the centralized logic from openshift/library-go@087d2eb13a
(pkg/manifest: Add 'overrides' handling, 2023-04-18,
openshift/library-go#1502).
  • Loading branch information
wking committed Apr 28, 2023
1 parent f74d114 commit a12a66a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 31 deletions.
29 changes: 2 additions & 27 deletions pkg/cvo/sync_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/openshift/cluster-version-operator/lib/capability"
"github.com/openshift/cluster-version-operator/pkg/payload"
"github.com/openshift/cluster-version-operator/pkg/payload/precondition"
"github.com/openshift/library-go/pkg/manifest"
)

// ConfigSyncWorker abstracts how the image is synchronized to the server. Introduced for testing.
Expand Down Expand Up @@ -956,12 +955,7 @@ func (w *SyncWorker) apply(ctx context.Context, work *SyncWork, maxWorkers int,
if task.Manifest.GVK != configv1.GroupVersion.WithKind("ClusterOperator") {
continue
}
ov, ok := getOverrideForManifest(work.Overrides, task.Manifest)
if ok && ov.Unmanaged {
klog.V(2).Infof("Skipping precreation of %s as unmanaged", task)
continue
}
if err := task.Manifest.Include(nil, nil, nil, &capabilities); err != nil {
if err := task.Manifest.Include(nil, nil, nil, &capabilities, work.Overrides); err != nil {
klog.V(2).Infof("Skipping precreation of %s: %s", task, err)
continue
}
Expand All @@ -980,12 +974,7 @@ func (w *SyncWorker) apply(ctx context.Context, work *SyncWork, maxWorkers int,

klog.V(2).Infof("Running sync for %s", task)

ov, ok := getOverrideForManifest(work.Overrides, task.Manifest)
if ok && ov.Unmanaged {
klog.V(2).Infof("Skipping %s as unmanaged", task)
continue
}
if err := task.Manifest.Include(nil, nil, nil, &capabilities); err != nil {
if err := task.Manifest.Include(nil, nil, nil, &capabilities, work.Overrides); err != nil {
klog.V(2).Infof("Skipping %s: %s", task, err)
continue
}
Expand Down Expand Up @@ -1276,20 +1265,6 @@ func newMultipleError(errs []error) error {
}
}

// getOverrideForManifest returns the override and true when override exists for manifest.
func getOverrideForManifest(overrides []configv1.ComponentOverride, manifest *manifest.Manifest) (configv1.ComponentOverride, bool) {
for idx, ov := range overrides {
group, kind, namespace, name := manifest.GVK.Group, manifest.GVK.Kind, manifest.Obj.GetNamespace(), manifest.Obj.GetName()
if ov.Group == group &&
ov.Kind == kind &&
(namespace == "" || ov.Namespace == namespace) && // cluster-scoped objects don't have namespace.
ov.Name == name {
return overrides[idx], true
}
}
return configv1.ComponentOverride{}, false
}

// runThrottledStatusNotifier invokes fn every time ch is updated, but no more often than once
// every interval. If bucket is non-zero then the channel is throttled like a rate limiter bucket.
func runThrottledStatusNotifier(ctx context.Context, interval time.Duration, bucket int, ch <-chan SyncWorkerStatus, fn func()) {
Expand Down
8 changes: 4 additions & 4 deletions pkg/payload/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ func LoadUpdate(dir, releaseImage, excludeIdentifier string, requiredFeatureSet
filteredMs := []manifest.Manifest{}

for _, manifest := range ms {
if err := manifest.Include(&excludeIdentifier, &requiredFeatureSet, &profile, onlyKnownCaps); err != nil {
klog.V(2).Infof("excluding %s group=%s kind=%s namespace=%s name=%s: %v\n", manifest.OriginalFilename, manifest.GVK.Group, manifest.GVK.Kind, manifest.Obj.GetNamespace(), manifest.Obj.GetName(), err)
if err := manifest.Include(&excludeIdentifier, &requiredFeatureSet, &profile, onlyKnownCaps, nil); err != nil {
klog.V(2).Infof("excluding %s: %v\n", manifest, err)
continue
}
filteredMs = append(filteredMs, manifest)
Expand Down Expand Up @@ -246,7 +246,7 @@ func GetImplicitlyEnabledCapabilities(updatePayloadManifests []manifest.Manifest
implicitlyEnabledCaps := capabilities.ImplicitlyEnabledCapabilities

for _, updateManifest := range updatePayloadManifests {
updateManErr := updateManifest.IncludeAllowUnknownCapabilities(nil, nil, nil, &clusterCaps, true)
updateManErr := updateManifest.IncludeAllowUnknownCapabilities(nil, nil, nil, &clusterCaps, nil, true)

// update manifest is enabled, no need to check
if updateManErr == nil {
Expand All @@ -258,7 +258,7 @@ func GetImplicitlyEnabledCapabilities(updatePayloadManifests []manifest.Manifest
}

// current manifest is disabled, no need to check
if err := currentManifest.IncludeAllowUnknownCapabilities(nil, nil, nil, &clusterCaps, true); err != nil {
if err := currentManifest.IncludeAllowUnknownCapabilities(nil, nil, nil, &clusterCaps, nil, true); err != nil {
continue
}
caps := capability.GetImplicitlyEnabledCapabilities(currentManifest.GetManifestCapabilities(),
Expand Down

0 comments on commit a12a66a

Please sign in to comment.