-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Refactor operator to support several types of resources + propagate labels #38992
Conversation
093c0bb
to
40fb3b8
Compare
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.
I like the adapter approach - it seems like the best way to decouple from Teleport's internal changes a bit and this looks fairly tidy. Look forward to adding Bots using this.
I wonder if we can apply the learnings from this to the Terraform provider ?
return fmt.Errorf("failed to convert Object into Resource object: %T", obj) | ||
} | ||
k8sResource := newKubeResource[K]() | ||
debugLog.Info(fmt.Sprintf("Converting resource from unstructured to %T", k8sResource)) |
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.
Nit: it'd be preferable to use structured logging here. The reason you've had to use Sprintf is because they are trying to encourage people to switch to structured logging.
…bel propagation I initially just wanted to add label propagation (which is required for OpenSSH and OpenSSHEICE servers). However I ran into an issue: not all Teleport resources implement the `ResourceWithLabels` interface. Basically we have 4 cases: - resources implementing `ResourceWithLabels` (e.g. User, Role, ...) - resources implementing `ResourceWithOrigin` but not `ResourceWithLabels` (e.g. GitHub connector, ProvisionToken, ...) - resources that have been tweaked to implement only the operator `TeleportResource` interface (`LoginRule`) - resources implementing `Resource153` To support all those resoucres, we can either: - edit each resource so they expose the same methods (e.g. ProvisionToken exposes `GetLabels` instead of `GetStaticLabels`) - wrap each ressource in a wrapper that implements the operator TeleportResource interface - add multiple reconcilers, one for each resource kind I don't think it's sane for the operator to force changes on Teleport resources. Especially as those are known to be non consistent. I also don't want the operator to maintain a copy of each resource, this is not viable on the long term. For those reasons I chose the 3rd approach and built 3 reconcilers. Then I deducplicated the code to end up with a generic reconciler that can be tuned by passing an adapter. The adapter is an empty struct that has all the methods to extract the information the operator requires from the resource. The resulting PR is large and heavily uses generics but the amount of logical changes is quite low (the only diff is that we now copy labels). I can walk you through the PR if needed. With this PR, the operator supports properly any resource implementing `types.Resource153`, this will be useful to add `TeleportBotV1` support.
a86c3ab
to
3d55c8a
Compare
Co-authored-by: Noah Stride <[email protected]>
@hugoShaka See the table below for backport results.
|
…abels (#38992) * Refactor operator resource reconciler to support resource153 + add label propagation I initially just wanted to add label propagation (which is required for OpenSSH and OpenSSHEICE servers). However I ran into an issue: not all Teleport resources implement the `ResourceWithLabels` interface. Basically we have 4 cases: - resources implementing `ResourceWithLabels` (e.g. User, Role, ...) - resources implementing `ResourceWithOrigin` but not `ResourceWithLabels` (e.g. GitHub connector, ProvisionToken, ...) - resources that have been tweaked to implement only the operator `TeleportResource` interface (`LoginRule`) - resources implementing `Resource153` To support all those resoucres, we can either: - edit each resource so they expose the same methods (e.g. ProvisionToken exposes `GetLabels` instead of `GetStaticLabels`) - wrap each ressource in a wrapper that implements the operator TeleportResource interface - add multiple reconcilers, one for each resource kind I don't think it's sane for the operator to force changes on Teleport resources. Especially as those are known to be non consistent. I also don't want the operator to maintain a copy of each resource, this is not viable on the long term. For those reasons I chose the 3rd approach and built 3 reconcilers. Then I deducplicated the code to end up with a generic reconciler that can be tuned by passing an adapter. The adapter is an empty struct that has all the methods to extract the information the operator requires from the resource. The resulting PR is large and heavily uses generics but the amount of logical changes is quite low (the only diff is that we now copy labels). I can walk you through the PR if needed. With this PR, the operator supports properly any resource implementing `types.Resource153`, this will be useful to add `TeleportBotV1` support. * Update integrations/operator/controllers/reconcilers/base.go Co-authored-by: Noah Stride <[email protected]> * use structured logging --------- Co-authored-by: Noah Stride <[email protected]>
) * integrations/operator: Add openSSH and openSSHEICE servers * lint * Update integrations/operator/controllers/resources/openssheiceserverv2_controller.go Co-authored-by: Marco André Dinis <[email protected]> * rename Openssh to OpenSSH and fix comments * hide cmdlabels * Refactor operator to support several types of resources + propagate labels (#38992) * Refactor operator resource reconciler to support resource153 + add label propagation I initially just wanted to add label propagation (which is required for OpenSSH and OpenSSHEICE servers). However I ran into an issue: not all Teleport resources implement the `ResourceWithLabels` interface. Basically we have 4 cases: - resources implementing `ResourceWithLabels` (e.g. User, Role, ...) - resources implementing `ResourceWithOrigin` but not `ResourceWithLabels` (e.g. GitHub connector, ProvisionToken, ...) - resources that have been tweaked to implement only the operator `TeleportResource` interface (`LoginRule`) - resources implementing `Resource153` To support all those resoucres, we can either: - edit each resource so they expose the same methods (e.g. ProvisionToken exposes `GetLabels` instead of `GetStaticLabels`) - wrap each ressource in a wrapper that implements the operator TeleportResource interface - add multiple reconcilers, one for each resource kind I don't think it's sane for the operator to force changes on Teleport resources. Especially as those are known to be non consistent. I also don't want the operator to maintain a copy of each resource, this is not viable on the long term. For those reasons I chose the 3rd approach and built 3 reconcilers. Then I deducplicated the code to end up with a generic reconciler that can be tuned by passing an adapter. The adapter is an empty struct that has all the methods to extract the information the operator requires from the resource. The resulting PR is large and heavily uses generics but the amount of logical changes is quite low (the only diff is that we now copy labels). I can walk you through the PR if needed. With this PR, the operator supports properly any resource implementing `types.Resource153`, this will be useful to add `TeleportBotV1` support. * Update integrations/operator/controllers/reconcilers/base.go Co-authored-by: Noah Stride <[email protected]> * use structured logging --------- Co-authored-by: Noah Stride <[email protected]> --------- Co-authored-by: Marco André Dinis <[email protected]> Co-authored-by: Noah Stride <[email protected]>
Changelog: The operator now supports setting labels on Teleport resources. Labels are copied from the Kubernetes CR.
I initially just wanted to add label propagation (which is required for OpenSSH and OpenSSHEICE servers).
However I ran into an issue: not all Teleport resources implement the
ResourceWithLabels
interface.Basically we have 4 cases:
ResourceWithLabels
(e.g. User, Role, ...)ResourceWithOrigin
but notResourceWithLabels
(e.g. GitHub connector, ProvisionToken, ...)TeleportResource
interface (LoginRule
)Resource153
To support all those resoucres, we can either:
GetLabels
instead ofGetStaticLabels
)I don't think it's sane for the operator to force changes on Teleport resources. Especially as those are known to be non consistent. I also don't want the operator to maintain a copy of each resource, this is not viable on the long term.
For those reasons I chose the 3rd approach and built 3 reconcilers. Then I deducplicated the code to end up with a generic reconciler that can be tuned by passing an adapter. The adapter is an empty struct that has all the methods to extract the information the operator requires from the resource.
The resulting PR is large and heavily uses generics but the amount of logical changes is quite low (the only diff is that we now copy labels). I can walk you through the PR if needed.
With this PR, the operator supports properly any resource implementing
types.Resource153
, this will be useful to addTeleportBotV1
support.