Skip to content

Commit 5024947

Browse files
PavanNeeruduPavan Neerudu
andauthored
Check CloudAgent reachability in caph liveness probe (#266)
* Init commit: Check cloudagent reachability in liveness probe * Take the liveness probe values are arguments to the binary and default those values * Changes post merge conflict * Remove exponential backoff, liveness probe parameters should be good enough * Revert image change * Remove unused parameters --------- Co-authored-by: Pavan Neerudu <[email protected]>
1 parent b97f32c commit 5024947

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

cmd/manager/main.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030

3131
// +kubebuilder:scaffold:imports
3232

33+
"github.com/microsoft/cluster-api-provider-azurestackhci/pkg/network"
3334
"github.com/spf13/pflag"
3435
"k8s.io/apimachinery/pkg/runtime"
3536
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
@@ -42,6 +43,7 @@ import (
4243
ctrl "sigs.k8s.io/controller-runtime"
4344
"sigs.k8s.io/controller-runtime/pkg/controller"
4445
"sigs.k8s.io/controller-runtime/pkg/healthz"
46+
ctrlmgr "sigs.k8s.io/controller-runtime/pkg/manager"
4547

4648
"github.com/microsoft/cluster-api-provider-azurestackhci/controllers"
4749
)
@@ -253,19 +255,32 @@ func main() {
253255
os.Exit(1)
254256
}
255257

258+
// Setup Health checks
259+
setupChecks(mgr)
260+
261+
setupLog.Info("starting manager")
262+
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
263+
setupLog.Error(err, "problem running manager")
264+
os.Exit(1)
265+
}
266+
}
267+
268+
func setupChecks(mgr ctrlmgr.Manager) {
256269
if err := mgr.AddReadyzCheck("ping", healthz.Ping); err != nil {
257270
setupLog.Error(err, "unable to create ready check")
258271
os.Exit(1)
259272
}
260273

261-
if err := mgr.AddHealthzCheck("ping", healthz.Ping); err != nil {
262-
setupLog.Error(err, "unable to create health check")
274+
// Get the cloudagent fqdn
275+
cloudAgentFqdn := os.Getenv("AZURESTACKHCI_CLOUDAGENT_FQDN")
276+
if cloudAgentFqdn == "" {
277+
setupLog.Error(nil, "AZURESTACKHCI_CLOUDAGENT_FQDN is not set")
263278
os.Exit(1)
264279
}
265280

266-
setupLog.Info("starting manager")
267-
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
268-
setupLog.Error(err, "problem running manager")
281+
cloudAgentAddress := cloudAgentFqdn + ":55000"
282+
if err := mgr.AddHealthzCheck("ping", network.EndpointChecker(cloudAgentAddress)); err != nil {
283+
setupLog.Error(err, "unable to create health check")
269284
os.Exit(1)
270285
}
271286
}

pkg/network/network.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package network
2+
3+
import (
4+
"fmt"
5+
"net"
6+
"net/http"
7+
"time"
8+
9+
"sigs.k8s.io/controller-runtime/pkg/healthz"
10+
)
11+
12+
func EndpointChecker(targetIPAddress string) healthz.Checker {
13+
return func(req *http.Request) error {
14+
dialTimeout := 1 * time.Second
15+
16+
_, err := net.DialTimeout("tcp", targetIPAddress, dialTimeout)
17+
if err != nil {
18+
return fmt.Errorf("failed to dial: %v", err)
19+
}
20+
21+
return nil
22+
}
23+
}

0 commit comments

Comments
 (0)