Skip to content
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

[vnet] vnet_config resource #41399

Merged
merged 21 commits into from May 16, 2024
Merged

[vnet] vnet_config resource #41399

merged 21 commits into from May 16, 2024

Conversation

nklaassen
Copy link
Contributor

@nklaassen nklaassen commented May 10, 2024

This PR adds a storage layer, gRPC service, and tctl support for vnet_config resources https://github.com/gravitational/teleport/blob/master/rfd/0163-vnet.md

TODO: support resource bootstrap and add to the cache, tracked in #39330

@nklaassen nklaassen added the no-changelog Indicates that a PR does not require a changelog entry label May 10, 2024
@github-actions github-actions bot added size/lg tctl tctl - Teleport admin tool labels May 10, 2024
@@ -180,7 +180,7 @@ type fakeChecker struct {

func (f fakeChecker) CheckAccessToRule(_ services.RuleContext, _ string, resource string, verb string) error {
if resource == types.KindCrownJewel {
for slices.Contains(f.allowedVerbs, verb) {
if slices.Contains(f.allowedVerbs, verb) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you end up finding this? Linter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied the test and noticed it while making edits, in practice it makes no difference

lib/auth/vnetconfig/v1/service.go Outdated Show resolved Hide resolved
lib/auth/vnetconfig/v1/service.go Outdated Show resolved Hide resolved
lib/auth/vnetconfig/v1/service.go Outdated Show resolved Hide resolved
lib/services/resource.go Outdated Show resolved Hide resolved
Base automatically changed from nklaassen/vnet-config-proto to master May 10, 2024 16:10
@@ -41,57 +39,21 @@ type KubeWaitingContainer interface {

// MarshalKubeWaitingContainer marshals a KubernetesWaitingContainer resource to JSON.
func MarshalKubeWaitingContainer(in *kubewaitingcontainerpb.KubernetesWaitingContainer, opts ...MarshalOption) ([]byte, error) {
if in == nil {
return nil, trace.BadParameter("message is nil")
}
if err := kubewaitingcontainer.ValidateKubeWaitingContainer(in); err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this also does a nil check

@nklaassen nklaassen requested a review from tigrato May 14, 2024 14:40
@nklaassen
Copy link
Contributor Author

friendly ping @tigrato and @GavinFrazar

lib/services/local/vnet_config.go Outdated Show resolved Hide resolved
lib/auth/vnetconfig/v1/service.go Outdated Show resolved Hide resolved
// Opting out of forward compatibility, this service must implement all service methods.
vnet.UnsafeVnetConfigServiceServer

storage *local.VnetConfigService
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We generally have some kind of interface to decouple the RPC service from the storage layer. Any reason not to follow that pattern as well here?

Copy link
Contributor Author

@nklaassen nklaassen May 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is one area where I'm not really sure what we want to do going forward

we could have an interface here but I don't really see why, there is only one storage layer implementation that we'll use, is it to break the (api layer) -> (storage layer) dependency?

some other types use that same interface and implement it with both the storage layer and an api client. Just to take the most recent example, the CrownJewel service uses this interface in the gRPC api layer to abstract the storage layer, and also makes this gRPC client wrapper implement that same interface

Backend services.CrownJewels

return c.APIClient.CrownJewelServiceClient()

I do see why it's useful to have authclient.Client.<SomeService>Client return an interface rather than a concrete type, so that you can mock authclient.Client and have it return a mocked <SomeService>Client. What I don't see is why you should need the storage layer to implement that same interface, but maybe it has something to do with the cache needing an interface too and it's just easier to have a single common interface? I just haven't dug that deep yet. Would be nice to have some guidance on this in RFD153 I just haven't figured it out

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The interest I see here is to be able to mock the underlying storage and test error handling.
Usually we don't do it 😞

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright, switch to interface and added tests for storage-layer errors

lib/services/resource.go Outdated Show resolved Hide resolved
Comment on lines 801 to 804
resource = proto.Clone(resource).(T)
//nolint:staticcheck // SA1019. Id is deprecated, but still needed.
resource.GetMetadata().Id = 0
resource.GetMetadata().Revision = ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use maybeResetProtoResourceID here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote a maybeResetProtoResourceIDv2 that works with the new types, in #41562

lib/services/resource.go Outdated Show resolved Hide resolved
@nklaassen nklaassen changed the base branch from master to nklaassen/marshalprotoresource May 14, 2024 22:30
// Opting out of forward compatibility, this service must implement all service methods.
vnet.UnsafeVnetConfigServiceServer

storage *local.VnetConfigService
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The interest I see here is to be able to mock the underlying storage and test error handling.
Usually we don't do it 😞

lib/auth/vnetconfig/v1/service.go Show resolved Hide resolved
lib/auth/vnetconfig/v1/service.go Show resolved Hide resolved
lib/services/local/vnet_config.go Show resolved Hide resolved
lib/services/local/vnet_config.go Show resolved Hide resolved
lib/services/local/vnet_config.go Outdated Show resolved Hide resolved
lib/services/local/vnet_config.go Outdated Show resolved Hide resolved
lib/services/local/vnet_config.go Outdated Show resolved Hide resolved
lib/services/local/vnet_config.go Show resolved Hide resolved
tool/tctl/common/collection.go Outdated Show resolved Hide resolved
Base automatically changed from nklaassen/marshalprotoresource to master May 15, 2024 18:35
tool/tctl/common/resource_command.go Outdated Show resolved Hide resolved
tool/tctl/common/resource_command.go Outdated Show resolved Hide resolved
@nklaassen
Copy link
Contributor Author

@tigrato this is ready for another look

tool/tctl/common/collection.go Outdated Show resolved Hide resolved
tool/tctl/common/resource_command.go Show resolved Hide resolved
lib/services/local/vnet_config.go Show resolved Hide resolved
lib/services/local/vnet_config.go Outdated Show resolved Hide resolved
@nklaassen nklaassen enabled auto-merge May 15, 2024 22:34
@nklaassen nklaassen added this pull request to the merge queue May 15, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 15, 2024
@nklaassen nklaassen added this pull request to the merge queue May 16, 2024
Merged via the queue into master with commit 64d5d25 May 16, 2024
37 checks passed
@nklaassen nklaassen deleted the nklaassen/vnet-config branch May 16, 2024 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog Indicates that a PR does not require a changelog entry size/lg tctl tctl - Teleport admin tool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants