Skip to content

Commit

Permalink
Merge pull request #56 from myaser/customizable-schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
zbindenren authored Oct 26, 2022
2 parents 520195c + 3598254 commit d63aadd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ kubenurse is configured with environment variables:
- `KUBENURSE_NAMESPACE`: Namespace in which to look for the neighbour kubenurses
- `KUBENURSE_NEIGHBOUR_FILTER`: A Kubernetes label selector (eg. `app=kubenurse`) to filter neighbour kubenurses
- `KUBENURSE_ALLOW_UNSCHEDULABLE`: If this is `"true"`, path checks to neighbouring kubenurses are made even if they are running on unschedulable nodes.
- `KUBENURSE_CHECK_API_SERVER_DIRECT`: If this is `"true"` kubenurse will perform the check [API Server Direct](###API Server Direct). default is "true"
- `KUBENURSE_CHECK_API_SERVER_DNS`: If this is `"true"`, kubenurse will perform the check [API Server DNS](###API Server DNS). default is "true"
- `KUBENURSE_CHECK_ME_INGRESS`: If this is `"true"`, kubenurse will perform the check [Me Ingress](###Me Ingress). default is "true"
- `KUBENURSE_CHECK_ME_SERVICE`: If this is `"true"`, kubenurse will perform the check [Me Service](###Me Service). default is "true"
- `KUBENURSE_CHECK_NEIGHBOURHOOD`: If this is `"true"`, kubenurse will perform the check [Neighbourhood](###Neighbourhood). default is "true"
- `KUBENURSE_CHECK_API_SERVER_DIRECT`: If this is `"true"` kubenurse will perform the check [API Server Direct](#API Server Direct). default is "true"
- `KUBENURSE_CHECK_API_SERVER_DNS`: If this is `"true"`, kubenurse will perform the check [API Server DNS](#API Server DNS). default is "true"
- `KUBENURSE_CHECK_ME_INGRESS`: If this is `"true"`, kubenurse will perform the check [Me Ingress](#Me Ingress). default is "true"
- `KUBENURSE_CHECK_ME_SERVICE`: If this is `"true"`, kubenurse will perform the check [Me Service](#Me Service). default is "true"
- `KUBENURSE_CHECK_NEIGHBOURHOOD`: If this is `"true"`, kubenurse will perform the check [Neighbourhood](#Neighbourhood). default is "true"
- `KUBENURSE_CHECK_INTERVAL`: the frequency to perform kubenurse checks. the string should be formatted for [time.ParseDuration](https://pkg.go.dev/time#ParseDuration). defaults to `5s`
- `KUBENURSE_USE_TLS`: If this is `"true"`, enable TLS endpoint on port 8443
- `KUBENURSE_CERT_FILE`: Certificate to use with TLS endpoint
- `KUBENURSE_CERT_KEY`: Key to use with TLS endpoint
Expand Down
25 changes: 20 additions & 5 deletions internal/kubenurse/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"k8s.io/client-go/kubernetes"
)

const defaultCheckInterval = 5 * time.Second

// Server is used to build the kubenurse http/https server(s).
type Server struct {
http http.Server
Expand All @@ -25,7 +27,8 @@ type Server struct {
checker *servicecheck.Checker

// Configuration options
useTLS bool
useTLS bool
checkInterval time.Duration
// If we want to consider kubenurses on unschedulable nodes
allowUnschedulable bool

Expand All @@ -48,9 +51,21 @@ type Server struct {
// * KUBENURSE_CHECK_ME_INGRESS
// * KUBENURSE_CHECK_ME_SERVICE
// * KUBENURSE_CHECK_NEIGHBOURHOOD
// * KUBENURSE_CHECK_INTERVAL
func New(ctx context.Context, k8s kubernetes.Interface) (*Server, error) {
mux := http.NewServeMux()

checkInterval := defaultCheckInterval

if v, ok := os.LookupEnv("KUBENURSE_CHECK_INTERVAL"); ok {
var err error
checkInterval, err = time.ParseDuration(v)

if err != nil {
return nil, err
}
}

server := &Server{
http: http.Server{
Addr: ":8080",
Expand All @@ -70,9 +85,9 @@ func New(ctx context.Context, k8s kubernetes.Interface) (*Server, error) {
//nolint:goconst // No need to make "true" a constant in my opinion, readability is better like this.
useTLS: os.Getenv("KUBENURSE_USE_TLS") == "true",
allowUnschedulable: os.Getenv("KUBENURSE_ALLOW_UNSCHEDULABLE") == "true",

mu: new(sync.Mutex),
ready: true,
checkInterval: checkInterval,
mu: new(sync.Mutex),
ready: true,
}

promRegistry := prometheus.NewRegistry()
Expand Down Expand Up @@ -132,7 +147,7 @@ func (s *Server) Run() error {
go func() {
defer wg.Done()

s.checker.RunScheduled(5 * time.Second)
s.checker.RunScheduled(s.checkInterval)
}()

wg.Add(1)
Expand Down

0 comments on commit d63aadd

Please sign in to comment.