Skip to content

Commit 94b6f26

Browse files
committed
Use k8s.io/utils set instead of apimachinery sets
Following kubernetes/utils#243 it's likely that the k8s.io/utils version will end up being the canonical one. Signed-off-by: Stephen Kitt <[email protected]>
1 parent 861f524 commit 94b6f26

File tree

11 files changed

+38
-38
lines changed

11 files changed

+38
-38
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ require (
4040
k8s.io/cli-runtime v0.26.2
4141
k8s.io/client-go v0.26.2
4242
k8s.io/kubectl v0.26.2
43-
k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5
43+
k8s.io/utils v0.0.0-20230505201702-9f6742963106
4444
sigs.k8s.io/controller-runtime v0.14.5
4545
sigs.k8s.io/controller-tools v0.11.3
4646
sigs.k8s.io/kubebuilder/v3 v3.9.1

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -1649,8 +1649,8 @@ k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 h1:+70TFaan3hfJzs+7VK2o+O
16491649
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280/go.mod h1:+Axhij7bCpeqhklhUTe3xmOn6bWxolyZEeyaFpjGtl4=
16501650
k8s.io/kubectl v0.26.2 h1:SMPB4j48eVFxsYluBq3VLyqXtE6b72YnszkbTAtFye4=
16511651
k8s.io/kubectl v0.26.2/go.mod h1:KYWOXSwp2BrDn3kPeoU/uKzKtdqvhK1dgZGd0+no4cM=
1652-
k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5 h1:kmDqav+P+/5e1i9tFfHq1qcF3sOrDp+YEkVDAHu7Jwk=
1653-
k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
1652+
k8s.io/utils v0.0.0-20230505201702-9f6742963106 h1:EObNQ3TW2D+WptiYXlApGNLVy0zm/JIBVY9i+M4wpAU=
1653+
k8s.io/utils v0.0.0-20230505201702-9f6742963106/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
16541654
oras.land/oras-go v1.2.2 h1:0E9tOHUfrNH7TCDk5KU0jVBEzCqbfdyuVfGmJ7ZeRPE=
16551655
oras.land/oras-go v1.2.2/go.mod h1:Apa81sKoZPpP7CDciE006tSZ0x3Q3+dOoBcMZ/aNxvw=
16561656
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=

hack/generate/cncf-maintainers/main.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"log"
55
"os"
66

7-
"k8s.io/apimachinery/pkg/util/sets"
7+
"k8s.io/utils/set"
88
"sigs.k8s.io/yaml"
99
)
1010

@@ -33,9 +33,9 @@ func main() {
3333
log.Fatal(err)
3434
}
3535

36-
expandedOwners := make(map[string]sets.Set[string])
36+
expandedOwners := make(map[string]set.Set[string])
3737
for group, ownersAliases := range owners {
38-
expandedOwners[group] = sets.New[string]()
38+
expandedOwners[group] = set.New[string]()
3939
for _, alias := range ownersAliases {
4040
if members, ok := aliases.Aliases[alias]; ok {
4141
expandedOwners[group].Insert(members...)
@@ -47,7 +47,7 @@ func main() {
4747

4848
outOwners := make(map[string][]string)
4949
for g, m := range expandedOwners {
50-
outOwners[g] = sets.List(m)
50+
outOwners[g] = m.SortedList()
5151
}
5252

5353
out, err := yaml.Marshal(outOwners)

internal/ansible/proxy/cache_response.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
"k8s.io/apimachinery/pkg/fields"
3232
"k8s.io/apimachinery/pkg/labels"
3333
"k8s.io/apimachinery/pkg/runtime/schema"
34-
"k8s.io/apimachinery/pkg/util/sets"
34+
"k8s.io/utils/set"
3535
"sigs.k8s.io/controller-runtime/pkg/cache"
3636
"sigs.k8s.io/controller-runtime/pkg/client"
3737

@@ -58,8 +58,8 @@ func (c *cacheResponseHandler) ServeHTTP(w http.ResponseWriter, req *http.Reques
5858
switch req.Method {
5959
case http.MethodGet:
6060
// GET request means we need to check the cache
61-
rf := k8sRequest.RequestInfoFactory{APIPrefixes: sets.Set[string]{"api": {}, "apis": {}},
62-
GrouplessAPIPrefixes: sets.Set[string]{"api": {}}}
61+
rf := k8sRequest.RequestInfoFactory{APIPrefixes: set.New("api", "apis"),
62+
GrouplessAPIPrefixes: set.New("api")}
6363
r, err := rf.NewRequestInfo(req)
6464
if err != nil {
6565
log.Error(err, "Failed to convert request")

internal/ansible/proxy/inject_owner.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2828
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2929
"k8s.io/apimachinery/pkg/runtime/schema"
30-
"k8s.io/apimachinery/pkg/util/sets"
30+
"k8s.io/utils/set"
3131

3232
"github.com/operator-framework/operator-sdk/internal/ansible/proxy/controllermap"
3333
k8sRequest "github.com/operator-framework/operator-sdk/internal/ansible/proxy/requestfactory"
@@ -50,8 +50,8 @@ func (i *injectOwnerReferenceHandler) ServeHTTP(w http.ResponseWriter, req *http
5050
case http.MethodPost:
5151
dump, _ := httputil.DumpRequest(req, false)
5252
log.V(2).Info("Dumping request", "RequestDump", string(dump))
53-
rf := k8sRequest.RequestInfoFactory{APIPrefixes: sets.Set[string]{"api": {}, "apis": {}},
54-
GrouplessAPIPrefixes: sets.Set[string]{"api": {}}}
53+
rf := k8sRequest.RequestInfoFactory{APIPrefixes: set.New("api", "apis"),
54+
GrouplessAPIPrefixes: set.New("api")}
5555
r, err := rf.NewRequestInfo(req)
5656
if err != nil {
5757
m := "Could not convert request"

internal/ansible/proxy/requestfactory/requestinfo.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion"
3030
metainternalscheme "k8s.io/apimachinery/pkg/apis/meta/internalversion/scheme"
3131
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
32-
"k8s.io/apimachinery/pkg/util/sets"
32+
"k8s.io/utils/set"
3333

3434
logf "sigs.k8s.io/controller-runtime/pkg/log"
3535
)
@@ -75,24 +75,24 @@ type RequestInfo struct {
7575
// actions that don't fall under the normal CRUDdy GET/POST/PUT/DELETE actions
7676
// on REST objects. TODO: find a way to keep this up to date automatically.
7777
// Maybe dynamically populate list as handlers added to master's Mux.
78-
var specialVerbs = sets.NewString("proxy", "watch")
78+
var specialVerbs = set.New("proxy", "watch")
7979

8080
// specialVerbsNoSubresources contains root verbs which do not allow
8181
// subresources
82-
var specialVerbsNoSubresources = sets.NewString("proxy")
82+
var specialVerbsNoSubresources = set.New("proxy")
8383

8484
// namespaceSubresources contains subresources of namespace this list allows
8585
// the parser to distinguish between a namespace subresource, and a namespaced
8686
// resource
87-
var namespaceSubresources = sets.NewString("status", "finalize")
87+
var namespaceSubresources = set.New("status", "finalize")
8888

8989
// NamespaceSubResourcesForTest exports namespaceSubresources for testing in
9090
// pkg/master/master_test.go, so we never drift
91-
var NamespaceSubResourcesForTest = sets.NewString(namespaceSubresources.List()...)
91+
var NamespaceSubResourcesForTest = set.New(namespaceSubresources.SortedList()...)
9292

9393
type RequestInfoFactory struct {
94-
APIPrefixes sets.Set[string] // without leading and trailing slashes
95-
GrouplessAPIPrefixes sets.Set[string] // without leading and trailing slashes
94+
APIPrefixes set.Set[string] // without leading and trailing slashes
95+
GrouplessAPIPrefixes set.Set[string] // without leading and trailing slashes
9696
}
9797

9898
// TODO write an integration test against the swagger doc to test the

internal/cmd/operator-sdk/generate/internal/relatedimages.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"github.com/operator-framework/operator-sdk/internal/generate/collector"
2323
log "github.com/sirupsen/logrus"
2424
corev1 "k8s.io/api/core/v1"
25-
"k8s.io/apimachinery/pkg/util/sets"
25+
"k8s.io/utils/set"
2626
)
2727

2828
// FindRelatedImages looks in the controller manager's environment for images used by the operator.
@@ -31,7 +31,7 @@ func FindRelatedImages(manifestCol *collector.Manifests) ([]operatorsv1alpha1.Re
3131
relatedImages: []*relatedImage{},
3232
relatedImagesByName: make(map[string][]*relatedImage),
3333
relatedImagesByImageRef: make(map[string][]*relatedImage),
34-
seenRelatedImages: sets.Set[string]{},
34+
seenRelatedImages: set.Set[string]{},
3535
}
3636

3737
for _, deployment := range manifestCol.Deployments {
@@ -65,7 +65,7 @@ type relatedImageCollector struct {
6565
relatedImages []*relatedImage
6666
relatedImagesByName map[string][]*relatedImage
6767
relatedImagesByImageRef map[string][]*relatedImage
68-
seenRelatedImages sets.Set[string]
68+
seenRelatedImages set.Set[string]
6969
}
7070

7171
func (c *relatedImageCollector) collectFromEnvironment(containerRef string, env []corev1.EnvVar) error {

internal/olm/client/status.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
"k8s.io/apimachinery/pkg/runtime/schema"
3434
"k8s.io/apimachinery/pkg/types"
3535
apiutilerrors "k8s.io/apimachinery/pkg/util/errors"
36-
"k8s.io/apimachinery/pkg/util/sets"
36+
"k8s.io/utils/set"
3737
"sigs.k8s.io/controller-runtime/pkg/client"
3838
)
3939

@@ -111,8 +111,8 @@ func (s Status) HasInstalledResources() (bool, error) {
111111
}
112112

113113
// getCRDKindSet returns the set of all kinds specified by all CRDs in s.
114-
func (s Status) getCRDKindSet() (sets.Set[string], error) {
115-
crdKindSet := sets.New[string]()
114+
func (s Status) getCRDKindSet() (set.Set[string], error) {
115+
crdKindSet := set.New[string]()
116116
for _, r := range s.Resources {
117117
if r.GVK.Kind == "CustomResourceDefinition" {
118118
u := &unstructured.Unstructured{}

internal/olm/operator/install_mode.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import (
2121
"strings"
2222

2323
"github.com/operator-framework/api/pkg/operators/v1alpha1"
24-
"k8s.io/apimachinery/pkg/util/sets"
2524
"k8s.io/apimachinery/pkg/util/validation"
25+
"k8s.io/utils/set"
2626
)
2727

2828
type InstallMode struct {
@@ -131,8 +131,8 @@ func (i InstallMode) CheckCompatibility(csv *v1alpha1.ClusterServiceVersion, ope
131131

132132
// GetSupportedInstallModes returns the given slice of InstallModes as a
133133
// String set.
134-
func GetSupportedInstallModes(csvInstallModes []v1alpha1.InstallMode) sets.Set[string] {
135-
supported := sets.New[string]()
134+
func GetSupportedInstallModes(csvInstallModes []v1alpha1.InstallMode) set.Set[string] {
135+
supported := set.New[string]()
136136
for _, im := range csvInstallModes {
137137
if im.Supported {
138138
supported.Insert(string(im.Type))

internal/olm/operator/registry/operator_installer.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ import (
2424
"github.com/operator-framework/api/pkg/operators/v1alpha1"
2525
log "github.com/sirupsen/logrus"
2626
"k8s.io/apimachinery/pkg/types"
27-
"k8s.io/apimachinery/pkg/util/sets"
2827
"k8s.io/apimachinery/pkg/util/wait"
2928
"k8s.io/client-go/util/retry"
29+
"k8s.io/utils/set"
3030
"sigs.k8s.io/controller-runtime/pkg/client"
3131

3232
olmclient "github.com/operator-framework/operator-sdk/internal/olm/client"
@@ -43,7 +43,7 @@ type OperatorInstaller struct {
4343
InstallMode operator.InstallMode
4444
CatalogCreator CatalogCreator
4545
CatalogUpdater CatalogUpdater
46-
SupportedInstallModes sets.Set[string]
46+
SupportedInstallModes set.Set[string]
4747

4848
cfg *operator.Configuration
4949
}
@@ -210,7 +210,7 @@ func (o OperatorInstaller) ensureOperatorGroup(ctx context.Context) error {
210210
return fmt.Errorf("use install mode %q to watch operator's namespace %q", v1alpha1.InstallModeTypeOwnNamespace, o.cfg.Namespace)
211211
}
212212

213-
supported = supported.Intersection(sets.New[string](string(o.InstallMode.InstallModeType)))
213+
supported = supported.Intersection(set.New(string(o.InstallMode.InstallModeType)))
214214
if supported.Len() == 0 {
215215
return fmt.Errorf("operator %q does not support install mode %q", o.StartingCSV, o.InstallMode.InstallModeType)
216216
}
@@ -248,8 +248,8 @@ func (o *OperatorInstaller) isOperatorGroupCompatible(og v1.OperatorGroup, targe
248248
}
249249

250250
// otherwise, check that the target namespaces match
251-
targets := sets.New[string](targetNamespaces...)
252-
ogtargets := sets.New[string](og.Spec.TargetNamespaces...)
251+
targets := set.New(targetNamespaces...)
252+
ogtargets := set.New(og.Spec.TargetNamespaces...)
253253
if !ogtargets.Equal(targets) {
254254
return fmt.Errorf("existing operatorgroup %q is not compatible with install mode %q", og.Name, o.InstallMode)
255255
}
@@ -369,7 +369,7 @@ func (o OperatorInstaller) waitForInstallPlan(ctx context.Context, sub *v1alpha1
369369
return nil
370370
}
371371

372-
func (o *OperatorInstaller) getTargetNamespaces(supported sets.Set[string]) ([]string, error) {
372+
func (o *OperatorInstaller) getTargetNamespaces(supported set.Set[string]) ([]string, error) {
373373
switch {
374374
case supported.Has(string(v1alpha1.InstallModeTypeAllNamespaces)):
375375
return nil, nil

internal/olm/operator/registry/operator_installer_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2626
"k8s.io/apimachinery/pkg/runtime"
2727
"k8s.io/apimachinery/pkg/types"
28-
"k8s.io/apimachinery/pkg/util/sets"
28+
"k8s.io/utils/set"
2929
crclient "sigs.k8s.io/controller-runtime/pkg/client"
3030
"sigs.k8s.io/controller-runtime/pkg/client/fake"
3131

@@ -617,13 +617,13 @@ var _ = Describe("OperatorInstaller", func() {
617617
Describe("getTargetNamespaces", func() {
618618
var (
619619
oi OperatorInstaller
620-
supported sets.Set[string]
620+
supported set.Set[string]
621621
)
622622
BeforeEach(func() {
623623
oi = OperatorInstaller{
624624
cfg: &operator.Configuration{},
625625
}
626-
supported = sets.New[string]()
626+
supported = set.New[string]()
627627
})
628628
It("should return an error when nothing is supported", func() {
629629
target, err := oi.getTargetNamespaces(supported)

0 commit comments

Comments
 (0)