I have a pod.yaml, I want to retrieve a new annotation integer value, to make a sleep. So I used Go to fetch the integer after the name : new-anno. With this value, I want to return a function to make time.Sleep(SleepFunct * timeSecond)
on main Part
apiVersion: v1
kind: Pod
metadata:
name: ubuntu
annotations:
new-anno/sleep: "5"
my handler.go
package main
import (
"strings"
"time"
"strconv"
"github.com/avast/retry-go"
log "github.com/sirupsen/logrus"
core_v1 "k8s.io/api/core/v1"
"k8s.io/client-go/tools/clientcmd"
set "github.com/deckarep/golang-set"
)
type SidecarShutdownHandler struct{}
func (t *SidecarShutdownHandler) Init() error {
log.Info("SidecarShutdownHandler.Init")
return nil
}
func (t *SidecarShutdownHandler) SleepFunct(obj interface{}) int{
pod := obj.(*core_v1.Pod)
sleepString, exists := pod.Annotations["new-anno/sleep"]
if exists {
log.Debugf(" ResourceTrackable: true")
log.Infof(" sleep: %s", sleepString)
} else {
return
}
res := strings.Split(sleepString, ",")
i, err := strconv.Atoi(s)
if err != nil {
panic(err)
}
return i
}
But I got an error:
8.504 ./handler.go:92:17: not enough return values 8.504 have ()
8.504 want (int)
8.504 ./handler.go:96:32: cannot use res (variable of type []string) as string value in argument to strconv.Atoi
2