Skip to content

Tests failing locally #867

@lkingland

Description

@lkingland

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 false if the user doesn't have services get permission on the openshift-image-registry namespace.

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-containerregistry uses a GET /v2/ HTTP /1.1 probe 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions