Skip to content
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

add way to draft k8s resources without local kubeconfig #87

Merged
merged 1 commit into from
Apr 7, 2023
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
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