pkg/credentialprovider: fix staticcheck warning

This commit is contained in:
hwdef 2019-11-11 09:46:52 +08:00
parent 6c6fd9c575
commit 170eadc3d2
5 changed files with 8 additions and 12 deletions

View File

@ -16,8 +16,6 @@ pkg/controller/podgc
pkg/controller/replicaset
pkg/controller/resourcequota
pkg/controller/statefulset
pkg/credentialprovider
pkg/credentialprovider/aws
pkg/kubeapiserver/admission
pkg/kubectl/cmd/get
pkg/kubelet/apis/podresources

View File

@ -196,7 +196,7 @@ func TestECRProvide(t *testing.T) {
// Verify that we get an error for other images.
for _, otherRegistry := range otherRegistries {
image = path.Join(otherRegistry, "foo/bar")
creds, ok = keyring.Lookup(image)
_, ok = keyring.Lookup(image)
if ok {
t.Errorf("Unexpectedly found image: %s", image)
return
@ -293,7 +293,7 @@ func TestChinaECRProvide(t *testing.T) {
// Verify that we get an error for other images.
for _, otherRegistry := range otherRegistries {
image = path.Join(otherRegistry, image)
creds, ok = keyring.Lookup(image)
_, ok = keyring.Lookup(image)
if ok {
t.Errorf("Unexpectedly found image: %s", image)
return

View File

@ -91,22 +91,22 @@ func receiveChallengeFromLoginServer(serverAddress string) (*authDirective, erro
var challenge *http.Response
if challenge, err = client.Do(r); err != nil {
return nil, fmt.Errorf("Error reaching registry endpoint %s, error: %s", challengeURL.String(), err)
return nil, fmt.Errorf("error reaching registry endpoint %s, error: %s", challengeURL.String(), err)
}
defer challenge.Body.Close()
if challenge.StatusCode != 401 {
return nil, fmt.Errorf("Registry did not issue a valid AAD challenge, status: %d", challenge.StatusCode)
return nil, fmt.Errorf("registry did not issue a valid AAD challenge, status: %d", challenge.StatusCode)
}
var authHeader []string
var ok bool
if authHeader, ok = challenge.Header["Www-Authenticate"]; !ok {
return nil, fmt.Errorf("Challenge response does not contain header 'Www-Authenticate'")
return nil, fmt.Errorf("challenge response does not contain header 'Www-Authenticate'")
}
if len(authHeader) != 1 {
return nil, fmt.Errorf("Registry did not issue a valid AAD challenge, authenticate header [%s]",
return nil, fmt.Errorf("registry did not issue a valid AAD challenge, authenticate header [%s]",
strings.Join(authHeader, ", "))
}
@ -114,7 +114,7 @@ func receiveChallengeFromLoginServer(serverAddress string) (*authDirective, erro
authType := strings.ToLower(authSections[0])
var authParams *map[string]string
if authParams, err = parseAssignments(authSections[1]); err != nil {
return nil, fmt.Errorf("Unable to understand the contents of Www-Authenticate header %s", authSections[1])
return nil, fmt.Errorf("unable to understand the contents of Www-Authenticate header %s", authSections[1])
}
// verify headers

View File

@ -29,7 +29,6 @@ import (
func TestReadDockerConfigFile(t *testing.T) {
configJsonFileName := "config.json"
var fileInfo *os.File
preferredPaths := []string{}
//test dockerconfig json
inputDockerconfigJsonFile := "{ \"auths\": { \"http://foo.example.com\":{\"auth\":\"Zm9vOmJhcgo=\",\"email\":\"foo@example.com\"}}}"
@ -40,7 +39,6 @@ func TestReadDockerConfigFile(t *testing.T) {
return
}
defer os.RemoveAll(preferredPath)
preferredPaths = append(preferredPaths, preferredPath)
absDockerConfigFileLocation, err := filepath.Abs(filepath.Join(preferredPath, configJsonFileName))
if err != nil {
t.Fatalf("While trying to canonicalize %s: %v", preferredPath, err)

View File

@ -265,7 +265,7 @@ func TestContainerRegistryBasics(t *testing.T) {
}
val := creds[0]
if "_token" != val.Username {
if val.Username != "_token" {
t.Errorf("Unexpected username value, want: %s, got: %s", "_token", val.Username)
}
if token.AccessToken != val.Password {