Skip to content
This repository was archived by the owner on Oct 27, 2021. It is now read-only.

Commit 6591063

Browse files
committed
memory is cool
1 parent ea7d33e commit 6591063

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

main.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,22 @@ import (
2929
nodeutil "k8s.io/kubernetes/pkg/api/v1/node"
3030
)
3131

32-
func setLed(key string) error {
32+
// LED contains the state of the NUC's LED
33+
type LED struct {
34+
state string
35+
}
36+
37+
// SetState updates the value of the LED.
38+
func (led *LED) SetState(key string) error {
3339
value := os.Getenv(fmt.Sprintf("NUC_LED_%s", strings.ToUpper(key)))
40+
if led.state != value {
41+
return led.writeState(value)
42+
}
43+
return nil
44+
}
45+
46+
func (led *LED) writeState(value string) error {
47+
led.state = value
3448
bytes := []byte(value)
3549
log.Printf("Setting NUC LED to: %s", value)
3650
return ioutil.WriteFile("/proc/acpi/nuc_led", bytes, 0644)
@@ -49,19 +63,21 @@ func main() {
4963

5064
fmt.Printf("greetings\n")
5165

66+
led := &LED{}
67+
5268
for {
5369
node, err := clientset.CoreV1().Nodes().Get(os.Getenv("NODE_NAME"), metav1.GetOptions{})
5470
if err != nil {
55-
setLed("error")
71+
led.SetState("error")
5672
} else {
5773
if nodeutil.IsNodeReady(node) {
5874
if node.Spec.Unschedulable == true {
59-
setLed("unschedulable")
75+
led.SetState("unschedulable")
6076
} else {
61-
setLed("ready")
77+
led.SetState("ready")
6278
}
6379
} else {
64-
setLed("not_ready")
80+
led.SetState("not_ready")
6581
}
6682
}
6783
time.Sleep(10 * time.Second)

0 commit comments

Comments
 (0)