-
Notifications
You must be signed in to change notification settings - Fork 625
Separate controller client concerns #4253
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
base: main
Are you sure you want to change the base?
Conversation
We want to be mindful of our interactions with the Kubernetes API, and these interfaces will help keep functions focused. These interfaces are also narrower than client.Reader and client.Writer and may help us keep RBAC markers accurate. A new constructor populates these fields with a single client.Client. The client.WithFieldOwner constructor allows us to drop our Owner field and patch method.
We want to be mindful of our interactions with the Kubernetes API, and these interfaces will help keep functions focused. These interfaces are also narrower than client.Reader and client.Writer and may help us keep RBAC markers accurate. A new constructor populates these fields with a single client.Client. The client.WithFieldOwner constructor allows us to drop our Owner field and patch method. This allows `make check` to cover 47% more of the "crunchybridgecluster" package.
We want to be mindful of our interactions with the Kubernetes API, and these interfaces will help keep functions focused. These interfaces are also narrower than client.Reader and client.Writer and may help us keep RBAC markers accurate. A new constructor populates these fields with a single client.Client. The client.WithFieldOwner constructor allows us to drop our Owner field and patch method.
@@ -316,8 +316,7 @@ func TestWritePGAdminUsers(t *testing.T) { | |||
assert.Equal(t, calls, 1, "PodExec should be called once") | |||
|
|||
secret := &corev1.Secret{ObjectMeta: naming.StandalonePGAdmin(pgadmin)} | |||
assert.NilError(t, | |||
reconciler.Get(ctx, client.ObjectKeyFromObject(secret), secret)) | |||
assert.NilError(t, cc.Get(ctx, client.ObjectKeyFromObject(secret), secret)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but we could use reconciler.Reader.Get, yeah? Which is more indirection but maybe a reminder of separation of client powers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But then -- who cares? This step isn't about what our operator does, this is just a step to get the object. "Getting the object" is not what we're testing here.
Client: tClient, | ||
Owner: "crunchybridgecluster-controller", | ||
} | ||
reconciler := &CrunchyBridgeClusterReconciler{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kind of want to rename generatePostgresRoleSecret
generatePostgresRoleSecretIntent
or something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, there's a few funcs here that, from the name, I would've said call kubernetes.
@@ -5,6 +5,9 @@ | |||
package naming | |||
|
|||
const ( | |||
ControllerBridge = "bridge-controller" | |||
ControllerPGAdmin = "pgadmin-controller" | |||
ControllerBridge = "bridge-controller" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, the bridge installation controller already has this split between reader/writer, but no statuswriter -- and we never touch the status
This separates the
client.Client
interface in our controllers into three:Reader
,Writer
, andStatusWriter
. The idea is to add a little friction when adding a Client to a test, so we're more intentional about separating reads from writes. During this refactor, I found a number of tests that didn't need Kubernetes at all. This exercise has increased the amount of code covered bymake check
.This refactor is one step toward my goal of a single, shared SSA Apply function.
Checklist:
Type of Changes:
Other Information:
📝 The changes to the PGUpgrade controller are representative and rather small.
📝 The PostgresCluster controller is kinda big, so I'll submit it as a separate PR.