Skip to content

Commit 4b8b780

Browse files
authored
Decouple readiness from controller-runtime startup (#570)
* manager, poolManager: Start controller-runtime before pool manager is ready Currently both liveness and readiness probes are bound by the poolManager being ready. This makes no sense, as the pod is responsive even though the pool is being constructed. - Decouple controller-runtime Manager startup from poolManager startup to prevent liveness failures during pool initialization unless there is a real connection issue. - Add readiness probe wait mechanism to explicitly wait for the pool to be ready. Signed-off-by: Ram Lavi <ralavi@redhat.com> * config: Remove publishNotReadyAddresses from webhook service Currently the kubemacpool service is set to answer webhook calls even if the manager is not ready. This is not the desired behavior - webhook should not answer VMs until pool is ready. Removing publishNotReadyAddresses from the webhook service. Signed-off-by: Ram Lavi <ralavi@redhat.com> --------- Signed-off-by: Ram Lavi <ralavi@redhat.com>
1 parent 6a74ff4 commit 4b8b780

File tree

6 files changed

+30
-9
lines changed

6 files changed

+30
-9
lines changed

config/default/manager/manager.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ metadata:
285285
name: service
286286
namespace: kubemacpool-system
287287
spec:
288-
publishNotReadyAddresses: true
289288
ports:
290289
- port: 443
291290
targetPort: 8000

config/release/kubemacpool.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ spec:
137137
ports:
138138
- port: 443
139139
targetPort: 8000
140-
publishNotReadyAddresses: true
141140
selector:
142141
control-plane: mac-controller-manager
143142
---

config/test/kubemacpool.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ spec:
138138
ports:
139139
- port: 443
140140
targetPort: 8000
141-
publishNotReadyAddresses: true
142141
selector:
143142
control-plane: mac-controller-manager
144143
---

pkg/manager/manager.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,17 @@ func (k *KubeMacPoolManager) Run(rangeStart, rangeEnd net.HardwareAddr) error {
133133
return errors.Wrap(err, "unable to register webhooks to the manager")
134134
}
135135

136-
err = poolManager.Start()
137-
if err != nil {
138-
return errors.Wrap(err, "failed to start pool manager routines")
139-
}
140-
136+
log.Info("Setting up Pool Manager")
137+
go func() {
138+
err := poolManager.Start()
139+
if err != nil {
140+
log.Error(err, "failed to start pool manager routines")
141+
k.cancel()
142+
return
143+
}
144+
}()
145+
146+
log.Info("Starting Runtime Manager")
141147
err = k.runtimeManager.Start(ctx)
142148
if err != nil {
143149
log.Error(err, "unable to run the manager")

pkg/pool-manager/pool.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"net"
2727
"reflect"
2828
"sync"
29+
"sync/atomic"
2930
"time"
3031

3132
"github.com/pkg/errors"
@@ -67,6 +68,7 @@ type PoolManager struct {
6768
rangeMutex sync.RWMutex // mutex for range operations to support dynamic updates
6869
isKubevirt bool // bool if kubevirt virtualmachine crd exist in the cluster
6970
waitTime int // Duration in second to free macs of allocated vms that failed to start.
71+
isPoolReady atomic.Bool // indicates whether the pool manager has completed initialization
7072
}
7173

7274
type OptMode string
@@ -131,9 +133,18 @@ func (p *PoolManager) Start() error {
131133
if p.isKubevirt {
132134
go p.vmWaitingCleanupLook()
133135
}
136+
137+
log.Info("Pool Manager is ready")
138+
p.isPoolReady.Store(true)
139+
134140
return nil
135141
}
136142

143+
// IsReady returns true if the pool manager has completed initialization
144+
func (p *PoolManager) IsReady() bool {
145+
return p.isPoolReady.Load()
146+
}
147+
137148
// getManagedNamespaces pre-computes which namespaces are managed by kubemacpool for a specific webhook
138149
func (p *PoolManager) getManagedNamespaces(webhookName string) ([]string, error) {
139150
log.V(1).Info("computing managed namespaces for initialization", "webhookName", webhookName)

pkg/webhook/webhook.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ package webhook
1818

1919
import (
2020
"crypto/tls"
21+
"fmt"
22+
"net/http"
2123
"os"
2224
"strings"
2325

@@ -66,7 +68,12 @@ func AddToManager(mgr manager.Manager, poolManager *pool_manager.PoolManager) er
6668
}},
6769
})
6870

69-
s.Register("/readyz", healthz.CheckHandler{Checker: healthz.Ping})
71+
s.Register("/readyz", healthz.CheckHandler{Checker: healthz.Checker(func(_ *http.Request) error {
72+
if !poolManager.IsReady() {
73+
return fmt.Errorf("pool manager not ready")
74+
}
75+
return nil
76+
})})
7077
s.Register("/healthz", healthz.CheckHandler{Checker: healthz.Ping})
7178

7279
for _, f := range AddToWebhookFuncs {

0 commit comments

Comments
 (0)