-
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
Add cluster autoupdate resources with enabled cache #45617
Changes from 16 commits
a3dd69d
4287f85
61c3443
db12db8
1e57600
e1aca13
0e45c8f
bb0e806
99a9e7e
70b7c54
3b03379
9796d4e
1877695
4e4962b
12e1b79
b3a62d7
4cceaac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Copyright 2024 Gravitational, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package autoupdate | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/gravitational/trace" | ||
|
||
"github.com/gravitational/teleport/api/gen/proto/go/teleport/autoupdate/v1" | ||
) | ||
|
||
// Client is an AutoupdateService client that conforms to the following lib/services interfaces: | ||
// - services.AutoupdateService | ||
type Client struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need a dedicated client? There isn't much going on here besides hiding gRPC requests. Consider following the same approach that Noah took with the SPIFFE resource: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in codebase there are 3 ways how it is implemented, legacy one with interface in types, methods implementation and this one with wrapping grpc client to be interface compatible to service definition, this PR by iterations implemented all of them. Last one was added because I was trying to eliminate methods declarations for client (as it was requested previously in this review) and use only client wrapper: but its not possible right now because if we use cache wrapping, interfaces of the interface ReadRemoteProxyAccessPoint {
GetAutoupdateConfig(ctx context.Context) (*autoupdate.AutoupdateConfig, error)
GetAutoupdateVersion(ctx context.Context) (*autoupdate.AutoupdateVersion, error)
}
type RemoteProxyAccessPoint interface {
ReadRemoteProxyAccessPoint
accessPoint
}
func NewRemoteProxyWrapper(base RemoteProxyAccessPoint, cache ReadRemoteProxyAccessPoint) RemoteProxyAccessPoint {...}
// newLocalCacheForRemoteProxy returns new instance of access point configured for a remote proxy.
func (process *TeleportProcess) newLocalCacheForRemoteProxy(clt authclient.ClientI, cacheName []string) (authclient.RemoteProxyAccessPoint, error) {
// if caching is disabled, return access point
if !process.Config.CachePolicy.Enabled {
return clt, nil
}
cache, err := process.NewLocalCache(clt, cache.ForRemoteProxy, cacheName)
if err != nil {
return nil, trace.Wrap(err)
}
return authclient.NewRemoteProxyWrapper(clt, cache), nil
} |
||
grpcClient autoupdate.AutoupdateServiceClient | ||
} | ||
|
||
// NewClient creates a new AutoupdateService client. | ||
func NewClient(grpcClient autoupdate.AutoupdateServiceClient) *Client { | ||
return &Client{ | ||
grpcClient: grpcClient, | ||
} | ||
} | ||
|
||
// GetAutoupdateConfig returns the specified AutoupdateConfig resource. | ||
func (c *Client) GetAutoupdateConfig(ctx context.Context) (*autoupdate.AutoupdateConfig, error) { | ||
resp, err := c.grpcClient.GetAutoupdateConfig(ctx, &autoupdate.GetAutoupdateConfigRequest{}) | ||
return resp, trace.Wrap(err) | ||
} | ||
|
||
// CreateAutoupdateConfig creates a AutoupdateConfig. | ||
func (c *Client) CreateAutoupdateConfig(ctx context.Context, config *autoupdate.AutoupdateConfig) (*autoupdate.AutoupdateConfig, error) { | ||
resp, err := c.grpcClient.CreateAutoupdateConfig(ctx, &autoupdate.CreateAutoupdateConfigRequest{Config: config}) | ||
return resp, trace.Wrap(err) | ||
} | ||
|
||
// UpdateAutoupdateConfig updates a AutoupdateConfig. | ||
func (c *Client) UpdateAutoupdateConfig(ctx context.Context, config *autoupdate.AutoupdateConfig) (*autoupdate.AutoupdateConfig, error) { | ||
resp, err := c.grpcClient.UpdateAutoupdateConfig(ctx, &autoupdate.UpdateAutoupdateConfigRequest{Config: config}) | ||
return resp, trace.Wrap(err) | ||
} | ||
|
||
// UpsertAutoupdateConfig creates or updates a AutoupdateConfig. | ||
func (c *Client) UpsertAutoupdateConfig(ctx context.Context, config *autoupdate.AutoupdateConfig) (*autoupdate.AutoupdateConfig, error) { | ||
resp, err := c.grpcClient.UpsertAutoupdateConfig(ctx, &autoupdate.UpsertAutoupdateConfigRequest{Config: config}) | ||
return resp, trace.Wrap(err) | ||
} | ||
|
||
// DeleteAutoupdateConfig removes the specified AutoupdateConfig resource. | ||
func (c *Client) DeleteAutoupdateConfig(ctx context.Context) error { | ||
_, err := c.grpcClient.DeleteAutoupdateConfig(ctx, &autoupdate.DeleteAutoupdateConfigRequest{}) | ||
return trace.Wrap(err) | ||
} | ||
|
||
// GetAutoupdateVersion returns the specified AutoupdateVersion resource. | ||
func (c *Client) GetAutoupdateVersion(ctx context.Context) (*autoupdate.AutoupdateVersion, error) { | ||
resp, err := c.grpcClient.GetAutoupdateVersion(ctx, &autoupdate.GetAutoupdateVersionRequest{}) | ||
return resp, trace.Wrap(err) | ||
} | ||
|
||
// CreateAutoupdateVersion creates a AutoupdateVersion. | ||
func (c *Client) CreateAutoupdateVersion(ctx context.Context, config *autoupdate.AutoupdateVersion) (*autoupdate.AutoupdateVersion, error) { | ||
resp, err := c.grpcClient.CreateAutoupdateVersion(ctx, &autoupdate.CreateAutoupdateVersionRequest{Version: config}) | ||
return resp, trace.Wrap(err) | ||
} | ||
|
||
// UpdateAutoupdateVersion updates a AutoupdateVersion. | ||
func (c *Client) UpdateAutoupdateVersion(ctx context.Context, config *autoupdate.AutoupdateVersion) (*autoupdate.AutoupdateVersion, error) { | ||
resp, err := c.grpcClient.UpdateAutoupdateVersion(ctx, &autoupdate.UpdateAutoupdateVersionRequest{Version: config}) | ||
return resp, trace.Wrap(err) | ||
} | ||
|
||
// UpsertAutoupdateVersion creates or updates a AutoupdateVersion. | ||
func (c *Client) UpsertAutoupdateVersion(ctx context.Context, version *autoupdate.AutoupdateVersion) (*autoupdate.AutoupdateVersion, error) { | ||
resp, err := c.grpcClient.UpsertAutoupdateVersion(ctx, &autoupdate.UpsertAutoupdateVersionRequest{Version: version}) | ||
return resp, trace.Wrap(err) | ||
} | ||
|
||
// DeleteAutoupdateVersion removes the specified AutoupdateVersion resource. | ||
func (c *Client) DeleteAutoupdateVersion(ctx context.Context) error { | ||
_, err := c.grpcClient.DeleteAutoupdateVersion(ctx, &autoupdate.DeleteAutoupdateVersionRequest{}) | ||
return trace.Wrap(err) | ||
} |
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 don't think we should mention services in the api package since API does not an cannot depend on gravitational/teleport without creating an import cycle.
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.
ok, will remove this one, we have other 4 clients declaring the same