diagnostics endpoints: Support -token (#11993)

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.
This commit is contained in:
Oliver Gould 2024-01-26 11:02:57 -08:00 committed by GitHub
parent 796bb85323
commit 3cfb05d360
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 5 deletions

View File

@ -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)

View File

@ -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)
}