mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-04-08 22:32:16 +08:00
This reverts commit 1cae8dfe8b6485cf29c5699565ba557165b600b0.
This commit is contained in:
parent
1cae8dfe8b
commit
cafbab6665
@ -1,10 +1,9 @@
|
||||
'use strict';
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
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 step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
|
||||
@ -1,10 +1,9 @@
|
||||
'use strict';
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
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 step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
class KubernetesWorkload {
|
||||
}
|
||||
exports.KubernetesWorkload = KubernetesWorkload;
|
||||
KubernetesWorkload.pod = 'Pod';
|
||||
KubernetesWorkload.replicaset = 'Replicaset';
|
||||
KubernetesWorkload.deployment = 'Deployment';
|
||||
@ -10,17 +9,18 @@ KubernetesWorkload.statefulSet = 'StatefulSet';
|
||||
KubernetesWorkload.daemonSet = 'DaemonSet';
|
||||
KubernetesWorkload.job = 'job';
|
||||
KubernetesWorkload.cronjob = 'cronjob';
|
||||
exports.KubernetesWorkload = KubernetesWorkload;
|
||||
class DiscoveryAndLoadBalancerResource {
|
||||
}
|
||||
exports.DiscoveryAndLoadBalancerResource = DiscoveryAndLoadBalancerResource;
|
||||
DiscoveryAndLoadBalancerResource.service = 'service';
|
||||
DiscoveryAndLoadBalancerResource.ingress = 'ingress';
|
||||
exports.DiscoveryAndLoadBalancerResource = DiscoveryAndLoadBalancerResource;
|
||||
class ServiceTypes {
|
||||
}
|
||||
exports.ServiceTypes = ServiceTypes;
|
||||
ServiceTypes.loadBalancer = 'LoadBalancer';
|
||||
ServiceTypes.nodePort = 'NodePort';
|
||||
ServiceTypes.clusterIP = 'ClusterIP';
|
||||
exports.ServiceTypes = ServiceTypes;
|
||||
exports.deploymentTypes = ['deployment', 'replicaset', 'daemonset', 'pod', 'statefulset'];
|
||||
exports.workloadTypes = ['deployment', 'replicaset', 'daemonset', 'pod', 'statefulset', 'job', 'cronjob'];
|
||||
exports.workloadTypesWithRolloutStatus = ['deployment', 'daemonset', 'statefulset'];
|
||||
|
||||
@ -1,82 +1,82 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
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 step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const os = require("os");
|
||||
const path = require("path");
|
||||
const util = require("util");
|
||||
const fs = require("fs");
|
||||
const toolCache = require("@actions/tool-cache");
|
||||
const core = require("@actions/core");
|
||||
const kubectlToolName = 'kubectl';
|
||||
const stableKubectlVersion = 'v1.15.0';
|
||||
const stableVersionUrl = 'https://storage.googleapis.com/kubernetes-release/release/stable.txt';
|
||||
const trafficSplitAPIVersionPrefix = 'split.smi-spec.io';
|
||||
function getExecutableExtension() {
|
||||
if (os.type().match(/^Win/)) {
|
||||
return '.exe';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
function getkubectlDownloadURL(version) {
|
||||
switch (os.type()) {
|
||||
case 'Linux':
|
||||
return util.format('https://storage.googleapis.com/kubernetes-release/release/%s/bin/linux/amd64/kubectl', version);
|
||||
case 'Darwin':
|
||||
return util.format('https://storage.googleapis.com/kubernetes-release/release/%s/bin/darwin/amd64/kubectl', version);
|
||||
case 'Windows_NT':
|
||||
default:
|
||||
return util.format('https://storage.googleapis.com/kubernetes-release/release/%s/bin/windows/amd64/kubectl.exe', version);
|
||||
}
|
||||
}
|
||||
function getStableKubectlVersion() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return toolCache.downloadTool(stableVersionUrl).then((downloadPath) => {
|
||||
let version = fs.readFileSync(downloadPath, 'utf8').toString().trim();
|
||||
if (!version) {
|
||||
version = stableKubectlVersion;
|
||||
}
|
||||
return version;
|
||||
}, (error) => {
|
||||
core.debug(error);
|
||||
core.warning('GetStableVersionFailed');
|
||||
return stableKubectlVersion;
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.getStableKubectlVersion = getStableKubectlVersion;
|
||||
function downloadKubectl(version) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let cachedToolpath = toolCache.find(kubectlToolName, version);
|
||||
let kubectlDownloadPath = '';
|
||||
if (!cachedToolpath) {
|
||||
try {
|
||||
kubectlDownloadPath = yield toolCache.downloadTool(getkubectlDownloadURL(version));
|
||||
}
|
||||
catch (exception) {
|
||||
throw new Error('DownloadKubectlFailed');
|
||||
}
|
||||
cachedToolpath = yield toolCache.cacheFile(kubectlDownloadPath, kubectlToolName + getExecutableExtension(), kubectlToolName, version);
|
||||
}
|
||||
const kubectlPath = path.join(cachedToolpath, kubectlToolName + getExecutableExtension());
|
||||
fs.chmodSync(kubectlPath, '777');
|
||||
return kubectlPath;
|
||||
});
|
||||
}
|
||||
exports.downloadKubectl = downloadKubectl;
|
||||
function getTrafficSplitAPIVersion(kubectl) {
|
||||
const result = kubectl.executeCommand('api-versions');
|
||||
const trafficSplitAPIVersion = result.stdout.split('\n').find(version => version.startsWith(trafficSplitAPIVersionPrefix));
|
||||
if (!trafficSplitAPIVersion) {
|
||||
throw new Error('UnableToCreateTrafficSplitManifestFile');
|
||||
}
|
||||
return trafficSplitAPIVersion;
|
||||
}
|
||||
exports.getTrafficSplitAPIVersion = getTrafficSplitAPIVersion;
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
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 step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const os = require("os");
|
||||
const path = require("path");
|
||||
const util = require("util");
|
||||
const fs = require("fs");
|
||||
const toolCache = require("@actions/tool-cache");
|
||||
const core = require("@actions/core");
|
||||
const kubectlToolName = 'kubectl';
|
||||
const stableKubectlVersion = 'v1.15.0';
|
||||
const stableVersionUrl = 'https://storage.googleapis.com/kubernetes-release/release/stable.txt';
|
||||
const trafficSplitAPIVersionPrefix = 'split.smi-spec.io';
|
||||
function getExecutableExtension() {
|
||||
if (os.type().match(/^Win/)) {
|
||||
return '.exe';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
function getkubectlDownloadURL(version) {
|
||||
switch (os.type()) {
|
||||
case 'Linux':
|
||||
return util.format('https://storage.googleapis.com/kubernetes-release/release/%s/bin/linux/amd64/kubectl', version);
|
||||
case 'Darwin':
|
||||
return util.format('https://storage.googleapis.com/kubernetes-release/release/%s/bin/darwin/amd64/kubectl', version);
|
||||
case 'Windows_NT':
|
||||
default:
|
||||
return util.format('https://storage.googleapis.com/kubernetes-release/release/%s/bin/windows/amd64/kubectl.exe', version);
|
||||
}
|
||||
}
|
||||
function getStableKubectlVersion() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return toolCache.downloadTool(stableVersionUrl).then((downloadPath) => {
|
||||
let version = fs.readFileSync(downloadPath, 'utf8').toString().trim();
|
||||
if (!version) {
|
||||
version = stableKubectlVersion;
|
||||
}
|
||||
return version;
|
||||
}, (error) => {
|
||||
core.debug(error);
|
||||
core.warning('GetStableVersionFailed');
|
||||
return stableKubectlVersion;
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.getStableKubectlVersion = getStableKubectlVersion;
|
||||
function downloadKubectl(version) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let cachedToolpath = toolCache.find(kubectlToolName, version);
|
||||
let kubectlDownloadPath = '';
|
||||
if (!cachedToolpath) {
|
||||
try {
|
||||
kubectlDownloadPath = yield toolCache.downloadTool(getkubectlDownloadURL(version));
|
||||
}
|
||||
catch (exception) {
|
||||
throw new Error('DownloadKubectlFailed');
|
||||
}
|
||||
cachedToolpath = yield toolCache.cacheFile(kubectlDownloadPath, kubectlToolName + getExecutableExtension(), kubectlToolName, version);
|
||||
}
|
||||
const kubectlPath = path.join(cachedToolpath, kubectlToolName + getExecutableExtension());
|
||||
fs.chmodSync(kubectlPath, '777');
|
||||
return kubectlPath;
|
||||
});
|
||||
}
|
||||
exports.downloadKubectl = downloadKubectl;
|
||||
function getTrafficSplitAPIVersion(kubectl) {
|
||||
const result = kubectl.executeCommand('api-versions');
|
||||
const trafficSplitAPIVersion = result.stdout.split('\n').find(version => version.startsWith(trafficSplitAPIVersionPrefix));
|
||||
if (!trafficSplitAPIVersion) {
|
||||
throw new Error('UnableToCreateTrafficSplitManifestFile');
|
||||
}
|
||||
return trafficSplitAPIVersion;
|
||||
}
|
||||
exports.getTrafficSplitAPIVersion = getTrafficSplitAPIVersion;
|
||||
|
||||
@ -87,61 +87,6 @@ function updateImagePullSecrets(inputObject, newImagePullSecrets, override) {
|
||||
setImagePullSecrets(inputObject, existingImagePullSecretObjects);
|
||||
}
|
||||
exports.updateImagePullSecrets = updateImagePullSecrets;
|
||||
function updateImageDetails(inputObject, containers) {
|
||||
if (!inputObject || !inputObject.spec || !containers) {
|
||||
return;
|
||||
}
|
||||
if (inputObject.spec.template && !!inputObject.spec.template.spec) {
|
||||
if (inputObject.spec.template.spec.containers) {
|
||||
updateContainers(inputObject.spec.template.spec.containers, containers);
|
||||
}
|
||||
if (inputObject.spec.template.spec.initContainers) {
|
||||
updateContainers(inputObject.spec.template.spec.initContainers, containers);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (inputObject.spec.jobTemplate && inputObject.spec.jobTemplate.spec && inputObject.spec.jobTemplate.spec.template && inputObject.spec.jobTemplate.spec.template.spec) {
|
||||
if (inputObject.spec.jobTemplate.spec.template.spec.containers) {
|
||||
updateContainers(inputObject.spec.jobTemplate.spec.template.spec.containers, containers);
|
||||
}
|
||||
if (inputObject.spec.jobTemplate.spec.template.spec.initContainers) {
|
||||
updateContainers(inputObject.spec.jobTemplate.spec.template.spec.initContainers, containers);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (inputObject.spec.containers) {
|
||||
updateContainers(inputObject.spec.containers, containers);
|
||||
}
|
||||
if (inputObject.spec.initContainers) {
|
||||
updateContainers(inputObject.spec.initContainers, containers);
|
||||
}
|
||||
}
|
||||
exports.updateImageDetails = updateImageDetails;
|
||||
function updateContainers(containers, images) {
|
||||
if (!containers || containers.length === 0) {
|
||||
return containers;
|
||||
}
|
||||
containers.forEach((container) => {
|
||||
const imageName = extractImageName(container.image.trim());
|
||||
images.forEach(image => {
|
||||
if (extractImageName(image) === imageName) {
|
||||
container.image = image;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
function extractImageName(imageName) {
|
||||
let img = '';
|
||||
if (imageName.indexOf('/') > 0) {
|
||||
const registry = imageName.substring(0, imageName.indexOf('/'));
|
||||
const imgName = imageName.substring(imageName.indexOf('/') + 1).split(':')[0];
|
||||
img = `${registry}/${imgName}`;
|
||||
}
|
||||
else {
|
||||
img = imageName.split(':')[0];
|
||||
}
|
||||
return img;
|
||||
}
|
||||
function updateSpecLabels(inputObject, newLabels, override) {
|
||||
if (!inputObject) {
|
||||
throw ('NullInputObject');
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
'use strict';
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
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 step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const core = require("@actions/core");
|
||||
const yaml = require("js-yaml");
|
||||
const canaryDeploymentHelper = require("./canary-deployment-helper");
|
||||
@ -20,7 +20,6 @@ const fileHelper = require("../files-helper");
|
||||
const utils = require("../manifest-utilities");
|
||||
const KubernetesManifestUtility = require("../manifest-stability-utility");
|
||||
const KubernetesConstants = require("../../constants");
|
||||
const string_comparison_1 = require("./../string-comparison");
|
||||
const pod_canary_deployment_helper_1 = require("./pod-canary-deployment-helper");
|
||||
const smi_canary_deployment_helper_1 = require("./smi-canary-deployment-helper");
|
||||
const utility_1 = require("../utility");
|
||||
@ -29,7 +28,9 @@ function deploy(kubectl, manifestFilePaths, deploymentStrategy) {
|
||||
// get manifest files
|
||||
let inputManifestFiles = getManifestFiles(manifestFilePaths);
|
||||
// artifact substitution
|
||||
inputManifestFiles = updateResourceObjects(inputManifestFiles, TaskInputParameters.containers, TaskInputParameters.imagePullSecrets);
|
||||
inputManifestFiles = updateContainerImagesInManifestFiles(inputManifestFiles, TaskInputParameters.containers);
|
||||
// imagePullSecrets addition
|
||||
inputManifestFiles = updateImagePullSecretsInManifestFiles(inputManifestFiles, TaskInputParameters.imagePullSecrets);
|
||||
// deployment
|
||||
const deployedManifestFiles = deployManifests(inputManifestFiles, kubectl, isCanaryDeploymentStrategy(deploymentStrategy));
|
||||
// check manifest stability
|
||||
@ -100,37 +101,49 @@ function checkManifestStability(kubectl, resources) {
|
||||
yield KubernetesManifestUtility.checkManifestStability(kubectl, resources);
|
||||
});
|
||||
}
|
||||
function updateResourceObjects(filePaths, imagePullSecrets, containers) {
|
||||
const newObjectsList = [];
|
||||
const updateResourceObject = (inputObject) => {
|
||||
if (!!imagePullSecrets && imagePullSecrets.length > 0) {
|
||||
KubernetesObjectUtility.updateImagePullSecrets(inputObject, imagePullSecrets, false);
|
||||
}
|
||||
if (!!containers && containers.length > 0) {
|
||||
KubernetesObjectUtility.updateImageDetails(inputObject, containers);
|
||||
}
|
||||
};
|
||||
filePaths.forEach((filePath) => {
|
||||
const fileContents = fs.readFileSync(filePath).toString();
|
||||
yaml.safeLoadAll(fileContents, function (inputObject) {
|
||||
if (inputObject && inputObject.kind) {
|
||||
const kind = inputObject.kind;
|
||||
if (KubernetesObjectUtility.isWorkloadEntity(kind)) {
|
||||
updateResourceObject(inputObject);
|
||||
function updateContainerImagesInManifestFiles(filePaths, containers) {
|
||||
if (!!containers && containers.length > 0) {
|
||||
const newFilePaths = [];
|
||||
const tempDirectory = fileHelper.getTempDirectory();
|
||||
filePaths.forEach((filePath) => {
|
||||
let contents = fs.readFileSync(filePath).toString();
|
||||
containers.forEach((container) => {
|
||||
let imageName = container.split(':')[0];
|
||||
if (imageName.indexOf('@') > 0) {
|
||||
imageName = imageName.split('@')[0];
|
||||
}
|
||||
else if (string_comparison_1.isEqual(kind, 'list', string_comparison_1.StringComparer.OrdinalIgnoreCase)) {
|
||||
let items = inputObject.items;
|
||||
if (items.length > 0) {
|
||||
items.forEach((item) => updateResourceObject(item));
|
||||
}
|
||||
if (contents.indexOf(imageName) > 0) {
|
||||
contents = utils.substituteImageNameInSpecFile(contents, imageName, container);
|
||||
}
|
||||
newObjectsList.push(inputObject);
|
||||
}
|
||||
});
|
||||
const fileName = path.join(tempDirectory, path.basename(filePath));
|
||||
fs.writeFileSync(path.join(fileName), contents);
|
||||
newFilePaths.push(fileName);
|
||||
});
|
||||
});
|
||||
core.debug('New K8s objects after addin imagePullSecrets are :' + JSON.stringify(newObjectsList));
|
||||
const newFilePaths = fileHelper.writeObjectsToFile(newObjectsList);
|
||||
return newFilePaths;
|
||||
return newFilePaths;
|
||||
}
|
||||
return filePaths;
|
||||
}
|
||||
function updateImagePullSecretsInManifestFiles(filePaths, imagePullSecrets) {
|
||||
if (!!imagePullSecrets && imagePullSecrets.length > 0) {
|
||||
const newObjectsList = [];
|
||||
filePaths.forEach((filePath) => {
|
||||
const fileContents = fs.readFileSync(filePath).toString();
|
||||
yaml.safeLoadAll(fileContents, function (inputObject) {
|
||||
if (!!inputObject && !!inputObject.kind) {
|
||||
const kind = inputObject.kind;
|
||||
if (KubernetesObjectUtility.isWorkloadEntity(kind)) {
|
||||
KubernetesObjectUtility.updateImagePullSecrets(inputObject, imagePullSecrets, false);
|
||||
}
|
||||
newObjectsList.push(inputObject);
|
||||
}
|
||||
});
|
||||
});
|
||||
core.debug('New K8s objects after addin imagePullSecrets are :' + JSON.stringify(newObjectsList));
|
||||
const newFilePaths = fileHelper.writeObjectsToFile(newObjectsList);
|
||||
return newFilePaths;
|
||||
}
|
||||
return filePaths;
|
||||
}
|
||||
function isCanaryDeploymentStrategy(deploymentStrategy) {
|
||||
return deploymentStrategy != null && deploymentStrategy.toUpperCase() === canaryDeploymentHelper.CANARY_DEPLOYMENT_STRATEGY.toUpperCase();
|
||||
|
||||
@ -102,67 +102,6 @@ export function updateImagePullSecrets(inputObject: any, newImagePullSecrets: st
|
||||
setImagePullSecrets(inputObject, existingImagePullSecretObjects);
|
||||
}
|
||||
|
||||
export function updateImageDetails(inputObject: any, containers: string[]) {
|
||||
if (!inputObject || !inputObject.spec || !containers) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (inputObject.spec.template && !!inputObject.spec.template.spec) {
|
||||
if (inputObject.spec.template.spec.containers) {
|
||||
updateContainers(inputObject.spec.template.spec.containers, containers);
|
||||
}
|
||||
if (inputObject.spec.template.spec.initContainers) {
|
||||
updateContainers(inputObject.spec.template.spec.initContainers, containers);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (inputObject.spec.jobTemplate && inputObject.spec.jobTemplate.spec && inputObject.spec.jobTemplate.spec.template && inputObject.spec.jobTemplate.spec.template.spec) {
|
||||
if (inputObject.spec.jobTemplate.spec.template.spec.containers) {
|
||||
updateContainers(inputObject.spec.jobTemplate.spec.template.spec.containers, containers);
|
||||
}
|
||||
|
||||
if (inputObject.spec.jobTemplate.spec.template.spec.initContainers) {
|
||||
updateContainers(inputObject.spec.jobTemplate.spec.template.spec.initContainers, containers);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (inputObject.spec.containers) {
|
||||
updateContainers(inputObject.spec.containers, containers);
|
||||
}
|
||||
|
||||
if (inputObject.spec.initContainers) {
|
||||
updateContainers(inputObject.spec.initContainers, containers);
|
||||
}
|
||||
}
|
||||
|
||||
function updateContainers(containers: any[], images: string[]) {
|
||||
if (!containers || containers.length === 0) {
|
||||
return containers;
|
||||
}
|
||||
containers.forEach((container) => {
|
||||
const imageName: string = extractImageName(container.image.trim());
|
||||
images.forEach(image => {
|
||||
if (extractImageName(image) === imageName) {
|
||||
container.image = image;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function extractImageName(imageName) {
|
||||
let img = '';
|
||||
if (imageName.indexOf('/') > 0) {
|
||||
const registry = imageName.substring(0, imageName.indexOf('/'));
|
||||
const imgName = imageName.substring(imageName.indexOf('/') + 1).split(':')[0];
|
||||
img = `${registry}/${imgName}`;
|
||||
} else {
|
||||
img = imageName.split(':')[0];
|
||||
}
|
||||
return img;
|
||||
}
|
||||
|
||||
export function updateSpecLabels(inputObject: any, newLabels: Map<string, string>, override: boolean) {
|
||||
if (!inputObject) {
|
||||
throw ('NullInputObject');
|
||||
|
||||
@ -13,7 +13,6 @@ import * as utils from '../manifest-utilities';
|
||||
import * as KubernetesManifestUtility from '../manifest-stability-utility';
|
||||
import * as KubernetesConstants from '../../constants';
|
||||
import { Kubectl, Resource } from '../../kubectl-object-model';
|
||||
import { StringComparer, isEqual } from './../string-comparison';
|
||||
|
||||
import { deployPodCanary } from './pod-canary-deployment-helper';
|
||||
import { deploySMICanary } from './smi-canary-deployment-helper';
|
||||
@ -26,7 +25,10 @@ export async function deploy(kubectl: Kubectl, manifestFilePaths: string[], depl
|
||||
let inputManifestFiles: string[] = getManifestFiles(manifestFilePaths);
|
||||
|
||||
// artifact substitution
|
||||
inputManifestFiles = updateResourceObjects(inputManifestFiles, TaskInputParameters.containers, TaskInputParameters.imagePullSecrets);
|
||||
inputManifestFiles = updateContainerImagesInManifestFiles(inputManifestFiles, TaskInputParameters.containers);
|
||||
|
||||
// imagePullSecrets addition
|
||||
inputManifestFiles = updateImagePullSecretsInManifestFiles(inputManifestFiles, TaskInputParameters.imagePullSecrets);
|
||||
|
||||
// deployment
|
||||
const deployedManifestFiles = deployManifests(inputManifestFiles, kubectl, isCanaryDeploymentStrategy(deploymentStrategy));
|
||||
@ -102,37 +104,56 @@ async function checkManifestStability(kubectl: Kubectl, resources: Resource[]):
|
||||
await KubernetesManifestUtility.checkManifestStability(kubectl, resources);
|
||||
}
|
||||
|
||||
function updateResourceObjects(filePaths: string[], imagePullSecrets: string[], containers: string[]): string[] {
|
||||
const newObjectsList = [];
|
||||
const updateResourceObject = (inputObject) => {
|
||||
if (!!imagePullSecrets && imagePullSecrets.length > 0) {
|
||||
KubernetesObjectUtility.updateImagePullSecrets(inputObject, imagePullSecrets, false);
|
||||
}
|
||||
if (!!containers && containers.length > 0) {
|
||||
KubernetesObjectUtility.updateImageDetails(inputObject, containers);
|
||||
}
|
||||
}
|
||||
filePaths.forEach((filePath: string) => {
|
||||
const fileContents = fs.readFileSync(filePath).toString();
|
||||
yaml.safeLoadAll(fileContents, function (inputObject: any) {
|
||||
if (inputObject && inputObject.kind) {
|
||||
const kind = inputObject.kind;
|
||||
if (KubernetesObjectUtility.isWorkloadEntity(kind)) {
|
||||
updateResourceObject(inputObject);
|
||||
function updateContainerImagesInManifestFiles(filePaths: string[], containers: string[]): string[] {
|
||||
if (!!containers && containers.length > 0) {
|
||||
const newFilePaths = [];
|
||||
const tempDirectory = fileHelper.getTempDirectory();
|
||||
filePaths.forEach((filePath: string) => {
|
||||
let contents = fs.readFileSync(filePath).toString();
|
||||
containers.forEach((container: string) => {
|
||||
let imageName = container.split(':')[0];
|
||||
if (imageName.indexOf('@') > 0) {
|
||||
imageName = imageName.split('@')[0];
|
||||
}
|
||||
else if (isEqual(kind, 'list', StringComparer.OrdinalIgnoreCase)) {
|
||||
let items = inputObject.items;
|
||||
if (items.length > 0) {
|
||||
items.forEach((item) => updateResourceObject(item));
|
||||
}
|
||||
if (contents.indexOf(imageName) > 0) {
|
||||
contents = utils.substituteImageNameInSpecFile(contents, imageName, container);
|
||||
}
|
||||
newObjectsList.push(inputObject);
|
||||
}
|
||||
});
|
||||
|
||||
const fileName = path.join(tempDirectory, path.basename(filePath));
|
||||
fs.writeFileSync(
|
||||
path.join(fileName),
|
||||
contents
|
||||
);
|
||||
newFilePaths.push(fileName);
|
||||
});
|
||||
});
|
||||
core.debug('New K8s objects after addin imagePullSecrets are :' + JSON.stringify(newObjectsList));
|
||||
const newFilePaths = fileHelper.writeObjectsToFile(newObjectsList);
|
||||
return newFilePaths;
|
||||
|
||||
return newFilePaths;
|
||||
}
|
||||
|
||||
return filePaths;
|
||||
}
|
||||
|
||||
function updateImagePullSecretsInManifestFiles(filePaths: string[], imagePullSecrets: string[]): string[] {
|
||||
if (!!imagePullSecrets && imagePullSecrets.length > 0) {
|
||||
const newObjectsList = [];
|
||||
filePaths.forEach((filePath: string) => {
|
||||
const fileContents = fs.readFileSync(filePath).toString();
|
||||
yaml.safeLoadAll(fileContents, function (inputObject: any) {
|
||||
if (!!inputObject && !!inputObject.kind) {
|
||||
const kind = inputObject.kind;
|
||||
if (KubernetesObjectUtility.isWorkloadEntity(kind)) {
|
||||
KubernetesObjectUtility.updateImagePullSecrets(inputObject, imagePullSecrets, false);
|
||||
}
|
||||
newObjectsList.push(inputObject);
|
||||
}
|
||||
});
|
||||
});
|
||||
core.debug('New K8s objects after addin imagePullSecrets are :' + JSON.stringify(newObjectsList));
|
||||
const newFilePaths = fileHelper.writeObjectsToFile(newObjectsList);
|
||||
return newFilePaths;
|
||||
}
|
||||
return filePaths;
|
||||
}
|
||||
|
||||
function isCanaryDeploymentStrategy(deploymentStrategy: string): boolean {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user