Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add k8s.io/apimachinery/pkg/util/sets #462

Merged
merged 1 commit into from
Oct 16, 2023
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
7 changes: 4 additions & 3 deletions internal/resolution/variablesources/bundle_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/operator-framework/deppy/pkg/deppy"
"github.com/operator-framework/deppy/pkg/deppy/input"
rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1"
"k8s.io/apimachinery/pkg/util/sets"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down Expand Up @@ -36,14 +37,14 @@ func (o *BundleDeploymentVariableSource) GetVariables(ctx context.Context) ([]de
return nil, err
}

processed := map[string]struct{}{}
processed := sets.Set[string]{}
for _, bundleDeployment := range bundleDeployments.Items {
sourceImage := bundleDeployment.Spec.Template.Spec.Source.Image
if sourceImage != nil && sourceImage.Ref != "" {
if _, ok := processed[sourceImage.Ref]; ok {
if processed.Has(sourceImage.Ref) {
continue
}
processed[sourceImage.Ref] = struct{}{}
processed.Insert(sourceImage.Ref)
ips, err := NewInstalledPackageVariableSource(o.catalogClient, bundleDeployment.Spec.Template.Spec.Source.Image.Ref)
if err != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/operator-framework/deppy/pkg/deppy"
"github.com/operator-framework/deppy/pkg/deppy/input"
"k8s.io/apimachinery/pkg/util/sets"

"github.com/operator-framework/operator-controller/internal/catalogmetadata"
catalogfilter "github.com/operator-framework/operator-controller/internal/catalogmetadata/filter"
Expand Down Expand Up @@ -57,7 +58,7 @@ func (b *BundlesAndDepsVariableSource) GetVariables(ctx context.Context) ([]depp
}

// build bundle and dependency variables
visited := map[deppy.Identifier]struct{}{}
visited := sets.Set[deppy.Identifier]{}
for len(bundleQueue) > 0 {
// pop head of queue
var head *catalogmetadata.Bundle
Expand All @@ -66,10 +67,10 @@ func (b *BundlesAndDepsVariableSource) GetVariables(ctx context.Context) ([]depp
id := olmvariables.BundleVariableID(head)

// ignore bundles that have already been processed
if _, ok := visited[id]; ok {
if visited.Has(id) {
continue
}
visited[id] = struct{}{}
visited.Insert(id)

// get bundle dependencies
dependencies, err := b.filterBundleDependencies(allBundles, head)
Expand All @@ -89,7 +90,7 @@ func (b *BundlesAndDepsVariableSource) GetVariables(ctx context.Context) ([]depp

func (b *BundlesAndDepsVariableSource) filterBundleDependencies(allBundles []*catalogmetadata.Bundle, bundle *catalogmetadata.Bundle) ([]*catalogmetadata.Bundle, error) {
var dependencies []*catalogmetadata.Bundle
added := map[deppy.Identifier]struct{}{}
added := sets.Set[deppy.Identifier]{}

// gather required package dependencies
// todo(perdasilva): disambiguate between not found and actual errors
Expand All @@ -102,9 +103,9 @@ func (b *BundlesAndDepsVariableSource) filterBundleDependencies(allBundles []*ca
for i := 0; i < len(packageDependencyBundles); i++ {
bundle := packageDependencyBundles[i]
id := olmvariables.BundleVariableID(bundle)
if _, ok := added[id]; !ok {
if !added.Has(id) {
dependencies = append(dependencies, bundle)
added[id] = struct{}{}
added.Insert(id)
}
}
}
Expand Down