Skip to content

Commit

Permalink
fix: follow the import rules and correct non-standard files
Browse files Browse the repository at this point in the history
  • Loading branch information
ozline committed Oct 26, 2024
1 parent 302bcd4 commit 54d366e
Show file tree
Hide file tree
Showing 24 changed files with 38 additions and 62 deletions.
5 changes: 3 additions & 2 deletions pkg/client/control/resourcerecommend.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ import (
"encoding/json"
"fmt"

apis "github.com/kubewharf/katalyst-api/pkg/apis/recommendation/v1alpha1"
clientset "github.com/kubewharf/katalyst-api/pkg/client/clientset/versioned"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/jsonmergepatch"

apis "github.com/kubewharf/katalyst-api/pkg/apis/recommendation/v1alpha1"
clientset "github.com/kubewharf/katalyst-api/pkg/client/clientset/versioned"
)

// ResourceRecommendUpdater is used to update ResourceRecommend CR
Expand Down
5 changes: 3 additions & 2 deletions pkg/client/control/resourcerecommend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ import (
"context"
"testing"

apis "github.com/kubewharf/katalyst-api/pkg/apis/recommendation/v1alpha1"
externalfake "github.com/kubewharf/katalyst-api/pkg/client/clientset/versioned/fake"
"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

apis "github.com/kubewharf/katalyst-api/pkg/apis/recommendation/v1alpha1"
externalfake "github.com/kubewharf/katalyst-api/pkg/client/clientset/versioned/fake"
)

func TestPatchResourceRecommend(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (

"github.com/kubewharf/katalyst-api/pkg/apis/recommendation/v1alpha1"
reclister "github.com/kubewharf/katalyst-api/pkg/client/listers/recommendation/v1alpha1"

katalystbase "github.com/kubewharf/katalyst-core/cmd/base"
"github.com/kubewharf/katalyst-core/pkg/client/control"
"github.com/kubewharf/katalyst-core/pkg/config/controller"
Expand Down Expand Up @@ -206,21 +205,23 @@ func (rrc *ResourceRecommendController) updateRec(oldObj, newObj interface{}) {
}

func (rrc *ResourceRecommendController) deleteRec(obj interface{}) {
v, ok := obj.(*v1alpha1.ResourceRecommend)
if !ok {
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
var rec *v1alpha1.ResourceRecommend = nil
var ok = false

Check failure on line 209 in pkg/controller/resource-recommend/controller/resourcerecommend_controller.go

View workflow job for this annotation

GitHub Actions / Lint

ineffectual assignment to ok (ineffassign)
switch t := obj.(type) {
case *v1alpha1.ResourceRecommend:
rec = t
case cache.DeletedFinalStateUnknown:
rec, ok = t.Obj.(*v1alpha1.ResourceRecommend)
if !ok {
klog.Errorf("[resource-recommend] cannot convert obj to *apis.ResourceRecommend: %v", obj)
return
}
v, ok = tombstone.Obj.(*v1alpha1.ResourceRecommend)
if !ok {
klog.Errorf("[resource-recommend] cannot convert obj to *apis.ResourceRecommend: %v", obj)
klog.ErrorS(nil, "[resource-recommend] cannot convert obj to *apis.ResourceRecommend: %v", "Obj", t)
return
}
default:
klog.ErrorS(nil, "Cannot convert to *v1alpha1.ResourceRecommend", "Obj", t)
return
}
klog.V(4).Infof("[resource-recommend] notice deletion of ResourceRecommend %s", v.Name)
rrc.dequeueRec(v)
klog.V(4).Infof("[resource-recommend] notice deletion of ResourceRecommend %s", rec.Name)
rrc.dequeueRec(rec)
}

func (rrc *ResourceRecommendController) enqueueRec(rec *v1alpha1.ResourceRecommend) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ import (
"time"

"github.com/bytedance/mockey"
"github.com/smartystreets/goconvey/convey"

promapiv1 "github.com/prometheus/client_golang/api/prometheus/v1"
"github.com/smartystreets/goconvey/convey"
"github.com/stretchr/testify/mock"

"github.com/kubewharf/katalyst-core/pkg/config/controller"
Expand Down
18 changes: 10 additions & 8 deletions pkg/controller/resource-recommend/oom/oom_recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ import (
"sync"
"time"

"github.com/pkg/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"

"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/client-go/util/workqueue"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client"
)

const (
Expand Down Expand Up @@ -144,9 +142,9 @@ func (r *PodOOMRecorder) updateOOMRecordConfigMap() error {
return err
}
oomConfigMap, err := r.Client.ConfigMaps(ConfigMapOOMRecordNameSpace).
Get(context.TODO(), ConfigMapOOMRecordName, metav1.GetOptions{})
Get(context.TODO(), ConfigMapOOMRecordName, metav1.GetOptions{ResourceVersion: "0"})
if err != nil {
if apierrors.IsNotFound(err) {
if !apierrors.IsNotFound(err) {
return err
}
oomConfigMap.Name = ConfigMapOOMRecordName
Expand Down Expand Up @@ -214,9 +212,13 @@ func (r *PodOOMRecorder) Run(stopCh <-chan struct{}) error {

func (r *PodOOMRecorder) ListOOMRecordsFromConfigmap() ([]OOMRecord, error) {
oomConfigMap, err := r.Client.ConfigMaps(ConfigMapOOMRecordNameSpace).
Get(context.TODO(), ConfigMapOOMRecordName, metav1.GetOptions{})
Get(context.TODO(), ConfigMapOOMRecordName, metav1.GetOptions{ResourceVersion: "0"})
if err != nil {
return nil, client.IgnoreNotFound(err)
// if ConfigMap cant be found, we return an empty list
if apierrors.IsNotFound(err) {
return []OOMRecord{}, nil
}
return nil, err
}
oomRecords := make([]OOMRecord, 0)
err = json.Unmarshal([]byte(oomConfigMap.Data[ConfigMapDataOOMRecord]), &oomRecords)
Expand Down
3 changes: 1 addition & 2 deletions pkg/controller/resource-recommend/oom/oom_recorder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ import (
"testing"
"time"

k8sfake "k8s.io/client-go/kubernetes/fake"

v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
k8sfake "k8s.io/client-go/kubernetes/fake"
)

func TestCleanOOMRecord(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

"github.com/kubewharf/katalyst-api/pkg/apis/recommendation/v1alpha1"
lister "github.com/kubewharf/katalyst-api/pkg/client/listers/recommendation/v1alpha1"

"github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/datasource"
"github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/processor"
"github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/processor/percentile"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"time"

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

"github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/processor"
"github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/log"
errortypes "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/types/error"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ import (
"time"

"k8s.io/apimachinery/pkg/labels"

"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2"

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

"github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/processor/percentile/task"
"github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/log"
processortypes "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/types/processor"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ import (
"sync"
"time"

"github.com/kubewharf/katalyst-api/pkg/client/listers/recommendation/v1alpha1"

"github.com/pkg/errors"
"golang.org/x/time/rate"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/workqueue"
"k8s.io/klog/v2"

"github.com/kubewharf/katalyst-api/pkg/client/listers/recommendation/v1alpha1"
"github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/datasource"
"github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/processor"
"github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/processor/percentile/task"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"k8s.io/klog/v2"

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

"github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/oom"
processormanager "github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/processor/manager"
"github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/recommender"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"k8s.io/klog/v2"

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

"github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/oom"
"github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/processor"
"github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/recommender"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"k8s.io/apimachinery/pkg/types"

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

"github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/oom"
datasourcetypes "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/types/datasource"
customtypes "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/types/error"
Expand Down
7 changes: 1 addition & 6 deletions pkg/util/resource-recommend/resource/k8s_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ func ConvertAndGetResource(ctx context.Context, client dynamic.Interface,
Group: gvk.Group,
Version: gvk.Version,
Resource: mapping.Resource.Resource,
}).Namespace(namespace).Get(ctx, targetRef.Name, metav1.GetOptions{
TypeMeta: metav1.TypeMeta{
APIVersion: targetRef.APIVersion,
Kind: targetRef.Kind,
},
})
}).Namespace(namespace).Get(ctx, targetRef.Name, metav1.GetOptions{ResourceVersion: "0"})
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/util/resource-recommend/resource/k8s_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ import (
"reflect"
"testing"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/dynamic"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
dynamicfake "k8s.io/client-go/dynamic/fake"

"github.com/kubewharf/katalyst-api/pkg/apis/recommendation/v1alpha1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package resource
import (
"context"

v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand All @@ -29,8 +30,6 @@ import (
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/restmapper"
clientTesting "k8s.io/client-go/testing"

v1 "k8s.io/api/core/v1"
)

func CreateMockPod(labels, annotations map[string]string, name, namespace, nodeName string, containers []v1.Container, client corev1.CoreV1Interface) error {
Expand Down
1 change: 0 additions & 1 deletion pkg/util/resource-recommend/types/conditions/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

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

errortypes "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/types/error"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ import (

"github.com/bytedance/mockey"
"github.com/smartystreets/goconvey/convey"

v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

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

errortypes "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/types/error"
)

Expand Down
1 change: 0 additions & 1 deletion pkg/util/resource-recommend/types/processor/task_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"k8s.io/apimachinery/pkg/types"

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

datasourcetypes "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/types/datasource"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"k8s.io/apimachinery/pkg/types"

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

datasourcetype "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/types/datasource"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"k8s.io/klog/v2"

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

conditionstypes "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/types/conditions"
errortypes "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/types/error"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,13 @@ import (
"time"

"github.com/bytedance/mockey"
_ "github.com/bytedance/mockey"
"github.com/smartystreets/goconvey/convey"
_ "github.com/smartystreets/goconvey/convey"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
dynamicfake "k8s.io/client-go/dynamic/fake"

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

resourceutils "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/resource"
conditionstypes "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/types/conditions"
errortypes "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/types/error"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
k8sclient "sigs.k8s.io/controller-runtime/pkg/client"

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

"github.com/kubewharf/katalyst-core/pkg/util/general"
resourceutils "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/resource"
errortypes "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/types/error"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@ import (
"reflect"
"testing"

"k8s.io/client-go/dynamic"
k8sfake "k8s.io/client-go/kubernetes/fake"
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"

v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/dynamic"
dynamicfake "k8s.io/client-go/dynamic/fake"
k8sfake "k8s.io/client-go/kubernetes/fake"
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"

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

resourceutils "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/resource"
errortypes "github.com/kubewharf/katalyst-core/pkg/util/resource-recommend/types/error"
)
Expand Down

0 comments on commit 54d366e

Please sign in to comment.