forked from kgateway-dev/kgateway
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathenvoy.go
56 lines (48 loc) · 1.69 KB
/
envoy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package assertions
import (
"context"
"io"
"net"
"time"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/solo-io/gloo/pkg/utils/envoyutils/admincli"
"github.com/solo-io/gloo/pkg/utils/kubeutils/portforward"
"github.com/solo-io/gloo/pkg/utils/requestutils/curl"
)
func (p *Provider) AssertEnvoyAdminApi(
ctx context.Context,
envoyDeployment metav1.ObjectMeta,
adminAssertions ...func(ctx context.Context, adminClient *admincli.Client),
) {
// Before opening a port-forward, we assert that there is at least one Pod that is ready
p.EventuallyRunningReplicas(ctx, envoyDeployment, BeNumerically(">=", 1))
portForwarder, err := p.clusterContext.Cli.StartPortForward(ctx,
portforward.WithDeployment(envoyDeployment.GetName(), envoyDeployment.GetNamespace()),
portforward.WithPorts(admincli.DefaultAdminPort, admincli.DefaultAdminPort),
)
p.Require.NoError(err, "can open port-forward")
defer func() {
portForwarder.Close()
portForwarder.WaitForStop()
}()
// the port-forward returns before it completely starts up (https://github.com/solo-io/gloo/issues/9353),
// so as a workaround we try to keep dialing the address until it succeeds
p.Gomega.Eventually(func(g Gomega) {
_, err = net.Dial("tcp", portForwarder.Address())
g.Expect(err).NotTo(HaveOccurred())
}).
WithContext(ctx).
WithTimeout(time.Second * 15).
WithPolling(time.Second).
Should(Succeed())
adminClient := admincli.NewClient().
WithReceiver(io.Discard). // adminAssertion can overwrite this
WithCurlOptions(
curl.WithRetries(3, 0, 10),
curl.WithPort(admincli.DefaultAdminPort),
)
for _, adminAssertion := range adminAssertions {
adminAssertion(ctx, adminClient)
}
}