Skip to content

Commit

Permalink
fix sum comment
Browse files Browse the repository at this point in the history
  • Loading branch information
shijieqin committed Apr 21, 2022
1 parent cb7704e commit 09bd549
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cmd/crane-agent/app/options/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Options struct {
// MaxInactivity is the maximum time from last recorded activity before automatic restart
MaxInactivity time.Duration
// Ifaces is the network devices to collect metric
Ifaces []string
Ifaces []string
NodeResourceReserved map[string]string
}

Expand Down
21 changes: 16 additions & 5 deletions pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/uuid"
Expand Down Expand Up @@ -143,8 +144,13 @@ func getAgentName(nodeName string) string {
}

func (a *Agent) CreateNodeResourceTsp() (string, error) {
tsp, _ := a.craneClient.PredictionV1alpha1().TimeSeriesPredictions(resource.TspNamespace).Get(context.TODO(), a.GenerateNodeResourceTspName(), metav1.GetOptions{})

tsp, err := a.craneClient.PredictionV1alpha1().TimeSeriesPredictions(resource.TspNamespace).Get(context.TODO(), a.GenerateNodeResourceTspName(), metav1.GetOptions{})
if err != nil {
if !errors.IsNotFound(err) {
klog.Errorf("Failed to get noderesource tsp : %v", err)
return "", err
}
}
config, err := a.kubeClient.CoreV1().ConfigMaps(resource.TspNamespace).Get(context.TODO(), "noderesource-tsp-template", metav1.GetOptions{})

if err != nil {
Expand Down Expand Up @@ -190,16 +196,20 @@ func (a *Agent) CreateNodeResourceTsp() (string, error) {
}

if tsp != nil {
if reflect.DeepEqual(tsp.Spec, spec){
klog.V(4).Infof("Discover the presence of old noderesource tsp and try to contrast the changes: %s", a.GenerateNodeResourceTspName())
if reflect.DeepEqual(tsp.Spec, spec) {
return a.GenerateNodeResourceTspName(), nil
}
klog.V(4).Infof("Discover the presence of old noderesource tsp and the Tsp rules have been changed: %s", a.GenerateNodeResourceTspName())
tsp.Spec = spec
_, err := a.craneClient.PredictionV1alpha1().TimeSeriesPredictions(tsp.Namespace).Update(context.TODO(), tsp, metav1.UpdateOptions{})
if err != nil {
klog.Errorf("Failed to update noderesource tsp %s : %v", a.GenerateNodeResourceTspName(), err)
return "", err
}
}else{
klog.V(4).Infof("The noderesource tsp is updated successfully: %s", a.GenerateNodeResourceTspName())
} else {
klog.V(4).Infof("The noderesource tsp does not exist, try to create a new one: %s", a.GenerateNodeResourceTspName())
tsp = &v1alpha12.TimeSeriesPrediction{}
tsp.Name = a.GenerateNodeResourceTspName()
tsp.Namespace = resource.TspNamespace
Expand All @@ -210,6 +220,7 @@ func (a *Agent) CreateNodeResourceTsp() (string, error) {
klog.Errorf("Failed to create noderesource tsp %s : %v", a.GenerateNodeResourceTspName(), err)
return "", err
}
klog.V(4).Infof("The noderesource tsp is created successfully: %s", a.GenerateNodeResourceTspName())
}

return a.GenerateNodeResourceTspName(), nil
Expand All @@ -232,4 +243,4 @@ func appendManagerIfNotNil(managers []manager.Manager, m manager.Manager) []mana
return append(managers, m)
}
return managers
}
}
5 changes: 4 additions & 1 deletion pkg/ensurance/collector/cadvisor/cadvisor_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@
package cadvisor

import (
"errors"

info "github.com/google/cadvisor/info/v1"
cadvisorapiv2 "github.com/google/cadvisor/info/v2"
corelisters "k8s.io/client-go/listers/core/v1"

"github.com/gocrane/crane/pkg/common"
"github.com/gocrane/crane/pkg/ensurance/collector/types"
)

var errUnsupported = errors.New("cAdvisor is unsupported in this build")

type CadvisorCollectorUnsupport struct {
Manager Manager
}

type CadvisorManagerUnsupport struct {}
type CadvisorManagerUnsupport struct{}

func NewCadvisorManager() Manager {
return &CadvisorManagerUnsupport{}
Expand Down
2 changes: 1 addition & 1 deletion pkg/ensurance/collector/nodelocal/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package nodelocal
import (
"errors"
"fmt"
"k8s.io/kubernetes/pkg/kubelet/cm/cpuset"
"math"
"strconv"
"strings"
Expand All @@ -12,6 +11,7 @@ import (
"github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/load"
"k8s.io/klog/v2"
"k8s.io/kubernetes/pkg/kubelet/cm/cpuset"

"github.com/gocrane/crane/pkg/common"
"github.com/gocrane/crane/pkg/ensurance/collector/types"
Expand Down
8 changes: 4 additions & 4 deletions pkg/resource/node_resource_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type NodeResourceManager struct {
tspLister predictionlisters.TimeSeriesPredictionLister
tspSynced cache.InformerSynced

recorder record.EventRecorder
recorder record.EventRecorder

stateChann chan map[string][]common.TimeSeries

Expand Down Expand Up @@ -193,7 +193,7 @@ func (o *NodeResourceManager) FindTargetNode(tsp *predictionapi.TimeSeriesPredic
return false, nil
}

func (o *NodeResourceManager) BuildNodeStatus(node *v1.Node) map[v1.ResourceName]string{
func (o *NodeResourceManager) BuildNodeStatus(node *v1.Node) map[v1.ResourceName]string {
tspCanNotBeReclaimedResource := o.GetCanNotBeReclaimedResourceFromTsp(node)
localCanNotBeReclaimedResource := o.GetCanNotBeReclaimedResourceFromLocal()
reserveCpuPercent := o.reserveResource.CpuPercent
Expand All @@ -215,9 +215,9 @@ func (o *NodeResourceManager) BuildNodeStatus(node *v1.Node) map[v1.ResourceName
switch resourceName {
case v1.ResourceCPU:
if reserveCpuPercent != nil {
nextRecommendation = float64(node.Status.Allocatable.Cpu().Value()) - float64(node.Status.Allocatable.Cpu().Value()) **reserveCpuPercent - maxUsage / 1000
nextRecommendation = float64(node.Status.Allocatable.Cpu().Value()) - float64(node.Status.Allocatable.Cpu().Value())*(*reserveCpuPercent) - maxUsage/1000
} else {
nextRecommendation = float64(node.Status.Allocatable.Cpu().Value()) - maxUsage / 1000
nextRecommendation = float64(node.Status.Allocatable.Cpu().Value()) - maxUsage/1000
}
case v1.ResourceMemory:
// unit of memory in prometheus is in Ki, need to be converted to byte
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func GetContainerNameFromPod(pod *v1.Pod, containerId string) string {
}

func GetContainerFromPod(pod *v1.Pod, containerName string) *v1.Container {
if containerName == ""{
if containerName == "" {
return nil
}
for _, v := range pod.Spec.Containers {
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ func ParsePercentage(input string) (float64, error) {
return 0, err
}
return value / 100, nil
}
}

0 comments on commit 09bd549

Please sign in to comment.