Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions api/types/desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ type DynamicWindowsDesktop interface {
// use the size passed by the client over TDP.
GetScreenSize() (width, height uint32)
// Copy returns a copy of this dynamic Windows desktop
Copy() *DynamicWindowsDesktopV1
Copy() DynamicWindowsDesktop
}

var _ DynamicWindowsDesktop = &DynamicWindowsDesktopV1{}
Expand Down Expand Up @@ -225,7 +225,7 @@ func (d *DynamicWindowsDesktopV1) MatchSearch(values []string) bool {
}

// Copy returns a deep copy of this dynamic Windows desktop object.
func (d *DynamicWindowsDesktopV1) Copy() *DynamicWindowsDesktopV1 {
func (d *DynamicWindowsDesktopV1) Copy() DynamicWindowsDesktop {
return utils.CloneProtoMsg(d)
}

Expand Down Expand Up @@ -320,7 +320,7 @@ type WindowsDesktop interface {
// use the size passed by the client over TDP.
GetScreenSize() (width, height uint32)
// Copy returns a copy of this windows desktop
Copy() *WindowsDesktopV3
Copy() WindowsDesktop
// CloneResource returns a copy of the WindowDesktop as a ResourceWithLabels
CloneResource() ResourceWithLabels
}
Expand Down Expand Up @@ -402,7 +402,7 @@ func (d *WindowsDesktopV3) MatchSearch(values []string) bool {
}

// Copy returns a copy of this windows desktop object.
func (d *WindowsDesktopV3) Copy() *WindowsDesktopV3 {
func (d *WindowsDesktopV3) Copy() WindowsDesktop {
return utils.CloneProtoMsg(d)
}

Expand Down
8 changes: 4 additions & 4 deletions api/types/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ type KubeCluster interface {
// IsKubeconfig identifies if the KubeCluster contains kubeconfig data.
IsKubeconfig() bool
// Copy returns a copy of this kube cluster resource.
Copy() *KubernetesClusterV3
Copy() KubeCluster
// GetCloud gets the cloud this kube cluster is running on, or an empty string if it
// isn't running on a cloud provider.
GetCloud() string
Expand Down Expand Up @@ -119,9 +119,9 @@ func NewKubernetesClusterV3WithoutSecrets(cluster KubeCluster) (*KubernetesClust
// Force a copy of the cluster to deep copy the Metadata fields.
copiedCluster := cluster.Copy()
clusterWithoutCreds, err := NewKubernetesClusterV3(
copiedCluster.Metadata,
copiedCluster.GetMetadata(),
KubernetesClusterSpecV3{
DynamicLabels: copiedCluster.Spec.DynamicLabels,
DynamicLabels: LabelsToV2(copiedCluster.GetDynamicLabels()),
},
)
return clusterWithoutCreds, trace.Wrap(err)
Expand Down Expand Up @@ -337,7 +337,7 @@ func (k *KubernetesClusterV3) String() string {
}

// Copy returns a copy of this resource.
func (k *KubernetesClusterV3) Copy() *KubernetesClusterV3 {
func (k *KubernetesClusterV3) Copy() KubeCluster {
return utils.CloneProtoMsg(k)
}

Expand Down
54 changes: 24 additions & 30 deletions lib/cache/access_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ func newAccessListCollection(upstream services.AccessLists, w types.WatchKind) (
}

return &collection[*accesslist.AccessList, accessListIndex]{
store: newStore(map[accessListIndex]func(*accesslist.AccessList) string{
accessListNameIndex: func(al *accesslist.AccessList) string {
return al.GetMetadata().Name
},
}),
store: newStore(
(*accesslist.AccessList).Clone,
map[accessListIndex]func(*accesslist.AccessList) string{
accessListNameIndex: func(al *accesslist.AccessList) string {
return al.GetMetadata().Name
},
}),
fetcher: func(ctx context.Context, loadSecrets bool) ([]*accesslist.AccessList, error) {
var resources []*accesslist.AccessList
var nextToken string
Expand Down Expand Up @@ -115,9 +117,6 @@ func (c *Cache) ListAccessLists(ctx context.Context, pageSize int, pageToken str
nextToken: func(t *accesslist.AccessList) string {
return t.GetMetadata().Name
},
clone: func(al *accesslist.AccessList) *accesslist.AccessList {
return al.Clone()
},
}
out, next, err := lister.list(ctx, pageSize, pageToken)
return out, next, trace.Wrap(err)
Expand All @@ -137,9 +136,6 @@ func (c *Cache) GetAccessList(ctx context.Context, name string) (*accesslist.Acc
upstreamRead = true
return c.Config.AccessLists.GetAccessList(ctx, s)
},
clone: func(al *accesslist.AccessList) *accesslist.AccessList {
return al.Clone()
},
}
out, err := getter.get(ctx, name)
if trace.IsNotFound(err) && !upstreamRead {
Expand All @@ -165,14 +161,16 @@ func newAccessListMemberCollection(upstream services.AccessLists, w types.WatchK
}

return &collection[*accesslist.AccessListMember, accessListMemberIndex]{
store: newStore(map[accessListMemberIndex]func(*accesslist.AccessListMember) string{
accessListMemberNameIndex: func(r *accesslist.AccessListMember) string {
return r.Spec.AccessList + "/" + r.GetName()
},
accessListMemberKindIndex: func(r *accesslist.AccessListMember) string {
return r.Spec.AccessList + "/" + r.Spec.MembershipKind + "/" + r.GetName()
},
}),
store: newStore(
(*accesslist.AccessListMember).Clone,
map[accessListMemberIndex]func(*accesslist.AccessListMember) string{
accessListMemberNameIndex: func(r *accesslist.AccessListMember) string {
return r.Spec.AccessList + "/" + r.GetName()
},
accessListMemberKindIndex: func(r *accesslist.AccessListMember) string {
return r.Spec.AccessList + "/" + r.Spec.MembershipKind + "/" + r.GetName()
},
}),
fetcher: func(ctx context.Context, loadSecrets bool) ([]*accesslist.AccessListMember, error) {
var resources []*accesslist.AccessListMember
var nextToken string
Expand Down Expand Up @@ -288,9 +286,6 @@ func (c *Cache) ListAllAccessListMembers(ctx context.Context, pageSize int, page
nextToken: func(t *accesslist.AccessListMember) string {
return t.GetMetadata().Name
},
clone: func(al *accesslist.AccessListMember) *accesslist.AccessListMember {
return al.Clone()
},
}
out, next, err := lister.list(ctx, pageSize, nextToken)
return out, next, trace.Wrap(err)
Expand Down Expand Up @@ -332,11 +327,13 @@ func newAccessListReviewCollection(upstream services.AccessLists, w types.WatchK
}

return &collection[*accesslist.Review, accessListReviewIndex]{
store: newStore(map[accessListReviewIndex]func(*accesslist.Review) string{
accessListReviewNameIndex: func(r *accesslist.Review) string {
return r.Spec.AccessList + "/" + r.GetName()
},
}),
store: newStore(
(*accesslist.Review).Clone,
map[accessListReviewIndex]func(*accesslist.Review) string{
accessListReviewNameIndex: func(r *accesslist.Review) string {
return r.Spec.AccessList + "/" + r.GetName()
},
}),
fetcher: func(ctx context.Context, loadSecrets bool) ([]*accesslist.Review, error) {
var resources []*accesslist.Review
var nextToken string
Expand Down Expand Up @@ -391,9 +388,6 @@ func (c *Cache) ListAccessListReviews(ctx context.Context, accessList string, pa
nextToken: func(t *accesslist.Review) string {
return t.GetName()
},
clone: func(r *accesslist.Review) *accesslist.Review {
return r.Clone()
},
}

start := accessList
Expand Down
17 changes: 8 additions & 9 deletions lib/cache/access_monitoring_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import (
"context"

"github.com/gravitational/trace"
"google.golang.org/protobuf/proto"

accessmonitoringrulesv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/accessmonitoringrules/v1"
headerv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/header/v1"
"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/api/utils"
"github.com/gravitational/teleport/lib/services"
)

Expand All @@ -38,11 +38,13 @@ func newAccessMonitoringRuleCollection(upstream services.AccessMonitoringRules,
}

return &collection[*accessmonitoringrulesv1.AccessMonitoringRule, accessMonitoringRuleIndex]{
store: newStore(map[accessMonitoringRuleIndex]func(*accessmonitoringrulesv1.AccessMonitoringRule) string{
accessMonitoringRuleNameIndex: func(r *accessmonitoringrulesv1.AccessMonitoringRule) string {
return r.GetMetadata().Name
},
}),
store: newStore(
proto.CloneOf[*accessmonitoringrulesv1.AccessMonitoringRule],
map[accessMonitoringRuleIndex]func(*accessmonitoringrulesv1.AccessMonitoringRule) string{
accessMonitoringRuleNameIndex: func(r *accessmonitoringrulesv1.AccessMonitoringRule) string {
return r.GetMetadata().Name
},
}),
fetcher: func(ctx context.Context, loadSecrets bool) ([]*accessmonitoringrulesv1.AccessMonitoringRule, error) {
var resources []*accessmonitoringrulesv1.AccessMonitoringRule
var nextToken string
Expand Down Expand Up @@ -87,7 +89,6 @@ func (c *Cache) ListAccessMonitoringRules(ctx context.Context, pageSize int, pag
nextToken: func(t *accessmonitoringrulesv1.AccessMonitoringRule) string {
return t.GetMetadata().Name
},
clone: utils.CloneProtoMsg[*accessmonitoringrulesv1.AccessMonitoringRule],
}
out, next, err := lister.list(ctx, pageSize, pageToken)
return out, next, trace.Wrap(err)
Expand All @@ -106,7 +107,6 @@ func (c *Cache) ListAccessMonitoringRulesWithFilter(ctx context.Context, req *ac
nextToken: func(t *accessmonitoringrulesv1.AccessMonitoringRule) string {
return t.GetMetadata().Name
},
clone: utils.CloneProtoMsg[*accessmonitoringrulesv1.AccessMonitoringRule],
filter: func(rule *accessmonitoringrulesv1.AccessMonitoringRule) bool {
return services.MatchAccessMonitoringRule(rule, req.GetSubjects(), req.GetNotificationName(), req.GetAutomaticReviewName())
},
Expand All @@ -125,7 +125,6 @@ func (c *Cache) GetAccessMonitoringRule(ctx context.Context, name string) (*acce
collection: c.collections.accessMonitoringRules,
index: accessMonitoringRuleNameIndex,
upstreamGet: c.Config.AccessMonitoringRules.GetAccessMonitoringRule,
clone: utils.CloneProtoMsg[*accessmonitoringrulesv1.AccessMonitoringRule],
}
out, err := getter.get(ctx, name)
return out, trace.Wrap(err)
Expand Down
56 changes: 26 additions & 30 deletions lib/cache/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,21 @@ func newAppCollection(p services.Apps, w types.WatchKind) (*collection[types.App
}

return &collection[types.Application, appIndex]{
store: newStore(map[appIndex]func(types.Application) string{
appNameIndex: func(u types.Application) string {
return u.GetName()
store: newStore(
func(a types.Application) types.Application {
return a.Copy()
},
}),
map[appIndex]func(types.Application) string{
appNameIndex: types.Application.GetName,
}),
fetcher: func(ctx context.Context, loadSecrets bool) ([]types.Application, error) {
return p.GetApps(ctx)
apps, err := p.GetApps(ctx)
return apps, trace.Wrap(err)
},
headerTransform: func(hdr *types.ResourceHeader) types.Application {
return &types.AppV3{
Kind: types.KindApp,
Version: types.V3,
Kind: hdr.Kind,
Version: hdr.Version,
Metadata: types.Metadata{
Name: hdr.Metadata.Name,
},
Expand Down Expand Up @@ -86,23 +89,14 @@ func (c *Cache) GetApp(ctx context.Context, name string) (types.Application, err
ctx, span := c.Tracer.Start(ctx, "cache/GetApp")
defer span.End()

rg, err := acquireReadGuard(c, c.collections.apps)
if err != nil {
return nil, trace.Wrap(err)
}
defer rg.Release()

if !rg.ReadCache() {
apps, err := c.Config.Apps.GetApp(ctx, name)
return apps, trace.Wrap(err)
getter := genericGetter[types.Application, appIndex]{
cache: c,
collection: c.collections.apps,
index: appNameIndex,
upstreamGet: c.Config.Apps.GetApp,
}

a, err := rg.store.get(appNameIndex, name)
if err != nil {
return nil, trace.Wrap(err)
}

return a.Copy(), nil
out, err := getter.get(ctx, name)
return out, trace.Wrap(err)
}

type appServerIndex string
Expand All @@ -115,18 +109,20 @@ func newAppServerCollection(p services.Presence, w types.WatchKind) (*collection
}

return &collection[types.AppServer, appServerIndex]{
store: newStore(map[appServerIndex]func(types.AppServer) string{
appServerNameIndex: func(u types.AppServer) string {
return u.GetHostID() + "/" + u.GetName()
},
}),
store: newStore(
types.AppServer.Copy,
map[appServerIndex]func(types.AppServer) string{
appServerNameIndex: func(u types.AppServer) string {
return u.GetHostID() + "/" + u.GetName()
},
}),
fetcher: func(ctx context.Context, loadSecrets bool) ([]types.AppServer, error) {
return p.GetApplicationServers(ctx, defaults.Namespace)
},
headerTransform: func(hdr *types.ResourceHeader) types.AppServer {
return &types.AppServerV3{
Kind: types.KindAppServer,
Version: types.V3,
Kind: hdr.Kind,
Version: hdr.Version,
Metadata: types.Metadata{
Name: hdr.Metadata.Name,
},
Expand Down
14 changes: 7 additions & 7 deletions lib/cache/auth_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ func newAuthServerCollection(p services.Presence, w types.WatchKind) (*collectio
}

return &collection[types.Server, authServerIndex]{
store: newStore(map[authServerIndex]func(types.Server) string{
authServerNameIndex: func(u types.Server) string {
return u.GetName()
},
}),
store: newStore(
types.Server.DeepCopy,
map[authServerIndex]func(types.Server) string{
authServerNameIndex: types.Server.GetName,
}),
fetcher: func(ctx context.Context, loadSecrets bool) ([]types.Server, error) {
servers, err := p.GetAuthServers()
return servers, trace.Wrap(err)
},
headerTransform: func(hdr *types.ResourceHeader) types.Server {
return &types.ServerV2{
Kind: types.KindAuthServer,
Version: types.V2,
Kind: hdr.Kind,
Version: hdr.Version,
Metadata: types.Metadata{
Name: hdr.GetName(),
},
Expand Down
Loading
Loading