-
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
[KubernetesManifest] Check manifest stability for Pods #10684
Changes from all commits
827236e
d7b60ad
bf96147
04f5acd
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 |
---|---|---|
|
@@ -13,6 +13,7 @@ import * as fileHelper from '../utils/FileHelper'; | |
import * as utils from '../utils/utilities'; | ||
import { IExecSyncResult } from 'azure-pipelines-task-lib/toolrunner'; | ||
import { Kubectl, Resource } from 'kubernetes-common-v2/kubectl-object-model'; | ||
import { isEqual, StringComparer } from './StringComparison'; | ||
|
||
export function deploy(kubectl: Kubectl, manifestFilePaths: string[], deploymentStrategy: string) { | ||
|
||
|
@@ -40,7 +41,7 @@ function getManifestFiles(manifestFilePaths: string[]): string[] { | |
const files: string[] = utils.getManifestFiles(manifestFilePaths); | ||
|
||
if (files == null || files.length === 0) { | ||
throw (tl.loc('ManifestFileNotFound')); | ||
throw (tl.loc('ManifestFileNotFound', manifestFilePaths)); | ||
} | ||
|
||
return files; | ||
|
@@ -65,6 +66,13 @@ function checkManifestStability(kubectl: Kubectl, resourceTypes: Resource[]) { | |
if (models.recognizedWorkloadTypesWithRolloutStatus.indexOf(resource.type.toLowerCase()) >= 0) { | ||
rolloutStatusResults.push(kubectl.checkRolloutStatus(resource.type, resource.name)); | ||
} | ||
if (isEqual(resource.type, constants.KubernetesWorkload.Pod, StringComparer.OrdinalIgnoreCase)) { | ||
thesattiraju marked this conversation as resolved.
Show resolved
Hide resolved
|
||
try { | ||
checkPodStatus(kubectl, resource.name); | ||
} catch (ex) { | ||
tl.warning(tl.loc('CouldNotDeterminePodStatus', JSON.stringify(ex))); | ||
} | ||
} | ||
}); | ||
utils.checkForErrors(rolloutStatusResults); | ||
} | ||
|
@@ -137,3 +145,59 @@ function updateImagePullSecretsInManifestFiles(filePaths: string[], imagePullSec | |
function isCanaryDeploymentStrategy(deploymentStrategy: string): boolean { | ||
return deploymentStrategy != null && deploymentStrategy.toUpperCase() == canaryDeploymentHelper.CANARY_DEPLOYMENT_STRATEGY.toUpperCase(); | ||
} | ||
|
||
function checkPodStatus(kubectl: Kubectl, podName: string) { | ||
const startTime = new Date(); | ||
const timeOut = 5 * 60 * 1000; // Timeout 5 min | ||
let currentTime = new Date(); | ||
let podStatus; | ||
while (currentTime.getTime() - startTime.getTime() < timeOut) { | ||
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 is busy loop. Can you add sleep and Instead of time use Iteration. |
||
tl.debug(`Polling for pod status: ${podName}`); | ||
podStatus = getPodStatus(kubectl, podName); | ||
if (podStatus.phase && podStatus.phase !== 'Pending') { | ||
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. In case of 'Unknown' status do you want to retry? |
||
break; | ||
} | ||
currentTime = new Date(); | ||
} | ||
podStatus = getPodStatus(kubectl, podName); | ||
switch (podStatus.phase) { | ||
case 'Succeeded': | ||
thesattiraju marked this conversation as resolved.
Show resolved
Hide resolved
|
||
case 'Running': | ||
if (isPodReady(podStatus)) { | ||
console.log(`pod/${podName} is successfully rolled out`); | ||
} | ||
thesattiraju marked this conversation as resolved.
Show resolved
Hide resolved
|
||
break; | ||
case 'Pending': | ||
if (!isPodReady(podStatus)) { | ||
tl.warning(`pod/${podName} rollout status check timedout`); | ||
} | ||
break; | ||
case 'Failed': | ||
tl.error(`pod/${podName} rollout failed`); | ||
break; | ||
default: | ||
tl.warning(`pod/${podName} rollout status: ${podStatus.phase}`); | ||
} | ||
} | ||
|
||
function getPodStatus(kubectl: Kubectl, podName: string): any { | ||
const podResult = kubectl.getResource('pod', podName); | ||
utils.checkForErrors([podResult]); | ||
const podStatus = JSON.parse(podResult.stdout).status; | ||
tl.debug(`Pod Status: ${JSON.stringify(podStatus)}`); | ||
return podStatus; | ||
} | ||
|
||
function isPodReady(podStatus: any): boolean { | ||
let allContainersAreReady = true; | ||
podStatus.containerStatuses.forEach(container => { | ||
if (container.ready === false) { | ||
console.log(`'${container.name}' status: ${JSON.stringify(container.state)}`); | ||
allContainersAreReady = false; | ||
} | ||
}); | ||
if (!allContainersAreReady) { | ||
tl.warning(tl.loc('AllContainersNotInReadyState')); | ||
} | ||
return allContainersAreReady; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
"version": { | ||
"Major": 0, | ||
"Minor": 154, | ||
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. 0.155.0 |
||
"Patch": 4 | ||
"Patch": 5 | ||
}, | ||
"demands": [], | ||
"groups": [], | ||
|
@@ -310,6 +310,8 @@ | |
"NullInputObjectMetadata": "ms-resource:loc.messages.NullInputObjectMetadata", | ||
"CanaryDeploymentAlreadyExistErrorMessage": "ms-resource:loc.messages.CanaryDeploymentAlreadyExistErrorMessage", | ||
"InvalidRejectActionDeploymentStrategy": "ms-resource:loc.messages.InvalidRejectActionDeploymentStrategy", | ||
"InvalidPromotetActionDeploymentStrategy": "ms-resource:loc.messages.InvalidPromotetActionDeploymentStrategy" | ||
"InvalidPromotetActionDeploymentStrategy": "ms-resource:loc.messages.InvalidPromotetActionDeploymentStrategy", | ||
"AllContainersNotInReadyState": "ms-resource:loc.messages.AllContainersNotInReadyState", | ||
"CouldNotDeterminePodStatus": "ms-resource:loc.messages.CouldNotDeterminePodStatus" | ||
} | ||
} |
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.
End with '.'. Add for below messages.