diff --git a/cmd/pro/provider/watch/workspaces.go b/cmd/pro/provider/watch/workspaces.go index a8fd5bf59b..926b957fc9 100644 --- a/cmd/pro/provider/watch/workspaces.go +++ b/cmd/pro/provider/watch/workspaces.go @@ -49,15 +49,15 @@ func NewWorkspacesCmd(globalFlags *flags.GlobalFlags) *cobra.Command { return c } -type ProWorkspaceInstance struct { +type WorkspaceInstance struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata"` Spec managementv1.DevsyWorkspaceInstanceSpec `json:"spec"` - Status ProWorkspaceInstanceStatus `json:"status"` + Status WorkspaceInstanceStatus `json:"status"` } -type ProWorkspaceInstanceStatus struct { +type WorkspaceInstanceStatus struct { managementv1.DevsyWorkspaceInstanceStatus `json:",inline"` Source *provider.WorkspaceSource `json:"source,omitempty"` @@ -175,7 +175,7 @@ type instanceStore struct { filterByOwner bool m sync.Mutex - instances map[string]*ProWorkspaceInstance + instances map[string]*WorkspaceInstance } func newStore( @@ -189,7 +189,7 @@ func newStore( self: self, context: context, filterByOwner: filterByOwner, - instances: map[string]*ProWorkspaceInstance{}, + instances: map[string]*WorkspaceInstance{}, } } @@ -198,11 +198,11 @@ func (s *instanceStore) Add(instance *managementv1.DevsyWorkspaceInstance) { return } - proInstance := s.buildProInstance(instance) + platformInstance := s.buildInstance(instance) key := s.key(instance.ObjectMeta) s.m.Lock() - s.instances[key] = proInstance + s.instances[key] = platformInstance s.m.Unlock() } @@ -224,8 +224,8 @@ func (s *instanceStore) Delete(instance *managementv1.DevsyWorkspaceInstance) { delete(s.instances, key) } -func (s *instanceStore) List() []*ProWorkspaceInstance { - instanceList := []*ProWorkspaceInstance{} +func (s *instanceStore) List() []*WorkspaceInstance { + instanceList := []*WorkspaceInstance{} // Check local imported workspaces // Eventually this should be implemented by filtering based on ownership and access // on the CRD, for now we're stuck with this approach... @@ -235,8 +235,8 @@ func (s *instanceStore) List() []*ProWorkspaceInstance { ) if err == nil { for _, workspace := range localWorkspaces { - if proInstance := s.importedProInstance(workspace); proInstance != nil { - instanceList = append(instanceList, proInstance) + if instance := s.importedInstance(workspace); instance != nil { + instanceList = append(instanceList, instance) } } } @@ -254,9 +254,9 @@ func (s *instanceStore) key(meta metav1.ObjectMeta) string { return fmt.Sprintf("%s/%s", meta.Namespace, meta.Name) } -func (s *instanceStore) buildProInstance( +func (s *instanceStore) buildInstance( instance *managementv1.DevsyWorkspaceInstance, -) *ProWorkspaceInstance { +) *WorkspaceInstance { var source *provider.WorkspaceSource if instance.GetAnnotations() != nil && instance.GetAnnotations()[storagev1.DevsyWorkspaceSourceAnnotation] != "" { @@ -274,11 +274,11 @@ func (s *instanceStore) buildProInstance( } } - return &ProWorkspaceInstance{ + return &WorkspaceInstance{ TypeMeta: instance.TypeMeta, ObjectMeta: instance.ObjectMeta, Spec: instance.Spec, - Status: ProWorkspaceInstanceStatus{ + Status: WorkspaceInstanceStatus{ DevsyWorkspaceInstanceStatus: instance.Status, Source: source, IDE: ideConfig, @@ -286,9 +286,9 @@ func (s *instanceStore) buildProInstance( } } -func (s *instanceStore) importedProInstance( +func (s *instanceStore) importedInstance( workspace *provider.Workspace, -) *ProWorkspaceInstance { +) *WorkspaceInstance { if !workspace.Imported || workspace.Pro == nil { return nil } @@ -320,10 +320,10 @@ func (s *instanceStore) importedProInstance( } s.m.Unlock() - return s.buildProInstance(instance) + return s.buildInstance(instance) } -func printInstances(w io.Writer, instances []*ProWorkspaceInstance) { +func printInstances(w io.Writer, instances []*WorkspaceInstance) { out, err := json.Marshal(instances) if err != nil { return diff --git a/pkg/daemon/platform/local_server.go b/pkg/daemon/platform/local_server.go index da225700eb..5a839a8342 100644 --- a/pkg/daemon/platform/local_server.go +++ b/pkg/daemon/platform/local_server.go @@ -546,7 +546,7 @@ func (l *localServer) watchWorkspaces( TsClient: l.lc, }, // we need to debounce events here to avoid spamming the client with too many events - throttle(func(instanceList []*ProWorkspaceInstance) { + throttle(func(instanceList []*WorkspaceInstance) { if r.Context().Err() != nil { return // Client disconnected, stop trying to write } @@ -576,15 +576,15 @@ func (l *localServer) watchWorkspaces( // every interval. If a call happens before the interval has elapsed, // the latest instanceList is saved and f will be called with it when possible. func throttle( - f func(instanceList []*ProWorkspaceInstance), + f func(instanceList []*WorkspaceInstance), interval time.Duration, -) func(instanceList []*ProWorkspaceInstance) { +) func(instanceList []*WorkspaceInstance) { var mu sync.Mutex - var lastExecuted time.Time // Time of the last execution of f. - var pending []*ProWorkspaceInstance // Latest instanceList waiting to be processed. - var timer *time.Timer // Timer scheduled to call f. + var lastExecuted time.Time // Time of the last execution of f. + var pending []*WorkspaceInstance // Latest instanceList waiting to be processed. + var timer *time.Timer // Timer scheduled to call f. - return func(instanceList []*ProWorkspaceInstance) { + return func(instanceList []*WorkspaceInstance) { mu.Lock() defer mu.Unlock() diff --git a/pkg/daemon/platform/workspace_watcher.go b/pkg/daemon/platform/workspace_watcher.go index 8319531a9b..7d98635eaa 100644 --- a/pkg/daemon/platform/workspace_watcher.go +++ b/pkg/daemon/platform/workspace_watcher.go @@ -27,15 +27,15 @@ import ( "tailscale.com/tailcfg" ) -type ProWorkspaceInstance struct { +type WorkspaceInstance struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata"` Spec managementv1.DevsyWorkspaceInstanceSpec `json:"spec"` - Status ProWorkspaceInstanceStatus `json:"status"` + Status WorkspaceInstanceStatus `json:"status"` } -type ProWorkspaceInstanceStatus struct { +type WorkspaceInstanceStatus struct { managementv1.DevsyWorkspaceInstanceStatus `json:",inline"` Source *provider.WorkspaceSource `json:"source,omitempty"` @@ -51,7 +51,7 @@ type watchConfig struct { OwnerFilter platform.OwnerFilter } -type changeFn func(instanceList []*ProWorkspaceInstance) +type changeFn func(instanceList []*WorkspaceInstance) func startWorkspaceWatcher(ctx context.Context, config watchConfig, onChange changeFn) error { self := config.PlatformClient.Self() @@ -170,7 +170,7 @@ type instanceStore struct { ownerFilter platform.OwnerFilter m sync.Mutex - instances map[string]*ProWorkspaceInstance + instances map[string]*WorkspaceInstance tsClient *local.Client metricsMu sync.RWMutex @@ -207,7 +207,7 @@ func newStore( return &instanceStore{ self: self, context: context, - instances: map[string]*ProWorkspaceInstance{}, + instances: map[string]*WorkspaceInstance{}, ownerFilter: ownerFilter, tsClient: tsClient, metrics: map[string][]WorkspaceNetworkMetrics{}, @@ -236,11 +236,11 @@ func (s *instanceStore) Add(instance *managementv1.DevsyWorkspaceInstance) { } } - proInstance := &ProWorkspaceInstance{ + platformInstance := &WorkspaceInstance{ TypeMeta: instance.TypeMeta, ObjectMeta: instance.ObjectMeta, Spec: instance.Spec, - Status: ProWorkspaceInstanceStatus{ + Status: WorkspaceInstanceStatus{ DevsyWorkspaceInstanceStatus: instance.Status, Source: source, IDE: ideConfig, @@ -249,7 +249,7 @@ func (s *instanceStore) Add(instance *managementv1.DevsyWorkspaceInstance) { key := s.key(instance.Namespace, instance.Name) s.m.Lock() - s.instances[key] = proInstance + s.instances[key] = platformInstance s.m.Unlock() } @@ -279,11 +279,11 @@ func (s *instanceStore) Delete(instance *managementv1.DevsyWorkspaceInstance) { delete(s.metrics, key) } -func (s *instanceStore) List() []*ProWorkspaceInstance { +func (s *instanceStore) List() []*WorkspaceInstance { s.m.Lock() defer s.m.Unlock() - instanceList := []*ProWorkspaceInstance{} + instanceList := []*WorkspaceInstance{} for _, instance := range s.instances { instanceList = append(instanceList, s.convert(instance)) } @@ -295,7 +295,7 @@ func (s *instanceStore) key(namespace, name string) string { return fmt.Sprintf("%s/%s", namespace, name) } -func (s *instanceStore) convert(instance *ProWorkspaceInstance) *ProWorkspaceInstance { +func (s *instanceStore) convert(instance *WorkspaceInstance) *WorkspaceInstance { if instance == nil { return nil } @@ -368,7 +368,7 @@ func (s *instanceStore) updateWorkspaceLatencies(ctx context.Context) { } wg.Add(1) - go func(peer *ipnstate.PeerStatus, key string, instance *ProWorkspaceInstance) { + go func(peer *ipnstate.PeerStatus, key string, instance *WorkspaceInstance) { defer wg.Done() s.pingAndRecord(ctx, peer, key, instance) }(peer, key, instance) @@ -381,7 +381,7 @@ func (s *instanceStore) pingAndRecord( ctx context.Context, peer *ipnstate.PeerStatus, key string, - instance *ProWorkspaceInstance, + instance *WorkspaceInstance, ) { timeoutCtx, cancel := context.WithTimeout(ctx, 5*time.Second) defer cancel()