redpanda-data / redpanda-operator

39 stars 10 forks source link

Add user controller acceptance tests #238

Closed andrewstucki closed 2 months ago

andrewstucki commented 2 months ago

This adds acceptance tests for the user controller written in gherkin/godog. The code is decently heavy due to initializing the test suite and defining a number of reusable helpers (i.e. initializing clients that can portforward to a cluster using either a superuser or as a particular user, ensuring a cluster is deployed and stable, etc.), but the steps particular to these tests are fairly light. There are three main tests:

  1. Ensuring a user can be created and subsequently authenticate to a cluster
  2. Ensuring a user can be created and only their auth credentials managed when they have pre-existing ACLs (and we don't touch the ACLs when an Authorization block isn't specified)
  3. Ensuring a user can be created who already has credentias created for them and we only sync over their ACLs (while not touching their auth creds when an Authentication block isn't specified)

I can add more if we want to check failure modes, like what happens when you try and create a user when SASL is disabled on the cluster, but I figured these are the major tests we'd want for this feature.

There is no CI configuration for this right now and the suite setup right now assumes that you have a Kubernetes cluster that is already up and running, with its kubeconfig file resolvable and the containers localhost/redpanda-operator:dev and localhost/configurator:dev already loaded into your cluster. When those are true you can run the tests with a simple go test -v (if you have a kubeconfig in a non-default location you can pass -kube-config to point to it).

andrewstucki commented 2 months ago

@chrisseto

Is there already something that will create/apply clusters/sasl/cluster.yaml or am I over looking that?

Because that's going to be such a common task and I want to share the cluster across specifically this set of scenarios in the feature (hence no universal BeforeFeature style hook), it does it with the magic of a feature tag:

https://github.com/redpanda-data/redpanda-operator/blob/1ecdd88a129d9755eb4dee030759277d78fe83a2/acceptance/features/user-crds.feature#L1