Skip to content

Commit

Permalink
handler,webhook:use variable to set min replicas (nmstate#812)
Browse files Browse the repository at this point in the history
In order to set the number of minimum webhook replicas dynamically, the operator
yaml should accept a variable to set number of minimum replicas.

An example use-case for that would be to set the minimum number of webhook replicas to 0 when running
on a Single-Node-Openshift cluster, to no interfere with the upgrade process, where the
number of active webhook pods will be reduced from 1 to 0 to perform the upgrade.

This commit introduce this variable and sets it with a fixed value of 1. In a follow-up work
This could be enhanced to be completely dynamic.

Signed-off-by: alonsadan <asadan@redhat.com>
  • Loading branch information
alonSadan authored and Radim Hrazdil committed Nov 9, 2021
1 parent cfefe57 commit 2ebbd0d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion controllers/nmstate_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ func (r *NMStateReconciler) applyHandler(instance *nmstatev1beta1.NMState) error
handlerTolerations = []corev1.Toleration{operatorExistsToleration}
}

const WEBHOOK_REPLICAS = int32(2)
const (
WEBHOOK_REPLICAS = int32(2)
WEBHOOK_MIN_REPLICAS = int32(1)
)

data.Data["HandlerNamespace"] = os.Getenv("HANDLER_NAMESPACE")
data.Data["HandlerImage"] = os.Getenv("RELATED_IMAGE_HANDLER_IMAGE")
Expand All @@ -183,6 +186,7 @@ func (r *NMStateReconciler) applyHandler(instance *nmstatev1beta1.NMState) error
data.Data["WebhookTolerations"] = []corev1.Toleration{masterExistsNoScheduleToleration}
data.Data["WebhookAffinity"] = corev1.Affinity{}
data.Data["WebhookReplicas"] = WEBHOOK_REPLICAS
data.Data["WebhookMinReplicas"] = WEBHOOK_MIN_REPLICAS
data.Data["HandlerNodeSelector"] = amd64AndCRNodeSelector
data.Data["HandlerTolerations"] = handlerTolerations
data.Data["HandlerAffinity"] = corev1.Affinity{}
Expand Down
2 changes: 1 addition & 1 deletion deploy/handler/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ metadata:
namespace: {{ .HandlerNamespace }}
name: {{template "handlerPrefix" .}}nmstate-webhook
spec:
minAvailable: 1
minAvailable: {{ .WebhookMinReplicas }}
selector:
matchLabels:
name: {{template "handlerPrefix" .}}nmstate-webhook

0 comments on commit 2ebbd0d

Please sign in to comment.