Skip to content

Commit 2961840

Browse files
authored
Merge pull request #8004 from sbueringer/pr-replace-string-set
🌱 Replace deprecated string set through generic set
2 parents ded5e65 + 00eefa3 commit 2961840

31 files changed

+82
-86
lines changed

.golangci.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,6 @@ issues:
268268
- staticcheck
269269
text: "SA1019: in.(.+) is deprecated"
270270
path: .*(api|types)\/.*\/conversion.*\.go$
271-
- linters:
272-
- staticcheck
273-
text: "SA1019: sets.String is deprecated"
274-
path: .*(cmd|controllers|controlplane|internal)\/.*\.go$
275271
- linters:
276272
- revive
277273
# Checking if an error is nil to just after return the error or nil is redundant

cmd/clusterctl/client/cluster/components.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func (p *providerComponents) Delete(options DeleteOptions) error {
146146

147147
// Filter the resources according to the delete options
148148
resourcesToDelete := []unstructured.Unstructured{}
149-
namespacesToDelete := sets.NewString()
149+
namespacesToDelete := sets.Set[string]{}
150150
instanceNamespacePrefix := fmt.Sprintf("%s-", options.Provider.Namespace)
151151
for _, obj := range resources {
152152
// If the CRDs should NOT be deleted, skip it;

cmd/clusterctl/client/cluster/crd_migration.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (m *crdMigrator) run(ctx context.Context, newCRD *apiextensionsv1.CustomRes
7777
log := logf.Log
7878

7979
// Gets the list of version supported by the new CRD
80-
newVersions := sets.NewString()
80+
newVersions := sets.Set[string]{}
8181
for _, version := range newCRD.Spec.Versions {
8282
newVersions.Insert(version.Name)
8383
}
@@ -105,11 +105,11 @@ func (m *crdMigrator) run(ctx context.Context, newCRD *apiextensionsv1.CustomRes
105105
return false, errors.Errorf("unable to upgrade CRD %q because the new CRD does not contain the storage version %q of the current CRD, thus not allowing CR migration", newCRD.Name, currentStorageVersion)
106106
}
107107

108-
currentStatusStoredVersions := sets.NewString(currentCRD.Status.StoredVersions...)
108+
currentStatusStoredVersions := sets.Set[string]{}.Insert(currentCRD.Status.StoredVersions...)
109109

110110
// If the new CRD still contains all current stored versions, nothing to do
111111
// as no previous storage version will be dropped.
112-
if newVersions.HasAll(currentStatusStoredVersions.List()...) {
112+
if newVersions.HasAll(currentStatusStoredVersions.UnsortedList()...) {
113113
log.V(2).Info("CRD migration check passed", "name", newCRD.Name)
114114
return false, nil
115115
}
@@ -123,7 +123,7 @@ func (m *crdMigrator) run(ctx context.Context, newCRD *apiextensionsv1.CustomRes
123123
// exposed by the apiserver.
124124
storedVersionsToDelete := currentStatusStoredVersions.Difference(newVersions)
125125
storedVersionsToPreserve := currentStatusStoredVersions.Intersection(newVersions)
126-
log.Info("CR migration required", "kind", newCRD.Spec.Names.Kind, "storedVersionsToDelete", strings.Join(storedVersionsToDelete.List(), ","), "storedVersionsToPreserve", strings.Join(storedVersionsToPreserve.List(), ","))
126+
log.Info("CR migration required", "kind", newCRD.Spec.Names.Kind, "storedVersionsToDelete", strings.Join(sets.List(storedVersionsToDelete), ","), "storedVersionsToPreserve", strings.Join(sets.List(storedVersionsToPreserve), ","))
127127

128128
if err := m.migrateResourcesForCRD(ctx, currentCRD, currentStorageVersion); err != nil {
129129
return false, err

cmd/clusterctl/client/cluster/installer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,11 @@ func simulateInstall(providerList *clusterctlv1.ProviderList, components reposit
350350
}
351351

352352
func (i *providerInstaller) Images() []string {
353-
ret := sets.NewString()
353+
ret := sets.Set[string]{}
354354
for _, components := range i.installQueue {
355355
ret = ret.Insert(components.Images()...)
356356
}
357-
return ret.List()
357+
return sets.List(ret)
358358
}
359359

360360
func newProviderInstaller(configClient config.Client, repositoryClientFactory RepositoryClientFactory, proxy Proxy, providerMetadata InventoryClient, providerComponents ComponentsClient) *providerInstaller {

cmd/clusterctl/client/cluster/inventory.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -338,14 +338,14 @@ func (p *inventoryClient) GetDefaultProviderName(providerType clusterctlv1.Provi
338338
}
339339

340340
// Group the providers by name, because we consider more instance of the same provider not relevant for the answer.
341-
names := sets.NewString()
341+
names := sets.Set[string]{}
342342
for _, p := range providerList.FilterByType(providerType) {
343343
names.Insert(p.ProviderName)
344344
}
345345

346346
// If there is only one provider, this is the default
347347
if names.Len() == 1 {
348-
return names.List()[0], nil
348+
return sets.List(names)[0], nil
349349
}
350350

351351
// There is no provider or more than one provider of this type; in both cases, a default provider name cannot be decided.
@@ -359,13 +359,13 @@ func (p *inventoryClient) GetProviderVersion(provider string, providerType clust
359359
}
360360

361361
// Group the provider instances by version.
362-
versions := sets.NewString()
362+
versions := sets.Set[string]{}
363363
for _, p := range providerList.FilterByProviderNameAndType(provider, providerType) {
364364
versions.Insert(p.Version)
365365
}
366366

367367
if versions.Len() == 1 {
368-
return versions.List()[0], nil
368+
return sets.List(versions)[0], nil
369369
}
370370

371371
// The default version for this provider cannot be decided.
@@ -379,13 +379,13 @@ func (p *inventoryClient) GetProviderNamespace(provider string, providerType clu
379379
}
380380

381381
// Group the providers by namespace
382-
namespaces := sets.NewString()
382+
namespaces := sets.Set[string]{}
383383
for _, p := range providerList.FilterByProviderNameAndType(provider, providerType) {
384384
namespaces.Insert(p.Namespace)
385385
}
386386

387387
if namespaces.Len() == 1 {
388-
return namespaces.List()[0], nil
388+
return sets.List(namespaces)[0], nil
389389
}
390390

391391
// The default provider namespace cannot be decided.

cmd/clusterctl/client/cluster/mover.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ func (o *objectMover) ensureNamespaces(graph *objectGraph, toProxy Proxy) error
669669
}
670670

671671
ensureNamespaceBackoff := newWriteBackoff()
672-
namespaces := sets.NewString()
672+
namespaces := sets.Set[string]{}
673673
for _, node := range graph.getMoveNodes() {
674674
// ignore global/cluster-wide objects
675675
if node.isGlobal {

cmd/clusterctl/client/cluster/objectgraph_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2337,7 +2337,7 @@ func Test_objectGraph_setGlobalIdentityTenants(t *testing.T) {
23372337

23382338
func deduplicateObjects(objs []client.Object) []client.Object {
23392339
res := []client.Object{}
2340-
uniqueObjectKeys := sets.NewString()
2340+
uniqueObjectKeys := sets.Set[string]{}
23412341
for _, o := range objs {
23422342
if !uniqueObjectKeys.Has(string(o.GetUID())) {
23432343
res = append(res, o)

cmd/clusterctl/client/cluster/proxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func (k *proxy) ListResources(labels map[string]string, namespaces ...string) ([
232232

233233
// Exclude from discovery the objects from the cert-manager/provider's CRDs.
234234
// Those objects are not part of the components, and they will eventually be removed when removing the CRD definition.
235-
crdsToExclude := sets.String{}
235+
crdsToExclude := sets.Set[string]{}
236236

237237
crdList := &apiextensionsv1.CustomResourceDefinitionList{}
238238
if err := retryWithExponentialBackoff(newReadBackoff(), func() error {

cmd/clusterctl/client/cluster/topology.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ func clusterClassUsesTemplate(cc *clusterv1.ClusterClass, templateRef *corev1.Ob
692692
}
693693

694694
func uniqueNamespaces(objs []*unstructured.Unstructured) []string {
695-
ns := sets.NewString()
695+
ns := sets.Set[string]{}
696696
for _, obj := range objs {
697697
// Namespace objects do not have metadata.namespace set, but we can add the
698698
// name of the obj to the namespace list, as it is another unique namespace.
@@ -707,7 +707,7 @@ func uniqueNamespaces(objs []*unstructured.Unstructured) []string {
707707
// objects from different namespaces.
708708
ns.Insert(obj.GetNamespace())
709709
}
710-
return ns.List()
710+
return sets.List(ns)
711711
}
712712

713713
func hasUniqueVersionPerGroupKind(objs []*unstructured.Unstructured) bool {

cmd/clusterctl/client/cluster/upgrader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func (u *providerUpgrader) createCustomPlan(upgradeItems []UpgradeItem) (*Upgrad
257257
}
258258

259259
// Builds the custom upgrade plan, by adding all the upgrade items after checking consistency with the targetContract.
260-
upgradeInstanceNames := sets.NewString()
260+
upgradeInstanceNames := sets.Set[string]{}
261261
upgradePlan := &UpgradePlan{
262262
Contract: targetContract,
263263
}

0 commit comments

Comments
 (0)