Skip to content

test(e2e): add e2e tests for authz, secret, log, accesslog, version and dump #1316

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

ravjot07
Copy link
Contributor

test(e2e): add end-to-end tests for kmeshctl commands

  • authz: enable/disable/status subcommands
  • secret: create and update IPsec secret
  • log: list, get and set logger levels
  • accesslog: enable/disable per-pod and cluster
  • dump: kernel-native, dual-engine, and invalid-mode handling
  • version: version for kmeshctl, for specific pod

Each test locates a running kmesh daemon pod, waits for readiness, invokes the CLI, and asserts expected behaviour or output.

Signed-off-by: ravjot07 <ravu2004@gmail.com>
Signed-off-by: ravjot07 <ravu2004@gmail.com>
Signed-off-by: ravjot07 <ravu2004@gmail.com>
Signed-off-by: ravjot07 <ravu2004@gmail.com>
Signed-off-by: ravjot07 <ravu2004@gmail.com>
Signed-off-by: ravjot07 <ravu2004@gmail.com>
@kmesh-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign lec-bit for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link

codecov bot commented Apr 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 46.26%. Comparing base (44253ce) to head (4cd923f).
Report is 16 commits behind head on main.


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1d2122a...4cd923f. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@yp969803
Copy link
Contributor

yp969803 commented Apr 20, 2025

accesslogs are reported periodically after (5 sec) for long tcp_connections, can you add a e2e test for this ?? @ravjot07

@ravjot07
Copy link
Contributor Author

accesslogs are reported periodically after (5 sec) for long tcp_connections, can you add a e2e test for this ?? @ravjot07

ya sure

"bufio"
"context"
"crypto/rand"
"encoding/hex"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gofmt?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use gofmt to format the code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
}

func runAuthzCmd(args ...string) (string, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can merge runAuthCmd, runVersionCmd, etc and pass parameters as needed, because you have not structed any subcommands yet.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done pl. review


t.Run("kernel-native", func(t *testing.T) {
out, err := runDumpCmd(pod, "kernel-native")
t.Logf("Output of 'kmeshctl dump %s kernel-native':\n%s", pod, out)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should at least check if the command output contains certain key strings instead of printing the log directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done i have updated the test

@YaoZengzeng
Copy link
Member

ping @ravjot07

Signed-off-by: ravjot07 <ravu2004@gmail.com>
Signed-off-by: ravjot07 <ravu2004@gmail.com>

func TestKmeshctlVersion(t *testing.T) {
pod := findKmeshPod(t)
waitForPodRunning(t, pod)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can ensure that the Kmesh pods are in the running status before running this test, ref: https://github.com/kmesh-net/kmesh/blob/main/test/e2e/run_test.sh#L118

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done pl. review

@kmesh-bot
Copy link
Collaborator

Adding label do-not-merge/contains-merge-commits because PR contains merge commits, which are not allowed in this repository.
Use git rebase to reapply your commits on top of the target branch. Detailed instructions for doing so can be found here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@YaoZengzeng
Copy link
Member

Adding label do-not-merge/contains-merge-commits because PR contains merge commits, which are not allowed in this repository. Use git rebase to reapply your commits on top of the target branch. Detailed instructions for doing so can be found here.

@ravjot07 you should use git rebase instead of merging.

return outStr, err
}

func waitForPodReady(t *testing.T, pod string) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
}

func findKmeshPod(t *testing.T) string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like it is implemented in init and can be deleted?

})

t.Run("list", func(t *testing.T) {
time.Sleep(2 * time.Second)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better not to sleep directly, polling is better, and an error will be reported if the timeout occurs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have changes this part using polling

@@ -272,8 +290,11 @@ if [[ -z "${SKIP_SETUP:-}" ]]; then
fi

if [[ -z "${SKIP_BUILD:-}" ]]; then
setup_kind_registry
build_and_push_images
setup_kind_registry
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

setup_kind_registry
build_and_push_images
echo "Building kmeshctl CLI..."
make kmeshctl || { echo "Failed to build kmeshctl" >&2; exit 1; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we don't compile kmeshctl? Already done in previous build_and_push_images?

ravjot07 and others added 2 commits May 13, 2025 10:56
Signed-off-by: ravjot07 <ravu2004@gmail.com>
@@ -209,6 +209,24 @@ function cleanup_docker_registry() {
docker rm "${KIND_REGISTRY_NAME}" || echo "Failed to remove or no such registry '${KIND_REGISTRY_NAME}'."
}

TMPBIN="${TMPBIN:-$(mktemp -d)/bin}"
mkdir -p "$TMPBIN"
export PATH="$PATH:$TMPBIN"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already have this dicretory

# Function to install kmeshctl into the test environment.
function install_kmeshctl() {
echo "Installing kmeshctl CLI into test environment..."
if [[ -f "$ROOT_DIR/kmeshctl" ]]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to check, just copy it.

// Package‐level init ensures Kmesh is ready before any tests run.
func init() {
// 1) Wait up to 2 minutes for all Kmesh pods to become Ready.
wait := exec.Command("kubectl", "-n", kmeshNamespace, "wait",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have already said that the Kmesh pod is ready, no need to check it again

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

Successfully merging this pull request may close these issues.

4 participants