Skip to content

Envtest is not idempotent when installing CRDs, an issue when UseExistingCluster=true #342

@teddyking

Description

@teddyking

We want to use envtest against an existing cluster and are having issues when installing CRDs. Envtest will fail on the second running of the tests because the CRDs already exist in the cluster. This is only an issue when using an existing cluster because normally envtest starts a new control plane each time.

Example setup we want to use:

		testEnv = &envtest.Environment{
			CRDDirectoryPaths:  []string{filepath.Join("..", "config", "crds")},
			UseExistingCluster: true,
		}

And error we get:

Expected error:
      <*errors.StatusError | 0xc00012a2d0>: {
          ErrStatus: {
              TypeMeta: {Kind: "", APIVersion: ""},
              ListMeta: {SelfLink: "", ResourceVersion: "", Continue: ""},
              Status: "Failure",
              Message: "customresourcedefinitions.apiextensions.k8s.io \"mycrd.meep.io\" already exists",
              Reason: "AlreadyExists",
              Details: {
                  Name: "mycrd.meep.io",
                  Group: "apiextensions.k8s.io",
                  Kind: "customresourcedefinitions",
                  UID: "",
                  Causes: nil,
                  RetryAfterSeconds: 0,
              },
              Code: 409,
          },
      }
      customresourcedefinitions.apiextensions.k8s.io "mycrd.meep.io" already exists
  not to have occurred

Is it possible to have envtest reinstall CRDs on every run rather than fail?

Thanks
Ed & @Samze & @ablease

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/featureCategorizes issue or PR as related to a new feature.lifecycle/frozenIndicates that an issue or PR should not be auto-closed due to staleness.priority/important-longtermImportant over the long term, but may not be staffed and/or may need multiple releases to complete.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions