Skip to content

Commit 54d366e

Browse files
committed
fix: follow the import rules and correct non-standard files
1 parent 302bcd4 commit 54d366e

24 files changed

+38
-62
lines changed

pkg/client/control/resourcerecommend.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ import (
2121
"encoding/json"
2222
"fmt"
2323

24-
apis "github.com/kubewharf/katalyst-api/pkg/apis/recommendation/v1alpha1"
25-
clientset "github.com/kubewharf/katalyst-api/pkg/client/clientset/versioned"
2624
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2725
"k8s.io/apimachinery/pkg/types"
2826
"k8s.io/apimachinery/pkg/util/jsonmergepatch"
27+
28+
apis "github.com/kubewharf/katalyst-api/pkg/apis/recommendation/v1alpha1"
29+
clientset "github.com/kubewharf/katalyst-api/pkg/client/clientset/versioned"
2930
)
3031

3132
// ResourceRecommendUpdater is used to update ResourceRecommend CR

pkg/client/control/resourcerecommend_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ import (
2020
"context"
2121
"testing"
2222

23-
apis "github.com/kubewharf/katalyst-api/pkg/apis/recommendation/v1alpha1"
24-
externalfake "github.com/kubewharf/katalyst-api/pkg/client/clientset/versioned/fake"
2523
"github.com/stretchr/testify/assert"
2624
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25+
26+
apis "github.com/kubewharf/katalyst-api/pkg/apis/recommendation/v1alpha1"
27+
externalfake "github.com/kubewharf/katalyst-api/pkg/client/clientset/versioned/fake"
2728
)
2829

2930
func TestPatchResourceRecommend(t *testing.T) {

pkg/controller/resource-recommend/controller/resourcerecommend_controller.go

+13-12
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import (
3838

3939
"github.com/kubewharf/katalyst-api/pkg/apis/recommendation/v1alpha1"
4040
reclister "github.com/kubewharf/katalyst-api/pkg/client/listers/recommendation/v1alpha1"
41-
4241
katalystbase "github.com/kubewharf/katalyst-core/cmd/base"
4342
"github.com/kubewharf/katalyst-core/pkg/client/control"
4443
"github.com/kubewharf/katalyst-core/pkg/config/controller"
@@ -206,21 +205,23 @@ func (rrc *ResourceRecommendController) updateRec(oldObj, newObj interface{}) {
206205
}
207206

208207
func (rrc *ResourceRecommendController) deleteRec(obj interface{}) {
209-
v, ok := obj.(*v1alpha1.ResourceRecommend)
210-
if !ok {
211-
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
208+
var rec *v1alpha1.ResourceRecommend = nil
209+
var ok = false
210+
switch t := obj.(type) {
211+
case *v1alpha1.ResourceRecommend:
212+
rec = t
213+
case cache.DeletedFinalStateUnknown:
214+
rec, ok = t.Obj.(*v1alpha1.ResourceRecommend)
212215
if !ok {
213-
klog.Errorf("[resource-recommend] cannot convert obj to *apis.ResourceRecommend: %v", obj)
214-
return
215-
}
216-
v, ok = tombstone.Obj.(*v1alpha1.ResourceRecommend)
217-
if !ok {
218-
klog.Errorf("[resource-recommend] cannot convert obj to *apis.ResourceRecommend: %v", obj)
216+
klog.ErrorS(nil, "[resource-recommend] cannot convert obj to *apis.ResourceRecommend: %v", "Obj", t)
219217
return
220218
}
219+
default:
220+
klog.ErrorS(nil, "Cannot convert to *v1alpha1.ResourceRecommend", "Obj", t)
221+
return
221222
}
222-
klog.V(4).Infof("[resource-recommend] notice deletion of ResourceRecommend %s", v.Name)
223-
rrc.dequeueRec(v)
223+
klog.V(4).Infof("[resource-recommend] notice deletion of ResourceRecommend %s", rec.Name)
224+
rrc.dequeueRec(rec)
224225
}
225226

226227
func (rrc *ResourceRecommendController) enqueueRec(rec *v1alpha1.ResourceRecommend) {

pkg/controller/resource-recommend/controller/resourcerecommend_controller_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ import (
2121
"time"
2222

2323
"github.com/bytedance/mockey"
24-
"github.com/smartystreets/goconvey/convey"
25-
2624
promapiv1 "github.com/prometheus/client_golang/api/prometheus/v1"
25+
"github.com/smartystreets/goconvey/convey"
2726
"github.com/stretchr/testify/mock"
2827

2928
"github.com/kubewharf/katalyst-core/pkg/config/controller"

pkg/controller/resource-recommend/oom/oom_recorder.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,13 @@ import (
2323
"sync"
2424
"time"
2525

26+
"github.com/pkg/errors"
2627
apierrors "k8s.io/apimachinery/pkg/api/errors"
28+
"k8s.io/apimachinery/pkg/api/resource"
2729
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2830
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
29-
30-
"github.com/pkg/errors"
31-
"k8s.io/apimachinery/pkg/api/resource"
3231
"k8s.io/client-go/util/workqueue"
3332
"k8s.io/klog/v2"
34-
"sigs.k8s.io/controller-runtime/pkg/client"
3533
)
3634

3735
const (
@@ -144,9 +142,9 @@ func (r *PodOOMRecorder) updateOOMRecordConfigMap() error {
144142
return err
145143
}
146144
oomConfigMap, err := r.Client.ConfigMaps(ConfigMapOOMRecordNameSpace).
147-
Get(context.TODO(), ConfigMapOOMRecordName, metav1.GetOptions{})
145+
Get(context.TODO(), ConfigMapOOMRecordName, metav1.GetOptions{ResourceVersion: "0"})
148146
if err != nil {
149-
if apierrors.IsNotFound(err) {
147+
if !apierrors.IsNotFound(err) {
150148
return err
151149
}
152150
oomConfigMap.Name = ConfigMapOOMRecordName
@@ -214,9 +212,13 @@ func (r *PodOOMRecorder) Run(stopCh <-chan struct{}) error {
214212

215213
func (r *PodOOMRecorder) ListOOMRecordsFromConfigmap() ([]OOMRecord, error) {
216214
oomConfigMap, err := r.Client.ConfigMaps(ConfigMapOOMRecordNameSpace).
217-
Get(context.TODO(), ConfigMapOOMRecordName, metav1.GetOptions{})
215+
Get(context.TODO(), ConfigMapOOMRecordName, metav1.GetOptions{ResourceVersion: "0"})
218216
if err != nil {
219-
return nil, client.IgnoreNotFound(err)
217+
// if ConfigMap cant be found, we return an empty list
218+
if apierrors.IsNotFound(err) {
219+
return []OOMRecord{}, nil
220+
}
221+
return nil, err
220222
}
221223
oomRecords := make([]OOMRecord, 0)
222224
err = json.Unmarshal([]byte(oomConfigMap.Data[ConfigMapDataOOMRecord]), &oomRecords)

pkg/controller/resource-recommend/oom/oom_recorder_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ import (
2121
"testing"
2222
"time"
2323

24-
k8sfake "k8s.io/client-go/kubernetes/fake"
25-
2624
v1 "k8s.io/api/core/v1"
2725
"k8s.io/apimachinery/pkg/api/resource"
2826
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27+
k8sfake "k8s.io/client-go/kubernetes/fake"
2928
)
3029

3130
func TestCleanOOMRecord(t *testing.T) {

pkg/controller/resource-recommend/processor/manager/processor_manager.go

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323

2424
"github.com/kubewharf/katalyst-api/pkg/apis/recommendation/v1alpha1"
2525
lister "github.com/kubewharf/katalyst-api/pkg/client/listers/recommendation/v1alpha1"
26-
2726
"github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/datasource"
2827
"github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/processor"
2928
"github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/processor/percentile"

pkg/controller/resource-recommend/processor/manager/processor_manager_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"time"
2424

2525
"github.com/kubewharf/katalyst-api/pkg/apis/recommendation/v1alpha1"
26-
2726
"github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/processor"
2827
"github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/log"
2928
errortypes "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/types/error"

pkg/controller/resource-recommend/processor/percentile/process_gc.go

-2
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ import (
2222
"time"
2323

2424
"k8s.io/apimachinery/pkg/labels"
25-
2625
"k8s.io/apimachinery/pkg/types"
2726
"k8s.io/klog/v2"
2827

2928
"github.com/kubewharf/katalyst-api/pkg/apis/recommendation/v1alpha1"
30-
3129
"github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/processor/percentile/task"
3230
"github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/log"
3331
processortypes "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/types/processor"

pkg/controller/resource-recommend/processor/percentile/processor.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ import (
2222
"sync"
2323
"time"
2424

25-
"github.com/kubewharf/katalyst-api/pkg/client/listers/recommendation/v1alpha1"
26-
2725
"github.com/pkg/errors"
2826
"golang.org/x/time/rate"
2927
"k8s.io/apimachinery/pkg/types"
3028
"k8s.io/client-go/util/workqueue"
3129
"k8s.io/klog/v2"
3230

31+
"github.com/kubewharf/katalyst-api/pkg/client/listers/recommendation/v1alpha1"
3332
"github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/datasource"
3433
"github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/processor"
3534
"github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/processor/percentile/task"

pkg/controller/resource-recommend/recommender/manager/recommender_manager.go

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"k8s.io/klog/v2"
2121

2222
"github.com/kubewharf/katalyst-api/pkg/apis/recommendation/v1alpha1"
23-
2423
"github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/oom"
2524
processormanager "github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/processor/manager"
2625
"github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/recommender"

pkg/controller/resource-recommend/recommender/recommenders/percentile_recommender.go

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"k8s.io/klog/v2"
2727

2828
"github.com/kubewharf/katalyst-api/pkg/apis/recommendation/v1alpha1"
29-
3029
"github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/oom"
3130
"github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/processor"
3231
"github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/recommender"

pkg/controller/resource-recommend/recommender/recommenders/percentile_recommender_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"k8s.io/apimachinery/pkg/types"
2828

2929
"github.com/kubewharf/katalyst-api/pkg/apis/recommendation/v1alpha1"
30-
3130
"github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/oom"
3231
datasourcetypes "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/types/datasource"
3332
customtypes "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/types/error"

pkg/util/resource-recommend/resource/k8s_resource.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,7 @@ func ConvertAndGetResource(ctx context.Context, client dynamic.Interface,
4545
Group: gvk.Group,
4646
Version: gvk.Version,
4747
Resource: mapping.Resource.Resource,
48-
}).Namespace(namespace).Get(ctx, targetRef.Name, metav1.GetOptions{
49-
TypeMeta: metav1.TypeMeta{
50-
APIVersion: targetRef.APIVersion,
51-
Kind: targetRef.Kind,
52-
},
53-
})
48+
}).Namespace(namespace).Get(ctx, targetRef.Name, metav1.GetOptions{ResourceVersion: "0"})
5449
if err != nil {
5550
return nil, err
5651
}

pkg/util/resource-recommend/resource/k8s_resource_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ import (
2121
"reflect"
2222
"testing"
2323

24+
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2425
"k8s.io/apimachinery/pkg/runtime"
2526
"k8s.io/client-go/dynamic"
26-
27-
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2827
dynamicfake "k8s.io/client-go/dynamic/fake"
2928

3029
"github.com/kubewharf/katalyst-api/pkg/apis/recommendation/v1alpha1"

pkg/util/resource-recommend/resource/k8s_resource_test_util.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package resource
1919
import (
2020
"context"
2121

22+
v1 "k8s.io/api/core/v1"
2223
"k8s.io/apimachinery/pkg/api/meta"
2324
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2425
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -29,8 +30,6 @@ import (
2930
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
3031
"k8s.io/client-go/restmapper"
3132
clientTesting "k8s.io/client-go/testing"
32-
33-
v1 "k8s.io/api/core/v1"
3433
)
3534

3635
func CreateMockPod(labels, annotations map[string]string, name, namespace, nodeName string, containers []v1.Container, client corev1.CoreV1Interface) error {

pkg/util/resource-recommend/types/conditions/conditions.go

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2424

2525
"github.com/kubewharf/katalyst-api/pkg/apis/recommendation/v1alpha1"
26-
2726
errortypes "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/types/error"
2827
)
2928

pkg/util/resource-recommend/types/conditions/conditions_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ import (
2323

2424
"github.com/bytedance/mockey"
2525
"github.com/smartystreets/goconvey/convey"
26-
2726
v1 "k8s.io/api/core/v1"
2827
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2928

3029
"github.com/kubewharf/katalyst-api/pkg/apis/recommendation/v1alpha1"
31-
3230
errortypes "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/types/error"
3331
)
3432

pkg/util/resource-recommend/types/processor/task_key.go

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"k8s.io/apimachinery/pkg/types"
2424

2525
"github.com/kubewharf/katalyst-api/pkg/apis/recommendation/v1alpha1"
26-
2726
datasourcetypes "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/types/datasource"
2827
)
2928

pkg/util/resource-recommend/types/processor/task_key_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"k8s.io/apimachinery/pkg/types"
2525

2626
"github.com/kubewharf/katalyst-api/pkg/apis/recommendation/v1alpha1"
27-
2827
datasourcetype "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/types/datasource"
2928
)
3029

pkg/util/resource-recommend/types/recommendation/recommendation.go

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"k8s.io/klog/v2"
2828

2929
"github.com/kubewharf/katalyst-api/pkg/apis/recommendation/v1alpha1"
30-
3130
conditionstypes "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/types/conditions"
3231
errortypes "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/types/error"
3332
)

pkg/util/resource-recommend/types/recommendation/recommendation_test.go

-3
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,13 @@ import (
2323
"time"
2424

2525
"github.com/bytedance/mockey"
26-
_ "github.com/bytedance/mockey"
2726
"github.com/smartystreets/goconvey/convey"
28-
_ "github.com/smartystreets/goconvey/convey"
2927
v1 "k8s.io/api/core/v1"
3028
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3129
"k8s.io/apimachinery/pkg/runtime"
3230
dynamicfake "k8s.io/client-go/dynamic/fake"
3331

3432
"github.com/kubewharf/katalyst-api/pkg/apis/recommendation/v1alpha1"
35-
3633
resourceutils "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/resource"
3734
conditionstypes "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/types/conditions"
3835
errortypes "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/types/error"

pkg/util/resource-recommend/types/recommendation/validate.go

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
2626

2727
"github.com/kubewharf/katalyst-api/pkg/apis/recommendation/v1alpha1"
28-
2928
"github.com/kubewharf/katalyst-core/pkg/util/general"
3029
resourceutils "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/resource"
3130
errortypes "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/types/error"

pkg/util/resource-recommend/types/recommendation/validate_test.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,14 @@ import (
2121
"reflect"
2222
"testing"
2323

24-
"k8s.io/client-go/dynamic"
25-
k8sfake "k8s.io/client-go/kubernetes/fake"
26-
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
27-
2824
v1 "k8s.io/api/core/v1"
2925
"k8s.io/apimachinery/pkg/runtime"
26+
"k8s.io/client-go/dynamic"
3027
dynamicfake "k8s.io/client-go/dynamic/fake"
28+
k8sfake "k8s.io/client-go/kubernetes/fake"
29+
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
3130

3231
"github.com/kubewharf/katalyst-api/pkg/apis/recommendation/v1alpha1"
33-
3432
resourceutils "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/resource"
3533
errortypes "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/types/error"
3634
)

0 commit comments

Comments
 (0)