Skip to content

Commit

Permalink
feat: remove get pod no-cache
Browse files Browse the repository at this point in the history
Signed-off-by: Airren <qiang.ren@intel.com>
  • Loading branch information
Airren committed Jun 27, 2024
1 parent 0f26e50 commit 63aa661
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 80 deletions.
4 changes: 3 additions & 1 deletion pkg/agent/orm/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import (
"github.com/kubewharf/katalyst-core/pkg/config"
"github.com/kubewharf/katalyst-core/pkg/config/generic"
"github.com/kubewharf/katalyst-core/pkg/metaserver"
metaserverpod "github.com/kubewharf/katalyst-core/pkg/metaserver/agent/pod"
"github.com/kubewharf/katalyst-core/pkg/metrics"
"github.com/kubewharf/katalyst-core/pkg/util/bitmask"
cgroupmgr "github.com/kubewharf/katalyst-core/pkg/util/cgroup/manager"
Expand Down Expand Up @@ -452,7 +453,8 @@ func (m *ManagerImpl) processAddPod(podUID string) error {
err error
)
if m.mode == workModeNri {
pod, err = m.metaManager.GetPodNoCache(m.ctx, podUID)
context.WithValue(m.ctx, metaserverpod.BypassCacheKey, metaserverpod.BypassCacheTrue)

Check failure on line 456 in pkg/agent/orm/manager.go

View workflow job for this annotation

GitHub Actions / Lint

unusedresult: result of context.WithValue call not used (govet)

Check failure on line 456 in pkg/agent/orm/manager.go

View workflow job for this annotation

GitHub Actions / Vet

result of context.WithValue call not used
pod, err = m.metaManager.GetPod(m.ctx, podUID)
} else {
pod, err = m.metaManager.GetPod(m.ctx, podUID)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ func (f *FakePodFetcher) GetPod(ctx context.Context, podUID string) (*v1.Pod, er
return f.GetPodFunc(ctx, podUID)
}

func (f *FakePodFetcher) GetPodNoCache(ctx context.Context, podUID string) (*v1.Pod, error) {
return f.GetPodFunc(ctx, podUID)
}

func (f *FakePodFetcher) GetPodList(ctx context.Context, podFilter func(*v1.Pod) bool) ([]*v1.Pod, error) {
return nil, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,6 @@ func (f *FakePodFetcher) GetPod(ctx context.Context, podUID string) (*v1.Pod, er
return f.GetPodFunc(ctx, podUID)
}

func (f *FakePodFetcher) GetPodNoCache(ctx context.Context, podUID string) (*v1.Pod, error) {
return f.GetPodFunc(ctx, podUID)
}

func (f *FakePodFetcher) GetPodList(ctx context.Context, podFilter func(*v1.Pod) bool) ([]*v1.Pod, error) {
return f.GetPodListFunc(ctx, podFilter)
}
13 changes: 0 additions & 13 deletions pkg/metaserver/agent/pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ type PodFetcher interface {
GetContainerSpec(podUID, containerName string) (*v1.Container, error)
// GetPod returns Pod by UID
GetPod(ctx context.Context, podUID string) (*v1.Pod, error)
GetPodNoCache(ctx context.Context, podUID string) (*v1.Pod, error)
}

type podFetcherImpl struct {
Expand Down Expand Up @@ -217,18 +216,6 @@ func (w *podFetcherImpl) GetPod(ctx context.Context, podUID string) (*v1.Pod, er
return nil, fmt.Errorf("failed to find pod by uid %v", podUID)
}

func (w *podFetcherImpl) GetPodNoCache(ctx context.Context, podUID string) (*v1.Pod, error) {
pods, err := w.kubeletPodFetcher.GetPodList(ctx, func(pod *v1.Pod) bool {
return podUID == string(pod.UID)
})
if err != nil || len(pods) == 0 {
klog.Errorf("get pod by uid %s failed: %v", podUID, err)
return nil, err
}
klog.V(6).Infof("get pod by uid %s success", podUID)
return pods[0], nil
}

func (w *podFetcherImpl) getKubeletPodsCache(ctx context.Context) (map[string]*v1.Pod, error) {
// if current kubelet pod cache is nil or enforce bypass, we sync cache first
w.kubeletPodsCacheLock.RLock()
Expand Down
11 changes: 0 additions & 11 deletions pkg/metaserver/agent/pod/pod_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,6 @@ func (p *PodFetcherStub) GetPod(_ context.Context, podUID string) (*v1.Pod, erro
return nil, fmt.Errorf("failed to find pod by uid %v", podUID)
}

func (p *PodFetcherStub) GetPodNoCache(_ context.Context, podUID string) (*v1.Pod, error) {
p.mutex.Lock()
defer p.mutex.Unlock()
for _, pod := range p.PodList {
if string(pod.UID) == podUID {
return pod, nil
}
}
return nil, fmt.Errorf("failed to find pod by uid %v", podUID)
}

func (p *PodFetcherStub) Run(_ context.Context) {}

func (p *PodFetcherStub) GetContainerID(podUID, containerName string) (string, error) {
Expand Down
47 changes: 0 additions & 47 deletions pkg/metaserver/agent/pod/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,9 @@ limitations under the License.
package pod

import (
"context"
"fmt"
"reflect"
"testing"

"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

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

"github.com/kubewharf/katalyst-core/pkg/util/cgroup/common"
)

Expand Down Expand Up @@ -56,43 +49,3 @@ func Test_getCgroupRootPaths(t *testing.T) {
t.Errorf("getAbsCgroupRootPaths() \n got = %v, \n want = %v\n", got, want)
}
}

type fakeKubeletPodFetcher struct{}

func (f *fakeKubeletPodFetcher) GetPodList(_ context.Context, podFilter func(*v1.Pod) bool) (pods []*v1.Pod, err error) {
podList := []*v1.Pod{{
TypeMeta: metav1.TypeMeta{},
ObjectMeta: metav1.ObjectMeta{
Name: "PodName",
UID: "PodUID",
},
Spec: v1.PodSpec{},
Status: v1.PodStatus{},
}}
for _, pod := range podList {
if podFilter != nil && !podFilter(pod) {
continue
}
pods = append(pods, pod)

}
if len(pods) == 0 {
return []*v1.Pod{}, fmt.Errorf("pod not found")
}
return pods, nil
}

func Test_podFetcherImpl_GetPodNoCache(t *testing.T) {
t.Parallel()

podFetcher := &podFetcherImpl{
kubeletPodFetcher: &fakeKubeletPodFetcher{},
}

podCache1, err := podFetcher.GetPodNoCache(context.TODO(), "PodUID")
assert.Equal(t, err, nil)
assert.Equal(t, string(podCache1.UID), "PodUID")

_, err = podFetcher.GetPodNoCache(context.TODO(), "PodUIDNotExist")
assert.Equal(t, err, fmt.Errorf("pod not found"))
}

0 comments on commit 63aa661

Please sign in to comment.