This commit is contained in:
Sean Knox 2018-08-20 17:28:34 -05:00
Родитель 6fde9d4a9f
Коммит 2d1d824031
1 изменённых файлов: 29 добавлений и 4 удалений

Просмотреть файл

@ -39,6 +39,7 @@ func main() {
}
deployments, err := clientset.AppsV1().Deployments("").List(metav1.ListOptions{})
daemonsets, err := clientset.AppsV1().DaemonSets("").List(metav1.ListOptions{})
if err != nil {
log.Fatalln("failed to get deployments:", err)
}
@ -77,22 +78,46 @@ func main() {
}
}
for _, ds := range daemonsets.Items {
containers := ds.Spec.Template.Spec.Containers
for _, c := range containers {
var cpuLimitMissing, memoryLimitMissing, cpuRequestMissing, memoryRequestMissing bool
if c.Resources.Limits.Cpu().IsZero() {
cpuLimitMissing = true
}
if c.Resources.Limits.Memory().IsZero() {
memoryLimitMissing = true
}
if c.Resources.Requests.Cpu().IsZero() {
cpuRequestMissing = true
}
if c.Resources.Requests.Memory().IsZero() {
memoryRequestMissing = true
}
if cpuLimitMissing || memoryLimitMissing {
container := Container{c.Name, cpuLimitMissing, memoryLimitMissing, cpuRequestMissing, memoryRequestMissing}
offenders[ds.GetName()] = append(offenders[ds.GetName()], &container)
}
}
}
fmt.Println("The following containers have no resources limits and may cause node resource starvation: ")
for k, containers := range offenders {
c := color.New(color.FgBlue, color.Underline, color.Bold)
c.Printf("Deployment name: %s\n", k)
c.Printf("Deployment/Daemon Set name: %s\n", k)
for _, c := range containers {
cc := color.New(color.Bold)
cc.Printf("- Container: %s\n", c.Name)
cc.Printf("Container: %s\n", c.Name)
v := reflect.Indirect(reflect.ValueOf(c))
// Purposely skip the first struct field, Name, which is a string
for i := 1; i < 5; i++ {
key := v.Type().Field(i).Name
value := v.Field(i).Bool()
if value == true {
color.Red("%+v has no limit set", key)
color.Red("- %+v has no limit set", key)
} else {
color.Green("%+v limit is set", key)
color.Green("- %+v limit is set", key)
}
}
}