mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-04-14 10:32:22 +08:00
Adding lib changes
This commit is contained in:
parent
d07b08fed0
commit
0451f7cf6e
@ -1,5 +1,5 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
@ -71,6 +71,9 @@ class Kubectl {
|
|||||||
});
|
});
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
executeCommand(customCommand, args) {
|
||||||
|
return args ? this.execute([customCommand, args]) : this.execute([customCommand]);
|
||||||
|
}
|
||||||
delete(args) {
|
delete(args) {
|
||||||
if (typeof args === 'string')
|
if (typeof args === 'string')
|
||||||
return this.execute(['delete', args]);
|
return this.execute(['delete', args]);
|
||||||
|
|||||||
@ -69,3 +69,12 @@ function downloadKubectl(version) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.downloadKubectl = downloadKubectl;
|
exports.downloadKubectl = downloadKubectl;
|
||||||
|
function getTrafficSplitAPIVersion(kubectl) {
|
||||||
|
const result = kubectl.executeCommand('api-versions');
|
||||||
|
const trafficSplitAPIVersion = result.stdout.split('\n').find(version => version.startsWith('split.smi-spec.io'));
|
||||||
|
if (trafficSplitAPIVersion == null || typeof trafficSplitAPIVersion == 'undefined') {
|
||||||
|
throw new Error('UnableToCreateTrafficSplitManifestFile');
|
||||||
|
}
|
||||||
|
return trafficSplitAPIVersion;
|
||||||
|
}
|
||||||
|
exports.getTrafficSplitAPIVersion = getTrafficSplitAPIVersion;
|
||||||
|
|||||||
@ -8,10 +8,12 @@ const TaskInputParameters = require("../../input-parameters");
|
|||||||
const fileHelper = require("../files-helper");
|
const fileHelper = require("../files-helper");
|
||||||
const helper = require("../resource-object-utility");
|
const helper = require("../resource-object-utility");
|
||||||
const utils = require("../manifest-utilities");
|
const utils = require("../manifest-utilities");
|
||||||
|
const kubectlUtils = require("../../kubectl-util");
|
||||||
const canaryDeploymentHelper = require("./canary-deployment-helper");
|
const canaryDeploymentHelper = require("./canary-deployment-helper");
|
||||||
const utility_1 = require("../utility");
|
const utility_1 = require("../utility");
|
||||||
const TRAFFIC_SPLIT_OBJECT_NAME_SUFFIX = '-workflow-rollout';
|
const TRAFFIC_SPLIT_OBJECT_NAME_SUFFIX = '-workflow-rollout';
|
||||||
const TRAFFIC_SPLIT_OBJECT = 'TrafficSplit';
|
const TRAFFIC_SPLIT_OBJECT = 'TrafficSplit';
|
||||||
|
var trafficSplitAPIVersion = null;
|
||||||
function deploySMICanary(kubectl, filePaths) {
|
function deploySMICanary(kubectl, filePaths) {
|
||||||
const newObjectsList = [];
|
const newObjectsList = [];
|
||||||
const canaryReplicaCount = parseInt(TaskInputParameters.baselineAndCanaryReplicas);
|
const canaryReplicaCount = parseInt(TaskInputParameters.baselineAndCanaryReplicas);
|
||||||
@ -80,7 +82,7 @@ function createCanaryService(kubectl, filePaths) {
|
|||||||
core.debug('New stable service object is: ' + JSON.stringify(newStableServiceObject));
|
core.debug('New stable service object is: ' + JSON.stringify(newStableServiceObject));
|
||||||
newObjectsList.push(newStableServiceObject);
|
newObjectsList.push(newStableServiceObject);
|
||||||
core.debug('Creating the traffic object for service: ' + name);
|
core.debug('Creating the traffic object for service: ' + name);
|
||||||
const trafficObject = createTrafficSplitManifestFile(name, 0, 0, 1000);
|
const trafficObject = createTrafficSplitManifestFile(kubectl, name, 0, 0, 1000);
|
||||||
core.debug('Creating the traffic object for service: ' + trafficObject);
|
core.debug('Creating the traffic object for service: ' + trafficObject);
|
||||||
trafficObjectsList.push(trafficObject);
|
trafficObjectsList.push(trafficObject);
|
||||||
}
|
}
|
||||||
@ -100,7 +102,7 @@ function createCanaryService(kubectl, filePaths) {
|
|||||||
}
|
}
|
||||||
if (updateTrafficObject) {
|
if (updateTrafficObject) {
|
||||||
core.debug('Stable service object present so updating the traffic object for service: ' + name);
|
core.debug('Stable service object present so updating the traffic object for service: ' + name);
|
||||||
trafficObjectsList.push(updateTrafficSplitObject(name));
|
trafficObjectsList.push(updateTrafficSplitObject(kubectl, name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,7 +135,7 @@ function adjustTraffic(kubectl, manifestFilePaths, stableWeight, canaryWeight) {
|
|||||||
const name = inputObject.metadata.name;
|
const name = inputObject.metadata.name;
|
||||||
const kind = inputObject.kind;
|
const kind = inputObject.kind;
|
||||||
if (helper.isServiceEntity(kind)) {
|
if (helper.isServiceEntity(kind)) {
|
||||||
trafficSplitManifests.push(createTrafficSplitManifestFile(name, stableWeight, 0, canaryWeight));
|
trafficSplitManifests.push(createTrafficSplitManifestFile(kubectl, name, stableWeight, 0, canaryWeight));
|
||||||
serviceObjects.push(name);
|
serviceObjects.push(name);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -145,24 +147,27 @@ function adjustTraffic(kubectl, manifestFilePaths, stableWeight, canaryWeight) {
|
|||||||
core.debug('serviceObjects:' + serviceObjects.join(',') + ' result:' + result);
|
core.debug('serviceObjects:' + serviceObjects.join(',') + ' result:' + result);
|
||||||
utility_1.checkForErrors([result]);
|
utility_1.checkForErrors([result]);
|
||||||
}
|
}
|
||||||
function updateTrafficSplitObject(serviceName) {
|
function updateTrafficSplitObject(kubectl, serviceName) {
|
||||||
const percentage = parseInt(TaskInputParameters.canaryPercentage) * 10;
|
const percentage = parseInt(TaskInputParameters.canaryPercentage) * 10;
|
||||||
const baselineAndCanaryWeight = percentage / 2;
|
const baselineAndCanaryWeight = percentage / 2;
|
||||||
const stableDeploymentWeight = 1000 - percentage;
|
const stableDeploymentWeight = 1000 - percentage;
|
||||||
core.debug('Creating the traffic object with canary weight: ' + baselineAndCanaryWeight + ',baseling weight: ' + baselineAndCanaryWeight + ',stable: ' + stableDeploymentWeight);
|
core.debug('Creating the traffic object with canary weight: ' + baselineAndCanaryWeight + ',baseling weight: ' + baselineAndCanaryWeight + ',stable: ' + stableDeploymentWeight);
|
||||||
return createTrafficSplitManifestFile(serviceName, stableDeploymentWeight, baselineAndCanaryWeight, baselineAndCanaryWeight);
|
return createTrafficSplitManifestFile(kubectl, serviceName, stableDeploymentWeight, baselineAndCanaryWeight, baselineAndCanaryWeight);
|
||||||
}
|
}
|
||||||
function createTrafficSplitManifestFile(serviceName, stableWeight, baselineWeight, canaryWeight) {
|
function createTrafficSplitManifestFile(kubectl, serviceName, stableWeight, baselineWeight, canaryWeight) {
|
||||||
const smiObjectString = getTrafficSplitObject(serviceName, stableWeight, baselineWeight, canaryWeight);
|
const smiObjectString = getTrafficSplitObject(kubectl, serviceName, stableWeight, baselineWeight, canaryWeight);
|
||||||
const manifestFile = fileHelper.writeManifestToFile(smiObjectString, TRAFFIC_SPLIT_OBJECT, serviceName);
|
const manifestFile = fileHelper.writeManifestToFile(smiObjectString, TRAFFIC_SPLIT_OBJECT, serviceName);
|
||||||
if (!manifestFile) {
|
if (!manifestFile) {
|
||||||
throw new Error('UnableToCreateTrafficSplitManifestFile');
|
throw new Error('UnableToCreateTrafficSplitManifestFile');
|
||||||
}
|
}
|
||||||
return manifestFile;
|
return manifestFile;
|
||||||
}
|
}
|
||||||
function getTrafficSplitObject(name, stableWeight, baselineWeight, canaryWeight) {
|
function getTrafficSplitObject(kubectl, name, stableWeight, baselineWeight, canaryWeight) {
|
||||||
|
if (!trafficSplitAPIVersion) {
|
||||||
|
trafficSplitAPIVersion = kubectlUtils.getTrafficSplitAPIVersion(kubectl);
|
||||||
|
}
|
||||||
const trafficSplitObjectJson = `{
|
const trafficSplitObjectJson = `{
|
||||||
"apiVersion": "split.smi-spec.io/v1alpha1",
|
"apiVersion": "${trafficSplitAPIVersion}",
|
||||||
"kind": "TrafficSplit",
|
"kind": "TrafficSplit",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"name": "%s"
|
"name": "%s"
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import * as fs from 'fs';
|
|||||||
|
|
||||||
import * as toolCache from '@actions/tool-cache';
|
import * as toolCache from '@actions/tool-cache';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import { Kubectl } from 'kubectl-object-model';
|
import { Kubectl } from './kubectl-object-model';
|
||||||
|
|
||||||
const kubectlToolName = 'kubectl';
|
const kubectlToolName = 'kubectl';
|
||||||
const stableKubectlVersion = 'v1.15.0';
|
const stableKubectlVersion = 'v1.15.0';
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user