-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vault: Initial wan fed support (tls and gossip only)
- Loading branch information
Showing
12 changed files
with
821 additions
and
267 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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package k8s | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
"github.com/hashicorp/consul-k8s/acceptance/framework/config" | ||
"github.com/hashicorp/consul-k8s/acceptance/framework/environment" | ||
"github.com/hashicorp/consul-k8s/acceptance/framework/helpers" | ||
"github.com/hashicorp/consul/sdk/testutil/retry" | ||
"github.com/stretchr/testify/require" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// KubernetesAPIServerHost returns the Kubernetes API server URL depending on test configuration. | ||
func KubernetesAPIServerHost(t *testing.T, cfg *config.TestConfig, ctx environment.TestContext) string { | ||
var k8sAPIHost string | ||
// When running on kind, the kube API address in kubeconfig will have a localhost address | ||
// which will not work from inside the container. That's why we need to use the endpoints address instead | ||
// which will point the node IP. | ||
if cfg.UseKind { | ||
// The Kubernetes AuthMethod host is read from the endpoints for the Kubernetes service. | ||
kubernetesEndpoint, err := ctx.KubernetesClient(t).CoreV1().Endpoints("default").Get(context.Background(), "kubernetes", metav1.GetOptions{}) | ||
require.NoError(t, err) | ||
k8sAPIHost = fmt.Sprintf("https://%s:%d", kubernetesEndpoint.Subsets[0].Addresses[0].IP, kubernetesEndpoint.Subsets[0].Ports[0].Port) | ||
} else { | ||
k8sAPIHost = helpers.KubernetesAPIServerHostFromOptions(t, ctx.KubectlOptions(t)) | ||
} | ||
|
||
return k8sAPIHost | ||
} | ||
|
||
// ServiceHost returns a host for a Kubernetes service depending on test configuration. | ||
func ServiceHost(t *testing.T, cfg *config.TestConfig, ctx environment.TestContext, serviceName string) string { | ||
if cfg.UseKind { | ||
nodeList, err := ctx.KubernetesClient(t).CoreV1().Nodes().List(context.Background(), metav1.ListOptions{}) | ||
require.NoError(t, err) | ||
// Get the address of the (only) node from the Kind cluster. | ||
return nodeList.Items[0].Status.Addresses[0].Address | ||
} else { | ||
var host string | ||
// It can take some time for the load balancers to be ready and have an IP/Hostname. | ||
// Wait for 60 seconds before failing. | ||
retry.RunWith(&retry.Counter{Wait: 1 * time.Second, Count: 60}, t, func(r *retry.R) { | ||
svc, err := ctx.KubernetesClient(t).CoreV1().Services(ctx.KubectlOptions(t).Namespace).Get(context.Background(), serviceName, metav1.GetOptions{}) | ||
require.NoError(t, err) | ||
require.NotEmpty(r, svc.Status.LoadBalancer.Ingress) | ||
// On AWS, load balancers have a hostname for ingress, while on Azure and GCP | ||
// load balancers have IPs. | ||
if svc.Status.LoadBalancer.Ingress[0].Hostname != "" { | ||
host = svc.Status.LoadBalancer.Ingress[0].Hostname | ||
} else { | ||
host = svc.Status.LoadBalancer.Ingress[0].IP | ||
} | ||
}) | ||
return host | ||
} | ||
} |
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
Oops, something went wrong.