Skip to content

Use k8s.io/utils set instead of apimachinery sets #6486

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

Merged
merged 1 commit into from
Jul 17, 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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ require (
k8s.io/cli-runtime v0.26.2
k8s.io/client-go v0.26.2
k8s.io/kubectl v0.26.2
k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5
k8s.io/utils v0.0.0-20230711102312-30195339c3c7
sigs.k8s.io/controller-runtime v0.14.5
sigs.k8s.io/controller-tools v0.11.3
sigs.k8s.io/kubebuilder/v3 v3.9.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1649,8 +1649,8 @@ k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 h1:+70TFaan3hfJzs+7VK2o+O
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280/go.mod h1:+Axhij7bCpeqhklhUTe3xmOn6bWxolyZEeyaFpjGtl4=
k8s.io/kubectl v0.26.2 h1:SMPB4j48eVFxsYluBq3VLyqXtE6b72YnszkbTAtFye4=
k8s.io/kubectl v0.26.2/go.mod h1:KYWOXSwp2BrDn3kPeoU/uKzKtdqvhK1dgZGd0+no4cM=
k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5 h1:kmDqav+P+/5e1i9tFfHq1qcF3sOrDp+YEkVDAHu7Jwk=
k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
k8s.io/utils v0.0.0-20230711102312-30195339c3c7 h1:ZgnF1KZsYxWIifwSNZFZgNtWE89WI5yiP5WwlfDoIyc=
k8s.io/utils v0.0.0-20230711102312-30195339c3c7/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
oras.land/oras-go v1.2.2 h1:0E9tOHUfrNH7TCDk5KU0jVBEzCqbfdyuVfGmJ7ZeRPE=
oras.land/oras-go v1.2.2/go.mod h1:Apa81sKoZPpP7CDciE006tSZ0x3Q3+dOoBcMZ/aNxvw=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
Expand Down
8 changes: 4 additions & 4 deletions hack/generate/cncf-maintainers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"log"
"os"

"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/utils/set"
"sigs.k8s.io/yaml"
)

Expand Down Expand Up @@ -33,9 +33,9 @@ func main() {
log.Fatal(err)
}

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

outOwners := make(map[string][]string)
for g, m := range expandedOwners {
outOwners[g] = sets.List(m)
outOwners[g] = m.SortedList()
}

out, err := yaml.Marshal(outOwners)
Expand Down
6 changes: 3 additions & 3 deletions internal/ansible/proxy/cache_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/utils/set"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand All @@ -58,8 +58,8 @@ func (c *cacheResponseHandler) ServeHTTP(w http.ResponseWriter, req *http.Reques
switch req.Method {
case http.MethodGet:
// GET request means we need to check the cache
rf := k8sRequest.RequestInfoFactory{APIPrefixes: sets.Set[string]{"api": {}, "apis": {}},
GrouplessAPIPrefixes: sets.Set[string]{"api": {}}}
rf := k8sRequest.RequestInfoFactory{APIPrefixes: set.New("api", "apis"),
GrouplessAPIPrefixes: set.New("api")}
r, err := rf.NewRequestInfo(req)
if err != nil {
log.Error(err, "Failed to convert request")
Expand Down
6 changes: 3 additions & 3 deletions internal/ansible/proxy/inject_owner.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/utils/set"

"github.com/operator-framework/operator-sdk/internal/ansible/proxy/controllermap"
k8sRequest "github.com/operator-framework/operator-sdk/internal/ansible/proxy/requestfactory"
Expand All @@ -50,8 +50,8 @@ func (i *injectOwnerReferenceHandler) ServeHTTP(w http.ResponseWriter, req *http
case http.MethodPost:
dump, _ := httputil.DumpRequest(req, false)
log.V(2).Info("Dumping request", "RequestDump", string(dump))
rf := k8sRequest.RequestInfoFactory{APIPrefixes: sets.Set[string]{"api": {}, "apis": {}},
GrouplessAPIPrefixes: sets.Set[string]{"api": {}}}
rf := k8sRequest.RequestInfoFactory{APIPrefixes: set.New("api", "apis"),
GrouplessAPIPrefixes: set.New("api")}
r, err := rf.NewRequestInfo(req)
if err != nil {
m := "Could not convert request"
Expand Down
14 changes: 7 additions & 7 deletions internal/ansible/proxy/requestfactory/requestinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion"
metainternalscheme "k8s.io/apimachinery/pkg/apis/meta/internalversion/scheme"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/utils/set"

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

// specialVerbsNoSubresources contains root verbs which do not allow
// subresources
var specialVerbsNoSubresources = sets.NewString("proxy")
var specialVerbsNoSubresources = set.New("proxy")

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

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

type RequestInfoFactory struct {
APIPrefixes sets.Set[string] // without leading and trailing slashes
GrouplessAPIPrefixes sets.Set[string] // without leading and trailing slashes
APIPrefixes set.Set[string] // without leading and trailing slashes
GrouplessAPIPrefixes set.Set[string] // without leading and trailing slashes
}

// TODO write an integration test against the swagger doc to test the
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/operator-sdk/generate/internal/relatedimages.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/operator-framework/operator-sdk/internal/generate/collector"
log "github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/utils/set"
)

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

for _, deployment := range manifestCol.Deployments {
Expand Down Expand Up @@ -65,7 +65,7 @@ type relatedImageCollector struct {
relatedImages []*relatedImage
relatedImagesByName map[string][]*relatedImage
relatedImagesByImageRef map[string][]*relatedImage
seenRelatedImages sets.Set[string]
seenRelatedImages set.Set[string]
}

func (c *relatedImageCollector) collectFromEnvironment(containerRef string, env []corev1.EnvVar) error {
Expand Down
6 changes: 3 additions & 3 deletions internal/olm/client/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
apiutilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/utils/set"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down Expand Up @@ -111,8 +111,8 @@ func (s Status) HasInstalledResources() (bool, error) {
}

// getCRDKindSet returns the set of all kinds specified by all CRDs in s.
func (s Status) getCRDKindSet() (sets.Set[string], error) {
crdKindSet := sets.New[string]()
func (s Status) getCRDKindSet() (set.Set[string], error) {
crdKindSet := set.New[string]()
for _, r := range s.Resources {
if r.GVK.Kind == "CustomResourceDefinition" {
u := &unstructured.Unstructured{}
Expand Down
6 changes: 3 additions & 3 deletions internal/olm/operator/install_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"strings"

"github.com/operator-framework/api/pkg/operators/v1alpha1"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/validation"
"k8s.io/utils/set"
)

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

// GetSupportedInstallModes returns the given slice of InstallModes as a
// String set.
func GetSupportedInstallModes(csvInstallModes []v1alpha1.InstallMode) sets.Set[string] {
supported := sets.New[string]()
func GetSupportedInstallModes(csvInstallModes []v1alpha1.InstallMode) set.Set[string] {
supported := set.New[string]()
for _, im := range csvInstallModes {
if im.Supported {
supported.Insert(string(im.Type))
Expand Down
12 changes: 6 additions & 6 deletions internal/olm/operator/registry/operator_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (
"github.com/operator-framework/api/pkg/operators/v1alpha1"
log "github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/util/retry"
"k8s.io/utils/set"
"sigs.k8s.io/controller-runtime/pkg/client"

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

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

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

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

func (o *OperatorInstaller) getTargetNamespaces(supported sets.Set[string]) ([]string, error) {
func (o *OperatorInstaller) getTargetNamespaces(supported set.Set[string]) ([]string, error) {
switch {
case supported.Has(string(v1alpha1.InstallModeTypeAllNamespaces)):
return nil, nil
Expand Down
6 changes: 3 additions & 3 deletions internal/olm/operator/registry/operator_installer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/utils/set"
crclient "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"

Expand Down Expand Up @@ -617,13 +617,13 @@ var _ = Describe("OperatorInstaller", func() {
Describe("getTargetNamespaces", func() {
var (
oi OperatorInstaller
supported sets.Set[string]
supported set.Set[string]
)
BeforeEach(func() {
oi = OperatorInstaller{
cfg: &operator.Configuration{},
}
supported = sets.New[string]()
supported = set.New[string]()
})
It("should return an error when nothing is supported", func() {
target, err := oi.getTargetNamespaces(supported)
Expand Down