Skip to content

Commit ef1d5d2

Browse files
enjk8s-publishing-bot
authored andcommitted
client-go exec: fix metrics related to plugin not found
These were missed because our tests did not pass in the correct test data input (the command to execute). Signed-off-by: Monis Khan <[email protected]> Kubernetes-commit: a6ac42082b4d7c0057b52900736bd7fbc2c44241
1 parent 7a90b08 commit ef1d5d2

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

plugin/pkg/client/auth/exec/metrics.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package exec
1818

1919
import (
2020
"errors"
21+
"io/fs"
2122
"os/exec"
2223
"reflect"
2324
"sync"
@@ -92,14 +93,15 @@ func (c *certificateExpirationTracker) set(a *Authenticator, t time.Time) {
9293
func incrementCallsMetric(err error) {
9394
execExitError := &exec.ExitError{}
9495
execError := &exec.Error{}
96+
pathError := &fs.PathError{}
9597
switch {
9698
case err == nil: // Binary execution succeeded.
9799
metrics.ExecPluginCalls.Increment(successExitCode, noError)
98100

99101
case errors.As(err, &execExitError): // Binary execution failed (see "os/exec".Cmd.Run()).
100102
metrics.ExecPluginCalls.Increment(execExitError.ExitCode(), pluginExecutionError)
101103

102-
case errors.As(err, &execError): // Binary does not exist (see exec.Error).
104+
case errors.As(err, &execError), errors.As(err, &pathError): // Binary does not exist (see exec.Error, fs.PathError).
103105
metrics.ExecPluginCalls.Increment(failureExitCode, pluginNotFoundError)
104106

105107
default: // We don't know about this error type.

plugin/pkg/client/auth/exec/metrics_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package exec
1818

1919
import (
2020
"fmt"
21+
"io"
2122
"testing"
2223
"time"
2324

@@ -147,6 +148,7 @@ func TestCallsMetric(t *testing.T) {
147148
if err != nil {
148149
t.Fatal(err)
149150
}
151+
a.stderr = io.Discard
150152

151153
// Run refresh creds twice so that our test validates that the metrics are set correctly twice
152154
// in a row with the same authenticator.
@@ -172,14 +174,15 @@ func TestCallsMetric(t *testing.T) {
172174
// metric values.
173175
refreshCreds := func(command string) {
174176
c := api.ExecConfig{
175-
Command: "does not exist",
177+
Command: command,
176178
APIVersion: "client.authentication.k8s.io/v1beta1",
177179
InteractiveMode: api.IfAvailableExecInteractiveMode,
178180
}
179181
a, err := newAuthenticator(newCache(), func(_ int) bool { return false }, &c, nil)
180182
if err != nil {
181183
t.Fatal(err)
182184
}
185+
a.stderr = io.Discard
183186
if err := a.refreshCredsLocked(&clientauthentication.Response{}); err == nil {
184187
t.Fatal("expected the authenticator to fail because the plugin does not exist")
185188
}

0 commit comments

Comments
 (0)