Repository: linkerd/linkerd2
Pull request #11993 (2024-01-26 18:05:34)

diagnostics endpoints: Support -token
The 'diagnostics endpoints' command does not allow the caller to specify a context token (indicating the requester nodeName). This change adds a command-line option to configure this value.

<!--  Thanks for sending a pull request!

If you already have a well-structured git commit message, chances are GitHub
set the title and description of this PR to the git commit message subject and
body, respectively. If so, you may delete these instructions and submit your PR.

If this is your first time, please read our contributor guide:
https://github.com/linkerd/linkerd2/blob/main/CONTRIBUTING.md

The title and description of your Pull Request should match the git commit
subject and body, respectively. Git commit messages are structured as follows:

```
Subject

Problem

Solution

Validation

Fixes #[GitHub issue ID]

DCO Sign off
```

Example git commit message:

```
Introduce Pull Request Template

GitHub's community guidelines recommend a pull request template, the repo was
lacking one.

Introduce a `PULL_REQUEST_TEMPLATE.md` file.

Once merged, the
[Community profile checklist](https://github.com/linkerd/linkerd2/community)
should indicate the repo now provides a pull request template.

Fixes #3321

Signed-off-by: Jane Smith <jane.smith@example.com>
```

Note the git commit message subject becomes the pull request title.

For more details around git commits, see the section on Committing in our
contributor guide:
https://github.com/linkerd/linkerd2/blob/main/CONTRIBUTING.md#committing
-->



Patch:
diff --git a/cli/cmd/endpoints.go b/cli/cmd/endpoints.go
index a25238b00..098908e26 100644
--- a/cli/cmd/endpoints.go
+++ b/cli/cmd/endpoints.go
@@ -28,6 +28,7 @@ import (
 type endpointsOptions struct {
 	outputFormat   string
 	destinationPod string
+	contextToken   string
 }
 
 type (
@@ -117,7 +118,7 @@ destination.`,
 
 			defer conn.Close()
 
-			endpoints, err := requestEndpointsFromAPI(client, args)
+			endpoints, err := requestEndpointsFromAPI(client, options.contextToken, args)
 			if err != nil {
 				fmt.Fprintf(os.Stderr, "Destination API error: %s\n", err)
 				os.Exit(1)
@@ -132,13 +133,14 @@ destination.`,
 
 	cmd.PersistentFlags().StringVarP(&options.outputFormat, "output", "o", options.outputFormat, fmt.Sprintf("Output format; one of: \"%s\" or \"%s\"", tableOutput, jsonOutput))
 	cmd.PersistentFlags().StringVar(&options.destinationPod, "destination-pod", "", "Target a specific destination Pod when there are multiple running")
+	cmd.PersistentFlags().StringVar(&options.contextToken, "token", "", "The context token to use when making the request to the destination API")
 
 	pkgcmd.ConfigureOutputFlagCompletion(cmd)
 
 	return cmd
 }
 
-func requestEndpointsFromAPI(client destinationPb.DestinationClient, authorities []string) (endpointsInfo, error) {
+func requestEndpointsFromAPI(client destinationPb.DestinationClient, token string, authorities []string) (endpointsInfo, error) {
 	info := make(endpointsInfo)
 	// buffered channels to avoid blocking
 	events := make(chan *destinationPb.Update, len(authorities))
@@ -151,8 +153,9 @@ func requestEndpointsFromAPI(client destinationPb.DestinationClient, authorities
 			defer wg.Done()
 			if len(errs) == 0 {
 				dest := &destinationPb.GetDestination{
-					Scheme: "http:",
-					Path:   authority,
+					Scheme:       "http:",
+					Path:         authority,
+					ContextToken: token,
 				}
 
 				rsp, err := client.Get(context.Background(), dest)


Test patch:
diff --git a/cli/cmd/endpoints_test.go b/cli/cmd/endpoints_test.go
index e30e90aa7..1e0ff9d4b 100644
--- a/cli/cmd/endpoints_test.go
+++ b/cli/cmd/endpoints_test.go
@@ -130,7 +130,7 @@ func testEndpointsCall(exp endpointsExp, t *testing.T) {
 		},
 	}
 
-	endpoints, err := requestEndpointsFromAPI(mockClient, exp.authorities)
+	endpoints, err := requestEndpointsFromAPI(mockClient, "", exp.authorities)
 	if err != nil {
 		t.Fatalf("Unexpected error: %v", err)
 	}