Skip to content

Commit

Permalink
d
Browse files Browse the repository at this point in the history
  • Loading branch information
Camila Macedo committed Dec 17, 2020
1 parent 8cca5f6 commit 0c849cd
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 27 deletions.
65 changes: 45 additions & 20 deletions changelog/fragments/liveness_readiness_probe_for_operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# release notes and/or the migration guide
entries:
- description: >
For Ansible/Helm-based operators, add Liveness and Readiness probe by default using [sigs.k8s.io/controller-runtime/pkg/healthz#CheckHandler](https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/healthz#CheckHandler).
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
Expand All @@ -18,13 +18,14 @@ entries:
# Migration can be defined to automatically add a section to
# the migration guide. This is required for breaking changes.
migration:
header: (Optional) For Ansible/Helm-based operators, add Liveness and Readiness probe
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 and then, add in the `config/default/manager`:
release base image, then add the following to the `manager` container in
`config/default/manager/manager.yaml`:
```yaml
livenessProbe:
Expand All @@ -40,28 +41,52 @@ entries:
initialDelaySeconds: 5
periodSeconds: 10
```
- description: >
For Ansible-based operators, the `/ping` endpoint is deprecated. Use `/healthz` and `/readyz` instead of that.
kind: "deprecation"
breaking: false
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).
- description: >
For Ansible-based operators, the default probe port used was changed from `6789` to `8081`.
kind: "change"
# 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, the probe port used changed
header: (Optional) For Ansible-based operators, add Liveness and Readiness probe
body: >
The default probe port used was changed from `6789` to `8081`to keep the project aligned
with the other language types. However, if you wish you can still using the port `6789`.
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.
Update the `config/manager/manager.yaml` and `config/default/manager_auth_proxy_patch.yaml`
file to inform the old value or any value that please you by using the
flag `health-probe-bind-address`:
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
- name: manager
args:
- "--health-probe-bind-address=6789"
```
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` and `/readyz` instead.
kind: "deprecation"
breaking: false
- description: >
For Ansible/Helm-based operators, added new flag `--health-probe-bind-address` to allow customize the probe
port used.
kind: "addition"
5 changes: 4 additions & 1 deletion internal/ansible/flags/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,12 @@ func (f *Flags) AddTo(flagSet *pflag.FlagSet) {
":8080",
"The address the metric endpoint binds to",
)
// todo: for Go/Helm the port used is: 8081
// update it to keep the project aligned to the other
// types for 2.0
flagSet.StringVar(&f.ProbeAddr,
"health-probe-bind-address",
":8081",
":6789",
"The address the probe endpoint binds to.",
)
flagSet.BoolVar(&f.EnableLeaderElection,
Expand Down
9 changes: 9 additions & 0 deletions internal/cmd/ansible-operator/run/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,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 {
Expand Down
10 changes: 10 additions & 0 deletions internal/cmd/helm-operator/run/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"k8s.io/client-go/tools/leaderelection/resourcelock"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/healthz"
logf "sigs.k8s.io/controller-runtime/pkg/log"
zapf "sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/manager"
Expand Down Expand Up @@ -131,6 +132,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)
}

ws, err := watches.Load(f.WatchesFile)
if err != nil {
log.Error(err, "Failed to create new manager factories.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ spec:
livenessProbe:
httpGet:
path: /readyz
port: 8081
port: 6789
initialDelaySeconds: 15
periodSeconds: 20
readinessProbe:
httpGet:
path: /healthz
port: 8081
port: 6789
initialDelaySeconds: 5
periodSeconds: 10
terminationGracePeriodSeconds: 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ spec:
livenessProbe:
httpGet:
path: /readyz
port: 8081
port: 6789
initialDelaySeconds: 15
periodSeconds: 20
name: manager
readinessProbe:
httpGet:
path: /healthz
port: 8081
port: 6789
initialDelaySeconds: 5
periodSeconds: 10
resources: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ spec:
livenessProbe:
httpGet:
path: /readyz
port: 8081
port: 6789
initialDelaySeconds: 15
periodSeconds: 20
readinessProbe:
httpGet:
path: /healthz
port: 8081
port: 6789
initialDelaySeconds: 5
periodSeconds: 10
terminationGracePeriodSeconds: 10

0 comments on commit 0c849cd

Please sign in to comment.