Skip to content

Commit

Permalink
add path to draft k8s resources without local kubeconfig (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverMKing authored Apr 7, 2023
1 parent e4a0b0f commit 6578903
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 89 deletions.
2 changes: 1 addition & 1 deletion src/commands/runDraftTool/helper/runDraftHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function ensureDraftBinary(): Promise<Errorable<null>> {
if (!latestReleaseTag) {
return {
succeeded: false,
error: `failed to get latest release tag`
error: `Failed to get latest release tag for downloading draft`
};
}

Expand Down
107 changes: 40 additions & 67 deletions src/commands/runDraftTool/runDraftDeployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,9 @@ export async function runDraftDeployment(
const az: AzApi = new Az(getAzCreds);

// Ensure Draft Binary
const downloadResult = await longRunning(`Downloading Draft.`, () =>
await longRunning(`Downloading Draft.`, () =>
getAsyncResult(ensureDraftBinary())
);
if (!downloadResult) {
vscode.window.showErrorMessage('Failed to download Draft');
return undefined;
}

const workspaceFolders = vscode.workspace.workspaceFolders;
if (!outputFolder && workspaceFolders && workspaceFolders.length !== 0) {
Expand Down Expand Up @@ -134,7 +130,6 @@ export async function runDraftDeployment(
new PromptAcrTag(az)
];
const executeSteps: IExecuteStep[] = [
new ExecuteCreateNamespace(k8s),
new ExecuteDraft(),
new ExecuteOpenFiles(),
new ExecuteSaveState(state),
Expand Down Expand Up @@ -225,38 +220,49 @@ class PromptNamespace extends AzureWizardPromptStep<WizardContext> {
}

public async prompt(wizardContext: WizardContext): Promise<void> {
const namespaces = getAsyncResult(this.k8s.listNamespaces());
const newOption = 'New Namespace';
const getOptions = async (): Promise<vscode.QuickPickItem[]> => {
const namespaceOptions: vscode.QuickPickItem[] = (
await namespaces
).map((version) => ({
label: version.metadata?.name || ''
}));

return [
{label: newOption},
{label: '', kind: vscode.QuickPickItemKind.Separator},
...namespaceOptions,
try {
const namespaces = getAsyncResult(this.k8s.listNamespaces());
const newOption = 'New Namespace';
const getOptions = async (): Promise<vscode.QuickPickItem[]> => {
const namespaceOptions: vscode.QuickPickItem[] = (
await namespaces
).map((version) => ({
label: version.metadata?.name || ''
}));

return [
{label: newOption},
{label: '', kind: vscode.QuickPickItemKind.Separator},
...namespaceOptions,
{
label: 'Existing namespaces',
kind: vscode.QuickPickItemKind.Separator
}
];
};
const namespacePick = await wizardContext.ui.showQuickPick(
getOptions(),
{
label: 'Existing namespaces',
kind: vscode.QuickPickItemKind.Separator
ignoreFocusOut,
stepName: 'Namespace',
placeHolder: 'Namespace'
}
];
};
const namespacePick = await wizardContext.ui.showQuickPick(getOptions(), {
ignoreFocusOut,
stepName: 'Namespace',
placeHolder: 'Namespace'
});
);

if (namespacePick.label === newOption) {
if (namespacePick.label === newOption) {
wizardContext.newNamespace = true;
return;
}

wizardContext.newNamespace = false;
wizardContext.namespace = namespacePick.label;
} catch (err) {
console.error(`Error prompting namespaces: ${err}`);

// make the user manually enter a namespace
wizardContext.newNamespace = true;
return;
}

wizardContext.newNamespace = false;
wizardContext.namespace = namespacePick.label;
}

public shouldPrompt(wizardContext: WizardContext): boolean {
Expand All @@ -268,8 +274,8 @@ class PromptNewNamespace extends AzureWizardPromptStep<WizardContext> {
public async prompt(wizardContext: WizardContext): Promise<void> {
wizardContext.namespace = await wizardContext.ui.showInputBox({
ignoreFocusOut,
prompt: 'New Namespace',
stepName: 'New Namespace',
prompt: 'Namespace',
stepName: 'Namespace',
validateInput: ValidateRfc1123,
value: wizardContext.namespace || wizardContext.applicationName // application name is a reasonable autofill guess
});
Expand Down Expand Up @@ -567,39 +573,6 @@ export class PromptPort extends AzureWizardPromptStep<
}
}

class ExecuteCreateNamespace extends AzureWizardExecuteStep<WizardContext> {
public priority: number = 1;

constructor(private k8s: KubernetesApi) {
super();
}

public async execute(
wizardContext: WizardContext,
progress: vscode.Progress<{
message?: string | undefined;
increment?: number | undefined;
}>
): Promise<void> {
const {namespace} = wizardContext;
if (namespace === undefined) {
throw Error('Namespace is undefined');
}

const result = await this.k8s.createNamespace(namespace);
if (failed(result)) {
throw Error(result.error);
}
}

public shouldExecute(wizardContext: WizardContext): boolean {
return (
!!wizardContext.newNamespace &&
wizardContext.format !== DraftFormat.Helm // Draft creates namespace manifest for Helm
);
}
}

class ExecuteDraft extends AzureWizardExecuteStep<WizardContext> {
public priority: number = 2;

Expand Down
6 changes: 1 addition & 5 deletions src/commands/runDraftTool/runDraftDockerfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,9 @@ export async function runDraftDockerfile(
const state: StateApi = State.construct(extensionContext);

// Ensure Draft Binary
const downloadResult = await longRunning(`Downloading Draft.`, () =>
await longRunning(`Downloading Draft.`, () =>
getAsyncResult(ensureDraftBinary())
);
if (!downloadResult) {
vscode.window.showErrorMessage('Failed to download Draft');
return undefined;
}

const workspaceFolders = vscode.workspace.workspaceFolders;
if (!sourceCodeFolder && workspaceFolders && workspaceFolders.length !== 0) {
Expand Down
17 changes: 1 addition & 16 deletions src/commands/runDraftTool/runDraftIngress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,9 @@ export async function runDraftIngress(
completedSteps: CompletedSteps
) {
// Ensure Draft Binary
const downloadResult = await longRunning(`Downloading Draft`, () =>
await longRunning(`Downloading Draft`, () =>
getAsyncResult(ensureDraftBinary())
);
if (!downloadResult) {
vscode.window.showErrorMessage('Failed to download Draft');
return undefined;
}

const az: AzApi = new Az(getAzCreds);

Expand Down Expand Up @@ -467,9 +463,6 @@ class ExecuteEnableAddOn extends AzureWizardExecuteStep<WizardContext> {
if (cluster.managedCluster.addonProfiles === undefined) {
cluster.managedCluster.addonProfiles = {};
}
cluster.managedCluster.addonProfiles.httpApplicationRouting = {
enabled: true
};
cluster.managedCluster.addonProfiles.azureKeyvaultSecretsProvider = {
config: {enableSecretRotation: 'true'},
enabled: true
Expand Down Expand Up @@ -606,14 +599,6 @@ class ExecuteUpdateAddOn extends AzureWizardExecuteStep<WizardContext> {
throw Error('DNS Zone id is undefined');
}

if (cluster.managedCluster.addonProfiles === undefined) {
cluster.managedCluster.addonProfiles = {};
}
cluster.managedCluster.addonProfiles.httpApplicationRouting = {
// eslint-disable-next-line @typescript-eslint/naming-convention
config: {HTTPApplicationRoutingZoneName: dnsZone},
enabled: true
};
if (cluster.managedCluster.ingressProfile === undefined) {
cluster.managedCluster.ingressProfile = {};
}
Expand Down

0 comments on commit 6578903

Please sign in to comment.