mirror of
https://github.com/fluxcd/flagger.git
synced 2026-04-15 06:57:34 +00:00
Compare commits
1 Commits
main
...
juparog/we
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d2e0b428b |
@@ -1135,6 +1135,9 @@ spec:
|
|||||||
retries:
|
retries:
|
||||||
description: Number of retries for this webhook
|
description: Number of retries for this webhook
|
||||||
type: number
|
type: number
|
||||||
|
disableTLS:
|
||||||
|
description: Disable TLS verification for this webhook
|
||||||
|
type: boolean
|
||||||
metadata:
|
metadata:
|
||||||
description: Metadata (key-value pairs) for this webhook
|
description: Metadata (key-value pairs) for this webhook
|
||||||
type: object
|
type: object
|
||||||
|
|||||||
@@ -1135,6 +1135,9 @@ spec:
|
|||||||
retries:
|
retries:
|
||||||
description: Number of retries for this webhook
|
description: Number of retries for this webhook
|
||||||
type: number
|
type: number
|
||||||
|
disableTLS:
|
||||||
|
description: Disable TLS verification for this webhook
|
||||||
|
type: boolean
|
||||||
metadata:
|
metadata:
|
||||||
description: Metadata (key-value pairs) for this webhook
|
description: Metadata (key-value pairs) for this webhook
|
||||||
type: object
|
type: object
|
||||||
|
|||||||
@@ -124,7 +124,10 @@ Event payload (HTTP POST):
|
|||||||
The event receiver can create alerts based on the received phase
|
The event receiver can create alerts based on the received phase
|
||||||
(possible values: `Initialized`, `Waiting`, `Progressing`, `Promoting`, `Finalising`, `Succeeded` or `Failed`).
|
(possible values: `Initialized`, `Waiting`, `Progressing`, `Promoting`, `Finalising`, `Succeeded` or `Failed`).
|
||||||
|
|
||||||
The webhook request can be retried by specifying a positive integer in the `retries` field.
|
Options:
|
||||||
|
* retries: The webhook request can be retried by specifying a positive integer in the `retries` field. This helps ensure reliability if the webhook fails due to transient network issues.
|
||||||
|
|
||||||
|
* disable TLS: Set `disableTLS` to `true` in the webhook spec to bypass TLS verification. This is useful in cases where the target service uses self-signed certificates, or you need to connect to an insecure service for testing purposes.
|
||||||
|
|
||||||
## Load Testing
|
## Load Testing
|
||||||
|
|
||||||
|
|||||||
@@ -1135,6 +1135,9 @@ spec:
|
|||||||
retries:
|
retries:
|
||||||
description: Number of retries for this webhook
|
description: Number of retries for this webhook
|
||||||
type: number
|
type: number
|
||||||
|
disableTLS:
|
||||||
|
description: Disable TLS verification for this webhook
|
||||||
|
type: boolean
|
||||||
metadata:
|
metadata:
|
||||||
description: Metadata (key-value pairs) for this webhook
|
description: Metadata (key-value pairs) for this webhook
|
||||||
type: object
|
type: object
|
||||||
|
|||||||
@@ -398,6 +398,10 @@ type CanaryWebhook struct {
|
|||||||
// Number of retries for this webhook
|
// Number of retries for this webhook
|
||||||
// +optional
|
// +optional
|
||||||
Retries int `json:"retries,omitempty"`
|
Retries int `json:"retries,omitempty"`
|
||||||
|
|
||||||
|
// Disable TLS verification for this webhook
|
||||||
|
// +optional
|
||||||
|
DisableTLS bool `json:"disableTls,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CanaryWebhookPayload holds the deployment info and metadata sent to webhooks
|
// CanaryWebhookPayload holds the deployment info and metadata sent to webhooks
|
||||||
|
|||||||
@@ -18,10 +18,12 @@ package controller
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"crypto/tls"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
@@ -32,7 +34,22 @@ import (
|
|||||||
"github.com/fluxcd/flagger/pkg/canary"
|
"github.com/fluxcd/flagger/pkg/canary"
|
||||||
)
|
)
|
||||||
|
|
||||||
func callWebhook(webhook string, payload interface{}, timeout string, retries int) error {
|
func newHTTPClient(retries int, timeout time.Duration, disableTls bool) *retryablehttp.Client {
|
||||||
|
httpClient := retryablehttp.NewClient()
|
||||||
|
httpClient.RetryMax = retries
|
||||||
|
httpClient.Logger = nil
|
||||||
|
httpClient.HTTPClient.Timeout = timeout
|
||||||
|
|
||||||
|
if disableTls {
|
||||||
|
httpClient.HTTPClient.Transport = &http.Transport{
|
||||||
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return httpClient
|
||||||
|
}
|
||||||
|
|
||||||
|
func callWebhook(webhook string, payload interface{}, timeout string, retries int, disableTls bool) error {
|
||||||
payloadBin, err := json.Marshal(payload)
|
payloadBin, err := json.Marshal(payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -43,17 +60,6 @@ func callWebhook(webhook string, payload interface{}, timeout string, retries in
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
httpClient := retryablehttp.NewClient()
|
|
||||||
httpClient.RetryMax = retries
|
|
||||||
httpClient.Logger = nil
|
|
||||||
|
|
||||||
req, err := retryablehttp.NewRequest("POST", hook.String(), bytes.NewBuffer(payloadBin))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
|
||||||
|
|
||||||
if timeout == "" {
|
if timeout == "" {
|
||||||
timeout = "10s"
|
timeout = "10s"
|
||||||
}
|
}
|
||||||
@@ -62,7 +68,13 @@ func callWebhook(webhook string, payload interface{}, timeout string, retries in
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
httpClient.HTTPClient.Timeout = t
|
httpClient := newHTTPClient(retries, t, disableTls)
|
||||||
|
|
||||||
|
req, err := retryablehttp.NewRequest("POST", hook.String(), bytes.NewBuffer(payloadBin))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
r, err := httpClient.Do(req)
|
r, err := httpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -100,7 +112,7 @@ func CallWebhook(canary flaggerv1.Canary, phase flaggerv1.CanaryPhase, w flagger
|
|||||||
w.Timeout = "10s"
|
w.Timeout = "10s"
|
||||||
}
|
}
|
||||||
|
|
||||||
return callWebhook(w.URL, payload, w.Timeout, w.Retries)
|
return callWebhook(w.URL, payload, w.Timeout, w.Retries, w.DisableTLS)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CallEventWebhook(r *flaggerv1.Canary, w flaggerv1.CanaryWebhook, message, eventtype string) error {
|
func CallEventWebhook(r *flaggerv1.Canary, w flaggerv1.CanaryWebhook, message, eventtype string) error {
|
||||||
@@ -126,7 +138,7 @@ func CallEventWebhook(r *flaggerv1.Canary, w flaggerv1.CanaryWebhook, message, e
|
|||||||
payload.Metadata[key] = value
|
payload.Metadata[key] = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return callWebhook(w.URL, payload, "5s", w.Retries)
|
return callWebhook(w.URL, payload, "5s", w.Retries, w.DisableTLS)
|
||||||
}
|
}
|
||||||
|
|
||||||
func canaryChecksum(c flaggerv1.Canary) string {
|
func canaryChecksum(c flaggerv1.Canary) string {
|
||||||
|
|||||||
@@ -289,3 +289,22 @@ func TestCallWebhook_Retries(t *testing.T) {
|
|||||||
flaggerv1.CanaryPhaseProgressing, hook)
|
flaggerv1.CanaryPhaseProgressing, hook)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCallWebhook_DisableTLS(t *testing.T) {
|
||||||
|
ts := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusAccepted)
|
||||||
|
}))
|
||||||
|
defer ts.Close()
|
||||||
|
hook := flaggerv1.CanaryWebhook{
|
||||||
|
Name: "validation",
|
||||||
|
URL: ts.URL,
|
||||||
|
DisableTLS: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
err := CallWebhook(
|
||||||
|
flaggerv1.Canary{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "podinfo", Namespace: corev1.NamespaceDefault}},
|
||||||
|
flaggerv1.CanaryPhaseProgressing, hook)
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user