Skip to content

Commit

Permalink
test restarts
Browse files Browse the repository at this point in the history
  • Loading branch information
jmurret committed Jul 30, 2024
1 parent 0d1af0f commit 4cc185c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
25 changes: 24 additions & 1 deletion acceptance/tests/consul-dns/consul_dns_partitions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,38 @@ func TestConsulDNSProxy_WithPartitionsAndCatalogSync(t *testing.T) {
if v.preProcessingFunc != nil {
v.preProcessingFunc(t)
}
verifyDNS(t, releaseName, c.enableDNSProxy, staticServerNamespace, v.requestingCtx, v.svcContext,
verifyDNS(t, releaseName, staticServerNamespace, v.requestingCtx, v.svcContext,
podLabelSelector, v.svcName, v.shouldResolveDNS, dnsUtilsPodIndex)
dnsUtilsPodIndex++
})
}

if c.enableDNSProxy {
t.Run("restart dns-proxy and verify DNS queries for exported services across partitions", func(t *testing.T) {
restartDNSProxy(t, releaseName, defaultClusterContext)
verifyDNS(t, releaseName, staticServerNamespace, defaultClusterContext, secondaryClusterContext,
podLabelSelector, fmt.Sprintf("%s.service.%s.ap.consul", staticServerName, secondaryPartition), true,
dnsUtilsPodIndex)
verifyDNS(t, releaseName, staticServerNamespace, secondaryClusterContext, defaultClusterContext,
podLabelSelector, fmt.Sprintf("%s.service.%s.ap.consul", staticServerName, defaultPartition), true,
dnsUtilsPodIndex)
})
}
})
}
}

func restartDNSProxy(t *testing.T, releaseName string, ctx environment.TestContext) {
dnsDeploymentName := fmt.Sprintf("deployment/%s-consul-dns-proxy", releaseName)
restartDNSProxyCommand := []string{"rollout", "restart", dnsDeploymentName}
_, err := k8s.RunKubectlAndGetOutputE(t, ctx.KubectlOptions(t), restartDNSProxyCommand...)
require.NoError(t, err)

// Wait for restart to finish.
out, err := k8s.RunKubectlAndGetOutputE(t, ctx.KubectlOptions(t), "rollout", "status", "--timeout", "1m", "--watch", dnsDeploymentName)
require.NoError(t, err, out, "rollout status command errored, this likely means the rollout didn't complete in time")
}

func getVerifications(defaultClusterContext environment.TestContext, secondaryClusterContext environment.TestContext,
shouldResolveUnexportedCrossPartitionDNSRecord bool, cfg *config.TestConfig) []dnsVerfication {
serviceRequestWithNoPartition := fmt.Sprintf("%s.service.consul", staticServerName)
Expand Down
9 changes: 6 additions & 3 deletions acceptance/tests/consul-dns/consul_dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestConsulDNS(t *testing.T) {
cluster.Create(t)

updateCoreDNSWithConsulDomain(t, ctx, releaseName, c.enableDNSProxy)
verifyDNS(t, releaseName, c.enableDNSProxy, ctx.KubectlOptions(t).Namespace, ctx, ctx, "app=consul,component=server",
verifyDNS(t, releaseName, ctx.KubectlOptions(t).Namespace, ctx, ctx, "app=consul,component=server",
"consul.service.consul", true, 0)
})
}
Expand All @@ -72,7 +72,7 @@ func TestConsulDNS(t *testing.T) {
func updateCoreDNSWithConsulDomain(t *testing.T, ctx environment.TestContext, releaseName string, enableDNSProxy bool) {
updateCoreDNSFile(t, ctx, releaseName, enableDNSProxy, "coredns-custom.yaml")
updateCoreDNS(t, ctx, "coredns-custom.yaml")
time.Sleep(5 * time.Second)

t.Cleanup(func() {
updateCoreDNS(t, ctx, "coredns-original.yaml")
time.Sleep(5 * time.Second)
Expand Down Expand Up @@ -101,9 +101,12 @@ func updateCoreDNS(t *testing.T, ctx environment.TestContext, coreDNSConfigFile
restartCoreDNSCommand := []string{"rollout", "restart", "deployment/coredns", "-n", "kube-system"}
_, err = k8s.RunKubectlAndGetOutputE(t, ctx.KubectlOptions(t), restartCoreDNSCommand...)
require.NoError(t, err)
// Wait for restart to finish.
out, err := k8s.RunKubectlAndGetOutputE(t, ctx.KubectlOptions(t), "rollout", "status", "--timeout", "1m", "--watch", "deployment/coredns", "-n", "kube-system")
require.NoError(t, err, out, "rollout status command errored, this likely means the rollout didn't complete in time")
}

func verifyDNS(t *testing.T, releaseName string, enableDNSProxy bool, svcNamespace string, requestingCtx, svcContext environment.TestContext,
func verifyDNS(t *testing.T, releaseName string, svcNamespace string, requestingCtx, svcContext environment.TestContext,
podLabelSelector, svcName string, shouldResolveDNSRecord bool, dnsUtilsPodIndex int) {
podList, err := svcContext.KubernetesClient(t).CoreV1().Pods(svcNamespace).List(context.Background(), metav1.ListOptions{
LabelSelector: podLabelSelector,
Expand Down

0 comments on commit 4cc185c

Please sign in to comment.