Skip to content

Commit 6a57442

Browse files
author
玖宇
committed
Enhancement: support to try by apireader client when errors occur in webhook
Signed-off-by: 玖宇 <guotongyu.gty@alibaba-inc.com>
1 parent c5ff317 commit 6a57442

21 files changed

Lines changed: 114 additions & 73 deletions

File tree

cmd/webhook/app/webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func handle() {
164164
}
165165

166166
// register admission handlers
167-
handler.Register(mgr, mgr.GetClient(), setupLog)
167+
handler.Register(mgr, setupLog)
168168

169169
// register pod mutating handlers
170170
err = plugins.RegisterMutatingHandlers(mgr.GetClient())

pkg/application/inject/fuse/injector_runtime_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func TestInjectList(t *testing.T) {
219219
if err != nil {
220220
t.Errorf("testcase %s failed due to error %v", testcase.name, err)
221221
}
222-
runtimeInfo.SetClient(fakeClient)
222+
runtimeInfo.SetClientReader(fakeClient)
223223
runtimeInfos[pvc] = runtimeInfo
224224
}
225225

@@ -261,7 +261,7 @@ func TestInjectUnstructured(t *testing.T) {
261261
if err != nil {
262262
t.Errorf("testcase %s failed due to error %v", name, err)
263263
}
264-
runtimeInfo.SetClient(fakeClient)
264+
runtimeInfo.SetClientReader(fakeClient)
265265
runtimeInfos[name] = runtimeInfo
266266
pod := corev1.Pod{
267267
TypeMeta: metav1.TypeMeta{
@@ -330,7 +330,7 @@ func TestInjectObject(t *testing.T) {
330330
if err != nil {
331331
t.Errorf("testcase %s failed due to error %v", name, err)
332332
}
333-
runtimeInfo.SetClient(fakeClient)
333+
runtimeInfo.SetClientReader(fakeClient)
334334
runtimeInfos[name] = runtimeInfo
335335

336336
deploy := appsv1.Deployment{

pkg/application/inject/fuse/injector_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ func TestInjectPod(t *testing.T) {
11581158
if err != nil {
11591159
t.Errorf("testcase %s failed due to error %v", testcase.name, err)
11601160
}
1161-
runtimeInfo.SetClient(fakeClient)
1161+
runtimeInfo.SetClientReader(fakeClient)
11621162
runtimeInfos[pvc] = runtimeInfo
11631163
}
11641164

@@ -1448,7 +1448,7 @@ func TestSkipInjectPod(t *testing.T) {
14481448
if err != nil {
14491449
t.Errorf("testcase %s failed due to error %v", testcase.name, err)
14501450
}
1451-
runtimeInfo.SetClient(fakeClient)
1451+
runtimeInfo.SetClientReader(fakeClient)
14521452
runtimeInfos[pvc] = runtimeInfo
14531453
}
14541454

@@ -2375,7 +2375,7 @@ func TestInjectPodWithMultiplePVC(t *testing.T) {
23752375
if err != nil {
23762376
t.Errorf("testcase %s failed due to error %v", testcase.name, err)
23772377
}
2378-
runtimeInfo.SetClient(fakeClient)
2378+
runtimeInfo.SetClientReader(fakeClient)
23792379
runtimeInfos[pvc] = runtimeInfo
23802380
}
23812381

@@ -2839,7 +2839,7 @@ func TestInjectPodWithDatasetSubPath(t *testing.T) {
28392839
if err != nil {
28402840
t.Errorf("testcase %s failed due to error %v", testcase.name, err)
28412841
}
2842-
runtimeInfo.SetClient(fakeClient)
2842+
runtimeInfo.SetClientReader(fakeClient)
28432843
runtimeInfos[pvc] = runtimeInfo
28442844
}
28452845

@@ -4120,7 +4120,7 @@ func TestInjectPodUnprivileged(t *testing.T) {
41204120
if err != nil {
41214121
t.Errorf("testcase %s failed due to error %v", testcase.name, err)
41224122
}
4123-
runtimeInfo.SetClient(fakeClient)
4123+
runtimeInfo.SetClientReader(fakeClient)
41244124
runtimeInfos[pvc] = runtimeInfo
41254125
}
41264126

@@ -5227,7 +5227,7 @@ func TestInjectPodWithInitContainer(t *testing.T) {
52275227
if err != nil {
52285228
t.Errorf("testcase %s failed due to error %v", testcase.name, err)
52295229
}
5230-
runtimeInfo.SetClient(fakeClient)
5230+
runtimeInfo.SetClientReader(fakeClient)
52315231
runtimeInfos[pvc] = runtimeInfo
52325232
}
52335233

@@ -6205,7 +6205,7 @@ func TestInjectPodWithEnabledFUSEMetrics(t *testing.T) {
62056205
if err != nil {
62066206
t.Errorf("testcase %s failed due to error %v", testcase.name, err)
62076207
}
6208-
runtimeInfo.SetClient(fakeClient)
6208+
runtimeInfo.SetClientReader(fakeClient)
62096209
runtimeInfos[pvc] = runtimeInfo
62106210
}
62116211

pkg/common/webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ const (
3535
type AdmissionHandler interface {
3636
admission.Handler
3737

38-
Setup(client client.Client, decoder *admission.Decoder)
38+
Setup(client client.Client, reader client.Reader, decoder *admission.Decoder)
3939
}

pkg/ddc/alluxio/cache_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestQueryCacheStatus(t *testing.T) {
5050
defer patch1.Reset()
5151

5252
patch2 := ApplyFunc(utils.GetDataset,
53-
func(_ client.Client, _ string, _ string) (*datav1alpha1.Dataset, error) {
53+
func(_ client.Reader, _ string, _ string) (*datav1alpha1.Dataset, error) {
5454
d := &datav1alpha1.Dataset{
5555
Status: datav1alpha1.DatasetStatus{
5656
UfsTotal: "52.18MiB",
@@ -95,7 +95,7 @@ func TestQueryCacheStatus(t *testing.T) {
9595
defer patch1.Reset()
9696

9797
patch2 := ApplyFunc(utils.GetDataset,
98-
func(_ client.Client, _ string, _ string) (*datav1alpha1.Dataset, error) {
98+
func(_ client.Reader, _ string, _ string) (*datav1alpha1.Dataset, error) {
9999
d := &datav1alpha1.Dataset{
100100
Status: datav1alpha1.DatasetStatus{
101101
UfsTotal: "[Calculating]",
@@ -132,7 +132,7 @@ func TestQueryCacheStatus(t *testing.T) {
132132
defer patch1.Reset()
133133

134134
patch2 := ApplyFunc(utils.GetDataset,
135-
func(_ client.Client, _ string, _ string) (*datav1alpha1.Dataset, error) {
135+
func(_ client.Reader, _ string, _ string) (*datav1alpha1.Dataset, error) {
136136
d := &datav1alpha1.Dataset{
137137
Status: datav1alpha1.DatasetStatus{
138138
UfsTotal: "",

pkg/ddc/base/runtime.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ type RuntimeInfoInterface interface {
101101

102102
GetFuseContainerTemplate() (template *common.FuseInjectionTemplate, err error)
103103

104-
SetClient(client client.Client)
104+
SetClientReader(client client.Reader)
105105

106106
GetMetadataList() []datav1alpha1.Metadata
107107

@@ -138,7 +138,7 @@ type RuntimeInfo struct {
138138
// Check if the deprecated PV naming style is used
139139
deprecatedPVName bool
140140

141-
client client.Client
141+
client client.Reader
142142

143143
annotations map[string]string
144144

@@ -367,7 +367,7 @@ func (info *RuntimeInfo) IsDeprecatedPVName() bool {
367367
return info.deprecatedPVName
368368
}
369369

370-
func (info *RuntimeInfo) SetClient(client client.Client) {
370+
func (info *RuntimeInfo) SetClientReader(client client.Reader) {
371371
info.client = client
372372
}
373373

@@ -432,8 +432,8 @@ func convertToTieredstoreInfo(tieredstore datav1alpha1.TieredStore) (TieredStore
432432
}
433433

434434
// GetRuntimeInfo gets the RuntimeInfo according to name and namespace of it
435-
func GetRuntimeInfo(client client.Client, name, namespace string) (runtimeInfo RuntimeInfoInterface, err error) {
436-
dataset, err := utils.GetDataset(client, name, namespace)
435+
func GetRuntimeInfo(reader client.Reader, name, namespace string) (runtimeInfo RuntimeInfoInterface, err error) {
436+
dataset, err := utils.GetDataset(reader, name, namespace)
437437
if err != nil {
438438
return runtimeInfo, err
439439
}
@@ -444,7 +444,7 @@ func GetRuntimeInfo(client client.Client, name, namespace string) (runtimeInfo R
444444
}
445445
switch runtimeType {
446446
case common.AlluxioRuntime:
447-
alluxioRuntime, err := utils.GetAlluxioRuntime(client, name, namespace)
447+
alluxioRuntime, err := utils.GetAlluxioRuntime(reader, name, namespace)
448448
if err != nil {
449449
return runtimeInfo, err
450450
}
@@ -460,7 +460,7 @@ func GetRuntimeInfo(client client.Client, name, namespace string) (runtimeInfo R
460460
runtimeInfo.SetFuseNodeSelector(alluxioRuntime.Spec.Fuse.NodeSelector)
461461
runtimeInfo.SetupFuseCleanPolicy(alluxioRuntime.Spec.Fuse.CleanPolicy)
462462
case common.JindoRuntime:
463-
jindoRuntime, err := utils.GetJindoRuntime(client, name, namespace)
463+
jindoRuntime, err := utils.GetJindoRuntime(reader, name, namespace)
464464
if err != nil {
465465
return runtimeInfo, err
466466
}
@@ -477,7 +477,7 @@ func GetRuntimeInfo(client client.Client, name, namespace string) (runtimeInfo R
477477
runtimeInfo.SetFuseNodeSelector(jindoRuntime.Spec.Fuse.NodeSelector)
478478
runtimeInfo.SetupFuseCleanPolicy(jindoRuntime.Spec.Fuse.CleanPolicy)
479479
case common.GooseFSRuntime:
480-
goosefsRuntime, err := utils.GetGooseFSRuntime(client, name, namespace)
480+
goosefsRuntime, err := utils.GetGooseFSRuntime(reader, name, namespace)
481481
if err != nil {
482482
return runtimeInfo, err
483483
}
@@ -493,7 +493,7 @@ func GetRuntimeInfo(client client.Client, name, namespace string) (runtimeInfo R
493493
runtimeInfo.SetFuseNodeSelector(goosefsRuntime.Spec.Fuse.NodeSelector)
494494
runtimeInfo.SetupFuseCleanPolicy(goosefsRuntime.Spec.Fuse.CleanPolicy)
495495
case common.JuiceFSRuntime:
496-
juicefsRuntime, err := utils.GetJuiceFSRuntime(client, name, namespace)
496+
juicefsRuntime, err := utils.GetJuiceFSRuntime(reader, name, namespace)
497497
if err != nil {
498498
return runtimeInfo, err
499499
}
@@ -509,7 +509,7 @@ func GetRuntimeInfo(client client.Client, name, namespace string) (runtimeInfo R
509509
runtimeInfo.SetFuseNodeSelector(juicefsRuntime.Spec.Fuse.NodeSelector)
510510
runtimeInfo.SetupFuseCleanPolicy(juicefsRuntime.Spec.Fuse.CleanPolicy)
511511
case common.ThinRuntime:
512-
thinRuntime, err := utils.GetThinRuntime(client, name, namespace)
512+
thinRuntime, err := utils.GetThinRuntime(reader, name, namespace)
513513
if err != nil {
514514
return runtimeInfo, err
515515
}
@@ -525,7 +525,7 @@ func GetRuntimeInfo(client client.Client, name, namespace string) (runtimeInfo R
525525
runtimeInfo.SetFuseNodeSelector(thinRuntime.Spec.Fuse.NodeSelector)
526526
runtimeInfo.SetupFuseCleanPolicy(thinRuntime.Spec.Fuse.CleanPolicy)
527527
case common.EFCRuntime:
528-
efcRuntime, err := utils.GetEFCRuntime(client, name, namespace)
528+
efcRuntime, err := utils.GetEFCRuntime(reader, name, namespace)
529529
if err != nil {
530530
return runtimeInfo, err
531531
}
@@ -541,7 +541,7 @@ func GetRuntimeInfo(client client.Client, name, namespace string) (runtimeInfo R
541541
runtimeInfo.SetFuseNodeSelector(efcRuntime.Spec.Fuse.NodeSelector)
542542
runtimeInfo.SetupFuseCleanPolicy(efcRuntime.Spec.Fuse.CleanPolicy)
543543
case common.VineyardRuntime:
544-
vineyardRuntime, err := utils.GetVineyardRuntime(client, name, namespace)
544+
vineyardRuntime, err := utils.GetVineyardRuntime(reader, name, namespace)
545545
if err != nil {
546546
return runtimeInfo, err
547547
}
@@ -562,7 +562,7 @@ func GetRuntimeInfo(client client.Client, name, namespace string) (runtimeInfo R
562562
}
563563

564564
if runtimeInfo != nil {
565-
runtimeInfo.SetClient(client)
565+
runtimeInfo.SetClientReader(reader)
566566
runtimeInfo.SetOwnerDatasetUID(dataset.UID)
567567
}
568568
return runtimeInfo, err

pkg/ddc/base/runtime_helper_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ import (
497497
// if err != nil {
498498
// t.Errorf("testcase %s failed due to error %v", testcase.name, err)
499499
// }
500-
// runtimeInfo.SetClient(fakeClient)
500+
// runtimeInfo.SetClientReader(fakeClient)
501501
// _, err = runtimeInfo.GetTemplateToInjectForFuse(testcase.pvcName, testcase.pvc.Namespace, options)
502502
// if (err == nil) == testcase.expectErr {
503503
// t.Errorf("testcase %s failed due to expecting want error: %v error %v", testcase.name, testcase.expectErr, err)
@@ -866,7 +866,7 @@ import (
866866
// if err != nil {
867867
// t.Errorf("testcase %s failed due to error %v", testcase.name, err)
868868
// }
869-
// runtimeInfo.SetClient(fakeClient)
869+
// runtimeInfo.SetClientReader(fakeClient)
870870
// _, err = runtimeInfo.GetTemplateToInjectForFuse(testcase.pvcName, testcase.pvc.Namespace, options)
871871
// if (err == nil) == testcase.expectErr {
872872
// t.Errorf("testcase %s failed due to expecting want error: %v error %v", testcase.name, testcase.expectErr, err)
@@ -1075,7 +1075,7 @@ import (
10751075
// if err != nil {
10761076
// t.Errorf("testcase %s failed due to error %v", testcase.name, err)
10771077
// }
1078-
// runtimeInfo.SetClient(fakeClient)
1078+
// runtimeInfo.SetClientReader(fakeClient)
10791079
// template, err := runtimeInfo.GetTemplateToInjectForFuse(testcase.pvcName, testcase.pvc.Namespace, options)
10801080
// if (err == nil) == testcase.expectErr {
10811081
// t.Errorf("testcase %s failed due to expecting want error: %v error %v", testcase.name, testcase.expectErr, err)
@@ -1158,7 +1158,7 @@ func TestGetFuseDaemonset(t *testing.T) {
11581158
}
11591159

11601160
if fakeClient != nil {
1161-
runtimeInfo.SetClient(fakeClient)
1161+
runtimeInfo.SetClientReader(fakeClient)
11621162
}
11631163

11641164
_, err := runtimeInfo.getFuseDaemonset()

pkg/ddc/base/runtime_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,11 +1149,11 @@ func TestGetRuntimeInfo(t *testing.T) {
11491149
return
11501150
}
11511151
if got != nil {
1152-
got.SetClient(nil)
1152+
got.SetClientReader(nil)
11531153
}
11541154

11551155
if tt.want != nil {
1156-
tt.want.SetClient(nil)
1156+
tt.want.SetClientReader(nil)
11571157
}
11581158

11591159
if !tt.wantErr && !reflect.DeepEqual(got, tt.want) {

pkg/ddc/goosefs/cache_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestQueryCacheStatus(t *testing.T) {
4444
defer patch1.Reset()
4545

4646
patch2 := ApplyFunc(utils.GetDataset,
47-
func(_ client.Client, _ string, _ string) (*datav1alpha1.Dataset, error) {
47+
func(_ client.Reader, _ string, _ string) (*datav1alpha1.Dataset, error) {
4848
d := &datav1alpha1.Dataset{
4949
Status: datav1alpha1.DatasetStatus{
5050
UfsTotal: "52.18MiB",
@@ -89,7 +89,7 @@ func TestQueryCacheStatus(t *testing.T) {
8989
defer patch1.Reset()
9090

9191
patch2 := ApplyFunc(utils.GetDataset,
92-
func(_ client.Client, _ string, _ string) (*datav1alpha1.Dataset, error) {
92+
func(_ client.Reader, _ string, _ string) (*datav1alpha1.Dataset, error) {
9393
d := &datav1alpha1.Dataset{
9494
Status: datav1alpha1.DatasetStatus{
9595
UfsTotal: "[Calculating]",
@@ -126,7 +126,7 @@ func TestQueryCacheStatus(t *testing.T) {
126126
defer patch1.Reset()
127127

128128
patch2 := ApplyFunc(utils.GetDataset,
129-
func(_ client.Client, _ string, _ string) (*datav1alpha1.Dataset, error) {
129+
func(_ client.Reader, _ string, _ string) (*datav1alpha1.Dataset, error) {
130130
d := &datav1alpha1.Dataset{
131131
Status: datav1alpha1.DatasetStatus{
132132
UfsTotal: "",

pkg/ddc/jindo/cache_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestQueryCacheStatus(t *testing.T) {
4444
defer patch1.Reset()
4545

4646
patch2 := ApplyFunc(utils.GetDataset,
47-
func(_ client.Client, _ string, _ string) (*datav1alpha1.Dataset, error) {
47+
func(_ client.Reader, _ string, _ string) (*datav1alpha1.Dataset, error) {
4848
d := &datav1alpha1.Dataset{
4949
Status: datav1alpha1.DatasetStatus{
5050
UfsTotal: "52.18MiB",
@@ -76,7 +76,7 @@ func TestQueryCacheStatus(t *testing.T) {
7676
defer patch1.Reset()
7777

7878
patch2 := ApplyFunc(utils.GetDataset,
79-
func(_ client.Client, _ string, _ string) (*datav1alpha1.Dataset, error) {
79+
func(_ client.Reader, _ string, _ string) (*datav1alpha1.Dataset, error) {
8080
d := &datav1alpha1.Dataset{
8181
Status: datav1alpha1.DatasetStatus{
8282
UfsTotal: "[Calculating]",
@@ -107,7 +107,7 @@ func TestQueryCacheStatus(t *testing.T) {
107107
defer patch1.Reset()
108108

109109
patch2 := ApplyFunc(utils.GetDataset,
110-
func(_ client.Client, _ string, _ string) (*datav1alpha1.Dataset, error) {
110+
func(_ client.Reader, _ string, _ string) (*datav1alpha1.Dataset, error) {
111111
d := &datav1alpha1.Dataset{
112112
Status: datav1alpha1.DatasetStatus{
113113
UfsTotal: "",

0 commit comments

Comments
 (0)