-
Notifications
You must be signed in to change notification settings - Fork 176
Description
Running go test ./... fails with:
--- FAIL: TestRoundTripper (5.01s)
openshift_test.go:27: Get "https://image-registry.openshift-image-registry.svc.cluster.local:5000/v2/": Post "https://127.0.0.1:54405/api/v1/namespaces/default/pods": dial tcp 127.0.0.1:54405: connect: connection refused
This appears to be because of the implementation of the new IsOpenShift function which assumes any error other than NotFound means the cluster is OpenShift:
func IsOpenShift() bool {
checkOpenShiftOnce.Do(func() {
client, err := k8s.NewKubernetesClientset()
if err != nil {
fmt.Print("error in NewKubernetesClientset")
isOpenShift = false
return
}
_, err = client.CoreV1().Services("openshift-image-registry").Get(context.TODO(), "image-registry", metav1.GetOptions{})
if k8sErrors.IsNotFound(err) {
isOpenShift = false
return
}
// FIXME(lkingland): This seems to ignoire legitimate errors other than NotFound
isOpenShift = true
})
return isOpenShift
}
As Evan mentioned in the PR in which this check was added, there might be a better way to detect this:
Hmm -- this will return
falseif the user doesn't haveservicesgetpermission on theopenshift-image-registrynamespace.I'm not sure if there's another / better way to detect this, either from server headers or by probing the registry and looking at its header / challenge. I think
go-containerregistryuses aGET /v2/ HTTP /1.1probe of the registry to figure out what and whether auth is required.
Originally posted by @evankanderson in #825 (comment)
The error appears to be a simple connection refused (no cluster is running locally, as one is not needed to run unit tests).
If this is expected behavior, and the test depends on a cluster being available, perhaps tagging it as an integration test would to the trick?
//go:build integration
// +build integration