Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit d9d0b51

Browse files
committed
Code refactor
1 parent cb009e5 commit d9d0b51

14 files changed

+592
-404
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea/**

cmd/per-node-resources/main.go

+18-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package main
22

33
import (
4-
"flag"
54
"os"
65
"time"
76

87
"github.com/spf13/cobra"
8+
"k8s.io/apimachinery/pkg/labels"
99
"k8s.io/client-go/kubernetes"
1010
ctrl "sigs.k8s.io/controller-runtime"
1111

@@ -15,24 +15,35 @@ import (
1515

1616
func main() {
1717
var port int
18-
var nodesToIgnore []string
18+
var selector string
19+
var resyncPeriod time.Duration
20+
var nodeSelector labels.Selector
21+
var includeVirtualNodes bool
1922

2023
var rootCmd = &cobra.Command{
2124
Use: os.Args[0],
22-
Short: "Liqo plugin which provides fixed resources to each remote cluster",
25+
Short: "Liqo plugin which devides the available resource among peered clusters",
2326
SilenceUsage: true,
27+
PreRunE: func(cmd *cobra.Command, args []string) error {
28+
var err error
29+
if nodeSelector, err = labels.Parse(selector); err != nil {
30+
return err
31+
}
32+
return nil
33+
},
2434
RunE: func(cmd *cobra.Command, args []string) error {
25-
resyncPeriod := flag.Duration("resync-period", 10*time.Hour, "The resync period for the informers")
2635
config := restcfg.SetRateLimiter(ctrl.GetConfigOrDie())
2736
clientset := kubernetes.NewForConfigOrDie(config)
2837

29-
return grpcserver.ListenAndServeGRPCServer(port, clientset, *resyncPeriod, nodesToIgnore)
38+
return grpcserver.ListenAndServeGRPCServer(port, clientset, resyncPeriod, nodeSelector, includeVirtualNodes)
3039
},
3140
}
3241

42+
rootCmd.PersistentFlags().BoolVar(&includeVirtualNodes, "include-virtual-nodes", false,
43+
"if true resources of virtual nodes are considered, otherwise ignored")
44+
rootCmd.PersistentFlags().DurationVar(&resyncPeriod, "resync-period", 10*time.Hour, "the resync period for the informers")
3345
rootCmd.PersistentFlags().IntVar(&port, "port", 6001, "set port where the server will listen on.")
34-
rootCmd.PersistentFlags().StringSliceVar(&nodesToIgnore, "ignore-node",
35-
make([]string, 0), "node's name to ignore. You can use this flag multiple times.")
46+
rootCmd.PersistentFlags().StringVar(&selector, "selector", "", "the selector to filter nodes. This flag can be used multiple times.")
3647

3748
err := rootCmd.Execute()
3849
if err != nil {

go.mod

+19-16
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,27 @@ go 1.19
44

55
require (
66
github.com/liqotech/liqo v0.6.0
7+
github.com/onsi/ginkgo/v2 v2.6.1
78
github.com/spf13/cobra v1.6.1
89
google.golang.org/grpc v1.50.1
9-
k8s.io/apimachinery v0.25.3
10+
k8s.io/apimachinery v0.26.0
1011
)
1112

1213
require (
1314
github.com/beorn7/perks v1.0.1 // indirect
1415
github.com/cespare/xxhash/v2 v2.1.2 // indirect
15-
github.com/fsnotify/fsnotify v1.5.4 // indirect
16+
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
17+
github.com/fsnotify/fsnotify v1.6.0 // indirect
1618
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
1719
github.com/google/uuid v1.3.0 // indirect
1820
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
19-
github.com/prometheus/client_golang v1.13.0 // indirect
20-
github.com/prometheus/client_model v0.2.0 // indirect
21+
github.com/prometheus/client_golang v1.14.0 // indirect
22+
github.com/prometheus/client_model v0.3.0 // indirect
2123
github.com/prometheus/common v0.37.0 // indirect
2224
github.com/prometheus/procfs v0.8.0 // indirect
2325
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
24-
k8s.io/apiextensions-apiserver v0.25.2 // indirect
25-
k8s.io/component-base v0.25.3 // indirect
26+
k8s.io/apiextensions-apiserver v0.26.0 // indirect
27+
k8s.io/component-base v0.26.0 // indirect
2628
)
2729

2830
require (
@@ -47,29 +49,30 @@ require (
4749
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
4850
github.com/modern-go/reflect2 v1.0.2 // indirect
4951
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
52+
github.com/onsi/gomega v1.24.2
5053
github.com/pkg/errors v0.9.1 // indirect
5154
github.com/spf13/pflag v1.0.5 // indirect
5255
github.com/virtual-kubelet/virtual-kubelet v1.6.1-0.20220831210300-d2523fe808a2 // indirect
53-
golang.org/x/net v0.1.0 // indirect
56+
golang.org/x/net v0.4.0 // indirect
5457
golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1 // indirect
55-
golang.org/x/sys v0.1.0 // indirect
56-
golang.org/x/term v0.1.0 // indirect
57-
golang.org/x/text v0.4.0 // indirect
58-
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af // indirect
58+
golang.org/x/sys v0.3.0 // indirect
59+
golang.org/x/term v0.3.0 // indirect
60+
golang.org/x/text v0.5.0 // indirect
61+
golang.org/x/time v0.3.0 // indirect
5962
google.golang.org/appengine v1.6.7 // indirect
6063
google.golang.org/genproto v0.0.0-20220930163606-c98284e70a91 // indirect
6164
google.golang.org/protobuf v1.28.1 // indirect
6265
gopkg.in/inf.v0 v0.9.1 // indirect
6366
gopkg.in/yaml.v2 v2.4.0 // indirect
6467
gopkg.in/yaml.v3 v3.0.1 // indirect
65-
k8s.io/api v0.25.3
66-
k8s.io/client-go v0.25.3
68+
k8s.io/api v0.26.0
69+
k8s.io/client-go v0.26.0
6770
k8s.io/klog/v2 v2.80.1 // indirect
68-
k8s.io/kube-openapi v0.0.0-20220928191237-829ce0c27909 // indirect
71+
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
6972
k8s.io/kubectl v0.25.3
7073
k8s.io/metrics v0.25.3 // indirect
71-
k8s.io/utils v0.0.0-20220922133306-665eaaec4324 // indirect
72-
sigs.k8s.io/controller-runtime v0.13.0
74+
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448 // indirect
75+
sigs.k8s.io/controller-runtime v0.14.0
7376
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
7477
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
7578
sigs.k8s.io/yaml v1.3.0 // indirect

0 commit comments

Comments
 (0)