Remove internal/psets in favor of k8s.io/apimachinery/pkg/util/sets
This commit is contained in:
parent
0d4a4fd2bf
commit
24cf7c5bcd
@ -12,12 +12,13 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
|
|
||||||
concierge "go.pinniped.dev/internal/concierge/server"
|
concierge "go.pinniped.dev/internal/concierge/server"
|
||||||
// this side effect import ensures that we use fipsonly crypto in fips_strict mode.
|
// this side effect import ensures that we use fipsonly crypto in fips_strict mode.
|
||||||
_ "go.pinniped.dev/internal/crypto/ptls"
|
_ "go.pinniped.dev/internal/crypto/ptls"
|
||||||
lua "go.pinniped.dev/internal/localuserauthenticator"
|
lua "go.pinniped.dev/internal/localuserauthenticator"
|
||||||
"go.pinniped.dev/internal/plog"
|
"go.pinniped.dev/internal/plog"
|
||||||
"go.pinniped.dev/internal/psets"
|
|
||||||
supervisor "go.pinniped.dev/internal/supervisor/server"
|
supervisor "go.pinniped.dev/internal/supervisor/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -37,7 +38,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
binary := filepath.Base(os.Args[0])
|
binary := filepath.Base(os.Args[0])
|
||||||
if subcommands[binary] == nil {
|
if subcommands[binary] == nil {
|
||||||
fail(fmt.Errorf("must be invoked as one of %v, not %q", psets.StringKeySet(subcommands).List(), binary))
|
fail(fmt.Errorf("must be invoked as one of %v, not %q", sets.StringKeySet(subcommands).List(), binary))
|
||||||
}
|
}
|
||||||
subcommands[binary]()
|
subcommands[binary]()
|
||||||
}
|
}
|
||||||
|
@ -1,70 +0,0 @@
|
|||||||
// Copyright 2023 the Pinniped contributors. All Rights Reserved.
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
package psets
|
|
||||||
|
|
||||||
import (
|
|
||||||
"reflect"
|
|
||||||
"sort"
|
|
||||||
)
|
|
||||||
|
|
||||||
// These were copied from https://github.com/kubernetes/kubernetes/tree/v1.25.5/staging/src/k8s.io/apimachinery/pkg/util/sets
|
|
||||||
// which is the last version before they were converted to generic functions which require the use
|
|
||||||
// of Go 1.18+ to compile. This is not a full copy of the files from k/k, but rather only copies of the
|
|
||||||
// functions that we actually use. When we are ready to require the use of Go 1.18+ to compile Pinniped,
|
|
||||||
// then we can go back to using the version of this package from the k8s libraries. Our use
|
|
||||||
// of this package was very minimal, so its easy enough to just copy the few functions that we were
|
|
||||||
// actually using to keep Go 1.17 compatibility a little longer.
|
|
||||||
|
|
||||||
// Empty is public since it is used by some internal API objects for conversions between external
|
|
||||||
// string arrays and internal sets, and conversion logic requires public types today.
|
|
||||||
type Empty struct{}
|
|
||||||
|
|
||||||
// sets.String is a set of strings, implemented via map[string]struct{} for minimal memory consumption.
|
|
||||||
type String map[string]Empty
|
|
||||||
|
|
||||||
// StringKeySet creates a String from a keys of a map[string](? extends interface{}).
|
|
||||||
// If the value passed in is not actually a map, this will panic.
|
|
||||||
func StringKeySet(theMap interface{}) String {
|
|
||||||
v := reflect.ValueOf(theMap)
|
|
||||||
ret := String{}
|
|
||||||
|
|
||||||
for _, keyValue := range v.MapKeys() {
|
|
||||||
ret.Insert(keyValue.Interface().(string))
|
|
||||||
}
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
// Insert adds items to the set.
|
|
||||||
func (s String) Insert(items ...string) String {
|
|
||||||
for _, item := range items {
|
|
||||||
s[item] = Empty{}
|
|
||||||
}
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// Has returns true if and only if item is contained in the set.
|
|
||||||
func (s String) Has(item string) bool {
|
|
||||||
_, contained := s[item]
|
|
||||||
return contained
|
|
||||||
}
|
|
||||||
|
|
||||||
type sortableSliceOfString []string
|
|
||||||
|
|
||||||
func (s sortableSliceOfString) Len() int { return len(s) }
|
|
||||||
func (s sortableSliceOfString) Less(i, j int) bool { return lessString(s[i], s[j]) }
|
|
||||||
func (s sortableSliceOfString) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
|
||||||
|
|
||||||
// List returns the contents as a sorted string slice.
|
|
||||||
func (s String) List() []string {
|
|
||||||
res := make(sortableSliceOfString, 0, len(s))
|
|
||||||
for key := range s {
|
|
||||||
res = append(res, key)
|
|
||||||
}
|
|
||||||
sort.Sort(res)
|
|
||||||
return []string(res)
|
|
||||||
}
|
|
||||||
|
|
||||||
func lessString(lhs, rhs string) bool {
|
|
||||||
return lhs < rhs
|
|
||||||
}
|
|
@ -18,12 +18,12 @@ import (
|
|||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
|
|
||||||
oidcapi "go.pinniped.dev/generated/latest/apis/supervisor/oidc"
|
oidcapi "go.pinniped.dev/generated/latest/apis/supervisor/oidc"
|
||||||
"go.pinniped.dev/internal/httputil/httperr"
|
"go.pinniped.dev/internal/httputil/httperr"
|
||||||
"go.pinniped.dev/internal/oidc/provider"
|
"go.pinniped.dev/internal/oidc/provider"
|
||||||
"go.pinniped.dev/internal/plog"
|
"go.pinniped.dev/internal/plog"
|
||||||
"go.pinniped.dev/internal/psets"
|
|
||||||
"go.pinniped.dev/pkg/oidcclient/nonce"
|
"go.pinniped.dev/pkg/oidcclient/nonce"
|
||||||
"go.pinniped.dev/pkg/oidcclient/oidctypes"
|
"go.pinniped.dev/pkg/oidcclient/oidctypes"
|
||||||
"go.pinniped.dev/pkg/oidcclient/pkce"
|
"go.pinniped.dev/pkg/oidcclient/pkce"
|
||||||
@ -421,7 +421,7 @@ func maybeLogClaims(msg, name string, claims map[string]interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if plog.Enabled(plog.LevelDebug) { // log keys at debug level
|
if plog.Enabled(plog.LevelDebug) { // log keys at debug level
|
||||||
keys := psets.StringKeySet(claims).List() // note: this is only safe because the compiler asserts that claims is a map[string]<anything>
|
keys := sets.StringKeySet(claims).List() // note: this is only safe because the compiler asserts that claims is a map[string]<anything>
|
||||||
plog.Debug(msg, "providerName", name, "keys", keys)
|
plog.Debug(msg, "providerName", name, "keys", keys)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -17,13 +17,13 @@ import (
|
|||||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/util/rand"
|
"k8s.io/apimachinery/pkg/util/rand"
|
||||||
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
"k8s.io/client-go/util/retry"
|
"k8s.io/client-go/util/retry"
|
||||||
"k8s.io/utils/pointer"
|
"k8s.io/utils/pointer"
|
||||||
|
|
||||||
"go.pinniped.dev/internal/downward"
|
"go.pinniped.dev/internal/downward"
|
||||||
"go.pinniped.dev/internal/kubeclient"
|
"go.pinniped.dev/internal/kubeclient"
|
||||||
"go.pinniped.dev/internal/leaderelection"
|
"go.pinniped.dev/internal/leaderelection"
|
||||||
"go.pinniped.dev/internal/psets"
|
|
||||||
"go.pinniped.dev/test/testlib"
|
"go.pinniped.dev/test/testlib"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -175,7 +175,7 @@ func leaderElectionClients(t *testing.T, namespace *corev1.Namespace, leaseName
|
|||||||
clients[identity], cancels[identity] = leaderElectionClient(t, namespace, leaseName, identity)
|
clients[identity], cancels[identity] = leaderElectionClient(t, namespace, leaseName, identity)
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Logf("running leader election client tests with %d clients: %v", len(clients), psets.StringKeySet(clients).List())
|
t.Logf("running leader election client tests with %d clients: %v", len(clients), sets.StringKeySet(clients).List())
|
||||||
|
|
||||||
return clients, cancels
|
return clients, cancels
|
||||||
}
|
}
|
||||||
@ -191,7 +191,7 @@ func pickRandomLeaderElectionClient(clients map[string]*kubeclient.Client) *kube
|
|||||||
func waitForIdentity(ctx context.Context, t *testing.T, namespace *corev1.Namespace, leaseName string, clients map[string]*kubeclient.Client) *coordinationv1.Lease {
|
func waitForIdentity(ctx context.Context, t *testing.T, namespace *corev1.Namespace, leaseName string, clients map[string]*kubeclient.Client) *coordinationv1.Lease {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
identities := psets.StringKeySet(clients)
|
identities := sets.StringKeySet(clients)
|
||||||
var out *coordinationv1.Lease
|
var out *coordinationv1.Lease
|
||||||
|
|
||||||
testlib.RequireEventuallyWithoutError(t, func() (bool, error) {
|
testlib.RequireEventuallyWithoutError(t, func() (bool, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user