當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript kubectl-object-model.Kubectl類代碼示例

本文整理匯總了TypeScript中kubernetes-common/kubectl-object-model.Kubectl的典型用法代碼示例。如果您正苦於以下問題:TypeScript Kubectl類的具體用法?TypeScript Kubectl怎麽用?TypeScript Kubectl使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Kubectl類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: deleteResources

export async function deleteResources() {
    let args = TaskInputParameters.args;

    if (args == null || args.length == 0) {
        throw (tl.loc("ArgumentsInputNotSupplied"));
    }

    let kubectl = new Kubectl(await utils.getKubectl(), TaskInputParameters.namespace);
    var result = kubectl.delete(args);
    utils.checkForErrors([result]);
}
開發者ID:Microsoft,項目名稱:vsts-tasks,代碼行數:11,代碼來源:delete.ts

示例2: scale

export async function scale() {
    let kubectl = new Kubectl(await utils.getKubectl(), tl.getInput("namespace", false));
    let kind = tl.getInput("kind", true).toLowerCase();
    let replicas = tl.getInput("replicas", true);
    let name = tl.getInput("name", true);
    let result = kubectl.scale(kind, name, replicas);
    utils.checkForErrors([result]);
    utils.checkForErrors([kubectl.checkRolloutStatus(kind, name)]);
    utils.checkForErrors([kubectl.annotate(kind, name, constants.pipelineAnnotations, true)]);
    utils.checkForErrors(utils.annotateChildPods(kubectl, kind, name, JSON.parse((kubectl.getAllPods()).stdout)));
}
開發者ID:Microsoft,項目名稱:vsts-tasks,代碼行數:11,代碼來源:scale.ts

示例3: annotateResources

function annotateResources(files: string[], kubectl: Kubectl, resourceTypes: Resource[]) {
    let annotateResults: IExecSyncResult[] = [];
    var allPods = JSON.parse((kubectl.getAllPods()).stdout);
    annotateResults.push(kubectl.annotateFiles(files, constants.pipelineAnnotations, true));
    resourceTypes.forEach(resource => {
        if (resource.type.toUpperCase() != models.KubernetesWorkload.Pod.toUpperCase()) {
            utils.annotateChildPods(kubectl, resource.type, resource.name, allPods)
                .forEach(execResult => annotateResults.push(execResult));
        }
    });
    utils.checkForErrors(annotateResults, true);
}
開發者ID:Microsoft,項目名稱:vsts-tasks,代碼行數:12,代碼來源:DeploymentHelper.ts

示例4: createSecret

export async function createSecret() {
    let args = "";
    if (utils.isEqual(TaskInputParameters.secretType, "dockerRegistry", utils.StringComparer.OrdinalIgnoreCase)) {
        args = getDockerRegistrySecretArgs();
    }
    else {
        args = getGenericSecretArgs();
    }

    let kubectl = new Kubectl(await utils.getKubectl(), TaskInputParameters.namespace);
    var result = kubectl.createSecret(args, true, TaskInputParameters.secretName.trim());
    utils.checkForErrors([result]);
}
開發者ID:Microsoft,項目名稱:vsts-tasks,代碼行數:13,代碼來源:createSecret.ts

示例5: deployManifests

function deployManifests(files: string[], kubectl: Kubectl, isCanaryDeploymentStrategy: boolean): string[] {
    let result;
    if (isCanaryDeploymentStrategy) {
        var canaryDeploymentOutput = canaryDeploymentHelper.deployCanary(kubectl, files);
        result = canaryDeploymentOutput.result;
        files = canaryDeploymentOutput.newFilePaths;
    } else {
        result = kubectl.apply(files);
    }
    utils.checkForErrors([result]);
    return files;
}
開發者ID:Microsoft,項目名稱:vsts-tasks,代碼行數:12,代碼來源:DeploymentHelper.ts

示例6: patch

export async function patch() {
    let kubectl = new Kubectl(await utils.getKubectl(), tl.getInput("namespace", false));
    let kind = tl.getInput("kind", false).toLowerCase();
    let name = tl.getInput("name", false);
    let filePath = tl.getInput("resourceFileToPatch", false);
    let strategy = tl.getInput("mergeStrategy", false);
    let patch = tl.getInput("patch", true);
    if (tl.filePathSupplied("resourceFileToPatch") && tl.getInput("resourceToPatch") == "file") {
        kind = "-f";
        name = filePath;
    }

    let result = kubectl.patch(kind, name, patch, strategy);
    utils.checkForErrors([result]);
    let resources = kubectl.getResources(result.stdout, ["deployment", "replicaset", "daemonset", "pod", "statefulset"]);

    resources.forEach(resource => {
        utils.checkForErrors([kubectl.checkRolloutStatus(resource.type, resource.name)]);
        utils.checkForErrors([kubectl.annotate(resource.type, resource.name, constants.pipelineAnnotations, true)]);
        utils.checkForErrors(utils.annotateChildPods(kubectl, resource.type, resource.name, JSON.parse((kubectl.getAllPods()).stdout)));
    });
}
開發者ID:Microsoft,項目名稱:vsts-tasks,代碼行數:22,代碼來源:patch.ts

示例7: deployCanary

export function deployCanary(kubectl: Kubectl, filePaths: string[]) {
    var newObjectsList = [];
    var percentage = parseInt(TaskInputParameters.canaryPercentage);

    filePaths.forEach((filePath: string) => {
        var fileContents = fs.readFileSync(filePath);
        yaml.safeLoadAll(fileContents, function (inputObject) {

            var name = inputObject.metadata.name;
            var kind = inputObject.kind;
            if (helper.isDeploymentEntity(kind)) {
                var existing_canary_object = fetchCanaryResource(kubectl, kind, name);

                if (!!existing_canary_object) {
                    throw (tl.loc("CanaryDeploymentAlreadyExistErrorMessage"));
                }

                tl.debug("Calculating replica count for canary");
                var canaryReplicaCount = calculateReplicaCountForCanary(inputObject, percentage);
                tl.debug("Replica count is " + canaryReplicaCount);
                // Get stable object
                tl.debug("Querying stable object");
                var stable_object = fetchResource(kubectl, kind, name);
                if (!stable_object) {
                    tl.debug("Stable object not found. Creating only canary object");
                    // If stable object not found, create canary deployment.
                    var newCanaryObject = getNewCanaryResource(inputObject, canaryReplicaCount);
                    tl.debug("New canary object is: " + JSON.stringify(newCanaryObject));
                    newObjectsList.push(newCanaryObject);
                } else {
                    tl.debug("Stable object found. Creating canary and baseline objects");
                    // If canary object not found, create canary and baseline object.
                    var newCanaryObject = getNewCanaryResource(inputObject, canaryReplicaCount);
                    var newBaselineObject = getNewBaselineResource(stable_object, canaryReplicaCount);
                    tl.debug("New canary object is: " + JSON.stringify(newCanaryObject));
                    tl.debug("New baseline object is: " + JSON.stringify(newBaselineObject));
                    newObjectsList.push(newCanaryObject);
                    newObjectsList.push(newBaselineObject);
                }
            } else {
                // Updating non deployment entity as it is.
                newObjectsList.push(inputObject);
            }
        });
    });

    var manifestFiles = fileHelper.writeObjectsToFile(newObjectsList);
    var result = kubectl.apply(manifestFiles);
    return { "result": result, "newFilePaths": manifestFiles };
}
開發者ID:Microsoft,項目名稱:vsts-tasks,代碼行數:50,代碼來源:CanaryDeploymentHelper.ts

示例8: fetchResource

function fetchResource(kubectl: Kubectl, kind: string, name: string): object {
    var result = kubectl.getResource(kind, name);

    if (result == null || !!result.stderr) {
        return null;
    }

    if (!!result.stdout) {
        try {
            var resource = JSON.parse(result.stdout);
            UnsetsClusterSpecficDetails(resource);
            return resource;
        } catch (ex) {
            tl.debug("Exception occurred while Parsing " + resource + " in Json object");
            return null;
        }
    }
    return null;
}
開發者ID:Microsoft,項目名稱:vsts-tasks,代碼行數:19,代碼來源:CanaryDeploymentHelper.ts

示例9: annotateChildPods

export function annotateChildPods(kubectl: Kubectl, resourceType: string, resourceName: string, allPods): IExecSyncResult[] {
    let commandExecutionResults = [];
    var owner = resourceName;
    if (resourceType.toLowerCase().indexOf("deployment") > -1) {
        owner = kubectl.getNewReplicaSet(resourceName);
    }

    if (!!allPods && !!allPods["items"] && allPods["items"].length > 0) {
        allPods["items"].forEach((pod) => {
            let owners = pod["metadata"]["ownerReferences"];
            if (!!owners) {
                owners.forEach(ownerRef => {
                    if (ownerRef["name"] == owner) {
                        commandExecutionResults.push(kubectl.annotate("pod", pod["metadata"]["name"], pipelineAnnotations, true));
                    }
                });
            }
        });
    }

    return commandExecutionResults;
}
開發者ID:Microsoft,項目名稱:vsts-tasks,代碼行數:22,代碼來源:utilities.ts

示例10: deleteCanaryDeployment

export function deleteCanaryDeployment(kubectl: Kubectl, manifestFilesPath: string) {

    // get manifest files
    var inputManifestFiles: string[] = utils.getManifestFiles(manifestFilesPath);

    if (inputManifestFiles == null || inputManifestFiles.length == 0) {
        throw (tl.loc("ManifestFileNotFound"));
    }

    // create delete cmd prefix
    let argsPrefix: string;
    argsPrefix = createCanaryObjectsArgumentString(inputManifestFiles);

    // append delete cmd args as suffix (if present)
    let args = utils.getDeleteCmdArgs(argsPrefix, TaskInputParameters.args);
    tl.debug("Delete cmd args : " + args);

    if (!!args && args.length > 0) {
        // run kubectl delete cmd
        var result = kubectl.delete(args);
        utils.checkForErrors([result]);
    }
}
開發者ID:Microsoft,項目名稱:vsts-tasks,代碼行數:23,代碼來源:CanaryDeploymentHelper.ts


注:本文中的kubernetes-common/kubectl-object-model.Kubectl類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。