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

Add cluster autoupdate resources with enabled cache #45617

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions api/client/autoupdate/autoupdate.go
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
Copy link
Contributor

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.

Copy link
Contributor Author

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

type Client struct {
Copy link
Contributor

Choose a reason for hiding this comment

The 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:

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)
1877695#diff-f5e514e352c12c01eab507e6d9bbdfa697791b35bf914d949b92245a8e950447R2873-R2889

and use only client wrapper:
1877695#diff-3bdff46f360deb2937ae725b5117a2462cf0bcaaff86400d08179c652a2ce2f3R2653

but its not possible right now because if we use cache wrapping, interfaces of the cache.Cache and authclient.ClientI must be compatible

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)
}
25 changes: 25 additions & 0 deletions api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import (
"github.com/gravitational/teleport/api/breaker"
"github.com/gravitational/teleport/api/client/accesslist"
"github.com/gravitational/teleport/api/client/accessmonitoringrules"
"github.com/gravitational/teleport/api/client/autoupdate"
crownjewelapi "github.com/gravitational/teleport/api/client/crownjewel"
"github.com/gravitational/teleport/api/client/discoveryconfig"
"github.com/gravitational/teleport/api/client/externalauditstorage"
Expand All @@ -66,6 +67,7 @@ import (
accesslistv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/accesslist/v1"
accessmonitoringrulev1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/accessmonitoringrules/v1"
auditlogpb "github.com/gravitational/teleport/api/gen/proto/go/teleport/auditlog/v1"
autoupdatepb "github.com/gravitational/teleport/api/gen/proto/go/teleport/autoupdate/v1"
clusterconfigpb "github.com/gravitational/teleport/api/gen/proto/go/teleport/clusterconfig/v1"
crownjewelv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/crownjewel/v1"
dbobjectv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/dbobject/v1"
Expand Down Expand Up @@ -890,6 +892,11 @@ func (c *Client) GetVnetConfig(ctx context.Context) (*vnet.VnetConfig, error) {
return c.VnetConfigServiceClient().GetVnetConfig(ctx, &vnet.GetVnetConfigRequest{})
}

// AutoupdateServiceClient returns an unadorned client for the Autoupdate service.
func (c *Client) AutoupdateServiceClient() *autoupdate.Client {
return autoupdate.NewClient(autoupdatepb.NewAutoupdateServiceClient(c.conn))
}

// Ping gets basic info about the auth server.
func (c *Client) Ping(ctx context.Context) (proto.PingResponse, error) {
rsp, err := c.grpc.Ping(ctx, &proto.PingRequest{})
Expand Down Expand Up @@ -2863,6 +2870,24 @@ func (c *Client) GetClusterAuditConfig(ctx context.Context) (types.ClusterAuditC
return resp, nil
}

// GetAutoupdateConfig gets autoupdate configuration.
func (c *Client) GetAutoupdateConfig(ctx context.Context) (*autoupdatepb.AutoupdateConfig, error) {
resp, err := c.AutoupdateServiceClient().GetAutoupdateConfig(ctx)
if err != nil {
return nil, trace.Wrap(err)
}
return resp, nil
}

// GetAutoupdateVersion gets autoupdate version.
func (c *Client) GetAutoupdateVersion(ctx context.Context) (*autoupdatepb.AutoupdateVersion, error) {
resp, err := c.AutoupdateServiceClient().GetAutoupdateVersion(ctx)
if err != nil {
return nil, trace.Wrap(err)
}
return resp, nil
}

// GetClusterAccessGraphConfig retrieves the Cluster Access Graph configuration from Auth server.
func (c *Client) GetClusterAccessGraphConfig(ctx context.Context) (*clusterconfigpb.AccessGraphConfig, error) {
rsp, err := c.ClusterConfigClient().GetClusterAccessGraphConfig(ctx, &clusterconfigpb.GetClusterAccessGraphConfigRequest{})
Expand Down
15 changes: 15 additions & 0 deletions api/client/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"github.com/gravitational/teleport/api/client/proto"
accessmonitoringrulesv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/accessmonitoringrules/v1"
"github.com/gravitational/teleport/api/gen/proto/go/teleport/autoupdate/v1"
clusterconfigpb "github.com/gravitational/teleport/api/gen/proto/go/teleport/clusterconfig/v1"
crownjewelv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/crownjewel/v1"
dbobjectv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/dbobject/v1"
Expand Down Expand Up @@ -99,6 +100,14 @@ func EventToGRPC(in types.Event) (*proto.Event, error) {
out.Resource = &proto.Event_StaticHostUser{
StaticHostUser: r,
}
case *autoupdate.AutoupdateConfig:
out.Resource = &proto.Event_AutoupdateConfig{
AutoupdateConfig: r,
}
case *autoupdate.AutoupdateVersion:
out.Resource = &proto.Event_AutoupdateVersion{
AutoupdateVersion: r,
}
default:
return nil, trace.BadParameter("resource type %T is not supported", r)
}
Expand Down Expand Up @@ -542,6 +551,12 @@ func EventFromGRPC(in *proto.Event) (*types.Event, error) {
} else if r := in.GetStaticHostUser(); r != nil {
out.Resource = types.Resource153ToLegacy(r)
return &out, nil
} else if r := in.GetAutoupdateConfig(); r != nil {
out.Resource = types.Resource153ToLegacy(r)
return &out, nil
} else if r := in.GetAutoupdateVersion(); r != nil {
out.Resource = types.Resource153ToLegacy(r)
return &out, nil
} else {
return nil, trace.BadParameter("received unsupported resource %T", in.Resource)
}
Expand Down
Loading
Loading