-
Notifications
You must be signed in to change notification settings - Fork 1.8k
For Ansible/Helm-based operators, add Liveness and Readiness probe #4326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5a85561
61b639d
e34525a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# entries is a list of entries to include in | ||
# release notes and/or the migration guide | ||
entries: | ||
- description: > | ||
For Helm-based operators, added Liveness and Readiness probe by default using [`healthz.Ping`](https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/healthz#CheckHandler). | ||
|
||
# kind is one of: | ||
# - addition | ||
# - change | ||
# - deprecation | ||
# - removal | ||
# - bugfix | ||
kind: "addition" | ||
|
||
# Is this a breaking change? | ||
breaking: false | ||
|
||
# Migration can be defined to automatically add a section to | ||
# the migration guide. This is required for breaking changes. | ||
migration: | ||
header: (Optional) For Helm-based operators, add Liveness and Readiness probe | ||
body: > | ||
New projects built with the tool will have the probes configured by default. The endpoints `/healthz` and | ||
`/readyz` are available now in the image based provided. | ||
|
||
You can update your pre-existing project to use them. For that update the Dockerfile to use the latest | ||
release base image, then add the following to the `manager` container in | ||
`config/default/manager/manager.yaml`: | ||
|
||
```yaml | ||
livenessProbe: | ||
httpGet: | ||
path: /healthz | ||
port: 8081 | ||
initialDelaySeconds: 15 | ||
periodSeconds: 20 | ||
readinessProbe: | ||
httpGet: | ||
path: /readyz | ||
port: 8081 | ||
initialDelaySeconds: 5 | ||
periodSeconds: 10 | ||
``` | ||
- description: > | ||
For Ansible-based operators, added Liveness and Readiness probe by default using [`healthz.Ping`](https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/healthz#CheckHandler). | ||
|
||
# kind is one of: | ||
# - addition | ||
# - change | ||
# - deprecation | ||
# - removal | ||
# - bugfix | ||
kind: "addition" | ||
|
||
# Is this a breaking change? | ||
breaking: false | ||
|
||
# Migration can be defined to automatically add a section to | ||
# the migration guide. This is required for breaking changes. | ||
migration: | ||
header: (Optional) For Ansible-based operators, add Liveness and Readiness probe | ||
body: > | ||
New projects built with the tool will have the probes configured by default. The endpoints `/healthz` and | ||
`/readyz` are available now in the image based provided. | ||
|
||
You can update your pre-existing project to use them. For that update the Dockerfile to use the latest | ||
release base image, then add the following to the `manager` container in | ||
`config/default/manager/manager.yaml`: | ||
|
||
```yaml | ||
livenessProbe: | ||
httpGet: | ||
path: /healthz | ||
port: 6789 | ||
initialDelaySeconds: 15 | ||
periodSeconds: 20 | ||
readinessProbe: | ||
httpGet: | ||
path: /readyz | ||
port: 6789 | ||
initialDelaySeconds: 5 | ||
periodSeconds: 10 | ||
``` | ||
- description: > | ||
For Ansible-based operators, the `/ping` endpoint is deprecated. Use `/healthz` instead. | ||
kind: "deprecation" | ||
breaking: false | ||
|
||
- description: > | ||
For Ansible/Helm-based operators, added new flag `--health-probe-bind-address` to set the health probe address. | ||
kind: "addition" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,11 +45,7 @@ import ( | |
sdkVersion "github.com/operator-framework/operator-sdk/internal/version" | ||
) | ||
|
||
var ( | ||
metricsHost = "0.0.0.0" | ||
log = logf.Log.WithName("cmd") | ||
healthProbePort int32 = 6789 | ||
) | ||
var log = logf.Log.WithName("cmd") | ||
|
||
func printVersion() { | ||
log.Info("Version", | ||
|
@@ -105,8 +101,8 @@ func run(cmd *cobra.Command, f *flags.Flags) { | |
// Set default manager options | ||
// TODO: probably should expose the host & port as an environment variables | ||
options := manager.Options{ | ||
HealthProbeBindAddress: fmt.Sprintf("%s:%d", metricsHost, healthProbePort), | ||
MetricsBindAddress: f.MetricsAddress, | ||
HealthProbeBindAddress: f.ProbeAddr, | ||
LeaderElection: f.EnableLeaderElection, | ||
LeaderElectionID: f.LeaderElectionID, | ||
LeaderElectionResourceLock: resourcelock.ConfigMapsResourceLock, | ||
|
@@ -148,6 +144,15 @@ func run(cmd *cobra.Command, f *flags.Flags) { | |
os.Exit(1) | ||
} | ||
|
||
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil { | ||
log.Error(err, "Unable to set up health check") | ||
os.Exit(1) | ||
} | ||
if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil { | ||
log.Error(err, "Unable to set up ready check") | ||
os.Exit(1) | ||
} | ||
|
||
cMap := controllermap.NewControllerMap() | ||
watches, err := watches.Load(f.WatchesFile, f.MaxConcurrentReconciles, f.AnsibleVerbosity) | ||
if err != nil { | ||
|
@@ -183,6 +188,7 @@ func run(cmd *cobra.Command, f *flags.Flags) { | |
}, w.Blacklist) | ||
} | ||
|
||
// todo: remove when a upper version be bumped | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it might be a good idea to file an issue for this and put a "backwards incompatible" label, or put this in the 2.0 milestone. Otherwise, we will probably forget this when we bump to 2.0.0 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
err = mgr.AddHealthzCheck("ping", healthz.Ping) | ||
camilamacedo86 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
log.Error(err, "Failed to add Healthz check.") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,5 +78,17 @@ spec: | |
- name: ANSIBLE_GATHERING | ||
value: explicit | ||
image: {{ .Image }} | ||
livenessProbe: | ||
httpGet: | ||
path: /readyz | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. livenessProbe using |
||
port: 6789 | ||
initialDelaySeconds: 15 | ||
periodSeconds: 20 | ||
readinessProbe: | ||
httpGet: | ||
path: /healthz | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. readinessProbe using |
||
port: 6789 | ||
initialDelaySeconds: 5 | ||
periodSeconds: 10 | ||
terminationGracePeriodSeconds: 10 | ||
` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,7 +124,19 @@ spec: | |
- name: ANSIBLE_GATHERING | ||
value: explicit | ||
image: quay.io/example/memcached-operator:v0.0.1 | ||
livenessProbe: | ||
httpGet: | ||
path: /readyz | ||
port: 6789 | ||
initialDelaySeconds: 15 | ||
periodSeconds: 20 | ||
name: manager | ||
readinessProbe: | ||
httpGet: | ||
path: /healthz | ||
port: 6789 | ||
initialDelaySeconds: 5 | ||
periodSeconds: 10 | ||
Comment on lines
+127
to
+139
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. livenessProbe using /readyz endpoint and readinessProbe using /healthz endpoint. Should be the other way around I guess. |
||
resources: {} | ||
terminationGracePeriodSeconds: 10 | ||
permissions: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,4 +31,16 @@ spec: | |
- name: ANSIBLE_GATHERING | ||
value: explicit | ||
image: controller:latest | ||
livenessProbe: | ||
httpGet: | ||
path: /readyz | ||
port: 6789 | ||
initialDelaySeconds: 15 | ||
periodSeconds: 20 | ||
readinessProbe: | ||
httpGet: | ||
path: /healthz | ||
port: 6789 | ||
initialDelaySeconds: 5 | ||
periodSeconds: 10 | ||
Comment on lines
+34
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. livenessProbe using /readyz endpoint and readinessProbe using /healthz endpoint. Should be the other way around I guess. |
||
terminationGracePeriodSeconds: 10 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -209,7 +209,19 @@ spec: | |
- --enable-leader-election | ||
- --leader-election-id=memcached-operator | ||
image: quay.io/example/memcached-operator:v0.0.1 | ||
livenessProbe: | ||
httpGet: | ||
path: /readyz | ||
port: 8081 | ||
initialDelaySeconds: 15 | ||
periodSeconds: 20 | ||
name: manager | ||
readinessProbe: | ||
httpGet: | ||
path: /healthz | ||
port: 8081 | ||
initialDelaySeconds: 5 | ||
periodSeconds: 10 | ||
Comment on lines
+212
to
+224
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. livenessProbe using /readyz endpoint and readinessProbe using /healthz endpoint. Should be the other way around I guess. |
||
resources: | ||
limits: | ||
cpu: 100m | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,18 @@ spec: | |
- "--enable-leader-election" | ||
- "--leader-election-id=memcached-operator" | ||
name: manager | ||
livenessProbe: | ||
httpGet: | ||
path: /readyz | ||
port: 8081 | ||
initialDelaySeconds: 15 | ||
periodSeconds: 20 | ||
readinessProbe: | ||
httpGet: | ||
path: /healthz | ||
port: 8081 | ||
initialDelaySeconds: 5 | ||
periodSeconds: 10 | ||
Comment on lines
+31
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. livenessProbe using /readyz endpoint and readinessProbe using /healthz endpoint. Should be the other way around I guess. |
||
resources: | ||
limits: | ||
cpu: 100m | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The path to the manager resource seems to be wrong. Should be
config/manager/manager.yaml
instead.