-
Notifications
You must be signed in to change notification settings - Fork 17
Decouple editTargetPort from createContainerApp
#371
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c04699e
IContainerAppContext
MicroFish91 246c64e
Refactor work to extend IContainerAppContext
MicroFish91 23f1516
Fix file name
MicroFish91 0482467
Edit target port refactor
MicroFish91 93851f7
Merge with main
MicroFish91 96b5c43
Import types
MicroFish91 3cf25c7
Revert accidental change
MicroFish91 7ec33a5
Add comment
MicroFish91 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This step is meant to (eventually) completely replace the use of |
||
| 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); | ||
| } | ||
| } | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/commands/ingress/editTargetPort/TargetPortUpdateStep.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.