This repository was archived by the owner on Oct 27, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +21
-5
lines changed Expand file tree Collapse file tree 1 file changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -29,8 +29,22 @@ import (
2929nodeutil "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 {
3339value := 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
3448bytes := []byte (value )
3549log .Printf ("Setting NUC LED to: %s" , value )
3650return ioutil .WriteFile ("/proc/acpi/nuc_led" , bytes , 0644 )
@@ -49,19 +63,21 @@ func main() {
4963
5064fmt .Printf ("greetings\n " )
5165
66+ led := & LED {}
67+
5268for {
5369node , err := clientset .CoreV1 ().Nodes ().Get (os .Getenv ("NODE_NAME" ), metav1.GetOptions {})
5470if err != nil {
55- setLed ("error" )
71+ led . SetState ("error" )
5672} else {
5773if nodeutil .IsNodeReady (node ) {
5874if 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}
6783time .Sleep (10 * time .Second )
You can’t perform that action at this time.
0 commit comments