Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add envtest based tests for KongAdminAPIServiceReconciler #3568

Closed
pmalek opened this issue Feb 16, 2023 · 0 comments · Fixed by #3635
Closed

Add envtest based tests for KongAdminAPIServiceReconciler #3568

pmalek opened this issue Feb 16, 2023 · 0 comments · Fixed by #3635
Assignees
Milestone

Comments

@pmalek
Copy link
Member

pmalek commented Feb 16, 2023

Problem statement

After the introduction of support for Admin API service discovery #702 and hence single controller deployments (partially via KongAdminAPIServiceReconciler) we need to add tests for this functionality.

Some of the related functionality is already being tests with

  • UTs e.g. https://github.com/Kong/kubernetes-ingress-controller/blob/93fc98efc6249dfaaa65420b76f22e36ddf602ba/internal/adminapi/endpoints.go
  • of E2E tests e.g.
    func TestDeployAllInOneDBLESSMultiGW(t *testing.T) {
    t.Parallel()
    const (
    manifestFileName = "all-in-one-dbless-multi-gw.yaml"
    manifestFilePath = "../../deploy/single/" + manifestFileName
    )
    t.Logf("configuring %s manifest test", manifestFileName)
    ctx, env := setupE2ETest(t)
    t.Log("deploying kong components")
    f, err := os.Open(manifestFilePath)
    require.NoError(t, err)
    defer f.Close()
    var manifest io.Reader = f
    manifest, err = patchControllerImageFromEnv(manifest, manifestFilePath)
    require.NoError(t, err)
    deployment := deployKong(ctx, t, env, manifest)
    t.Log("running ingress tests to verify all-in-one deployed ingress controller and proxy are functional")
    deployIngress(ctx, t, env)
    verifyIngress(ctx, t, env)
    gatewayDeployment, err := env.Cluster().Client().AppsV1().Deployments(deployment.Namespace).Get(ctx, "proxy-kong", metav1.GetOptions{})
    require.NoError(t, err)
    gatewayDeployment.Spec.Replicas = lo.ToPtr(int32(3))
    _, err = env.Cluster().Client().AppsV1().Deployments(deployment.Namespace).Update(ctx, gatewayDeployment, metav1.UpdateOptions{})
    require.NoError(t, err)
    var podList *corev1.PodList
    t.Log("waiting all the dataplane instances to be ready")
    require.Eventually(t, func() bool {
    forDeployment := metav1.ListOptions{
    LabelSelector: "app=proxy-kong",
    }
    podList, err = env.Cluster().Client().CoreV1().Pods(deployment.Namespace).List(ctx, forDeployment)
    require.NoError(t, err)
    return len(podList.Items) == 3
    }, time.Minute, time.Second)
    t.Log("confirming that all dataplanes got the config")
    for _, pod := range podList.Items {
    client := &http.Client{
    Timeout: time.Second * 30,
    Transport: &http.Transport{
    TLSClientConfig: &tls.Config{
    InsecureSkipVerify: true, //nolint:gosec
    },
    },
    }
    forwardCtx, cancel := context.WithCancel(context.Background())
    defer cancel()
    localPort := startPortForwarder(forwardCtx, t, env, deployment.Namespace, pod.Name, "8444")
    address := fmt.Sprintf("https://localhost:%d", localPort)
    kongClient, err := gokong.NewClient(lo.ToPtr(address), client)
    require.NoError(t, err)
    requireIngressConfiguredInAdminAPIEventually(ctx, t, kongClient)
    t.Logf("proxy pod %s/%s: got the config", pod.Namespace, pod.Name)
    }
    }

but ideally we would like like to add some integration tests. This unfortunately is not easy because service discovery is being done via EndpointSlice watch which returns cluster internal addresses.

Proposed solution

Add envtest based tests to test predicates about KongAdminAPIServiceReconciler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants