Merge pull request #6586 from wallrj/check-deprecated

Replace calls to deprecated sets.String functions
This commit is contained in:
jetstack-bot 2024-01-02 18:02:40 +00:00 committed by GitHub
commit 65e78f3cef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 37 additions and 28 deletions

View File

@ -11,6 +11,7 @@ linters:
disable-all: true
enable:
- gosec
- staticcheck
issues:
# When we enable a new linter or a new issue check, we want to show **all**
# instances of each issue in the GitHub UI or in the CLI report. This allows
@ -28,3 +29,9 @@ issues:
- linters:
- gosec
text: "G(101|107|204|306|402)"
- linters:
- staticcheck
text: "SA(1002|1006|4000|4006)"
- linters:
- staticcheck
text: "(ioutil|KubeCtl|NewCertManagerBasicCertificate|DeprecatedCertificateTemplateFromCertificateRequestAndAllowInsecureCSRUsageDefinition|eab.KeyAlgorithm|testCA.Subjects|RootCAs.Subjects|pki.GenerateTemplate|adal.NewServicePrincipalTokenFromFederatedToken|azure-sdk-for-go|c.SingleInflight|x509.ParseCRL|v.client.RawRequest)"

View File

@ -28,6 +28,7 @@ import (
"golang.org/x/sync/errgroup"
"k8s.io/apimachinery/pkg/api/resource"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/leaderelection"
"k8s.io/client-go/tools/leaderelection/resourcelock"
@ -80,7 +81,7 @@ func Run(opts *config.ControllerConfiguration, stopCh <-chan struct{}) error {
}
enabledControllers := options.EnabledControllers(opts)
log.Info(fmt.Sprintf("enabled controllers: %s", enabledControllers.List()))
log.Info(fmt.Sprintf("enabled controllers: %s", sets.List(enabledControllers)))
// Start metrics server
metricsLn, err := net.Listen("tcp", opts.MetricsListenAddress)

View File

@ -210,9 +210,9 @@ func AddConfigFlags(fs *pflag.FlagSet, c *config.ControllerConfiguration) {
logf.AddFlags(&c.Logging, fs)
}
func EnabledControllers(o *config.ControllerConfiguration) sets.String {
func EnabledControllers(o *config.ControllerConfiguration) sets.Set[string] {
var disabled []string
enabled := sets.NewString()
enabled := sets.New[string]()
for _, controller := range o.Controllers {
switch {

View File

@ -31,27 +31,27 @@ import (
func TestEnabledControllers(t *testing.T) {
tests := map[string]struct {
controllers []string
expEnabled sets.String
expEnabled sets.Set[string]
}{
"if no controllers enabled, return empty": {
controllers: []string{},
expEnabled: sets.NewString(),
expEnabled: sets.New[string](),
},
"if some controllers enabled, return list": {
controllers: []string{"foo", "bar"},
expEnabled: sets.NewString("foo", "bar"),
expEnabled: sets.New[string]("foo", "bar"),
},
"if some controllers enabled, one then disabled, return list without disabled": {
controllers: []string{"foo", "bar", "-foo"},
expEnabled: sets.NewString("bar"),
expEnabled: sets.New[string]("bar"),
},
"if all default controllers enabled, return all default controllers": {
controllers: []string{"*"},
expEnabled: sets.NewString(defaults.DefaultEnabledControllers...),
expEnabled: sets.New[string](defaults.DefaultEnabledControllers...),
},
"if all controllers enabled, some diabled, return all controllers with disabled": {
controllers: []string{"*", "-clusterissuers", "-issuers"},
expEnabled: sets.NewString(defaults.DefaultEnabledControllers...).Delete("clusterissuers", "issuers"),
expEnabled: sets.New[string](defaults.DefaultEnabledControllers...).Delete("clusterissuers", "issuers"),
},
}

View File

@ -216,7 +216,7 @@ func (m *Migrator) patchCRDStoredVersions(ctx context.Context, crds []*apiext.Cu
return newUnexpectedChangeError(crd)
}
newlyAddedVersions := storedVersionsAdded(crd, freshCRD)
if newlyAddedVersions.Len() != 0 && !newlyAddedVersions.Equal(sets.NewString(expectedStorageVersion)) {
if newlyAddedVersions.Len() != 0 && !newlyAddedVersions.Equal(sets.New[string](expectedStorageVersion)) {
return newUnexpectedChangeError(crd)
}
@ -245,9 +245,9 @@ func storageVersionForCRD(crd *apiext.CustomResourceDefinition) string {
// storedVersionsAdded returns a list of any versions added to the `status.storedVersions` field on
// a CRD resource.
func storedVersionsAdded(old, new *apiext.CustomResourceDefinition) sets.String {
oldStoredVersions := sets.NewString(old.Status.StoredVersions...)
newStoredVersions := sets.NewString(new.Status.StoredVersions...)
func storedVersionsAdded(old, new *apiext.CustomResourceDefinition) sets.Set[string] {
oldStoredVersions := sets.New[string](old.Status.StoredVersions...)
newStoredVersions := sets.New[string](new.Status.StoredVersions...)
return newStoredVersions.Difference(oldStoredVersions)
}

View File

@ -39,8 +39,8 @@ func RegisterAllPlugins(plugins *admission.Plugins) {
resourcevalidation.Register(plugins)
}
func DefaultOnAdmissionPlugins() sets.String {
return sets.NewString(
func DefaultOnAdmissionPlugins() sets.Set[string] {
return sets.New[string](
apideprecation.PluginName,
resourcevalidation.PluginName,
certificaterequestidentity.PluginName,
@ -49,6 +49,6 @@ func DefaultOnAdmissionPlugins() sets.String {
}
// DefaultOffAdmissionPlugins gets admission plugins off by default for the webhook.
func DefaultOffAdmissionPlugins() sets.String {
return sets.NewString(AllOrderedPlugins...).Difference(DefaultOnAdmissionPlugins())
func DefaultOffAdmissionPlugins() sets.Set[string] {
return sets.New[string](AllOrderedPlugins...).Difference(DefaultOnAdmissionPlugins())
}

View File

@ -21,6 +21,7 @@ import (
"time"
"github.com/go-logr/logr"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apiserver/pkg/authorization/authorizerfactory"
"k8s.io/client-go/kubernetes"
@ -109,7 +110,7 @@ func buildAdmissionChain(client kubernetes.Interface) (*admission.RequestHandler
return nil, fmt.Errorf("error creating authorization handler: %v", err)
}
pluginInitializer := initializer.New(client, nil, authorizer, nil)
pluginChain, err := pluginHandler.NewFromPlugins(plugin.DefaultOnAdmissionPlugins().List(), pluginInitializer)
pluginChain, err := pluginHandler.NewFromPlugins(sets.List(plugin.DefaultOnAdmissionPlugins()), pluginInitializer)
if err != nil {
return nil, fmt.Errorf("error building admission chain: %v", err)
}

View File

@ -267,17 +267,17 @@ func (c *controller) createOrder(ctx context.Context, cl acmecl.Interface, o *cm
}
log.V(logf.DebugLevel).Info("order URL not set, submitting Order to ACME server")
dnsIdentifierSet := sets.NewString(o.Spec.DNSNames...)
dnsIdentifierSet := sets.New[string](o.Spec.DNSNames...)
if o.Spec.CommonName != "" {
dnsIdentifierSet.Insert(o.Spec.CommonName)
}
log.V(logf.DebugLevel).Info("build set of domains for Order", "domains", dnsIdentifierSet.List())
log.V(logf.DebugLevel).Info("build set of domains for Order", "domains", sets.List(dnsIdentifierSet))
ipIdentifierSet := sets.NewString(o.Spec.IPAddresses...)
log.V(logf.DebugLevel).Info("build set of IPs for Order", "domains", dnsIdentifierSet.List())
ipIdentifierSet := sets.New[string](o.Spec.IPAddresses...)
log.V(logf.DebugLevel).Info("build set of IPs for Order", "domains", sets.List(dnsIdentifierSet))
authzIDs := acmeapi.DomainIDs(dnsIdentifierSet.List()...)
authzIDs = append(authzIDs, acmeapi.IPIDs(ipIdentifierSet.List()...)...)
authzIDs := acmeapi.DomainIDs(sets.List(dnsIdentifierSet)...)
authzIDs = append(authzIDs, acmeapi.IPIDs(sets.List(ipIdentifierSet)...)...)
// create a new order with the acme server
var options []acmeapi.OrderOption

View File

@ -234,11 +234,11 @@ func SecretDataAltNamesMatchSpec(secret *corev1.Secret, spec cmapi.CertificateSp
// This check allows names to move between the DNSNames and CommonName
// field freely in order to account for CAs behaviour of promoting DNSNames
// to be CommonNames or vice-versa.
expectedDNSNames := sets.NewString(spec.DNSNames...)
expectedDNSNames := sets.New[string](spec.DNSNames...)
if spec.CommonName != "" {
expectedDNSNames.Insert(spec.CommonName)
}
allDNSNames := sets.NewString(x509cert.DNSNames...)
allDNSNames := sets.New[string](x509cert.DNSNames...)
if x509cert.Subject.CommonName != "" {
allDNSNames.Insert(x509cert.Subject.CommonName)
}

View File

@ -22,7 +22,7 @@ import (
)
type Handler struct {
operations sets.String
operations sets.Set[string]
}
func (h Handler) Handles(operation admissionv1.Operation) bool {
@ -32,7 +32,7 @@ func (h Handler) Handles(operation admissionv1.Operation) bool {
var _ Interface = &Handler{}
func NewHandler(ops ...admissionv1.Operation) *Handler {
operations := sets.NewString()
operations := sets.New[string]()
for _, op := range ops {
operations.Insert(string(op))
}