Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
k8s-ingress
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
3
Merge Requests
3
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
uplex-varnish
k8s-ingress
Commits
ac720f7a
Commit
ac720f7a
authored
Dec 28, 2018
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add the readyfile flag and a readiness probe to the controller.
parent
643a065d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
48 additions
and
5 deletions
+48
-5
main.go
cmd/main.go
+11
-1
controller.yaml
deploy/controller.yaml
+7
-3
ref-cli-options.md
docs/ref-cli-options.md
+7
-0
controller.go
pkg/controller/controller.go
+23
-1
No files found.
cmd/main.go
View file @
ac720f7a
...
...
@@ -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
(
...
...
deploy/controller.yaml
View file @
ac720f7a
...
...
@@ -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
docs/ref-cli-options.md
View file @
ac720f7a
...
...
@@ -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.
...
...
pkg/controller/controller.go
View file @
ac720f7a
...
...
@@ -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
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment