Skip to content

poc #20788

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

poc #20788

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
19 changes: 15 additions & 4 deletions components/ide-service/pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,11 @@ func grpcProbe(cfg baseserver.ServerConfiguration) func() error {
}

type IDESettings struct {
DefaultIde string `json:"defaultIde,omitempty"`
UseLatestVersion bool `json:"useLatestVersion,omitempty"`
PreferToolbox bool `json:"preferToolbox,omitempty"`
PinnedIDEversions map[string]string `json:"pinnedIDEversions,omitempty"`
DefaultIde string `json:"defaultIde,omitempty"`
UseLatestVersion bool `json:"useLatestVersion,omitempty"`
PreferToolbox bool `json:"preferToolbox,omitempty"`
PinnedIDEversions map[string]string `json:"pinnedIDEversions,omitempty"`
RestrictedEditorNames []string `json:"restrictedEditorNames,omitempty"`
}

type WorkspaceContext struct {
Expand Down Expand Up @@ -395,6 +396,11 @@ func (s *IDEServiceServer) ResolveWorkspaceConfig(ctx context.Context, req *api.
}

pinnedIDEversions := make(map[string]string)
restrictedEditorNames := make(map[string]struct{})

for _, editorName := range ideSettings.RestrictedEditorNames {
restrictedEditorNames[editorName] = struct{}{}
}

if ideSettings != nil {
pinnedIDEversions = ideSettings.PinnedIDEversions
Expand Down Expand Up @@ -482,6 +488,11 @@ func (s *IDEServiceServer) ResolveWorkspaceConfig(ctx context.Context, req *api.
resp.WebImage = getUserIDEImage(ideConfig.IdeOptions.DefaultIde, useLatest)
resp.IdeImageLayers = getUserImageLayers(ideConfig.IdeOptions.DefaultIde, useLatest)

if _, ok := restrictedEditorNames["code"]; ok {
resp.WebImage = ""
resp.IdeImageLayers = []string{}
}

var desktopImageLayer string
var desktopUserImageLayers []string
if chosenIDE.Type == config.IDETypeDesktop {
Expand Down
40 changes: 20 additions & 20 deletions components/server/src/ide-service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ const expect = chai.expect;
describe("ide-service", function () {
describe("migrateSettings", function () {
const ideService = new IDEService();
it("with no ideSettings should be undefined", function () {
it("with no ideSettings should be undefined", async function () {
const user: User = {
id: "string",

creationDate: "string",
identities: [],
additionalData: {},
};
const result = ideService.migrateSettings(user);
const result = await ideService.migrateSettings(user);
expect(result).to.undefined;
});

it("with settingVersion 2.0 should be latest", function () {
it("with settingVersion 2.0 should be latest", async function () {
const user: User = {
id: "string",
creationDate: "string",
Expand All @@ -38,15 +38,15 @@ describe("ide-service", function () {
},
},
};
const result = ideService.migrateSettings(user);
const result = await ideService.migrateSettings(user);
expect(result).to.deep.equal({
settingVersion: IDESettingsVersion,
defaultIde: "code",
useLatestVersion: true,
});
});

it("with settingVersion 2.0 should be latest and remove intellij-previous", function () {
it("with settingVersion 2.0 should be latest and remove intellij-previous", async function () {
const user: User = {
id: "string",
creationDate: "string",
Expand All @@ -59,15 +59,15 @@ describe("ide-service", function () {
},
},
};
const result = ideService.migrateSettings(user);
const result = await ideService.migrateSettings(user);
expect(result).to.deep.equal({
settingVersion: IDESettingsVersion,
defaultIde: "code",
useLatestVersion: false,
});
});

it("with settingVersion latest should be undefined", function () {
it("with settingVersion latest should be undefined", async function () {
const user: User = {
id: "string",
creationDate: "string",
Expand All @@ -80,11 +80,11 @@ describe("ide-service", function () {
},
},
};
const result = ideService.migrateSettings(user);
const result = await ideService.migrateSettings(user);
expect(result).to.undefined;
});

it("with code-latest should be code latest", function () {
it("with code-latest should be code latest", async function () {
const user: User = {
id: "string",
creationDate: "string",
Expand All @@ -96,12 +96,12 @@ describe("ide-service", function () {
},
},
};
const result = ideService.migrateSettings(user);
const result = await ideService.migrateSettings(user);
expect(result?.defaultIde).to.equal("code");
expect(result?.useLatestVersion ?? false).to.be.true;
});

it("with code-desktop-insiders should be code-desktop latest", function () {
it("with code-desktop-insiders should be code-desktop latest", async function () {
const user: User = {
id: "string",
creationDate: "string",
Expand All @@ -114,12 +114,12 @@ describe("ide-service", function () {
},
},
};
const result = ideService.migrateSettings(user);
const result = await ideService.migrateSettings(user);
expect(result?.defaultIde).to.equal("code-desktop");
expect(result?.useLatestVersion ?? false).to.be.true;
});

it("with code-desktop should be code-desktop", function () {
it("with code-desktop should be code-desktop", async function () {
const user: User = {
id: "string",
creationDate: "string",
Expand All @@ -132,12 +132,12 @@ describe("ide-service", function () {
},
},
};
const result = ideService.migrateSettings(user);
const result = await ideService.migrateSettings(user);
expect(result?.defaultIde).to.equal("code-desktop");
expect(result?.useLatestVersion ?? false).to.be.false;
});

it("with intellij should be intellij", function () {
it("with intellij should be intellij", async function () {
const user: User = {
id: "string",
creationDate: "string",
Expand All @@ -151,12 +151,12 @@ describe("ide-service", function () {
},
},
};
const result = ideService.migrateSettings(user);
const result = await ideService.migrateSettings(user);
expect(result?.defaultIde).to.equal("intellij");
expect(result?.useLatestVersion ?? false).to.be.false;
});

it("with intellij latest version should be intellij latest", function () {
it("with intellij latest version should be intellij latest", async function () {
const user: User = {
id: "string",
creationDate: "string",
Expand All @@ -170,12 +170,12 @@ describe("ide-service", function () {
},
},
};
const result = ideService.migrateSettings(user);
const result = await ideService.migrateSettings(user);
expect(result?.defaultIde).to.equal("intellij");
expect(result?.useLatestVersion ?? false).to.be.true;
});

it("with user desktopIde false should be code latest", function () {
it("with user desktopIde false should be code latest", async function () {
const user: User = {
id: "string",
creationDate: "string",
Expand All @@ -189,7 +189,7 @@ describe("ide-service", function () {
},
},
};
const result = ideService.migrateSettings(user);
const result = await ideService.migrateSettings(user);
expect(result?.defaultIde).to.equal("code");
expect(result?.useLatestVersion ?? false).to.be.true;
});
Expand Down
10 changes: 7 additions & 3 deletions components/server/src/ide-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ interface ExtendedIDEOptions extends Omit<IDEOptions, "options"> {

export interface ExtendedIDESettings extends IDESettings {
pinnedIDEversions?: { [key: string]: string };
restrictedEditorNames?: string[];
}

export interface IDEConfig {
Expand Down Expand Up @@ -75,7 +76,7 @@ export class IDEService {
return Object.keys(config.ideOptions.options).includes(ide);
}

migrateSettings(user: User): IDESettings | undefined {
async migrateSettings(user: User): Promise<IDESettings | undefined> {
if (
!user?.additionalData?.ideSettings ||
user.additionalData.ideSettings.settingVersion === IDESettingsVersion
Expand All @@ -102,7 +103,7 @@ export class IDEService {
newIDESettings.useLatestVersion = useLatest;
}

if (ideSettings.defaultIde && !this.isIDEAvailable(ideSettings.defaultIde, { user })) {
if (ideSettings.defaultIde && !(await this.isIDEAvailable(ideSettings.defaultIde, { user }))) {
ideSettings.defaultIde = "code";
}
return newIDESettings;
Expand All @@ -117,7 +118,10 @@ export class IDEService {
workspace.type === "prebuild" ? IdeServiceApi.WorkspaceType.PREBUILD : IdeServiceApi.WorkspaceType.REGULAR;

// in case users have `auto-start` options set
if (userSelectedIdeSettings?.defaultIde && !this.isIDEAvailable(userSelectedIdeSettings.defaultIde, { user })) {
if (
userSelectedIdeSettings?.defaultIde &&
!(await this.isIDEAvailable(userSelectedIdeSettings.defaultIde, { user }))
) {
userSelectedIdeSettings.defaultIde = "code";
}

Expand Down
6 changes: 6 additions & 0 deletions components/server/src/workspace/workspace-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,12 @@ export class WorkspaceService {
options.ideSettings.pinnedIDEversions = orgSettings.pinnedEditorVersions;
}

if (orgSettings.restrictedEditorNames) {
if (!options.ideSettings) {
options.ideSettings = {};
}
options.ideSettings.restrictedEditorNames = orgSettings.restrictedEditorNames;
}
// at this point we're about to actually start a new workspace
const result = await this.workspaceStarter.startWorkspace(ctx, workspace, user, await projectPromise, options);
this.asyncUpdateDeletionEligibilityTime(user.id, workspaceId, true);
Expand Down
2 changes: 1 addition & 1 deletion components/server/src/workspace/workspace-starter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ export class WorkspaceStarter {
) {
const span = TraceContext.startSpan("resolveIDEConfiguration", ctx);
try {
const migrated = this.ideService.migrateSettings(user);
const migrated = await this.ideService.migrateSettings(user);
if (user.additionalData?.ideSettings && migrated) {
user.additionalData.ideSettings = migrated;
}
Expand Down
13 changes: 8 additions & 5 deletions components/supervisor/pkg/supervisor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const supervisorConfigFile = "supervisor-config.json"
// Config configures supervisor.
type Config struct {
StaticConfig
IDE IDEConfig
IDE *IDEConfig
DesktopIDEs []*IDEConfig
WorkspaceConfig
}
Expand Down Expand Up @@ -573,9 +573,12 @@ func GetConfig() (*Config, error) {
return nil, err
}

ide, err := loadIDEConfigFromFile(static.IDEConfigLocation)
if err != nil {
return nil, err
var ide *IDEConfig
if _, err := os.Stat(static.IDEConfigLocation); !os.IsNotExist(err) {
ide, err = loadIDEConfigFromFile(static.IDEConfigLocation)
if err != nil {
return nil, err
}
}
desktopIDEs, err := loadDesktopIDEs(static)
if err != nil {
Expand All @@ -589,7 +592,7 @@ func GetConfig() (*Config, error) {

return &Config{
StaticConfig: *static,
IDE: *ide,
IDE: ide,
DesktopIDEs: desktopIDEs,
WorkspaceConfig: *workspace,
}, nil
Expand Down
29 changes: 17 additions & 12 deletions components/supervisor/pkg/supervisor/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,20 @@ func (s *statusService) SupervisorStatus(ctx context.Context, req *api.Superviso

func (s *statusService) IDEStatus(ctx context.Context, req *api.IDEStatusRequest) (*api.IDEStatusResponse, error) {
if req.Wait {
select {
case <-s.ideReady.Wait():
{
// do nothing
}
case <-ctx.Done():
if errors.Is(ctx.Err(), context.Canceled) {
return nil, status.Error(codes.Canceled, "execution canceled")
}
if s.ideReady != nil {

return nil, status.Error(codes.DeadlineExceeded, ctx.Err().Error())
select {
case <-s.ideReady.Wait():
{
// do nothing
}
case <-ctx.Done():
if errors.Is(ctx.Err(), context.Canceled) {
return nil, status.Error(codes.Canceled, "execution canceled")
}

return nil, status.Error(codes.DeadlineExceeded, ctx.Err().Error())
}
}

if s.desktopIdeReady != nil {
Expand All @@ -169,8 +172,10 @@ func (s *statusService) IDEStatus(ctx context.Context, req *api.IDEStatusRequest
}
}
}

ok, _ := s.ideReady.Get()
ok := true
if s.ideReady != nil {
ok, _ = s.ideReady.Get()
}
desktopStatus := &api.IDEStatusResponse_DesktopStatus{}
if s.desktopIdeReady != nil {
okR, i := s.desktopIdeReady.Get()
Expand Down
Loading
Loading