Skip to content

DiscoveryConfig: init service and add resource to tctl#32399

Merged
marcoandredinis merged 4 commits intomasterfrom
marco/discovery_config_init_resource_tctl
Oct 11, 2023
Merged

DiscoveryConfig: init service and add resource to tctl#32399
marcoandredinis merged 4 commits intomasterfrom
marco/discovery_config_init_resource_tctl

Conversation

@marcoandredinis
Copy link
Copy Markdown
Contributor

@marcoandredinis marcoandredinis commented Sep 22, 2023

Context: #25494

This PR starts the DiscoveryConfig service in gRPC server and allows tctl to interact with those records.

It also adds access to the editor role.
Users should be able to RW any DiscoveryConfig.

DiscoveryService should be able to watch those resources, so that it can act upon any changes.

@marcoandredinis marcoandredinis added discover Issues related to Teleport Discover backport/branch/v14 labels Sep 22, 2023
@marcoandredinis marcoandredinis force-pushed the marco/discovery_config_service_with_rbac branch from 4bd0512 to 09ada06 Compare September 26, 2023 16:09
@marcoandredinis marcoandredinis changed the title DiscoveryConfig: init service and add it to tctl DiscoveryConfig: init service and add resource to tctl Sep 26, 2023
@marcoandredinis marcoandredinis force-pushed the marco/discovery_config_init_resource_tctl branch from a7e849e to b3afbec Compare September 26, 2023 16:10
@marcoandredinis marcoandredinis force-pushed the marco/discovery_config_service_with_rbac branch from 09ada06 to aa4b7a9 Compare September 27, 2023 18:23
Base automatically changed from marco/discovery_config_service_with_rbac to master September 27, 2023 20:27
@marcoandredinis marcoandredinis force-pushed the marco/discovery_config_init_resource_tctl branch 4 times, most recently from 6dfa8be to 497c64f Compare September 28, 2023 10:43
@marcoandredinis marcoandredinis marked this pull request as ready for review September 28, 2023 13:20
@github-actions github-actions Bot added size/md tctl tctl - Teleport admin tool labels Sep 28, 2023
Comment thread lib/cache/collections.go Outdated
Comment on lines 2408 to 2411
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a terrible approach to upsert, and it's not really justifiable for a brand new resource type IMO. Can we add a real upsert operation, outright drop the implementation of UpdateDiscoveryConfig in v14 and only support it in v15+ as a conditional update operation instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've just added the upsert method.

outright drop the implementation of UpdateDiscoveryConfig in v14 and only support it in v15+ as a conditional update operation instead?

Sorry, not sure I followed.
Are you suggesting to remove the UpdateDiscoveryConfig in v15/master but keep it in v14?
But then clients using v14 will hit the UpdateDiscoveryConfig and it will fail

Could you please clear this up?

(maybe by v15+ you meant v16 and ownards, not sure if your + was inclusive)

This resource is not yet in use, but we should be careful anyway because it was backported to v14

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since v14.0.1 doesn't have an implementation for UpdateDiscoveryConfig yet, I propose that we remove UpdateDiscoveryConfig from branch/v14 and leave it as a not implemented RPC, add (and backport) UpsertDiscoveryConfig from this PR and use it in v14 clients, then in master and branch/v15 we can implement it as a conditional update operation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

remove UpdateDiscoveryConfig from branch/v14 and leave it as a not implemented RPC

It might get released before we are able to merge the backport.
I think, the Update method is the intended one for 99% of the cases.
That also holds true when we implement the condition updates/revisions.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What is "write-if-any-exists" useful for?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Well, honestly the only other client (for now) is going to be the WebAPI
I'm not sure we need it there.

This should ease the path for the revision logic we intend to implement later.

I would rather not remove it.

Comment thread lib/services/local/events.go Outdated
@marcoandredinis marcoandredinis force-pushed the marco/discovery_config_init_resource_tctl branch from 497c64f to 53736e0 Compare September 29, 2023 09:28
Comment thread tool/tctl/common/resource_command.go Outdated
@marcoandredinis marcoandredinis force-pushed the marco/discovery_config_init_resource_tctl branch from 7fad84d to b809d6d Compare October 2, 2023 17:52
@marcoandredinis
Copy link
Copy Markdown
Contributor Author

@fheinecke Can you please take a look?

@marcoandredinis marcoandredinis force-pushed the marco/discovery_config_init_resource_tctl branch 4 times, most recently from 2a3c17c to 5af94ee Compare October 10, 2023 09:11
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Will this require optimistic locking?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think all resources will use it.

This is being used in tctl create -f and cache maintenance.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Upsert is always unconditional - we considered adding a primitive backend operation for "write if item doesn't exist or if it exists and it matches this revision" but we couldn't really think of uses for it. 🤷

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If you meant in general then yeah, unfortunately we have an implemented and released UpdateDiscoveryConfig that no one should use so the conditionally updating RPC used by tctl edit will probably be UpdateDiscoveryConfigV2 or something like that. 🥲

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I meant the Update endpoint but github doesn't let me add the comment to the correct place

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I'm following here.

tctl edit should use the UpdateDiscoveryConfig which conditionally updates the resource.
It's not doing that right now, but the flow is there:

// Use the UpdateHandler if the resource has one, otherwise fallback to using
// the CreateHandler. UpdateHandlers are preferred over CreateHandler because an update
// will not forcibly overwrite a resource unlike with create which requires the force
// flag to be set to update an existing resource.
updator, found := rc.UpdateHandlers[ResourceKind(raw.Kind)]
if found {
return trace.Wrap(updator(ctx, client, raw))
}
// TODO(tross) remove the fallback to CreateHandlers once all the resources
// have been updated to implement an UpdateHandler.
if creator, found := rc.CreateHandlers[ResourceKind(raw.Kind)]; found {
return trace.Wrap(creator(ctx, client, raw))
}

@public-teleport-github-review-bot public-teleport-github-review-bot Bot removed the request for review from fheinecke October 11, 2023 09:27
@marcoandredinis marcoandredinis added this pull request to the merge queue Oct 11, 2023
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 11, 2023
This PR starts the DiscoveryConfig service in gRPC server and allows
`tctl` to interact with those records.

It also adds access to the `editor` role.
Users should be able to RW any DiscoveryConfig.

DiscoveryService should be able to watch those resources, so that it can
act upon any changes.
@marcoandredinis marcoandredinis force-pushed the marco/discovery_config_init_resource_tctl branch from 5af94ee to 972995d Compare October 11, 2023 10:06
@marcoandredinis marcoandredinis added this pull request to the merge queue Oct 11, 2023
Merged via the queue into master with commit de3a0cc Oct 11, 2023
@marcoandredinis marcoandredinis deleted the marco/discovery_config_init_resource_tctl branch October 11, 2023 10:42
@public-teleport-github-review-bot
Copy link
Copy Markdown

@marcoandredinis See the table below for backport results.

Branch Result
branch/v14 Failed

marcoandredinis added a commit that referenced this pull request Oct 11, 2023
* DiscoveryConfig: init service and add it to `tctl`

This PR starts the DiscoveryConfig service in gRPC server and allows
`tctl` to interact with those records.

It also adds access to the `editor` role.
Users should be able to RW any DiscoveryConfig.

DiscoveryService should be able to watch those resources, so that it can
act upon any changes.

* add revision

* add upsert method

* improve tctl -f command
github-merge-queue Bot pushed a commit that referenced this pull request Oct 11, 2023
…3289)

* DiscoveryConfig: init service and add it to `tctl`

This PR starts the DiscoveryConfig service in gRPC server and allows
`tctl` to interact with those records.

It also adds access to the `editor` role.
Users should be able to RW any DiscoveryConfig.

DiscoveryService should be able to watch those resources, so that it can
act upon any changes.

* add revision

* add upsert method

* improve tctl -f command
lsgunn-teleport pushed a commit that referenced this pull request Oct 11, 2023
…3289)

* DiscoveryConfig: init service and add it to `tctl`

This PR starts the DiscoveryConfig service in gRPC server and allows
`tctl` to interact with those records.

It also adds access to the `editor` role.
Users should be able to RW any DiscoveryConfig.

DiscoveryService should be able to watch those resources, so that it can
act upon any changes.

* add revision

* add upsert method

* improve tctl -f command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

discover Issues related to Teleport Discover size/md tctl tctl - Teleport admin tool

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants