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 cmd/pro/provider/watch/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,6 @@ func newStore(
}
}

func (s *instanceStore) key(meta metav1.ObjectMeta) string {
return fmt.Sprintf("%s/%s", meta.Namespace, meta.Name)
}

func (s *instanceStore) Add(instance *managementv1.DevsyWorkspaceInstance) {
if s.filterByOwner && !platform.IsOwner(s.self, instance.Spec.Owner) {
return
Expand Down Expand Up @@ -253,6 +249,10 @@ func (s *instanceStore) List() []*ProWorkspaceInstance {
return instanceList
}

func (s *instanceStore) key(meta metav1.ObjectMeta) string {
return fmt.Sprintf("%s/%s", meta.Namespace, meta.Name)
}

func (s *instanceStore) buildProInstance(
instance *managementv1.DevsyWorkspaceInstance,
) *ProWorkspaceInstance {
Expand Down
28 changes: 14 additions & 14 deletions pkg/agent/tunnelserver/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,6 @@ type tunnelLogger struct {
logChan chan *tunnel.LogMessage
}

func (s *tunnelLogger) worker() {
for {
select {
case msg := <-s.logChan:
ctx, cancel := context.WithTimeout(s.ctx, 5*time.Second)
_, _ = s.client.Log(ctx, msg)
// ignore error since we can't use the logger itself
cancel()
case <-s.ctx.Done():
return
}
}
}

func (s *tunnelLogger) Debugf(format string, args ...any) {
if s.level < levelDebug {
return
Expand Down Expand Up @@ -108,3 +94,17 @@ func (s *tunnelLogger) Warnf(format string, args ...any) {
Message: fmt.Sprintf(format, args...) + "\n",
}
}

func (s *tunnelLogger) worker() {
for {
select {
case msg := <-s.logChan:
ctx, cancel := context.WithTimeout(s.ctx, 5*time.Second)
_, _ = s.client.Log(ctx, msg)
// ignore error since we can't use the logger itself
cancel()
case <-s.ctx.Done():
return
}
}
}
18 changes: 9 additions & 9 deletions pkg/apple/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,15 +349,6 @@ func (h *AppleHelper) EnsureBuilderRunning(ctx context.Context) error {
return fmt.Errorf("start container builder: %s: %w", strings.TrimSpace(string(out)), err)
}

func (h *AppleHelper) buildCmd(ctx context.Context, args ...string) *exec.Cmd {
//nolint:gosec // G204: operator-configured binary, internally-built args (as in pkg/docker)
cmd := exec.CommandContext(ctx, h.Command, args...)
if h.Environment != nil {
cmd.Env = append(os.Environ(), h.Environment...)
}
return cmd
}

// SystemRunning reports whether the container system service is running.
func (h *AppleHelper) SystemRunning(ctx context.Context) bool {
cctx, cancel := context.WithTimeout(ctx, 5*time.Second)
Expand All @@ -369,6 +360,15 @@ func (h *AppleHelper) SystemRunning(ctx context.Context) bool {
return strings.Contains(strings.ToLower(string(out)), stateRunning)
}

func (h *AppleHelper) buildCmd(ctx context.Context, args ...string) *exec.Cmd {
//nolint:gosec // G204: operator-configured binary, internally-built args (as in pkg/docker)
cmd := exec.CommandContext(ctx, h.Command, args...)
if h.Environment != nil {
cmd.Env = append(os.Environ(), h.Environment...)
}
return cmd
}

func (h *AppleHelper) listContainers(ctx context.Context) ([]containerInspect, error) {
out, err := h.buildCmd(ctx, "list", "--all", "--format", "json").Output()
if err != nil {
Expand Down
114 changes: 57 additions & 57 deletions pkg/client/clientimplementation/proxy_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,28 +159,6 @@ func tryLock(ctx context.Context, lock *flock.Flock, name string) error {
)
}

func (s *proxyClient) initLock() {
s.workspaceLockOnce.Do(func() {
s.m.Lock()
defer s.m.Unlock()

// get locks dir
workspaceLocksDir, err := provider.GetLocksDir(s.workspace.Context)
if err != nil {
panic(fmt.Errorf("get workspaces dir: %w", err))
}
// #nosec G301 -- TODO Consider using a more secure permission setting and ownership if needed.
if err = os.MkdirAll(workspaceLocksDir, 0o755); err != nil {
panic(fmt.Errorf("create workspace locks dir: %w", err))
}

// create workspace lock
s.workspaceLock = flock.New(
filepath.Join(workspaceLocksDir, s.workspace.ID+".workspace.lock"),
)
})
}

func (s *proxyClient) Provider() string {
return s.config.Name
}
Expand Down Expand Up @@ -295,41 +273,6 @@ func (s *proxyClient) Up(ctx context.Context, opt client.UpOptions) error {
})
}

// checkPlatformVersion validates the platform provider version compatibility.
func (s *proxyClient) checkPlatformVersion(
ctx context.Context,
providerOptions map[string]config.OptionValue,
) error {
devsyConfigPath := providerOptions["DEVSY_CONFIG"].Value
if devsyConfigPath == "" {
return nil
}

baseClient, err := platformclient.InitClientFromPath(ctx, devsyConfigPath)
if err != nil {
return fmt.Errorf("error initializing platform client: %w", err)
}

version, err := baseClient.Version()
if err != nil {
return fmt.Errorf("error retrieving platform version: %w", err)
}

parsedVersion, err := semver.Parse(strings.TrimPrefix(version.DevsyVersion, "v"))
if err != nil {
return fmt.Errorf("error parsing platform version: %w", err)
}

if parsedVersion.GE(semver.MustParse("0.6.99")) {
return fmt.Errorf(
"you are using an outdated provider version for this platform. " +
"Disconnect and reconnect the platform to update the provider",
)
}

return nil
}

func (s *proxyClient) Delete(ctx context.Context, opt client.DeleteOptions) error {
s.m.Lock()
defer s.m.Unlock()
Expand Down Expand Up @@ -407,6 +350,63 @@ func (s *proxyClient) Status(
return client.ParseStatus(status.State)
}

func (s *proxyClient) initLock() {
s.workspaceLockOnce.Do(func() {
s.m.Lock()
defer s.m.Unlock()

// get locks dir
workspaceLocksDir, err := provider.GetLocksDir(s.workspace.Context)
if err != nil {
panic(fmt.Errorf("get workspaces dir: %w", err))
}
// #nosec G301 -- TODO Consider using a more secure permission setting and ownership if needed.
if err = os.MkdirAll(workspaceLocksDir, 0o755); err != nil {
panic(fmt.Errorf("create workspace locks dir: %w", err))
}

// create workspace lock
s.workspaceLock = flock.New(
filepath.Join(workspaceLocksDir, s.workspace.ID+".workspace.lock"),
)
})
}

// checkPlatformVersion validates the platform provider version compatibility.
func (s *proxyClient) checkPlatformVersion(
ctx context.Context,
providerOptions map[string]config.OptionValue,
) error {
devsyConfigPath := providerOptions["DEVSY_CONFIG"].Value
if devsyConfigPath == "" {
return nil
}

baseClient, err := platformclient.InitClientFromPath(ctx, devsyConfigPath)
if err != nil {
return fmt.Errorf("error initializing platform client: %w", err)
}

version, err := baseClient.Version()
if err != nil {
return fmt.Errorf("error retrieving platform version: %w", err)
}

parsedVersion, err := semver.Parse(strings.TrimPrefix(version.DevsyVersion, "v"))
if err != nil {
return fmt.Errorf("error parsing platform version: %w", err)
}

if parsedVersion.GE(semver.MustParse("0.6.99")) {
return fmt.Errorf(
"you are using an outdated provider version for this platform. " +
"Disconnect and reconnect the platform to update the provider",
)
}

return nil
}

func (s *proxyClient) updateInstance(ctx context.Context) error {
if !terminal.IsTerminalIn {
return fmt.Errorf("unable to update instance through CLI if stdin is not a terminal")
Expand Down
8 changes: 4 additions & 4 deletions pkg/daemon/platform/workspace_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,6 @@ func newStore(
}
}

func (s *instanceStore) key(namespace, name string) string {
return fmt.Sprintf("%s/%s", namespace, name)
}

func (s *instanceStore) Add(instance *managementv1.DevsyWorkspaceInstance) {
if s.ownerFilter == platform.SelfOwnerFilter && !platform.IsOwner(s.self, instance.GetOwner()) {
return
Expand Down Expand Up @@ -295,6 +291,10 @@ func (s *instanceStore) List() []*ProWorkspaceInstance {
return instanceList
}

func (s *instanceStore) key(namespace, name string) string {
return fmt.Sprintf("%s/%s", namespace, name)
}

func (s *instanceStore) convert(instance *ProWorkspaceInstance) *ProWorkspaceInstance {
if instance == nil {
return nil
Expand Down
Loading
Loading