Skip to content

Commit 7161a7b

Browse files
authored
Add k8s.io/apimachinery/pkg/util/sets (#462)
Switches from `map` of empty structs to using sets package from apimachinery utils. Signed-off-by: Mikalai Radchuk <[email protected]>
1 parent e001a0f commit 7161a7b

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

internal/resolution/variablesources/bundle_deployment.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/operator-framework/deppy/pkg/deppy"
77
"github.com/operator-framework/deppy/pkg/deppy/input"
88
rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1"
9+
"k8s.io/apimachinery/pkg/util/sets"
910
"sigs.k8s.io/controller-runtime/pkg/client"
1011
)
1112

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

39-
processed := map[string]struct{}{}
40+
processed := sets.Set[string]{}
4041
for _, bundleDeployment := range bundleDeployments.Items {
4142
sourceImage := bundleDeployment.Spec.Template.Spec.Source.Image
4243
if sourceImage != nil && sourceImage.Ref != "" {
43-
if _, ok := processed[sourceImage.Ref]; ok {
44+
if processed.Has(sourceImage.Ref) {
4445
continue
4546
}
46-
processed[sourceImage.Ref] = struct{}{}
47+
processed.Insert(sourceImage.Ref)
4748
ips, err := NewInstalledPackageVariableSource(o.catalogClient, bundleDeployment.Spec.Template.Spec.Source.Image.Ref)
4849
if err != nil {
4950
return nil, err

internal/resolution/variablesources/bundles_and_dependencies.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/operator-framework/deppy/pkg/deppy"
99
"github.com/operator-framework/deppy/pkg/deppy/input"
10+
"k8s.io/apimachinery/pkg/util/sets"
1011

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

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

6869
// ignore bundles that have already been processed
69-
if _, ok := visited[id]; ok {
70+
if visited.Has(id) {
7071
continue
7172
}
72-
visited[id] = struct{}{}
73+
visited.Insert(id)
7374

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

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

9495
// gather required package dependencies
9596
// todo(perdasilva): disambiguate between not found and actual errors
@@ -102,9 +103,9 @@ func (b *BundlesAndDepsVariableSource) filterBundleDependencies(allBundles []*ca
102103
for i := 0; i < len(packageDependencyBundles); i++ {
103104
bundle := packageDependencyBundles[i]
104105
id := olmvariables.BundleVariableID(bundle)
105-
if _, ok := added[id]; !ok {
106+
if !added.Has(id) {
106107
dependencies = append(dependencies, bundle)
107-
added[id] = struct{}{}
108+
added.Insert(id)
108109
}
109110
}
110111
}

0 commit comments

Comments
 (0)