-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Changes from 9 commits
713791f
4328100
c6c463f
aced271
4261897
fede1f6
e48704b
e26f854
cef67a1
cedfad3
4d9a939
de33cda
c8385c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
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)) { | ||
|
@@ -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> { | ||
|
@@ -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}`); | ||
|
@@ -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
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. Can this be done at server side? Where you dump a variable called @vithati thoughts? 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. We can do that enhancement later. |
||
} | ||
|
||
return requestUrl; | ||
} |
There was a problem hiding this comment.
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.