forked from spidernet-io/spiderpool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Icarus9913 <[email protected]>
- Loading branch information
1 parent
72ecf5a
commit 2a03e45
Showing
6 changed files
with
82 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,3 +158,5 @@ const ( | |
OvsCNI = "ovs" | ||
CustomCNI = "custom" | ||
) | ||
|
||
const WebhookMutateRoute = "/webhook-health-check" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2024 Authors of spidernet-io | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package openapi | ||
|
||
import ( | ||
"crypto/tls" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/spidernet-io/spiderpool/pkg/constant" | ||
) | ||
|
||
// NewWebhookHealthCheckClient creates one http client which serves for webhook health check | ||
func NewWebhookHealthCheckClient() *http.Client { | ||
httpClient := &http.Client{ | ||
Transport: &http.Transport{ | ||
TLSClientConfig: &tls.Config{ | ||
InsecureSkipVerify: true, | ||
}, | ||
DisableKeepAlives: true, | ||
}, | ||
} | ||
|
||
return httpClient | ||
} | ||
|
||
// WebhookHealthyCheck servers for spiderpool controller readiness and liveness probe. | ||
// This is a Layer7 check. | ||
func WebhookHealthyCheck(httpClient *http.Client, webhookPort string, url *string) error { | ||
var webhookMutateURL string | ||
if url != nil { | ||
webhookMutateURL = fmt.Sprintf("https://%s:%s%s", *url, webhookPort, constant.WebhookMutateRoute) | ||
} else { | ||
webhookMutateURL = fmt.Sprintf("https://localhost:%s%s", webhookPort, constant.WebhookMutateRoute) | ||
} | ||
|
||
req, err := http.NewRequest(http.MethodGet, webhookMutateURL, nil) | ||
if nil != err { | ||
return fmt.Errorf("failed to new webhook https request, error: %v", err) | ||
} | ||
|
||
resp, err := httpClient.Do(req) | ||
if nil != err { | ||
return fmt.Errorf("webhook server is not reachable: %w", err) | ||
} | ||
defer func() { | ||
_ = resp.Body.Close() | ||
}() | ||
|
||
if resp.StatusCode != http.StatusOK { | ||
return fmt.Errorf("webhook health check status code: %d", resp.StatusCode) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters