Commit ac720f7a authored by Geoff Simmons's avatar Geoff Simmons

Add the readyfile flag and a readiness probe to the controller.

parent 643a065d
......@@ -68,6 +68,8 @@ var (
"out-of-cluster runs")
kubeconfigF = flag.String("kubeconfig", "", "config path for the "+
"cluster master URL, for out-of-cluster runs")
readyfileF = flag.String("readyfile", "", "path of a file to touch "+
"when the controller is ready, for readiness probes")
logFormat = logrus.TextFormatter{
DisableColors: true,
FullTimestamp: true,
......@@ -97,6 +99,14 @@ func main() {
os.Exit(0)
}
if *readyfileF != "" {
if err := os.Remove(*readyfileF); err != nil && !os.IsNotExist(err) {
fmt.Printf("Cannot remove ready file %s: %v",
*readyfileF, err)
os.Exit(-1)
}
}
lvl := strings.ToLower(*loglvlF)
switch lvl {
case "panic":
......@@ -167,7 +177,7 @@ func main() {
vController, informerFactory, vcrInformerFactory)
go handleTermination(log, ingController, vController, varnishDone)
informerFactory.Start(informerStop)
ingController.Run()
ingController.Run(*readyfileF)
}
func handleTermination(
......
......@@ -25,7 +25,11 @@ spec:
- -P
- "0"
- k8s-ingress
readinessProbe:
exec:
command:
- /usr/bin/test
- -e
- /ready
args:
# log-level default is info, so this can be left out.
# Shown here to demonstrate setting options for the controller.
- -log-level=info
- -readyfile=/ready
......@@ -25,6 +25,8 @@ Usage of ./k8s-ingress:
cluster master URL, for out-of-cluster runs
-namespace string
namespace in which to listen for resources (default all)
-readyfile string
path of a file to touch when the controller is ready, for readiness probes
-stderrthreshold value
logs at or above this threshold go to stderr
-templatedir string
......@@ -69,6 +71,11 @@ controller uses the value of the environment variable
``TEMPLATE_DIR``, or the current working director if neither of the
command-line option nor the environment variable are set.
If ``-readyfile /path/to/file`` is set, then the controller removes
the file at that path immediately at startup, if any exists, and
touches it when it is ready. Readiness probes can then test the file
for existence. By default, no readiness file is created.
``-log-level`` sets the log level for the main controller code,
``INFO`` by default.
......
......@@ -30,6 +30,7 @@ package controller
import (
"fmt"
"os"
"time"
vcr_informers "code.uplex.de/uplex-varnish/k8s-ingress/pkg/client/informers/externalversions"
......@@ -217,7 +218,10 @@ func (ingc *IngressController) updateObj(old, new interface{}) {
// Run the Ingress controller -- start the informers in goroutines,
// wait for the caches to sync, and call Run() for the
// NamespaceQueues. Then block until Stop() is invoked.
func (ingc *IngressController) Run() {
//
// If readyFile is non-empty, it is the path of a file to touch when
// the controller is ready (after informers have launched).
func (ingc *IngressController) Run(readyFile string) {
defer utilruntime.HandleCrash()
defer ingc.nsQs.Stop()
......@@ -228,6 +232,24 @@ func (ingc *IngressController) Run() {
go ingc.informers.secr.Run(ingc.stopCh)
go ingc.informers.vcfg.Run(ingc.stopCh)
ingc.log.Info("Controller ready")
if readyFile != "" {
f, err := os.Create(readyFile)
if err != nil {
e := fmt.Errorf("Cannot create ready file %s: %v",
readyFile, err)
utilruntime.HandleError(e)
return
}
if err = f.Close(); err != nil {
e := fmt.Errorf("Cannot close ready file %s: %v",
readyFile, err)
utilruntime.HandleError(e)
defer f.Close()
}
ingc.log.Infof("Created ready file %s", readyFile)
}
ingc.log.Info("Waiting for caches to sync")
if ok := cache.WaitForCacheSync(ingc.stopCh,
ingc.informers.ing.HasSynced,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment