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

cleanup: replace deprecated sets.String #116179

Merged
merged 1 commit into from Mar 2, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions staging/src/k8s.io/kubectl/pkg/cmd/apply/apply.go
Expand Up @@ -121,8 +121,8 @@ type ApplyOptions struct {

// Stores visited objects/namespaces for later use
// calculating the set of objects to prune.
VisitedUids sets.String
VisitedNamespaces sets.String
VisitedUids sets.Set[types.UID]
VisitedNamespaces sets.Set[string]

// Function run after the objects are generated and
// stored in the "objects" field, but before the
Expand Down Expand Up @@ -352,8 +352,8 @@ func (flags *ApplyFlags) ToOptions(f cmdutil.Factory, cmd *cobra.Command, baseNa
objects: []*resource.Info{},
objectsCached: false,

VisitedUids: sets.NewString(),
VisitedNamespaces: sets.NewString(),
VisitedUids: sets.New[types.UID](),
VisitedNamespaces: sets.New[string](),

ApplySet: applySet,
}
Expand Down Expand Up @@ -981,7 +981,7 @@ func (o *ApplyOptions) MarkObjectVisited(info *resource.Info) error {
if err != nil {
return err
}
o.VisitedUids.Insert(string(metadata.GetUID()))
o.VisitedUids.Insert(metadata.GetUID())
return nil
}

Expand Down
7 changes: 4 additions & 3 deletions staging/src/k8s.io/kubectl/pkg/cmd/apply/prune.go
Expand Up @@ -24,6 +24,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/cli-runtime/pkg/printers"
"k8s.io/client-go/dynamic"
Expand All @@ -35,8 +36,8 @@ type pruner struct {
mapper meta.RESTMapper
dynamicClient dynamic.Interface

visitedUids sets.String
visitedNamespaces sets.String
visitedUids sets.Set[types.UID]
visitedNamespaces sets.Set[string]
labelSelector string
fieldSelector string

Expand Down Expand Up @@ -119,7 +120,7 @@ func (p *pruner) prune(namespace string, mapping *meta.RESTMapping) error {
continue
}
uid := metadata.GetUID()
if p.visitedUids.Has(string(uid)) {
if p.visitedUids.Has(uid) {
continue
}
name := metadata.GetName()
Expand Down
13 changes: 7 additions & 6 deletions staging/src/k8s.io/kubectl/pkg/cmd/diff/prune.go
Expand Up @@ -24,6 +24,7 @@ import (
"k8s.io/apimachinery/pkg/api/meta"
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/cli-runtime/pkg/resource"
"k8s.io/client-go/dynamic"
Expand All @@ -34,16 +35,16 @@ type pruner struct {
mapper meta.RESTMapper
dynamicClient dynamic.Interface

visitedUids sets.String
visitedNamespaces sets.String
visitedUids sets.Set[types.UID]
visitedNamespaces sets.Set[string]
labelSelector string
resources []prune.Resource
}

func newPruner(dc dynamic.Interface, m meta.RESTMapper, r []prune.Resource, selector string) *pruner {
return &pruner{
visitedUids: sets.NewString(),
visitedNamespaces: sets.NewString(),
visitedUids: sets.New[types.UID](),
visitedNamespaces: sets.New[string](),
dynamicClient: dc,
mapper: m,
resources: r,
Expand Down Expand Up @@ -104,7 +105,7 @@ func (p *pruner) prune(namespace string, mapping *meta.RESTMapping) ([]runtime.O
continue
}
uid := metadata.GetUID()
if p.visitedUids.Has(string(uid)) {
if p.visitedUids.Has(uid) {
continue
}

Expand All @@ -123,5 +124,5 @@ func (p *pruner) MarkVisited(info *resource.Info) {
if err != nil {
return
}
p.visitedUids.Insert(string(metadata.GetUID()))
p.visitedUids.Insert(metadata.GetUID())
}