Skip to content

Commit

Permalink
replace k8s/openapi/util/sets with k8s.io/apimachinery/pkg/util/sets (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 committed Jun 5, 2023
1 parent dba3765 commit 942e5b7
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 185 deletions.
43 changes: 26 additions & 17 deletions cmd/network.go
Expand Up @@ -12,7 +12,8 @@ import (
"github.com/metal-stack/metalctl/cmd/sorters"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"k8s.io/kube-openapi/pkg/util/sets"
"golang.org/x/exp/slices"
"k8s.io/apimachinery/pkg/util/sets"
)

type networkCmd struct {
Expand Down Expand Up @@ -361,48 +362,56 @@ func (c *networkCmd) updateRequestFromCLI(args []string) (*models.V1NetworkUpdat
Prefixes: nil,
Shared: shared,
}
addPrefixes = sets.NewString(viper.GetStringSlice("add-prefixes")...)
removePrefixes = sets.NewString(viper.GetStringSlice("remove-prefixes")...)
addDestinationprefixes = sets.NewString(viper.GetStringSlice("add-destinationprefixes")...)
removeDestinationprefixes = sets.NewString(viper.GetStringSlice("remove-destinationprefixes")...)
currentPrefixes = sets.NewString(resp.Prefixes...)
currentDestinationprefixes = sets.NewString(resp.Destinationprefixes...)
addPrefixes = sets.New(viper.GetStringSlice("add-prefixes")...)
removePrefixes = sets.New(viper.GetStringSlice("remove-prefixes")...)
addDestinationprefixes = sets.New(viper.GetStringSlice("add-destinationprefixes")...)
removeDestinationprefixes = sets.New(viper.GetStringSlice("remove-destinationprefixes")...)
currentPrefixes = sets.New(resp.Prefixes...)
currentDestinationprefixes = sets.New(resp.Destinationprefixes...)
)

newPrefixes := sets.NewString(currentPrefixes.List()...)
newPrefixes := currentPrefixes.Clone()
if viper.IsSet("remove-prefixes") {
diff := removePrefixes.Difference(currentPrefixes)
if diff.Len() > 0 {
return nil, fmt.Errorf("cannot remove prefixes because they are currently not present: %s", diff.List())
difflist := diff.UnsortedList()
slices.Sort(difflist)
return nil, fmt.Errorf("cannot remove prefixes because they are currently not present: %s", difflist)
}
newPrefixes = newPrefixes.Difference(removePrefixes)
}
if viper.IsSet("add-prefixes") {
if currentPrefixes.HasAny(addPrefixes.List()...) {
return nil, fmt.Errorf("cannot add prefixes because they are already present: %s", addPrefixes.Intersection(currentPrefixes).List())
if currentPrefixes.HasAny(addPrefixes.UnsortedList()...) {
intersection := addPrefixes.Intersection(currentPrefixes).UnsortedList()
slices.Sort(intersection)
return nil, fmt.Errorf("cannot add prefixes because they are already present: %s", intersection)
}
newPrefixes = newPrefixes.Union(addPrefixes)
}
if !newPrefixes.Equal(currentPrefixes) {
ur.Prefixes = newPrefixes.List()
ur.Prefixes = newPrefixes.UnsortedList()
}

newDestinationprefixes := sets.NewString(currentDestinationprefixes.List()...)
newDestinationprefixes := currentDestinationprefixes.Clone()
if viper.IsSet("remove-destinationprefixes") {
diff := removeDestinationprefixes.Difference(currentDestinationprefixes)
if diff.Len() > 0 {
return nil, fmt.Errorf("cannot remove destination prefixes because they are currently not present: %s", diff.List())
difflist := diff.UnsortedList()
slices.Sort(difflist)
return nil, fmt.Errorf("cannot remove destination prefixes because they are currently not present: %s", difflist)
}
newDestinationprefixes = newDestinationprefixes.Difference(removeDestinationprefixes)
}
if viper.IsSet("add-destinationprefixes") {
if currentDestinationprefixes.HasAny(addDestinationprefixes.List()...) {
return nil, fmt.Errorf("cannot add destination prefixes because they are already present: %s", addDestinationprefixes.Intersection(currentDestinationprefixes).List())
if currentDestinationprefixes.HasAny(addDestinationprefixes.UnsortedList()...) {
interSection := addDestinationprefixes.Intersection(currentDestinationprefixes).UnsortedList()
slices.Sort(interSection)
return nil, fmt.Errorf("cannot add destination prefixes because they are already present: %s", interSection)
}
newDestinationprefixes = newDestinationprefixes.Union(addDestinationprefixes)
}
if !newDestinationprefixes.Equal(currentDestinationprefixes) {
ur.Destinationprefixes = newDestinationprefixes.List()
ur.Destinationprefixes = newDestinationprefixes.UnsortedList()
}

return ur, nil
Expand Down
2 changes: 1 addition & 1 deletion docs/metalctl_completion_zsh.md
Expand Up @@ -13,7 +13,7 @@ to enable it. You can execute the following once:

To load completions in your current shell session:

source <(metalctl completion zsh); compdef _metalctl metalctl
source <(metalctl completion zsh)

To load completions for every new session, execute once:

Expand Down
95 changes: 48 additions & 47 deletions go.mod
Expand Up @@ -4,59 +4,60 @@ go 1.20

require (
bou.ke/monkey v1.0.2
github.com/avast/retry-go/v4 v4.3.3
github.com/avast/retry-go/v4 v4.3.4
github.com/dustin/go-humanize v1.0.1
github.com/fatih/color v1.15.0
github.com/go-openapi/runtime v0.26.0
github.com/go-openapi/strfmt v0.21.7
github.com/google/go-cmp v0.5.9
github.com/google/uuid v1.3.0
github.com/metal-stack/metal-go v0.22.4
github.com/metal-stack/metal-lib v0.11.7
github.com/metal-stack/metal-go v0.22.5
github.com/metal-stack/metal-lib v0.11.8
github.com/metal-stack/updater v1.1.4
github.com/metal-stack/v v1.0.3
github.com/olekukonko/tablewriter v0.0.5
github.com/spf13/afero v1.9.5
github.com/spf13/cobra v1.6.1
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.15.0
github.com/stretchr/testify v1.8.2
github.com/spf13/viper v1.16.0
github.com/stretchr/testify v1.8.4
github.com/tailscale/golang-x-crypto v0.0.0-20221115211329-17a3db2c30d2
go.uber.org/zap v1.24.0
golang.org/x/exp v0.0.0-20230321023759-10a507213a29
golang.org/x/term v0.7.0
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1
golang.org/x/term v0.8.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/kube-openapi v0.0.0-20230308215209-15aac26d736a
tailscale.com v1.38.2
k8s.io/apimachinery v0.27.2
tailscale.com v1.42.0
)

require (
filippo.io/edwards25519 v1.0.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/akutz/memconn v0.1.0 // indirect
github.com/alexbrainman/sspi v0.0.0-20210105120005-909beea2cc74 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/aws/aws-sdk-go-v2 v1.17.3 // indirect
github.com/aws/aws-sdk-go-v2/config v1.11.0 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.6.4 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.8.2 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.27 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.21 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.2 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.5.2 // indirect
github.com/aws/aws-sdk-go-v2/service/ssm v1.35.0 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.6.2 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.11.1 // indirect
github.com/aws/aws-sdk-go-v2 v1.18.0 // indirect
github.com/aws/aws-sdk-go-v2/config v1.18.22 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.13.21 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.3 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.33 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.27 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.34 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.27 // indirect
github.com/aws/aws-sdk-go-v2/service/ssm v1.36.3 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.12.9 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.9 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.18.10 // indirect
github.com/aws/smithy-go v1.13.5 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cheggaaa/pb/v3 v3.1.2 // indirect
github.com/coreos/go-iptables v0.6.0 // indirect
github.com/coreos/go-oidc/v3 v3.5.0 // indirect
github.com/coreos/go-oidc/v3 v3.6.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
Expand All @@ -73,7 +74,7 @@ require (
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/loads v0.21.2 // indirect
github.com/go-openapi/spec v0.20.8 // indirect
github.com/go-openapi/spec v0.20.9 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-openapi/validate v0.22.1 // indirect
github.com/goccy/go-json v0.10.2 // indirect
Expand All @@ -88,17 +89,17 @@ require (
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hdevalence/ed25519consensus v0.1.0 // indirect
github.com/huandu/xstrings v1.4.0 // indirect
github.com/icza/dyno v0.0.0-20220812133438-f0b6f8a18845 // indirect
github.com/icza/dyno v0.0.0-20230330125955-09f820a8d9c0 // indirect
github.com/illarion/gonotify v1.0.1 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/insomniacslk/dhcp v0.0.0-20230307103557-e252950ab961 // indirect
github.com/insomniacslk/dhcp v0.0.0-20230516061539-49801966e6cb // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/josharian/native v1.1.1-0.20230202152459-5c7d0dd6ab86 // indirect
github.com/jsimonetti/rtnetlink v1.3.1 // indirect
github.com/jsimonetti/rtnetlink v1.3.3 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.16.3 // indirect
github.com/klauspost/compress v1.16.5 // indirect
github.com/kortschak/wol v0.0.0-20200729010619-da482cc4850a // indirect
github.com/lestrrat-go/backoff/v2 v2.0.8 // indirect
github.com/lestrrat-go/blackmagic v1.0.1 // indirect
Expand All @@ -109,12 +110,12 @@ require (
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/mdlayher/genetlink v1.3.1 // indirect
github.com/mdlayher/netlink v1.7.1 // indirect
github.com/mdlayher/genetlink v1.3.2 // indirect
github.com/mdlayher/netlink v1.7.2 // indirect
github.com/mdlayher/sdnotify v1.0.0 // indirect
github.com/mdlayher/socket v0.4.0 // indirect
github.com/mdlayher/socket v0.4.1 // indirect
github.com/metal-stack/security v0.6.6 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-ps v1.0.0 // indirect
Expand All @@ -124,42 +125,42 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.7 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pierrec/lz4/v4 v4.1.17 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/tailscale/certstore v0.1.1-0.20220316223106-78d6e1c49d8d // indirect
github.com/tailscale/goupnp v1.0.1-0.20210804011211-c64d0f06ea05 // indirect
github.com/tailscale/netlink v1.1.1-0.20211101221916-cabfb018fe85 // indirect
github.com/tailscale/wireguard-go v0.0.0-20221219190806-4fa124729667 // indirect
github.com/tailscale/wireguard-go v0.0.0-20230410165232-af172621b4dd // indirect
github.com/tcnksm/go-httpstat v0.2.0 // indirect
github.com/u-root/uio v0.0.0-20230220225925-ffce2a382923 // indirect
github.com/u-root/uio v0.0.0-20230305220412-3e8cd9d6bf63 // indirect
github.com/vishvananda/netlink v1.2.1-beta.2 // indirect
github.com/vishvananda/netns v0.0.4 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.mongodb.org/mongo-driver v1.11.4 // indirect
go.opentelemetry.io/otel v1.14.0 // indirect
go.opentelemetry.io/otel/trace v1.14.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go4.org/mem v0.0.0-20220726221520-4f986261bf13 // indirect
go4.org/netipx v0.0.0-20230303233057-f1b76eb4bb35 // indirect
golang.org/x/crypto v0.8.0 // indirect
golang.org/x/mod v0.9.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/oauth2 v0.7.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.7.0 // indirect
golang.org/x/tools v0.9.3 // indirect
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect
golang.zx2c4.com/wireguard/windows v0.5.3 // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand All @@ -168,7 +169,7 @@ require (
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gvisor.dev/gvisor v0.0.0-20221203005347-703fd9b7fbc0 // indirect
gvisor.dev/gvisor v0.0.0-20230504175454-7b0a1988a28f // indirect
inet.af/peercred v0.0.0-20210906144145-0893ea02156a // indirect
nhooyr.io/websocket v1.8.7 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
Expand Down

0 comments on commit 942e5b7

Please sign in to comment.