Skip to content

Commit

Permalink
add: config
Browse files Browse the repository at this point in the history
  • Loading branch information
StarCoral authored and justin0u0 committed Apr 6, 2022
1 parent 6175dfe commit b45309d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
2 changes: 2 additions & 0 deletions cmd/kubeshare-config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,6 @@ func main() {

config.NewConfig(ksl, promeAPI, clientset, informerFactory.Core().V1().Pods(), stopCh)

<-stopCh
ksl.Info("Shutting down config")
}
8 changes: 8 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,17 @@ func NewConfig(ksl *logrus.Logger, promeAPI promeV1.API, clientset kubernetes.In
cache.FilteringResourceEventHandler{
FilterFunc: config.filterPod,
Handler: cache.ResourceEventHandlerFuncs{
// AddFunc: func(obj interface{}) {
// gpuConfig, podMangerPortConfig := config.convertData(config.queryDecision())
// config.writeFile(gpuConfig, podMangerPortConfig)
// pod := obj.(*corev1.Pod)
// ksl.Infof("add: %v/%v", pod.Namespace, pod.Name)
// },
UpdateFunc: func(old, new interface{}) {
gpuConfig, podMangerPortConfig := config.convertData(config.queryDecision())
config.writeFile(gpuConfig, podMangerPortConfig)
pod := new.(*corev1.Pod)
ksl.Infof("update: %v/%v", pod.Namespace, pod.Name)
},
},
})
Expand Down
22 changes: 10 additions & 12 deletions pkg/config/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"strings"
"time"

"github.com/prometheus/common/model"
Expand All @@ -30,35 +31,32 @@ func (c *Config) queryDecision() []model.LabelSet {
if len(warnings) > 0 {
c.ksl.Warnf("Warnings: %v\n", warnings)
}
c.ksl.Printf("success")

return result
}

// gpuConfig
// -> key: uuid ; value: all pod request
// podMangerPortConfig
// -> key: uuid ; value: all pod manager port
func (c *Config) convertData(result []model.LabelSet) (gpuConfig, podMangerPortConfig map[string][]string) {
func (c *Config) convertData(result []model.LabelSet) (map[string][]string, map[string][]string) {

gpuConfig, podMangerPortConfig := map[string][]string{}, map[string][]string{}
for _, res := range result {
uuid := string(res["uuid"])
uuid := strings.ReplaceAll(string(res["uuid"]), ",", "")

namespace := res["namespace"]
name := res["pod"]
namespace := res["exported_namespace"]
name := res["exported_pod"]

gpuData := fmt.Sprintf("%v/%v %v %v %v\n", namespace, name, res["limit"], res["request"], res["memory"])
portData := fmt.Sprintf("%v/%v %v\n", namespace, name, res["port"])
c.ksl.Printf("TEST before")
if gpuConfig[uuid] == nil {
gpuConfig[uuid] = make([]string, 0)
podMangerPortConfig[uuid] = make([]string, 0)
}

gpuConfig[uuid] = append(gpuConfig[uuid], gpuData)
podMangerPortConfig[uuid] = append(podMangerPortConfig[uuid], portData)
c.ksl.Printf("TEST after")

}

return
return gpuConfig, podMangerPortConfig
}

// gpuConfigFile is named by UUID of GPU
Expand Down

0 comments on commit b45309d

Please sign in to comment.