Skip to content

Commit e63d73b

Browse files
authored
chore: upgrade kubernetes dependencies (#268)
* chore: upgrade kubernetes dependencies Signed-off-by: spencercjh <spencercjh@gmail.com> * fix: enhance event handling with typed events for ChaosBlade Signed-off-by: spencercjh <spencercjh@gmail.com> * fix: enhance manager options with scheme and default namespaces Signed-off-by: spencercjh <spencercjh@gmail.com> --------- Signed-off-by: spencercjh <spencercjh@gmail.com>
1 parent e244c9b commit e63d73b

File tree

12 files changed

+493
-512
lines changed

12 files changed

+493
-512
lines changed

channel/client.go

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ import (
3030
"k8s.io/client-go/kubernetes/scheme"
3131
"k8s.io/client-go/rest"
3232
"k8s.io/client-go/tools/remotecommand"
33-
"sigs.k8s.io/controller-runtime/pkg/cache"
3433
"sigs.k8s.io/controller-runtime/pkg/client"
35-
"sigs.k8s.io/controller-runtime/pkg/manager"
3634
)
3735

3836
// Client contains the kubernetes client, operator client and kubeconfig
@@ -43,25 +41,17 @@ type Client struct {
4341
}
4442

4543
// NewClientFunc returns the controller client
46-
func NewClientFunc() manager.NewClientFunc {
47-
return func(cache cache.Cache, config *rest.Config, options client.Options) (client.Client, error) {
48-
// Create the Client for Write operations.
44+
func NewClientFunc() client.NewClientFunc {
45+
return func(config *rest.Config, options client.Options) (client.Client, error) {
4946
c, err := client.New(config, options)
5047
if err != nil {
5148
return nil, err
5249
}
53-
cli := &Client{}
54-
cli.Interface = kubernetes.NewForConfigOrDie(config)
55-
cli.Client = &client.DelegatingClient{
56-
Reader: &client.DelegatingReader{
57-
CacheReader: cache,
58-
ClientReader: c,
59-
},
60-
Writer: c,
61-
StatusClient: c,
62-
}
63-
cli.Config = config
64-
return cli, nil
50+
return &Client{
51+
Interface: kubernetes.NewForConfigOrDie(config),
52+
Client: c,
53+
Config: config,
54+
}, nil
6555
}
6656
}
6757

cmd/hookfs/main.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"github.com/chaosblade-io/chaosblade-spec-go/util"
2929
"github.com/ethercflow/hookfs/hookfs"
3030
"github.com/sirupsen/logrus"
31-
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
31+
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
3232

3333
chaosbladehook "github.com/chaosblade-io/chaosblade-operator/pkg/hookfs"
3434
)
@@ -52,19 +52,19 @@ func main() {
5252
"original": original,
5353
"mountpoint": mountpoint,
5454
})
55-
stopCh := signals.SetupSignalHandler()
55+
stopCtx := signals.SetupSignalHandler()
5656
chaosbladeHookServer := chaosbladehook.NewChaosbladeHookServer(address)
5757
logFields.Infoln("Start chaosblade hook server.")
58-
go chaosbladeHookServer.Start(stopCh)
58+
go chaosbladeHookServer.Start(stopCtx)
5959

6060
logFields.Infoln("Start fuse server.")
61-
if err := startFuseServer(stopCh); err != nil {
61+
if err := startFuseServer(stopCtx); err != nil {
6262
logFields.WithError(err).Fatalln("Start fuse server failed")
6363
}
6464
}
6565

6666
// startFuseServer starts hookfs server
67-
func startFuseServer(stop <-chan struct{}) error {
67+
func startFuseServer(stop context.Context) error {
6868
if !util.IsExist(original) {
6969
if err := os.MkdirAll(original, os.FileMode(755)); err != nil {
7070
return fmt.Errorf("create original directory error, %v", err)
@@ -85,7 +85,7 @@ func startFuseServer(stop <-chan struct{}) error {
8585
}()
8686
for {
8787
select {
88-
case <-stop:
88+
case <-stop.Done():
8989
logFields := logrus.WithFields(logrus.Fields{
9090
"address": address,
9191
"original": original,

cmd/manager/main.go

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package main
1919
import (
2020
"context"
2121
"flag"
22+
"net/http"
2223
"runtime"
2324
"strings"
2425

@@ -28,18 +29,22 @@ import (
2829
sdkVersion "github.com/operator-framework/operator-sdk/version"
2930
"github.com/sirupsen/logrus"
3031
"github.com/spf13/pflag"
32+
corev1 "k8s.io/api/core/v1"
3133
"k8s.io/apimachinery/pkg/api/meta"
34+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
35+
runtimeutil "k8s.io/apimachinery/pkg/util/runtime"
3236
"sigs.k8s.io/controller-runtime/pkg/webhook"
3337

38+
apiruntime "k8s.io/apimachinery/pkg/runtime"
3439
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
3540
_ "k8s.io/client-go/plugin/pkg/client/auth"
3641
"k8s.io/client-go/rest"
3742
"sigs.k8s.io/controller-runtime/pkg/cache"
3843
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
3944
"sigs.k8s.io/controller-runtime/pkg/client/config"
45+
"sigs.k8s.io/controller-runtime/pkg/log"
4046
"sigs.k8s.io/controller-runtime/pkg/manager"
41-
"sigs.k8s.io/controller-runtime/pkg/runtime/log"
42-
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
47+
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
4348

4449
"github.com/chaosblade-io/chaosblade-operator/channel"
4550
"github.com/chaosblade-io/chaosblade-operator/pkg/apis"
@@ -87,7 +92,7 @@ func main() {
8792
if err != nil {
8893
logrus.Fatalf("Get apiserver config error, %v", err)
8994
}
90-
err = leader.Become(context.TODO(), "chaosblade-operator-lock")
95+
err = leader.Become(context.Background(), "chaosblade-operator-lock")
9196
if err != nil {
9297
logrus.Fatalf("Become leader error, %v", err)
9398
}
@@ -133,38 +138,53 @@ func initLogger() {
133138
}
134139

135140
func addWebhook(m manager.Manager) error {
136-
hookServer := &webhook.Server{
141+
server := webhook.NewServer(webhook.Options{
137142
Port: webhookcfg.Port,
138-
}
139-
if err := m.Add(hookServer); err != nil {
143+
})
144+
if err := m.Add(server); err != nil {
140145
return err
141146
}
142147
logrus.Infof("registering %s to the webhook server", "mutating-pods")
143-
hookServer.Register("/mutating-pods", &webhook.Admission{Handler: &mutator.Mutator{}})
148+
server.Register("/mutating-pods", &webhook.Admission{Handler: &mutator.Mutator{}})
144149
return nil
145150
}
146151

147152
// createManager supports multi namespaces configuration
148153
func createManager(cfg *rest.Config) (manager.Manager, error) {
154+
scheme := apiruntime.NewScheme()
155+
runtimeutil.Must(metav1.AddMetaToScheme(scheme))
156+
runtimeutil.Must(corev1.AddToScheme(scheme))
157+
runtimeutil.Must(apis.AddToScheme(scheme))
149158
watchNamespace, err := k8sutil.GetWatchNamespace()
150159
if err != nil {
151160
return nil, err
152161
}
153162
logrus.Infof("Get watch namespace is %s", watchNamespace)
154163
if strings.Contains(watchNamespace, ",") {
155-
namespaces := strings.Split(watchNamespace, ",")
164+
defaultNsps := make(map[string]cache.Config)
165+
for _, nsp := range strings.Split(watchNamespace, ",") {
166+
defaultNsps[nsp] = cache.Config{}
167+
}
156168
return manager.New(cfg, manager.Options{
157-
NewCache: cache.MultiNamespacedCacheBuilder(namespaces),
158-
MapperProvider: func(c *rest.Config) (meta.RESTMapper, error) {
159-
return apiutil.NewDynamicRESTMapper(c)
169+
Cache: cache.Options{
170+
Scheme: scheme,
171+
DefaultNamespaces: defaultNsps,
172+
},
173+
Scheme: scheme,
174+
MapperProvider: func(c *rest.Config, httpClient *http.Client) (meta.RESTMapper, error) {
175+
return apiutil.NewDynamicRESTMapper(c, httpClient)
160176
},
161177
NewClient: channel.NewClientFunc(),
162178
})
163179
}
164180
return manager.New(cfg, manager.Options{
165-
Namespace: watchNamespace,
166-
MapperProvider: func(c *rest.Config) (meta.RESTMapper, error) {
167-
return apiutil.NewDynamicRESTMapper(c)
181+
Cache: cache.Options{
182+
Scheme: scheme,
183+
DefaultNamespaces: map[string]cache.Config{watchNamespace: {}},
184+
},
185+
Scheme: scheme,
186+
MapperProvider: func(c *rest.Config, httpClient *http.Client) (meta.RESTMapper, error) {
187+
return apiutil.NewDynamicRESTMapper(c, httpClient)
168188
},
169189
NewClient: channel.NewClientFunc(),
170190
})

go.mod

Lines changed: 58 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,23 @@ require (
77
github.com/chaosblade-io/chaosblade-exec-os v1.8.0
88
github.com/chaosblade-io/chaosblade-spec-go v1.8.0
99
github.com/ethercflow/hookfs v0.3.0
10-
github.com/go-openapi/spec v0.19.4
1110
github.com/hanwen/go-fuse v1.0.0
1211
github.com/operator-framework/operator-sdk v0.17.0
1312
github.com/sirupsen/logrus v1.8.1
1413
github.com/spf13/pflag v1.0.5
15-
k8s.io/api v0.20.6
16-
k8s.io/apimachinery v0.20.6
14+
k8s.io/api v0.31.0
15+
k8s.io/apimachinery v0.31.0
1716
k8s.io/client-go v12.0.0+incompatible
18-
k8s.io/kube-openapi v0.0.0-20201113171705-d219536bb9fd
19-
sigs.k8s.io/controller-runtime v0.6.0
17+
sigs.k8s.io/controller-runtime v0.19.4
2018
)
2119

2220
require (
23-
cloud.google.com/go v0.54.0 // indirect
24-
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
25-
github.com/Azure/go-autorest/autorest v0.11.1 // indirect
26-
github.com/Azure/go-autorest/autorest/adal v0.9.5 // indirect
27-
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
28-
github.com/Azure/go-autorest/logger v0.2.0 // indirect
29-
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
3021
github.com/Microsoft/go-winio v0.4.17 // indirect
3122
github.com/Microsoft/hcsshim v0.8.21 // indirect
32-
github.com/PuerkitoBio/purell v1.1.1 // indirect
33-
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
3423
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
3524
github.com/beorn7/perks v1.0.1 // indirect
3625
github.com/bits-and-blooms/bitset v1.2.0 // indirect
37-
github.com/cespare/xxhash/v2 v2.1.1 // indirect
26+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
3827
github.com/cilium/ebpf v0.6.2 // indirect
3928
github.com/containerd/cgroups v1.0.2-0.20210605143700-23b51209bf7b // indirect
4029
github.com/containerd/containerd v1.5.6 // indirect
@@ -43,86 +32,94 @@ require (
4332
github.com/containerd/ttrpc v1.0.2 // indirect
4433
github.com/containerd/typeurl v1.0.2 // indirect
4534
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
46-
github.com/davecgh/go-spew v1.1.1 // indirect
35+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
4736
github.com/dimchansky/utfbom v1.1.1 // indirect
4837
github.com/docker/distribution v2.7.1+incompatible // indirect
4938
github.com/docker/docker v1.4.2-0.20200203170920-46ec8731fbce // indirect
5039
github.com/docker/go-connections v0.4.0 // indirect
5140
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c // indirect
5241
github.com/docker/go-units v0.4.0 // indirect
53-
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96 // indirect
54-
github.com/emicklei/go-restful v2.9.5+incompatible // indirect
55-
github.com/evanphx/json-patch v4.9.0+incompatible // indirect
56-
github.com/form3tech-oss/jwt-go v3.2.2+incompatible // indirect
57-
github.com/go-logr/logr v0.2.1 // indirect
58-
github.com/go-logr/zapr v0.2.0 // indirect
42+
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
43+
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
44+
github.com/fsnotify/fsnotify v1.7.0 // indirect
45+
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
46+
github.com/go-logr/logr v1.4.2 // indirect
47+
github.com/go-logr/zapr v1.3.0 // indirect
5948
github.com/go-ole/go-ole v1.2.6 // indirect
60-
github.com/go-openapi/jsonpointer v0.19.3 // indirect
61-
github.com/go-openapi/jsonreference v0.19.3 // indirect
62-
github.com/go-openapi/swag v0.19.5 // indirect
49+
github.com/go-openapi/jsonpointer v0.19.6 // indirect
50+
github.com/go-openapi/jsonreference v0.20.2 // indirect
51+
github.com/go-openapi/swag v0.22.4 // indirect
6352
github.com/godbus/dbus/v5 v5.0.4 // indirect
6453
github.com/gogo/googleapis v1.4.0 // indirect
6554
github.com/gogo/protobuf v1.3.2 // indirect
66-
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
67-
github.com/golang/protobuf v1.5.0 // indirect
55+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
56+
github.com/golang/protobuf v1.5.4 // indirect
6857
github.com/goodhosts/hostsfile v0.1.6 // indirect
69-
github.com/google/go-cmp v0.5.6 // indirect
70-
github.com/google/gofuzz v1.1.0 // indirect
71-
github.com/google/uuid v1.2.0 // indirect
72-
github.com/googleapis/gnostic v0.4.1 // indirect
73-
github.com/hashicorp/golang-lru v0.5.3 // indirect
58+
github.com/google/gnostic-models v0.6.8 // indirect
59+
github.com/google/go-cmp v0.6.0 // indirect
60+
github.com/google/gofuzz v1.2.0 // indirect
61+
github.com/google/uuid v1.6.0 // indirect
62+
github.com/gorilla/websocket v1.5.0 // indirect
7463
github.com/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c // indirect
7564
github.com/imdario/mergo v0.3.12 // indirect
76-
github.com/json-iterator/go v1.1.10 // indirect
65+
github.com/josharian/intern v1.0.0 // indirect
66+
github.com/json-iterator/go v1.1.12 // indirect
7767
github.com/klauspost/compress v1.11.13 // indirect
7868
github.com/magefile/mage v1.15.0 // indirect
79-
github.com/mailru/easyjson v0.7.0 // indirect
80-
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
69+
github.com/mailru/easyjson v0.7.7 // indirect
8170
github.com/moby/locker v1.0.1 // indirect
71+
github.com/moby/spdystream v0.4.0 // indirect
8272
github.com/moby/sys/mountinfo v0.4.1 // indirect
8373
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
84-
github.com/modern-go/reflect2 v1.0.1 // indirect
74+
github.com/modern-go/reflect2 v1.0.2 // indirect
75+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
76+
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
8577
github.com/opencontainers/go-digest v1.0.0 // indirect
8678
github.com/opencontainers/image-spec v1.0.1 // indirect
8779
github.com/opencontainers/runc v1.0.2 // indirect
8880
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417 // indirect
8981
github.com/opencontainers/selinux v1.8.2 // indirect
9082
github.com/pkg/errors v0.9.1 // indirect
91-
github.com/prometheus/client_golang v1.7.1 // indirect
92-
github.com/prometheus/client_model v0.2.0 // indirect
93-
github.com/prometheus/common v0.10.0 // indirect
94-
github.com/prometheus/procfs v0.6.0 // indirect
83+
github.com/prometheus/client_golang v1.19.1 // indirect
84+
github.com/prometheus/client_model v0.6.1 // indirect
85+
github.com/prometheus/common v0.55.0 // indirect
86+
github.com/prometheus/procfs v0.15.1 // indirect
9587
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
9688
github.com/tklauser/go-sysconf v0.3.9 // indirect
9789
github.com/tklauser/numcpus v0.3.0 // indirect
90+
github.com/x448/float16 v0.8.4 // indirect
9891
github.com/yusufpapurcu/wmi v1.2.4 // indirect
9992
go.opencensus.io v0.22.3 // indirect
100-
go.uber.org/atomic v1.6.0 // indirect
10193
go.uber.org/automaxprocs v1.6.0 // indirect
102-
go.uber.org/multierr v1.5.0 // indirect
103-
go.uber.org/zap v1.14.1 // indirect
104-
golang.org/x/crypto v0.1.0 // indirect
105-
golang.org/x/net v0.1.0 // indirect
106-
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
107-
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
108-
golang.org/x/sys v0.1.0 // indirect
109-
golang.org/x/term v0.1.0 // indirect
110-
golang.org/x/text v0.4.0 // indirect
111-
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
112-
gomodules.xyz/jsonpatch/v2 v2.0.1 // indirect
113-
google.golang.org/appengine v1.6.5 // indirect
94+
go.uber.org/multierr v1.11.0 // indirect
95+
go.uber.org/zap v1.26.0 // indirect
96+
golang.org/x/crypto v0.24.0 // indirect
97+
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc // indirect
98+
golang.org/x/net v0.26.0 // indirect
99+
golang.org/x/oauth2 v0.21.0 // indirect
100+
golang.org/x/sync v0.7.0 // indirect
101+
golang.org/x/sys v0.21.0 // indirect
102+
golang.org/x/term v0.21.0 // indirect
103+
golang.org/x/text v0.16.0 // indirect
104+
golang.org/x/time v0.3.0 // indirect
105+
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
114106
google.golang.org/genproto v0.0.0-20201110150050-8816d57aaa9a // indirect
115-
google.golang.org/grpc v1.39.0 // indirect
116-
google.golang.org/protobuf v1.26.0 // indirect
117-
gopkg.in/fsnotify.v1 v1.4.7 // indirect
107+
google.golang.org/grpc v1.65.0 // indirect
108+
google.golang.org/protobuf v1.34.2 // indirect
118109
gopkg.in/inf.v0 v0.9.1 // indirect
119110
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
120111
gopkg.in/yaml.v2 v2.4.0 // indirect
112+
gopkg.in/yaml.v3 v3.0.1 // indirect
121113
k8s.io/klog v1.0.0 // indirect
122-
k8s.io/klog/v2 v2.4.0 // indirect
123-
k8s.io/utils v0.0.0-20201110183641-67b214c5f920 // indirect
124-
sigs.k8s.io/structured-merge-diff/v4 v4.0.3 // indirect
125-
sigs.k8s.io/yaml v1.2.0 // indirect
114+
k8s.io/klog/v2 v2.130.1 // indirect
115+
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
116+
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
117+
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
118+
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
119+
sigs.k8s.io/yaml v1.4.0 // indirect
126120
)
127121

128-
replace k8s.io/client-go => k8s.io/client-go v0.20.6 // Required by prometheus-operator
122+
replace (
123+
k8s.io/client-go => k8s.io/client-go v0.31.0
124+
k8s.io/client-go/kubernetes/scheme => k8s.io/client-go/kubernetes/scheme v0.31.0
125+
)

0 commit comments

Comments
 (0)