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

Added environment link and describe dump for supportablity #12038

Merged
merged 13 commits into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from 9 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
10 changes: 4 additions & 6 deletions Tasks/AzureFunctionOnKubernetesV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 162,
"Patch": 1
"Minor": 164,
"Patch": 0
},
"demands": [],
"groups": [
{
"groups": [{
"name": "serviceConnections",
"displayName": "Service Connections",
"isExpanded": true
Expand All @@ -30,8 +29,7 @@
"isExpanded": true
}
],
"inputs": [
{
"inputs": [{
"name": "dockerRegistryServiceConnection",
"type": "connectedService:dockerregistry",
"label": "Docker registry service connection",
Expand Down
10 changes: 4 additions & 6 deletions Tasks/AzureFunctionOnKubernetesV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 162,
"Patch": 1
"Minor": 164,
"Patch": 0
},
"demands": [],
"groups": [
{
"groups": [{
"name": "serviceConnections",
"displayName": "ms-resource:loc.group.displayName.serviceConnections",
"isExpanded": true
Expand All @@ -30,8 +29,7 @@
"isExpanded": true
}
],
"inputs": [
{
"inputs": [{
"name": "dockerRegistryServiceConnection",
"type": "connectedService:dockerregistry",
"label": "ms-resource:loc.input.label.dockerRegistryServiceConnection",
Expand Down
50 changes: 47 additions & 3 deletions Tasks/Common/kubernetes-common-v2/kubernetesmanifestutility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,34 @@ import * as KubernetesConstants from './kubernetesconstants';
import { Kubectl, Resource } from './kubectl-object-model';

export async function checkManifestStability(kubectl: Kubectl, resources: Resource[], timeoutInSeconds?: string): Promise<void> {
const rolloutStatusResults = [];
const environmentUrl = getEnvironmentUrl();
if (environmentUrl)
tl.debug('For more information, go to ' + environmentUrl);

let rolloutStatusHasErrors = false;
const numberOfResources = resources.length;
for (let i = 0; i < numberOfResources; i++) {
const resource = resources[i];
if (KubernetesConstants.workloadTypesWithRolloutStatus.indexOf(resource.type.toLowerCase()) >= 0) {
rolloutStatusResults.push(kubectl.checkRolloutStatus(resource.type, resource.name, timeoutInSeconds));
try {
let result = kubectl.checkRolloutStatus(resource.type, resource.name, timeoutInSeconds);
utils.checkForErrors([result]);
} catch (ex) {
tl.error(ex);
kubectl.describe(resource.type, resource.name);
Copy link
Member

Choose a reason for hiding this comment

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

Move this to private function and use other places.

if (environmentUrl)
console.log(tl.loc('EnvironmentLink', environmentUrl));
rolloutStatusHasErrors = true;
}
}
if (utils.isEqual(resource.type, KubernetesConstants.KubernetesWorkload.pod, true)) {
try {
await checkPodStatus(kubectl, resource.name);
} catch (ex) {
tl.warning(tl.loc('CouldNotDeterminePodStatus', JSON.stringify(ex)));
kubectl.describe(resource.type, resource.name);
if (environmentUrl)
console.log(tl.loc('EnvironmentLink', environmentUrl));
}
}
if (utils.isEqual(resource.type, KubernetesConstants.DiscoveryAndLoadBalancerResource.service, true)) {
Expand All @@ -35,11 +51,16 @@ export async function checkManifestStability(kubectl: Kubectl, resources: Resour
}
} catch (ex) {
tl.warning(tl.loc('CouldNotDetermineServiceStatus', resource.name, JSON.stringify(ex)));
kubectl.describe(resource.type, resource.name);
if (environmentUrl)
console.log(tl.loc('EnvironmentLink', environmentUrl));
}
}
}

utils.checkForErrors(rolloutStatusResults);
if (rolloutStatusHasErrors) {
throw new Error(tl.loc('RolloutStatusTimedout'));
}
}

export async function checkPodStatus(kubectl: Kubectl, podName: string): Promise<void> {
Expand All @@ -55,20 +76,31 @@ export async function checkPodStatus(kubectl: Kubectl, podName: string): Promise
}
}
podStatus = getPodStatus(kubectl, podName);
const environmentUrl = getEnvironmentUrl();
switch (podStatus.phase) {
case 'Succeeded':
case 'Running':
if (isPodReady(podStatus)) {
console.log(`pod/${podName} is successfully rolled out`);
} else {
kubectl.describe(KubernetesConstants.KubernetesWorkload.pod, podName);
if (environmentUrl)
console.log(tl.loc('EnvironmentLink', environmentUrl));
}
break;
case 'Pending':
if (!isPodReady(podStatus)) {
tl.warning(`pod/${podName} rollout status check timedout`);
kubectl.describe(KubernetesConstants.KubernetesWorkload.pod, podName);
if (environmentUrl)
console.log(tl.loc('EnvironmentLink', environmentUrl));
}
break;
case 'Failed':
tl.error(`pod/${podName} rollout failed`);
kubectl.describe(KubernetesConstants.KubernetesWorkload.pod, podName);
if (environmentUrl)
console.log(tl.loc('EnvironmentLink', environmentUrl));
break;
default:
tl.warning(`pod/${podName} rollout status: ${podStatus.phase}`);
Expand Down Expand Up @@ -124,4 +156,16 @@ function isLoadBalancerIPAssigned(status: any) {
return true;
}
return false;
}

function getEnvironmentUrl(): string {
const environmentId = tl.getVariable('Environment.Id');
let requestUrl = null;
if (environmentId) {
requestUrl = tl.getVariable('System.TeamFoundationCollectionUri') + tl.getVariable('System.TeamProject') + '/_environments/' + tl.getVariable('Environment.Id');
const resourceId = tl.getVariable('Environment.ResourceId');
requestUrl = resourceId ? requestUrl + '/providers/kubernetes/' + resourceId : requestUrl;
Comment on lines +153 to +155
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be done at server side? Where you dump a variable called Environment.ResourceUrl or something like that?

@vithati thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

We can do that enhancement later.

}

return requestUrl;
}
4 changes: 2 additions & 2 deletions Tasks/HelmDeployV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 162,
"Patch": 8
"Minor": 164,
"Patch": 0
},
"demands": [],
"groups": [{
Expand Down
4 changes: 2 additions & 2 deletions Tasks/HelmDeployV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 162,
"Patch": 8
"Minor": 164,
"Patch": 0
},
"demands": [],
"groups": [
Expand Down
22 changes: 10 additions & 12 deletions Tasks/HelmInstallerV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,22 @@
"author": "Microsoft Corporation",
"version": {
"Major": 1,
"Minor": 162,
"Patch": 1
"Minor": 164,
"Patch": 0
},
"preview": true,
"demands": [],
"satisfies": [
"Helm"
],
"groups": [],
"inputs": [
{
"name": "helmVersionToInstall",
"label": "Helm Version Spec",
"type": "string",
"helpMarkDown": "Specify the version of Helm to install.",
"defaultValue": "latest"
}
],
"inputs": [{
"name": "helmVersionToInstall",
"label": "Helm Version Spec",
"type": "string",
"helpMarkDown": "Specify the version of Helm to install.",
"defaultValue": "latest"
}],
"instanceNameFormat": "Install Helm $(helmVersionToInstall)",
"execution": {
"Node": {
Expand All @@ -41,4 +39,4 @@
"NotAValidSemverVersion": "Version not specified in correct format. E.g: 1.8.2, v1.8.2, 2.8.2, v2.8.2.",
"VerifyHelmInstallation": "Verifying helm installation..."
}
}
}
20 changes: 9 additions & 11 deletions Tasks/HelmInstallerV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,22 @@
"author": "Microsoft Corporation",
"version": {
"Major": 1,
"Minor": 162,
"Patch": 1
"Minor": 164,
"Patch": 0
},
"preview": true,
"demands": [],
"satisfies": [
"Helm"
],
"groups": [],
"inputs": [
{
"name": "helmVersionToInstall",
"label": "ms-resource:loc.input.label.helmVersionToInstall",
"type": "string",
"helpMarkDown": "ms-resource:loc.input.help.helmVersionToInstall",
"defaultValue": "latest"
}
],
"inputs": [{
"name": "helmVersionToInstall",
"label": "ms-resource:loc.input.label.helmVersionToInstall",
"type": "string",
"helpMarkDown": "ms-resource:loc.input.help.helmVersionToInstall",
"defaultValue": "latest"
}],
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
"execution": {
"Node": {
Expand Down
22 changes: 10 additions & 12 deletions Tasks/KubectlInstallerV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,21 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 162,
"Patch": 1
"Minor": 164,
"Patch": 0
},
"demands": [],
"satisfies": [
"Kubectl"
],
"groups": [],
"inputs": [
{
"name": "kubectlVersion",
"label": "Kubectl Version Spec",
"type": "string",
"helpMarkDown": "Specify the version of Kubectl to install",
"defaultValue": "latest"
}
],
"inputs": [{
"name": "kubectlVersion",
"label": "Kubectl Version Spec",
"type": "string",
"helpMarkDown": "Specify the version of Kubectl to install",
"defaultValue": "latest"
}],
"instanceNameFormat": "Install Kubectl $(kubectlVersion)",
"execution": {
"Node": {
Expand All @@ -40,4 +38,4 @@
"NotAValidSemverVersion": "Version not specified in correct format. E.g: 1.8.2, v1.8.2, 2.8.2, v2.8.2.",
"VerifyKubectlInstallation": "Verifying kubectl installation..."
}
}
}
20 changes: 9 additions & 11 deletions Tasks/KubectlInstallerV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,21 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 162,
"Patch": 1
"Minor": 164,
"Patch": 0
},
"demands": [],
"satisfies": [
"Kubectl"
],
"groups": [],
"inputs": [
{
"name": "kubectlVersion",
"label": "ms-resource:loc.input.label.kubectlVersion",
"type": "string",
"helpMarkDown": "ms-resource:loc.input.help.kubectlVersion",
"defaultValue": "latest"
}
],
"inputs": [{
"name": "kubectlVersion",
"label": "ms-resource:loc.input.label.kubectlVersion",
"type": "string",
"helpMarkDown": "ms-resource:loc.input.help.kubectlVersion",
"defaultValue": "latest"
}],
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
"execution": {
"Node": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,7 @@
"loc.messages.StableSpecSelectorNotExist": "Resource %s not deployed using SMI canary deployment.",
"loc.messages.InvalidPercentage": "Invalid value for percentage.",
"loc.messages.InvalidBaselineAndCanaryReplicas": "Invalid value for replica count. Enter a value greater than 0.",
"loc.messages.InvalidTimeoutValue": "Invalid value for timeout. Enter a valid number."
"loc.messages.InvalidTimeoutValue": "Invalid value for timeout. Enter a valid number.",
"loc.messages.RolloutStatusTimedout": "Rollout status check failed.",
"loc.messages.EnvironmentLink": "For more information, go to %s"
}
8 changes: 5 additions & 3 deletions Tasks/KubernetesManifestV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 163,
"Patch": 1
"Minor": 164,
"Patch": 0
},
"demands": [],
"groups": [],
Expand Down Expand Up @@ -377,6 +377,8 @@
"StableSpecSelectorNotExist": "Resource %s not deployed using SMI canary deployment.",
"InvalidPercentage": "Invalid value for percentage.",
"InvalidBaselineAndCanaryReplicas": "Invalid value for replica count. Enter a value greater than 0.",
"InvalidTimeoutValue": "Invalid value for timeout. Enter a valid number."
"InvalidTimeoutValue": "Invalid value for timeout. Enter a valid number.",
"RolloutStatusTimedout": "Rollout status check failed.",
"EnvironmentLink": "For more information, go to %s"
}
}
8 changes: 5 additions & 3 deletions Tasks/KubernetesManifestV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 163,
"Patch": 1
"Minor": 164,
"Patch": 0
},
"demands": [],
"groups": [],
Expand Down Expand Up @@ -377,6 +377,8 @@
"StableSpecSelectorNotExist": "ms-resource:loc.messages.StableSpecSelectorNotExist",
"InvalidPercentage": "ms-resource:loc.messages.InvalidPercentage",
"InvalidBaselineAndCanaryReplicas": "ms-resource:loc.messages.InvalidBaselineAndCanaryReplicas",
"InvalidTimeoutValue": "ms-resource:loc.messages.InvalidTimeoutValue"
"InvalidTimeoutValue": "ms-resource:loc.messages.InvalidTimeoutValue",
"RolloutStatusTimedout": "ms-resource:loc.messages.RolloutStatusTimedout",
"EnvironmentLink": "ms-resource:loc.messages.EnvironmentLink"
}
}
Loading