Skip to content

Commit

Permalink
🐛 Remove unused code (koordinator-sh#35)
Browse files Browse the repository at this point in the history
* remove unused code

Signed-off-by: Jason Liu <[email protected]>

* fix static check

Signed-off-by: Jason Liu <[email protected]>
  • Loading branch information
jasonliu747 authored Apr 6, 2022
1 parent ffb8196 commit a18739b
Show file tree
Hide file tree
Showing 28 changed files with 42 additions and 257 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ test: manifests generate fmt vet envtest ## Run tests.
##@ Build

.PHONY: build
build: generate fmt vet lint build-koordlet build-koord-manager
build: generate fmt vet lint build-koordlet build-koord-manager build-koord-scheduler

.PHONY: build-koordlet
build-koordlet: ## Build koordlet binary.
Expand All @@ -91,6 +91,10 @@ build-koordlet: ## Build koordlet binary.
build-koord-manager: ## Build koord-manager binary.
go build -o bin/koord-manager cmd/koord-manager/main.go

.PHONY: build-koord-scheduler
build-koord-scheduler: ## Build koord-scheduler binary.
go build -o bin/koord-scheduler cmd/koord-scheduler/main.go

.PHONY: docker-build
docker-build: test docker-build-koordlet docker-build-koord-manager docker-build-koord-scheduler

Expand Down
3 changes: 1 addition & 2 deletions pkg/koordlet/audit/auditor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
type TestServer struct {
l net.Listener
server *http.Server
port int
}

func (t *TestServer) Serve() {
Expand Down Expand Up @@ -121,7 +120,7 @@ func TestAuditorLogger(t *testing.T) {
if len(response.Events) != 1 {
t.Errorf("failed to load events, expected %d actual %d", 1, len(response.Events))
}
if bytes.Compare(blocks[len(blocks)-11], []byte(response.Events[0].Message)) != 0 {
if !bytes.Equal(blocks[len(blocks)-11], []byte(response.Events[0].Message)) {
t.Errorf("failed to load events, expected %s actual %s", blocks[len(blocks)-11], response.Events[0].Message)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/koordlet/audit/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TestLogReader(t *testing.T) {

lines = append(lines, line)

if bytes.Compare(line, blocks[(i+1)%2]) != 0 {
if !bytes.Equal(line, blocks[(i+1)%2]) {
t.Errorf("failed to read line expected\n: %s\nactual: %v", blocks[(i+1)%2], line)
}
}
Expand Down
1 change: 0 additions & 1 deletion pkg/koordlet/koordlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ type daemon struct {
metricCache metriccache.MetricCache
reporter reporter.Reporter
resManager resmanager.ResManager
pleg pleg.Pleg
}

func NewDaemon(config *config.Configuration) (Daemon, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/koordlet/metriccache/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func fieldLastOfMetricList(metricsList interface{}, aggregateParam AggregatePara

timestamp, ok := fieldTimeValue.Interface().(time.Time)
if !ok {
return 0, fmt.Errorf("Timestamp field type must be *time.Time, and value must not be nil. %v is illegal! ", fieldTimeValue)
return 0, fmt.Errorf("timestamp field type must be *time.Time, and value must not be nil. %v is illegal! ", fieldTimeValue)
}
if timestamp.UnixNano() > lastTime {
lastTime = timestamp.UnixNano()
Expand Down
2 changes: 1 addition & 1 deletion pkg/koordlet/metricsadvisor/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ type contextRecord struct {

type collectContext struct {
// record latest cpu stat for calculate resource used
// lastBeCPUStat contextRecord
lastNodeCPUStat contextRecord
lastPodCPUStat sync.Map
lastContainerCPUStat sync.Map
lastBeCPUStat contextRecord

lastPodCPUThrottled sync.Map
lastContainerCPUThrottled sync.Map
Expand Down
25 changes: 0 additions & 25 deletions pkg/koordlet/pleg/watcher_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,6 @@ func NewWatcher() (Watcher, error) {
return nil, errNotSupported
}

type notSupportedWatcher struct {
}

func (w *notSupportedWatcher) Close() error {
return errNotSupported
}

func (w *notSupportedWatcher) AddWatch(path string) error {
return errNotSupported
}

func (w *notSupportedWatcher) RemoveWatch(path string) error {
return errNotSupported
}

func (w *notSupportedWatcher) Event() chan *inotify.Event {
ch := make(chan *inotify.Event)
close(ch)
return ch
}

func (w *notSupportedWatcher) Error() chan error {
return make(chan error)
}

func TypeOf(event *inotify.Event) EventType {
if event.Mask&IN_CREATE != 0 && event.Mask&IN_ISDIR != 0 {
return DirCreated
Expand Down
19 changes: 6 additions & 13 deletions pkg/koordlet/reporter/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (

"golang.org/x/time/rate"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -45,7 +44,7 @@ import (
listerbeta1 "github.com/koordinator-sh/koordinator/pkg/client/listers/slo/v1alpha1"
"github.com/koordinator-sh/koordinator/pkg/koordlet/metriccache"
"github.com/koordinator-sh/koordinator/pkg/koordlet/statesinformer"
"github.com/koordinator-sh/koordinator/pkg/koordlet/util"
"github.com/koordinator-sh/koordinator/pkg/util"
)

const (
Expand Down Expand Up @@ -84,7 +83,7 @@ func NewReporter(cfg *Config, kubeClient *clientset.Clientset, crdClient *client
eventBroadcaster := record.NewBroadcaster()
eventBroadcaster.StartRecordingToSink(&clientcorev1.EventSinkImpl{Interface: kubeClient.CoreV1().Events("")})

recorder := eventBroadcaster.NewRecorder(scheme, v1.EventSource{Component: "koordlet-reporter", Host: nodeName})
recorder := eventBroadcaster.NewRecorder(scheme, corev1.EventSource{Component: "koordlet-reporter", Host: nodeName})

r := &reporter{
config: cfg,
Expand Down Expand Up @@ -219,12 +218,6 @@ func (r *reporter) isNodeMetricInited() bool {
return r.nodeMetric != nil
}

func (r *reporter) getNodeMetricSpec() *slov1alpha1.NodeMetricSpec {
r.rwMutex.RLock()
defer r.rwMutex.RUnlock()
return r.nodeMetric.Spec.DeepCopy()
}

func (r *reporter) createNodeMetric(nodeMetric *slov1alpha1.NodeMetric) {
r.rwMutex.Lock()
defer r.rwMutex.Unlock()
Expand Down Expand Up @@ -338,17 +331,17 @@ func (su *statusUpdater) updateStatus(nodeMetric *slov1alpha1.NodeMetric, newSta
func convertNodeMetricToResourceMap(nodeMetric *metriccache.NodeResourceMetric) *slov1alpha1.ResourceMap {
return &slov1alpha1.ResourceMap{
ResourceList: corev1.ResourceList{
v1.ResourceCPU: nodeMetric.CPUUsed.CPUUsed,
v1.ResourceMemory: nodeMetric.MemoryUsed.MemoryWithoutCache,
corev1.ResourceCPU: nodeMetric.CPUUsed.CPUUsed,
corev1.ResourceMemory: nodeMetric.MemoryUsed.MemoryWithoutCache,
},
}
}

func convertPodMetricToResourceMap(podMetric *metriccache.PodResourceMetric) *slov1alpha1.ResourceMap {
return &slov1alpha1.ResourceMap{
ResourceList: corev1.ResourceList{
v1.ResourceCPU: podMetric.CPUUsed.CPUUsed,
v1.ResourceMemory: podMetric.MemoryUsed.MemoryWithoutCache,
corev1.ResourceCPU: podMetric.CPUUsed.CPUUsed,
corev1.ResourceMemory: podMetric.MemoryUsed.MemoryWithoutCache,
},
}
}
7 changes: 1 addition & 6 deletions pkg/koordlet/resmanager/cpu_suppress.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var (

cfsPeriod int64 = 100000
beMinQuota int64 = 2000
beMaxIncreaseCPUPercent = 0.1 //scale up slow
beMaxIncreaseCPUPercent = 0.1 // scale up slow
)

type suppressPolicyStatus string
Expand Down Expand Up @@ -108,7 +108,6 @@ func writeBECgroupsCPUSet(paths []string, cpusetStr string, isReversed bool) {
klog.Warningf("failed to write be cgroup cpuset: path %s, err %s", paths[i], err)
}
}
return
}

// calculateBESuppressCPU calculates the quantity of cpuset cpus for suppressing be pods
Expand Down Expand Up @@ -344,8 +343,6 @@ func (r *CPUSuppress) suppressBECPU() {
r.suppressPolicyStatuses[string(slov1alpha1.CPUSetPolicy)] = policyUsing
r.recoverCFSQuotaIfNeed()
}

return
}

func adjustByCPUSet(cpusetQuantity *resource.Quantity, nodeCPUInfo *metriccache.NodeCPUInfo) {
Expand Down Expand Up @@ -390,7 +387,6 @@ func (r *CPUSuppress) recoverCPUSetIfNeed() {
klog.V(6).Infof("recover bestEffort cpuset, cpuset %v", rootCPUSet)
writeBECgroupsCPUSet(cpusetCgroupPaths, cpusetStr, false)
r.suppressPolicyStatuses[string(slov1alpha1.CPUSetPolicy)] = policyRecovered
return
}

func adjustByCfsQuota(cpuQuantity *resource.Quantity, node *corev1.Node) {
Expand Down Expand Up @@ -439,5 +435,4 @@ func (r *CPUSuppress) recoverCFSQuotaIfNeed() {
return
}
r.suppressPolicyStatuses[string(slov1alpha1.CPUCfsQuotaPolicy)] = policyRecovered
return
}
56 changes: 1 addition & 55 deletions pkg/koordlet/resmanager/metrics_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ import (
"github.com/koordinator-sh/koordinator/pkg/koordlet/statesinformer"
)

func (r *resmanager) collectNodeMetricsAvg(windowSeconds int64) metriccache.NodeResourceQueryResult {
queryParam := generateQueryParamsAvg(windowSeconds)
return r.collectNodeMetric(queryParam)
}

//query data for 2 * collectResUsedIntervalSeconds
// query data for 2 * collectResUsedIntervalSeconds
func (r *resmanager) collectNodeAndPodMetricLast() (*metriccache.NodeResourceMetric, []*metriccache.PodResourceMetric) {
queryParam := generateQueryParamsLast(r.collectResUsedIntervalSeconds * 2)
return r.collectNodeAndPodMetrics(queryParam)
Expand Down Expand Up @@ -84,55 +79,6 @@ func (r *resmanager) collectPodMetric(podMeta *statesinformer.PodMeta, queryPara
return queryResult
}

func (r *resmanager) collectContainerResMetricLast(containerID *string) metriccache.ContainerResourceQueryResult {
if containerID == nil {
return metriccache.ContainerResourceQueryResult{
QueryResult: metriccache.QueryResult{Error: fmt.Errorf("container is nil")},
}
}
queryParam := generateQueryParamsLast(r.collectResUsedIntervalSeconds * 2)
queryResult := r.metricCache.GetContainerResourceMetric(containerID, queryParam)
if queryResult.Error != nil {
klog.Warningf("get container %v resource metric failed, error %v", containerID, queryResult.Error)
return queryResult
}
if queryResult.Metric == nil {
klog.Warningf("container %v metric not exist", containerID)
return queryResult
}
return queryResult
}

func (r *resmanager) collectContainerThrottledMetricLast(containerID *string) metriccache.ContainerThrottledQueryResult {
if containerID == nil {
return metriccache.ContainerThrottledQueryResult{
QueryResult: metriccache.QueryResult{Error: fmt.Errorf("container is nil")},
}
}
queryParam := generateQueryParamsLast(r.collectResUsedIntervalSeconds * 2)
queryResult := r.metricCache.GetContainerThrottledMetric(containerID, queryParam)
if queryResult.Error != nil {
klog.Warningf("get container %v throttled metric failed, error %v", containerID, queryResult.Error)
return queryResult
}
if queryResult.Metric == nil {
klog.Warningf("container %v metric not exist", containerID)
return queryResult
}
return queryResult
}

func generateQueryParamsAvg(windowSeconds int64) *metriccache.QueryParam {
end := time.Now()
start := end.Add(-time.Duration(windowSeconds) * time.Second)
queryParam := &metriccache.QueryParam{
Aggregate: metriccache.AggregationTypeAVG,
Start: &start,
End: &end,
}
return queryParam
}

func generateQueryParamsLast(windowSeconds int64) *metriccache.QueryParam {
end := time.Now()
start := end.Add(-time.Duration(windowSeconds) * time.Second)
Expand Down
2 changes: 1 addition & 1 deletion pkg/koordlet/resmanager/resmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func NewResManager(cfg *Config, schema *apiruntime.Scheme, kubeClient clientset.

// isFeatureDisabled returns whether the featuregate is disabled by nodeSLO config
func isFeatureDisabled(nodeSLO *slov1alpha1.NodeSLO, feature featuregate.Feature) (bool, error) {
if nodeSLO == nil || &nodeSLO.Spec == nil {
if nodeSLO == nil || nodeSLO.Spec == (slov1alpha1.NodeSLOSpec{}) {
return false, fmt.Errorf("cannot parse feature config for invalid nodeSLO %v", nodeSLO)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/koordlet/util/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,11 @@ func Test_FindContainerIdAndStatusByName(t *testing.T) {
ContainerStatuses: []corev1.ContainerStatus{
{
Name: "main",
ContainerID: fmt.Sprintf("%s", "main"),
ContainerID: "main",
},
{
Name: "sidecar",
ContainerID: fmt.Sprintf("%s", "sidecar"),
ContainerID: "sidecar",
},
},
},
Expand Down
12 changes: 0 additions & 12 deletions pkg/koordlet/util/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,15 @@ limitations under the License.
package util

import (
"fmt"
"path"
"strconv"
"strings"

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

slov1alpha1 "github.com/koordinator-sh/koordinator/apis/slo/v1alpha1"
sysutil "github.com/koordinator-sh/koordinator/pkg/koordlet/util/system"
)

// GetNodeKey returns a generated key with given node
func GetNodeKey(node *corev1.Node) string {
return fmt.Sprintf("%v/%v", node.GetNamespace(), node.GetName())
}

// GetNodeMetricKey returns a generated key with given nodeMetric
func GetNodeMetricKey(nodeMetric *slov1alpha1.NodeMetric) string {
return fmt.Sprintf("%v/%v", nodeMetric.GetNamespace(), nodeMetric.GetName())
}

// @output like kubepods.slice/kubepods-besteffort.slice/
func GetKubeQosRelativePath(qosClass corev1.PodQOSClass) string {
return GetPodCgroupDirWithKube(sysutil.CgroupPathFormatter.QOSDirFn(qosClass))
Expand Down
10 changes: 0 additions & 10 deletions pkg/koordlet/util/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package util

import (
"fmt"
"io/ioutil"
"path"
"strconv"
Expand All @@ -27,7 +26,6 @@ import (
resources "k8s.io/apiserver/pkg/quota/v1"
"k8s.io/kubernetes/pkg/apis/core/v1/helper/qos"

slov1alpha1 "github.com/koordinator-sh/koordinator/apis/slo/v1alpha1"
sysutil "github.com/koordinator-sh/koordinator/pkg/koordlet/util/system"
)

Expand Down Expand Up @@ -220,14 +218,6 @@ func GetPodRequest(pod *corev1.Pod) corev1.ResourceList {
return getPodRequestFromContainers(pod)
}

func GetPodKey(pod *corev1.Pod) string {
return fmt.Sprintf("%v/%v", pod.GetNamespace(), pod.GetName())
}

func GetPodMetricKey(podMetric *slov1alpha1.PodMetricInfo) string {
return fmt.Sprintf("%v/%v", podMetric.Namespace, podMetric.Name)
}

func GetKubeQosClass(pod *corev1.Pod) corev1.PodQOSClass {
qosClass := pod.Status.QOSClass
if qosClass == "" {
Expand Down
Loading

0 comments on commit a18739b

Please sign in to comment.