Skip to content
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

[BUG] tag v1.6.2 unit-test TestMatchRegistryAuths case4(test4) failed #1583

Closed
Colvin-Y opened this issue Apr 17, 2024 · 9 comments
Closed
Assignees
Labels
kind/bug Something isn't working

Comments

@Colvin-Y
Copy link
Contributor

What happened:
I use kruise tag v1.6.2 to run unit-test with go version 1.19 & 1.20
What you expected to happen:
All unit-test should pass but case TestMatchRegistryAuths(https://github.com/openkruise/kruise/blob/v1.6.2/pkg/daemon/criruntime/imageruntime/helpers_test.go#L89) failed,
How to reproduce it (as minimally and precisely as possible):
Run test case TestMatchRegistryAuths
Anything else we need to know?:

Environment:

  • Kruise version: tag v1.6.2
  • Kubernetes version (use kubectl version): unit-test
  • Install details (e.g. helm install args):
  • Others:
@Colvin-Y Colvin-Y added the kind/bug Something isn't working label Apr 17, 2024
@ABNER-1
Copy link
Contributor

ABNER-1 commented Apr 19, 2024

I attempted to reproduce it, but it passed. Can you still reproduce it now?

@Colvin-Y
Copy link
Contributor Author

Colvin-Y commented Apr 22, 2024

I attempted to reproduce it, but it passed. Can you still reproduce it now?

Yes, maybe because I use mac M1? I'm really confused, could u plz tell me ur environment?

Running tool: /opt/homebrew/bin/go test -timeout 30s -run ^TestMatchRegistryAuths$ github.com/openkruise/kruise/pkg/daemon/criruntime/imageruntime

--- FAIL: TestMatchRegistryAuths (0.00s)
    --- FAIL: TestMatchRegistryAuths/test4 (0.00s)
        /Users/bytedance/Profile/go_workspace/src/data-kruise/pkg/daemon/criruntime/imageruntime/helpers_test.go:117: convertToRegistryAuths failed
FAIL
FAIL	github.com/openkruise/kruise/pkg/daemon/criruntime/imageruntime	0.834s
FAIL

Env:

go version go1.19.13 darwin/arm64
go version go1.20.14 darwin/arm64

@ABNER-1
Copy link
Contributor

ABNER-1 commented Apr 27, 2024

Hi, @Colvin-Y .
I successfully reproduced the issue and discovered that it fails on any PC without Docker installed.

The core code stack is:

credentialprovider.ReadDockerConfigJSONFile (config.go:146) k8s.io/kubernetes/pkg/credentialprovider
credentialprovider.ReadDockerConfigFile (config.go:171) k8s.io/kubernetes/pkg/credentialprovider
credentialprovider.(*defaultDockerConfigProvider).Provide (provider.go:79) k8s.io/kubernetes/pkg/credentialprovider
credentialprovider.(*CachingDockerConfigProvider).Provide (provider.go:103) k8s.io/kubernetes/pkg/credentialprovider
credentialprovider.(*providersDockerKeyring).Lookup (keyring.go:269) k8s.io/kubernetes/pkg/credentialprovider
credentialprovider.UnionDockerKeyring.Lookup (keyring.go:299) k8s.io/kubernetes/pkg/credentialprovider
<autogenerated>:2
secret.ConvertToRegistryAuths (parse.go:33) github.com/openkruise/kruise/pkg/util/secret
imageruntime.TestMatchRegistryAuths.func6 (helpers_test.go:112) github.com/openkruise/kruise/pkg/daemon/criruntime/imageruntime
testing.tRunner (testing.go:1689) testing
testing.(*T).Run.gowrap1 (testing.go:1742) testing
runtime.goexit (asm_arm64.s:1222) runtime
 - Async Stack Trace
testing.(*T).Run (testing.go:1742) testing

ReadDockerConfigJSONFile(nil) will return different results based on whether Docker is installed.

@Colvin-Y
Copy link
Contributor Author

Colvin-Y commented May 6, 2024

ReadDockerConfigJSONFile

Hi, @ABNER-1.
Thanks for your reply, but actually I've installed docker

➜  ~ cat ~/.docker/config.json
{
	"auths": {
	},
	"credsStore": "desktop",
	"currentContext": "desktop-linux"
}

And I've tried to print the result from function secret.ConvertToRegistryAuths(cs.GetSecrets(), repoToPull)

infos: [{echoserver test}]
--- FAIL: TestMatchRegistryAuths (0.00s)
    --- FAIL: TestMatchRegistryAuths/test4 (0.00s)
        helpers_test.go:120: convertToRegistryAuths failed
FAIL

What config should I check?

@ABNER-1
Copy link
Contributor

ABNER-1 commented May 14, 2024

I plan to debug it again this weekend. However, if you'd like to take a crack at it, please feel free to do so. @Colvin-Y

@Colvin-Y
Copy link
Contributor Author

I plan to debug it again this weekend. However, if you'd like to take a crack at it, please feel free to do so. @Colvin-Y

Thank u! I also plan to figure out what the whole test cases are doing. @ABNER-1

@ABNER-1
Copy link
Contributor

ABNER-1 commented May 20, 2024

image

func readDockerConfigJSONFileFromBytes(contents []byte) (cfg DockerConfig, err error) {
	var cfgJSON DockerConfigJSON
	if err = json.Unmarshal(contents, &cfgJSON); err != nil {
		return nil, errors.New("error occurred while trying to unmarshal json")
	}
	cfg = cfgJSON.Auths
	return
}

The 'auths' value in docker/config.json will be regarded as authentication information for the public Docker registry. It should be disregarded in Test Case 4.

@ABNER-1
Copy link
Contributor

ABNER-1 commented May 20, 2024

A simple solution in my opinion:
len(infos) != cs.Expect => len(infos) < cs.Expect
refer code:

if len(infos) != cs.Expect {

@Colvin-Y
Copy link
Contributor Author

image

func readDockerConfigJSONFileFromBytes(contents []byte) (cfg DockerConfig, err error) {
	var cfgJSON DockerConfigJSON
	if err = json.Unmarshal(contents, &cfgJSON); err != nil {
		return nil, errors.New("error occurred while trying to unmarshal json")
	}
	cfg = cfgJSON.Auths
	return
}

The 'auths' value in docker/config.json will be regarded as authentication information for the public Docker registry. It should be disregarded in Test Case 4.

Got it! thx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants