Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
5 changes: 3 additions & 2 deletions src/commands/createContainerApp/EnableIngressStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

import { AzureWizardPromptStep, IWizardOptions } from "@microsoft/vscode-azext-utils";
import { localize } from "../../utils/localize";
import { TargetPortInputStep } from "../ingress/editTargetPort/TargetPortInputStep";
import { ICreateContainerAppContext } from "./ICreateContainerAppContext";
import { IngressVisibilityStep } from "./IngressVisibilityStep";
import { TargetPortStep } from "./TargetPortStep";

export class EnableIngressStep extends AzureWizardPromptStep<ICreateContainerAppContext> {
public async prompt(context: ICreateContainerAppContext): Promise<void> {
Expand All @@ -23,7 +23,8 @@ export class EnableIngressStep extends AzureWizardPromptStep<ICreateContainerApp
public async getSubWizard(context: ICreateContainerAppContext): Promise<IWizardOptions<ICreateContainerAppContext> | undefined> {
if (context.enableIngress) {
return {
promptSteps: [new IngressVisibilityStep(), new TargetPortStep()]
// @ts-ignore
Comment thread
MicroFish91 marked this conversation as resolved.
promptSteps: [new IngressVisibilityStep(), new TargetPortInputStep()]
}
}

Expand Down
14 changes: 14 additions & 0 deletions src/commands/ingress/IngressContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import type { ExecuteActivityContext } from "@microsoft/vscode-azext-utils";
import type { IContainerAppContext } from "../IContainerAppContext";

export interface IngressContext extends IContainerAppContext, ExecuteActivityContext {
enableIngress?: boolean;
enableExternal?: boolean;

targetPort?: number;
}
30 changes: 30 additions & 0 deletions src/commands/ingress/IngressUpdateBaseStep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import type { Ingress } from "@azure/arm-appcontainers";
import { AzureWizardExecuteStep, nonNullProp } from "@microsoft/vscode-azext-utils";
import type { Progress } from "vscode";
import { ext } from "../../extensionVariables";
import type { IContainerAppContext } from "../IContainerAppContext";
import { updateContainerApp } from "../deployContainerApp/updateContainerApp";

type IngressOptions = {
ingress: Ingress | null,
working: string,
workCompleted: string
}

export abstract class IngressUpdateBaseStep<T extends IContainerAppContext> extends AzureWizardExecuteStep<T> {
Copy link
Copy Markdown
Contributor Author

@MicroFish91 MicroFish91 May 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This step is meant to (eventually) completely replace the use of updateIngressSettings.ts

protected async updateIngressSettings(context: T, progress: Progress<{ message?: string | undefined}>, options: IngressOptions): Promise<void> {
const containerApp = nonNullProp(context, 'containerApp');
const { ingress, working, workCompleted } = options;

progress.report({ message: working });
await updateContainerApp(context, context.subscription, containerApp, { configuration: { ingress: ingress as Ingress | undefined } });

ext.outputChannel.appendLog(workCompleted);
ext.state.notifyChildrenChanged(containerApp.managedEnvironmentId);
}
}
41 changes: 0 additions & 41 deletions src/commands/ingress/editTargetPort.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
*--------------------------------------------------------------------------------------------*/

import { AzureWizardPromptStep } from "@microsoft/vscode-azext-utils";
import { localize } from "../../utils/localize";
import { ICreateContainerAppContext } from "./ICreateContainerAppContext";
import { localize } from "../../../utils/localize";
import type { IngressContext } from "../IngressContext";
import { getDefaultPort } from "./getDefaultPort";

export class TargetPortStep extends AzureWizardPromptStep<ICreateContainerAppContext> {
public async prompt(context: ICreateContainerAppContext): Promise<void> {
export class TargetPortInputStep extends AzureWizardPromptStep<IngressContext> {
public async prompt(context: IngressContext): Promise<void> {
context.targetPort = Number(await context.ui.showInputBox({
prompt: localize('targetPort', 'This is the port your container is listening on that will receive traffic. Set this value to the port number that your container uses.'),
value: String(context.defaultPort ?? 80),
value: String(getDefaultPort(context)),
validateInput: this.validateInput
}));
}

public shouldPrompt(context: ICreateContainerAppContext): boolean {
public shouldPrompt(context: IngressContext): boolean {
return !context.targetPort;
}

Expand Down
30 changes: 30 additions & 0 deletions src/commands/ingress/editTargetPort/TargetPortUpdateStep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { nonNullProp, nonNullValueAndProp } from "@microsoft/vscode-azext-utils";
import type { Progress } from "vscode";
import { localize } from "../../../utils/localize";
import type { IngressContext } from "../IngressContext";
import { IngressUpdateBaseStep } from "../IngressUpdateBaseStep";

export class TargetPortUpdateStep extends IngressUpdateBaseStep<IngressContext> {
public priority: number = 280;

public async execute(context: IngressContext, progress: Progress<{ message?: string | undefined; increment?: number | undefined }>): Promise<void> {
const containerApp = nonNullProp(context, 'containerApp');
const ingress = nonNullValueAndProp(containerApp.configuration, 'ingress');
ingress.targetPort = context.targetPort;

const working: string = localize('updatingTargetPort', 'Updating target port...');
const workCompleted: string = localize('updatedTargetPort', 'Updated target port to {0} for container app "{1}"', context.targetPort, containerApp.name);

context.activityTitle = localize('updateTargetPort', 'Update target port to {0} for container app "{1}"', context.targetPort, containerApp.name);
await this.updateIngressSettings(context, progress, { ingress, working, workCompleted });
}

public shouldExecute(): boolean {
return true;
}
}
46 changes: 46 additions & 0 deletions src/commands/ingress/editTargetPort/editTargetPort.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { AzureWizard, AzureWizardExecuteStep, AzureWizardPromptStep, createSubscriptionContext, IActionContext } from "@microsoft/vscode-azext-utils";
import type { ContainerAppItem } from "../../../tree/ContainerAppItem";
import { IngressItem } from "../../../tree/IngressItem";
import { createActivityContext } from "../../../utils/activityUtils";
import { localize } from "../../../utils/localize";
import { pickContainerApp } from "../../../utils/pickContainerApp";
import type { IngressContext } from "../IngressContext";
import { TargetPortInputStep } from "./TargetPortInputStep";
import { TargetPortUpdateStep } from "./TargetPortUpdateStep";

export async function editTargetPort(context: IActionContext, node?: IngressItem): Promise<void> {
const { subscription, containerApp }: ContainerAppItem | IngressItem = node ?? await pickContainerApp(context);

const wizardContext: IngressContext = {
...context,
...createSubscriptionContext(subscription),
...(await createActivityContext()),
subscription,
containerApp
};

const title: string = localize('updateTargetPort', 'Update target port for container app "{0}"', containerApp.name);

const promptSteps: AzureWizardPromptStep<IngressContext>[] = [
new TargetPortInputStep()
];

const executeSteps: AzureWizardExecuteStep<IngressContext>[] = [
new TargetPortUpdateStep()
];

const wizard: AzureWizard<IngressContext> = new AzureWizard(wizardContext, {
title,
promptSteps,
executeSteps,
showLoadingPrompt: true
});

await wizard.prompt();
await wizard.execute();
}
10 changes: 10 additions & 0 deletions src/commands/ingress/editTargetPort/getDefaultPort.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import type { IngressContext } from "../IngressContext";

export function getDefaultPort(context: IngressContext, fallbackPort: number = 80): number {
return context.containerApp?.configuration?.ingress?.targetPort || fallbackPort;
}
2 changes: 1 addition & 1 deletion src/commands/registerCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { connectToGitHub } from './gitHub/connectToGitHub/connectToGitHub';
import { disconnectRepo } from './gitHub/disconnectRepo/disconnectRepo';
import { openGitHubRepo } from './gitHub/openGitHubRepo';
import { disableIngress } from './ingress/disableIngress';
import { editTargetPort } from './ingress/editTargetPort';
import { editTargetPort } from './ingress/editTargetPort/editTargetPort';
import { enableIngress } from './ingress/enableIngress';
import { toggleIngressVisibility } from './ingress/toggleIngressVisibility';
import { startStreamingLogs } from './logStream/startStreamingLogs';
Expand Down