-
Notifications
You must be signed in to change notification settings - Fork 26
feat(mesh): core command surface for Kong Mesh control planes #2128
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
Draft
justindavies
wants to merge
22
commits into
Kong:main
Choose a base branch
from
justindavies:mesh-foundation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
86fd505
feat(mesh): add mesh command container and resource discovery
justindavies f271dcf
feat(mesh): read any resource type from a Kong Mesh 3 control plane
justindavies 13a155d
feat(mesh): create and delete mesh resources
justindavies 3d0c96d
feat(mesh): issue dataplane and zone tokens
justindavies 88d9211
feat(mesh): list control planes and select one by name
justindavies dcd7059
fix(mesh): satisfy the linter on yaml import and an unused parameter
justindavies 12fe535
feat(mesh): surface control plane warnings on create
justindavies 66a5680
fix(mesh): honor explicit control plane selection, stop shadowing --p…
justindavies cc2458e
fix(mesh): paginate collections, register the explicit path, modernize
justindavies e4d2282
fix(mesh): build HTTP clients from the configured timeout and transport
justindavies 1c3e302
fix(mesh): define the configuration contract for the remaining options
justindavies e4ebac5
feat(mesh): make apply the primary verb for sending resources
justindavies b744b38
feat(mesh): support self managed control planes
justindavies 834c5ad
refactor(mesh): name the shared column headers
justindavies 76761c5
refactor(mesh): drop the inspection type option, which moves with ins…
justindavies 5de9af0
fix(mesh): resolve the target once, and scope TLS to its destination
justindavies 0134a8e
fix(mesh): bind mesh flags in the mesh command, not in each caller
justindavies c80ca25
refactor(mesh)!: write resources with apply only, not create
justindavies 8cd9a0d
test(mesh): cover the environment rung and add mesh e2e scenarios
justindavies 8cdb6fa
refactor(mesh): drop the per-verb flag binding the mesh command now does
justindavies 2881399
test(mesh): exercise the real HTTP path, including the TLS isolation fix
justindavies 0fca846
test(mesh): pin explicit selector precedence at the command level
justindavies File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,149 @@ | ||
| package root | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
|
|
||
| meshcommon "github.com/kong/kongctl/internal/cmd/root/products/konnect/mesh/common" | ||
| ) | ||
|
|
||
| // Mesh is reachable both directly and under the explicit product path. The | ||
| // constructors promise both, but only the direct form was registered, so | ||
| // `kongctl get konnect mesh` failed with "unknown command". These assert the | ||
| // real command paths rather than the constructors. | ||
| func TestMeshCommandPathsResolve(t *testing.T) { | ||
| // Every verb Kong Mesh serves here. For Plan, Sync, Diff, Export, Apply | ||
| // and Delete, konnect.NewKonnectCmd replaces the konnect command with the | ||
| // declarative command and returns before any product is added, so | ||
| // `apply konnect mesh` and `delete konnect mesh` cannot be registered | ||
| // without restructuring that subtree. Those two are served by the direct | ||
| // form only, and fall through to the declarative command rather than | ||
| // erroring -- asserted below so the fall-through stays deliberate. | ||
| paths := [][]string{ | ||
| {"apply", "mesh", "--help"}, | ||
| {"get", "mesh", "--help"}, | ||
| {"get", "konnect", "mesh", "--help"}, | ||
| {"create", "mesh", "--help"}, | ||
| {"create", "konnect", "mesh", "--help"}, | ||
| {"delete", "mesh", "--help"}, | ||
| } | ||
|
|
||
| for _, args := range paths { | ||
| path := strings.Join(args[:len(args)-1], " ") | ||
|
|
||
| t.Run(path, func(t *testing.T) { | ||
| result := executeRootForTest(t, args...) | ||
|
|
||
| if result.exitCode != 0 { | ||
| t.Fatalf("expected %q to succeed\nstdout:\n%s\nstderr:\n%s", | ||
| path, result.stdout, result.stderr) | ||
| } | ||
| if strings.Contains(result.stderr, "unknown command") { | ||
| t.Fatalf("expected %q to be registered\nstderr:\n%s", path, result.stderr) | ||
| } | ||
| // The mesh command's own help, not a parent's help that merely | ||
| // lists it: a swallowed argument prints the parent's help and | ||
| // still exits zero. | ||
| if !strings.Contains(result.stdout, "Kong Mesh control plane") { | ||
| t.Fatalf("expected %q help to describe the mesh command\nstdout:\n%s", | ||
| path, result.stdout) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // The declarative verbs claim `<verb> konnect`, so mesh is not reachable | ||
| // there. That is a property of the konnect subtree rather than a mesh bug, but | ||
| // it is silent -- the declarative command accepts "mesh" as a positional | ||
| // argument and prints its own help -- so it is pinned here. If either of these | ||
| // ever resolves to the mesh command, meshVerbs and this test disagree. | ||
| func TestMeshIsNotReachableUnderTheDeclarativeVerbs(t *testing.T) { | ||
| for _, verb := range []string{"apply", "delete"} { | ||
| t.Run(verb, func(t *testing.T) { | ||
| result := executeRootForTest(t, verb, "konnect", "mesh", "--help") | ||
|
|
||
| if strings.Contains(result.stdout, "Kong Mesh control plane") { | ||
| t.Fatalf("%s konnect mesh now resolves to the mesh command; "+ | ||
| "add %q to meshVerbs and move it into TestMeshCommandPathsResolve\nstdout:\n%s", | ||
| verb, verb, result.stdout) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // A selector given on the command line must reach configuration on both | ||
| // command trees. | ||
| // | ||
| // The explicit path passed the general konnect pre-run, which binds only the | ||
| // konnect-common flags, so every mesh flag there was registered but unbound. | ||
| // The failure was silent in the worst way: with a control plane already in | ||
| // configuration, `get konnect mesh meshes --control-plane-url <other>` ignored | ||
| // the flag and listed the configured control plane instead. | ||
| func TestMeshFlagsBindOnBothCommandTrees(t *testing.T) { | ||
| // A port nothing listens on. The request must be attempted and fail to | ||
| // connect, which proves the flag reached configuration. --help would not: | ||
| // it returns before the pre-run binds anything, which is why a help-only | ||
| // test cannot catch this. | ||
| const wantURL = "http://127.0.0.1:1" | ||
|
|
||
| paths := [][]string{ | ||
| {"get", "mesh", "meshes"}, | ||
| {"get", "konnect", "mesh", "meshes"}, | ||
| } | ||
|
|
||
| for _, path := range paths { | ||
| name := strings.Join(path, " ") | ||
|
|
||
| t.Run(name, func(t *testing.T) { | ||
| args := append(append([]string{}, path...), "--control-plane-url", wantURL) | ||
| result := executeRootForTest(t, args...) | ||
|
|
||
| if currConfig == nil { | ||
| t.Fatal("expected config to be initialized") | ||
| } | ||
| if got := currConfig.GetString(meshcommon.ControlPlaneURLConfigPath); got != wantURL { | ||
| t.Fatalf("%s: control plane URL = %q, want %q (flag registered but not bound)", | ||
| name, got, wantURL) | ||
| } | ||
| // The selector must also decide the request. Binding it while | ||
| // sending the request elsewhere is the failure this guards. | ||
| if !strings.Contains(result.stderr, "127.0.0.1:1") { | ||
| t.Fatalf("%s: expected the request to address %s\nstderr:\n%s", | ||
| name, wantURL, result.stderr) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // Resource writes belong to apply. `create mesh -f` reached the same upsert | ||
| // and so replaced an existing resource while reporting "updated", without the | ||
| // operator asking for a replacement, so it was removed. Token issuance stays | ||
| // under create. | ||
| func TestCreateMeshOffersTokensNotResourceWrites(t *testing.T) { | ||
| t.Run("the -f flag is gone", func(t *testing.T) { | ||
| result := executeRootForTest(t, "create", "mesh", "-f", "policy.yaml") | ||
|
|
||
| if result.exitCode == 0 { | ||
| t.Fatalf("expected create mesh -f to be rejected\nstdout:\n%s", result.stdout) | ||
| } | ||
| if !strings.Contains(result.stderr, "shorthand flag: 'f'") { | ||
| t.Fatalf("expected an unknown-flag error for -f\nstderr:\n%s", result.stderr) | ||
| } | ||
| }) | ||
|
|
||
| t.Run("token subcommands remain", func(t *testing.T) { | ||
| for _, sub := range []string{"zone-token", "dataplane-token"} { | ||
| result := executeRootForTest(t, "create", "mesh", sub, "--help") | ||
| if result.exitCode != 0 { | ||
| t.Fatalf("create mesh %s should still resolve\nstderr:\n%s", sub, result.stderr) | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| t.Run("apply still takes -f", func(t *testing.T) { | ||
| result := executeRootForTest(t, "apply", "mesh", "--help") | ||
| if !strings.Contains(result.stdout, "-f") { | ||
| t.Fatalf("expected apply mesh to offer -f\nstdout:\n%s", result.stdout) | ||
| } | ||
| }) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add request-level command tests and dedicated Mesh E2E scenarios.
The additional tests are useful, but these command-path tests execute only
--help, which bypasses the bindings and requests that currently fail on the explicit Konnect path. Selector tests exercise flag detection rather than the combined URL/authentication decision.TestMeshOptionPrecedencealso claims environment coverage but contains no environment-variable case.Add complete command/HTTP tests for direct and explicit paths, selector/authentication combinations, file/environment/flag precedence, pagination, TLS credential isolation, and write behavior. Add isolated Mesh discovery/read, apply/get/delete, and token E2E scenarios with cleanup, and run them through trusted E2E. There are still no Mesh scenarios in this PR; passing smoke/version does not validate the feature.