Skip to content

Commit

Permalink
Merge pull request #8004 from sbueringer/pr-replace-string-set
Browse files Browse the repository at this point in the history
🌱 Replace deprecated string set through generic set
  • Loading branch information
k8s-ci-robot committed Jan 26, 2023
2 parents ded5e65 + 00eefa3 commit 2961840
Show file tree
Hide file tree
Showing 31 changed files with 82 additions and 86 deletions.
4 changes: 0 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,6 @@ issues:
- staticcheck
text: "SA1019: in.(.+) is deprecated"
path: .*(api|types)\/.*\/conversion.*\.go$
- linters:
- staticcheck
text: "SA1019: sets.String is deprecated"
path: .*(cmd|controllers|controlplane|internal)\/.*\.go$
- linters:
- revive
# Checking if an error is nil to just after return the error or nil is redundant
Expand Down
2 changes: 1 addition & 1 deletion cmd/clusterctl/client/cluster/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (p *providerComponents) Delete(options DeleteOptions) error {

// Filter the resources according to the delete options
resourcesToDelete := []unstructured.Unstructured{}
namespacesToDelete := sets.NewString()
namespacesToDelete := sets.Set[string]{}
instanceNamespacePrefix := fmt.Sprintf("%s-", options.Provider.Namespace)
for _, obj := range resources {
// If the CRDs should NOT be deleted, skip it;
Expand Down
8 changes: 4 additions & 4 deletions cmd/clusterctl/client/cluster/crd_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (m *crdMigrator) run(ctx context.Context, newCRD *apiextensionsv1.CustomRes
log := logf.Log

// Gets the list of version supported by the new CRD
newVersions := sets.NewString()
newVersions := sets.Set[string]{}
for _, version := range newCRD.Spec.Versions {
newVersions.Insert(version.Name)
}
Expand Down Expand Up @@ -105,11 +105,11 @@ func (m *crdMigrator) run(ctx context.Context, newCRD *apiextensionsv1.CustomRes
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)
}

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

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

if err := m.migrateResourcesForCRD(ctx, currentCRD, currentStorageVersion); err != nil {
return false, err
Expand Down
4 changes: 2 additions & 2 deletions cmd/clusterctl/client/cluster/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,11 @@ func simulateInstall(providerList *clusterctlv1.ProviderList, components reposit
}

func (i *providerInstaller) Images() []string {
ret := sets.NewString()
ret := sets.Set[string]{}
for _, components := range i.installQueue {
ret = ret.Insert(components.Images()...)
}
return ret.List()
return sets.List(ret)
}

func newProviderInstaller(configClient config.Client, repositoryClientFactory RepositoryClientFactory, proxy Proxy, providerMetadata InventoryClient, providerComponents ComponentsClient) *providerInstaller {
Expand Down
12 changes: 6 additions & 6 deletions cmd/clusterctl/client/cluster/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,14 @@ func (p *inventoryClient) GetDefaultProviderName(providerType clusterctlv1.Provi
}

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

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

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

// Group the provider instances by version.
versions := sets.NewString()
versions := sets.Set[string]{}
for _, p := range providerList.FilterByProviderNameAndType(provider, providerType) {
versions.Insert(p.Version)
}

if versions.Len() == 1 {
return versions.List()[0], nil
return sets.List(versions)[0], nil
}

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

// Group the providers by namespace
namespaces := sets.NewString()
namespaces := sets.Set[string]{}
for _, p := range providerList.FilterByProviderNameAndType(provider, providerType) {
namespaces.Insert(p.Namespace)
}

if namespaces.Len() == 1 {
return namespaces.List()[0], nil
return sets.List(namespaces)[0], nil
}

// The default provider namespace cannot be decided.
Expand Down
2 changes: 1 addition & 1 deletion cmd/clusterctl/client/cluster/mover.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ func (o *objectMover) ensureNamespaces(graph *objectGraph, toProxy Proxy) error
}

ensureNamespaceBackoff := newWriteBackoff()
namespaces := sets.NewString()
namespaces := sets.Set[string]{}
for _, node := range graph.getMoveNodes() {
// ignore global/cluster-wide objects
if node.isGlobal {
Expand Down
2 changes: 1 addition & 1 deletion cmd/clusterctl/client/cluster/objectgraph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2337,7 +2337,7 @@ func Test_objectGraph_setGlobalIdentityTenants(t *testing.T) {

func deduplicateObjects(objs []client.Object) []client.Object {
res := []client.Object{}
uniqueObjectKeys := sets.NewString()
uniqueObjectKeys := sets.Set[string]{}
for _, o := range objs {
if !uniqueObjectKeys.Has(string(o.GetUID())) {
res = append(res, o)
Expand Down
2 changes: 1 addition & 1 deletion cmd/clusterctl/client/cluster/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (k *proxy) ListResources(labels map[string]string, namespaces ...string) ([

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

crdList := &apiextensionsv1.CustomResourceDefinitionList{}
if err := retryWithExponentialBackoff(newReadBackoff(), func() error {
Expand Down
4 changes: 2 additions & 2 deletions cmd/clusterctl/client/cluster/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ func clusterClassUsesTemplate(cc *clusterv1.ClusterClass, templateRef *corev1.Ob
}

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

func hasUniqueVersionPerGroupKind(objs []*unstructured.Unstructured) bool {
Expand Down
2 changes: 1 addition & 1 deletion cmd/clusterctl/client/cluster/upgrader.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func (u *providerUpgrader) createCustomPlan(upgradeItems []UpgradeItem) (*Upgrad
}

// Builds the custom upgrade plan, by adding all the upgrade items after checking consistency with the targetContract.
upgradeInstanceNames := sets.NewString()
upgradeInstanceNames := sets.Set[string]{}
upgradePlan := &UpgradePlan{
Contract: targetContract,
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/clusterctl/client/cluster/upgrader_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func newUpgradeInfo(metadata *clusterctlv1.Metadata, currentVersion *version.Ver

// getContractsForUpgrade return the list of API Version of Cluster API (contract) version available for a provider upgrade.
func (i *upgradeInfo) getContractsForUpgrade() []string {
contractsForUpgrade := sets.NewString()
contractsForUpgrade := sets.Set[string]{}
for _, releaseSeries := range i.metadata.ReleaseSeries {
// Drop the release series if older than the current version, because not relevant for upgrade.
if i.currentVersion.Major() > releaseSeries.Major || (i.currentVersion.Major() == releaseSeries.Major && i.currentVersion.Minor() > releaseSeries.Minor) {
Expand All @@ -158,7 +158,7 @@ func (i *upgradeInfo) getContractsForUpgrade() []string {
contractsForUpgrade.Insert(releaseSeries.Contract)
}

return contractsForUpgrade.List()
return sets.List(contractsForUpgrade)
}

// getLatestNextVersion returns the next available version for a provider within the target API Version of Cluster API (contract).
Expand Down
14 changes: 7 additions & 7 deletions cmd/clusterctl/client/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func Test_clusterctlClient_Delete(t *testing.T) {
name string
fields fields
args args
wantProviders sets.String
wantProviders sets.Set[string]
wantErr bool
}{
{
Expand All @@ -63,7 +63,7 @@ func Test_clusterctlClient_Delete(t *testing.T) {
DeleteAll: true, // delete all the providers
},
},
wantProviders: sets.NewString(),
wantProviders: sets.Set[string]{},
wantErr: false,
},
{
Expand All @@ -84,7 +84,7 @@ func Test_clusterctlClient_Delete(t *testing.T) {
DeleteAll: false,
},
},
wantProviders: sets.NewString(
wantProviders: sets.Set[string]{}.Insert(
capiProviderConfig.Name(),
clusterctlv1.ManifestLabel(controlPlaneProviderConfig.Name(), controlPlaneProviderConfig.Type()),
clusterctlv1.ManifestLabel(infraProviderConfig.Name(), infraProviderConfig.Type())),
Expand All @@ -108,7 +108,7 @@ func Test_clusterctlClient_Delete(t *testing.T) {
DeleteAll: false,
},
},
wantProviders: sets.NewString(
wantProviders: sets.Set[string]{}.Insert(
capiProviderConfig.Name(),
clusterctlv1.ManifestLabel(bootstrapProviderConfig.Name(), bootstrapProviderConfig.Type()),
clusterctlv1.ManifestLabel(controlPlaneProviderConfig.Name(), controlPlaneProviderConfig.Type())),
Expand All @@ -132,7 +132,7 @@ func Test_clusterctlClient_Delete(t *testing.T) {
DeleteAll: false,
},
},
wantProviders: sets.NewString(
wantProviders: sets.Set[string]{}.Insert(
capiProviderConfig.Name(),
clusterctlv1.ManifestLabel(bootstrapProviderConfig.Name(), bootstrapProviderConfig.Type()),
clusterctlv1.ManifestLabel(controlPlaneProviderConfig.Name(), controlPlaneProviderConfig.Type()),
Expand All @@ -157,7 +157,7 @@ func Test_clusterctlClient_Delete(t *testing.T) {
DeleteAll: false,
},
},
wantProviders: sets.NewString(
wantProviders: sets.Set[string]{}.Insert(
clusterctlv1.ManifestLabel(controlPlaneProviderConfig.Name(), controlPlaneProviderConfig.Type()),
clusterctlv1.ManifestLabel(infraProviderConfig.Name(), infraProviderConfig.Type())),
wantErr: false,
Expand All @@ -182,7 +182,7 @@ func Test_clusterctlClient_Delete(t *testing.T) {
g.Expect(err).NotTo(HaveOccurred())
g.Expect(c.List(ctx, gotProviders)).To(Succeed())

gotProvidersSet := sets.NewString()
gotProvidersSet := sets.Set[string]{}
for _, gotProvider := range gotProviders.Items {
gotProvidersSet.Insert(gotProvider.Name)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/clusterctl/client/repository/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func MergeTemplates(templates ...Template) (Template, error) {
}

for _, tmpl := range templates {
merged.variables = sets.NewString(merged.variables...).Union(sets.NewString(tmpl.Variables()...)).List()
merged.variables = sets.List(sets.Set[string]{}.Insert(merged.variables...).Union(sets.Set[string]{}.Insert(tmpl.Variables()...)))

for key, val := range tmpl.VariableMap() {
if v, ok := merged.variableMap[key]; !ok || v == nil {
Expand Down
4 changes: 2 additions & 2 deletions controllers/remote/cluster_cache_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (t *ClusterCacheTracker) GetRESTConfig(ctc context.Context, cluster client.
type clusterAccessor struct {
cache *stoppableCache
client client.Client
watches sets.String
watches sets.Set[string]
config *rest.Config
}

Expand Down Expand Up @@ -338,7 +338,7 @@ func (t *ClusterCacheTracker) newClusterAccessor(ctx context.Context, cluster cl
cache: cache,
config: config,
client: delegatingClient,
watches: sets.NewString(),
watches: sets.Set[string]{},
}, nil
}

Expand Down
3 changes: 1 addition & 2 deletions controllers/remote/cluster_cache_tracker_fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ func NewTestClusterCacheTracker(log logr.Logger, cl client.Client, scheme *runti
}

testCacheTracker.clusterAccessors[objKey] = &clusterAccessor{

cache: nil,
client: delegatingClient,
watches: sets.NewString(watchObjects...),
watches: sets.Set[string]{}.Insert(watchObjects...),
}
return testCacheTracker
}
4 changes: 2 additions & 2 deletions controlplane/kubeadm/internal/etcd/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func MemberNames(members []*etcd.Member) []string {
// This function only checks that set of names of each member
// within the lists is the same.
func MemberEqual(members1, members2 []*etcd.Member) bool {
names1 := sets.NewString(MemberNames(members1)...)
names2 := sets.NewString(MemberNames(members2)...)
names1 := sets.Set[string]{}.Insert(MemberNames(members1)...)
names2 := sets.Set[string]{}.Insert(MemberNames(members2)...)
return names1.Equal(names2)
}
4 changes: 2 additions & 2 deletions controlplane/kubeadm/internal/etcd_client_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (c *EtcdClientGenerator) forLeader(ctx context.Context, nodeNames []string)
return nil, errors.New("invalid argument: forLeader can't be called with an empty list of nodes")
}

nodes := sets.NewString()
nodes := sets.Set[string]{}
for _, n := range nodeNames {
nodes.Insert(n)
}
Expand All @@ -118,7 +118,7 @@ func (c *EtcdClientGenerator) forLeader(ctx context.Context, nodeNames []string)
// getLeaderClient provides an etcd client connected to the leader. It returns an
// errEtcdNodeConnection if there was a connection problem with the given etcd
// node, which should be considered non-fatal by the caller.
func (c *EtcdClientGenerator) getLeaderClient(ctx context.Context, nodeName string, allNodes sets.String) (*etcd.Client, error) {
func (c *EtcdClientGenerator) getLeaderClient(ctx context.Context, nodeName string, allNodes sets.Set[string]) (*etcd.Client, error) {
// Get a temporary client to the etcd instance hosted on the node.
client, err := c.forFirstAvailableNode(ctx, []string{nodeName})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion controlplane/kubeadm/internal/workload_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ var _ WorkloadCluster = &Workload{}

func (w *Workload) getControlPlaneNodes(ctx context.Context) (*corev1.NodeList, error) {
controlPlaneNodes := &corev1.NodeList{}
controlPlaneNodeNames := sets.NewString()
controlPlaneNodeNames := sets.Set[string]{}

for _, label := range []string{labelNodeRoleOldControlPlane, labelNodeRoleControlPlane} {
nodes := &corev1.NodeList{}
Expand Down
18 changes: 9 additions & 9 deletions controlplane/kubeadm/internal/workload_cluster_conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,11 +514,11 @@ type aggregateFromMachinesToKCPInput struct {
func aggregateFromMachinesToKCP(input aggregateFromMachinesToKCPInput) {
// Aggregates machines for condition status.
// NB. A machine could be assigned to many groups, but only the group with the highest severity will be reported.
kcpMachinesWithErrors := sets.NewString()
kcpMachinesWithWarnings := sets.NewString()
kcpMachinesWithInfo := sets.NewString()
kcpMachinesWithTrue := sets.NewString()
kcpMachinesWithUnknown := sets.NewString()
kcpMachinesWithErrors := sets.Set[string]{}
kcpMachinesWithWarnings := sets.Set[string]{}
kcpMachinesWithInfo := sets.Set[string]{}
kcpMachinesWithTrue := sets.Set[string]{}
kcpMachinesWithUnknown := sets.Set[string]{}

for i := range input.controlPlane.Machines {
machine := input.controlPlane.Machines[i]
Expand All @@ -545,7 +545,7 @@ func aggregateFromMachinesToKCP(input aggregateFromMachinesToKCPInput) {

// In case of at least one machine with errors or KCP level errors (nodes without machines), report false, error.
if len(kcpMachinesWithErrors) > 0 {
input.kcpErrors = append(input.kcpErrors, fmt.Sprintf("Following machines are reporting %s errors: %s", input.note, strings.Join(kcpMachinesWithErrors.List(), ", ")))
input.kcpErrors = append(input.kcpErrors, fmt.Sprintf("Following machines are reporting %s errors: %s", input.note, strings.Join(sets.List(kcpMachinesWithErrors), ", ")))
}
if len(input.kcpErrors) > 0 {
conditions.MarkFalse(input.controlPlane.KCP, input.condition, input.unhealthyReason, clusterv1.ConditionSeverityError, strings.Join(input.kcpErrors, "; "))
Expand All @@ -554,13 +554,13 @@ func aggregateFromMachinesToKCP(input aggregateFromMachinesToKCPInput) {

// In case of no errors and at least one machine with warnings, report false, warnings.
if len(kcpMachinesWithWarnings) > 0 {
conditions.MarkFalse(input.controlPlane.KCP, input.condition, input.unhealthyReason, clusterv1.ConditionSeverityWarning, "Following machines are reporting %s warnings: %s", input.note, strings.Join(kcpMachinesWithWarnings.List(), ", "))
conditions.MarkFalse(input.controlPlane.KCP, input.condition, input.unhealthyReason, clusterv1.ConditionSeverityWarning, "Following machines are reporting %s warnings: %s", input.note, strings.Join(sets.List(kcpMachinesWithWarnings), ", "))
return
}

// In case of no errors, no warning, and at least one machine with info, report false, info.
if len(kcpMachinesWithWarnings) > 0 {
conditions.MarkFalse(input.controlPlane.KCP, input.condition, input.unhealthyReason, clusterv1.ConditionSeverityWarning, "Following machines are reporting %s info: %s", input.note, strings.Join(kcpMachinesWithInfo.List(), ", "))
conditions.MarkFalse(input.controlPlane.KCP, input.condition, input.unhealthyReason, clusterv1.ConditionSeverityWarning, "Following machines are reporting %s info: %s", input.note, strings.Join(sets.List(kcpMachinesWithInfo), ", "))
return
}

Expand All @@ -572,7 +572,7 @@ func aggregateFromMachinesToKCP(input aggregateFromMachinesToKCPInput) {

// Otherwise, if there is at least one machine with unknown, report unknown.
if len(kcpMachinesWithUnknown) > 0 {
conditions.MarkUnknown(input.controlPlane.KCP, input.condition, input.unknownReason, "Following machines are reporting unknown %s status: %s", input.note, strings.Join(kcpMachinesWithUnknown.List(), ", "))
conditions.MarkUnknown(input.controlPlane.KCP, input.condition, input.unknownReason, "Following machines are reporting unknown %s status: %s", input.note, strings.Join(sets.List(kcpMachinesWithUnknown), ", "))
return
}

Expand Down
2 changes: 1 addition & 1 deletion hack/tools/tilt-prepare/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func allowK8sConfig(ts *tiltSettings) error {
return nil
}

allowed := sets.NewString(ts.AllowedContexts...)
allowed := sets.Set[string]{}.Insert(ts.AllowedContexts...)
if !allowed.Has(config.CurrentContext) {
return errors.Errorf("context %s from the KubeConfig file is not allowed", config.CurrentContext)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (r *Reconciler) reconcile(ctx context.Context, clusterClass *clusterv1.Clus
// For example the same KubeadmConfigTemplate could be referenced in multiple MachineDeployment
// classes.
errs := []error{}
reconciledRefs := sets.NewString()
reconciledRefs := sets.Set[string]{}
outdatedRefs := map[*corev1.ObjectReference]*corev1.ObjectReference{}
for i := range refs {
ref := refs[i]
Expand Down
Loading

0 comments on commit 2961840

Please sign in to comment.