mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-04-12 01:15:09 +08:00
This reverts commit 1cae8dfe8b6485cf29c5699565ba557165b600b0.
This commit is contained in:
parent
1cae8dfe8b
commit
cafbab6665
@ -1,10 +1,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
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) {
|
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); } }
|
||||||
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());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,10 +1,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
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) {
|
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); } }
|
||||||
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());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
class KubernetesWorkload {
|
class KubernetesWorkload {
|
||||||
}
|
}
|
||||||
exports.KubernetesWorkload = KubernetesWorkload;
|
|
||||||
KubernetesWorkload.pod = 'Pod';
|
KubernetesWorkload.pod = 'Pod';
|
||||||
KubernetesWorkload.replicaset = 'Replicaset';
|
KubernetesWorkload.replicaset = 'Replicaset';
|
||||||
KubernetesWorkload.deployment = 'Deployment';
|
KubernetesWorkload.deployment = 'Deployment';
|
||||||
@ -10,17 +9,18 @@ KubernetesWorkload.statefulSet = 'StatefulSet';
|
|||||||
KubernetesWorkload.daemonSet = 'DaemonSet';
|
KubernetesWorkload.daemonSet = 'DaemonSet';
|
||||||
KubernetesWorkload.job = 'job';
|
KubernetesWorkload.job = 'job';
|
||||||
KubernetesWorkload.cronjob = 'cronjob';
|
KubernetesWorkload.cronjob = 'cronjob';
|
||||||
|
exports.KubernetesWorkload = KubernetesWorkload;
|
||||||
class DiscoveryAndLoadBalancerResource {
|
class DiscoveryAndLoadBalancerResource {
|
||||||
}
|
}
|
||||||
exports.DiscoveryAndLoadBalancerResource = DiscoveryAndLoadBalancerResource;
|
|
||||||
DiscoveryAndLoadBalancerResource.service = 'service';
|
DiscoveryAndLoadBalancerResource.service = 'service';
|
||||||
DiscoveryAndLoadBalancerResource.ingress = 'ingress';
|
DiscoveryAndLoadBalancerResource.ingress = 'ingress';
|
||||||
|
exports.DiscoveryAndLoadBalancerResource = DiscoveryAndLoadBalancerResource;
|
||||||
class ServiceTypes {
|
class ServiceTypes {
|
||||||
}
|
}
|
||||||
exports.ServiceTypes = ServiceTypes;
|
|
||||||
ServiceTypes.loadBalancer = 'LoadBalancer';
|
ServiceTypes.loadBalancer = 'LoadBalancer';
|
||||||
ServiceTypes.nodePort = 'NodePort';
|
ServiceTypes.nodePort = 'NodePort';
|
||||||
ServiceTypes.clusterIP = 'ClusterIP';
|
ServiceTypes.clusterIP = 'ClusterIP';
|
||||||
|
exports.ServiceTypes = ServiceTypes;
|
||||||
exports.deploymentTypes = ['deployment', 'replicaset', 'daemonset', 'pod', 'statefulset'];
|
exports.deploymentTypes = ['deployment', 'replicaset', 'daemonset', 'pod', 'statefulset'];
|
||||||
exports.workloadTypes = ['deployment', 'replicaset', 'daemonset', 'pod', 'statefulset', 'job', 'cronjob'];
|
exports.workloadTypes = ['deployment', 'replicaset', 'daemonset', 'pod', 'statefulset', 'job', 'cronjob'];
|
||||||
exports.workloadTypesWithRolloutStatus = ['deployment', 'daemonset', 'statefulset'];
|
exports.workloadTypesWithRolloutStatus = ['deployment', 'daemonset', 'statefulset'];
|
||||||
|
|||||||
@ -87,61 +87,6 @@ function updateImagePullSecrets(inputObject, newImagePullSecrets, override) {
|
|||||||
setImagePullSecrets(inputObject, existingImagePullSecretObjects);
|
setImagePullSecrets(inputObject, existingImagePullSecretObjects);
|
||||||
}
|
}
|
||||||
exports.updateImagePullSecrets = updateImagePullSecrets;
|
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) {
|
function updateSpecLabels(inputObject, newLabels, override) {
|
||||||
if (!inputObject) {
|
if (!inputObject) {
|
||||||
throw ('NullInputObject');
|
throw ('NullInputObject');
|
||||||
|
|||||||
@ -1,15 +1,15 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
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) {
|
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); } }
|
||||||
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());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
const path = require("path");
|
||||||
const core = require("@actions/core");
|
const core = require("@actions/core");
|
||||||
const yaml = require("js-yaml");
|
const yaml = require("js-yaml");
|
||||||
const canaryDeploymentHelper = require("./canary-deployment-helper");
|
const canaryDeploymentHelper = require("./canary-deployment-helper");
|
||||||
@ -20,7 +20,6 @@ const fileHelper = require("../files-helper");
|
|||||||
const utils = require("../manifest-utilities");
|
const utils = require("../manifest-utilities");
|
||||||
const KubernetesManifestUtility = require("../manifest-stability-utility");
|
const KubernetesManifestUtility = require("../manifest-stability-utility");
|
||||||
const KubernetesConstants = require("../../constants");
|
const KubernetesConstants = require("../../constants");
|
||||||
const string_comparison_1 = require("./../string-comparison");
|
|
||||||
const pod_canary_deployment_helper_1 = require("./pod-canary-deployment-helper");
|
const pod_canary_deployment_helper_1 = require("./pod-canary-deployment-helper");
|
||||||
const smi_canary_deployment_helper_1 = require("./smi-canary-deployment-helper");
|
const smi_canary_deployment_helper_1 = require("./smi-canary-deployment-helper");
|
||||||
const utility_1 = require("../utility");
|
const utility_1 = require("../utility");
|
||||||
@ -29,7 +28,9 @@ function deploy(kubectl, manifestFilePaths, deploymentStrategy) {
|
|||||||
// get manifest files
|
// get manifest files
|
||||||
let inputManifestFiles = getManifestFiles(manifestFilePaths);
|
let inputManifestFiles = getManifestFiles(manifestFilePaths);
|
||||||
// artifact substitution
|
// artifact substitution
|
||||||
inputManifestFiles = updateResourceObjects(inputManifestFiles, TaskInputParameters.containers, TaskInputParameters.imagePullSecrets);
|
inputManifestFiles = updateContainerImagesInManifestFiles(inputManifestFiles, TaskInputParameters.containers);
|
||||||
|
// imagePullSecrets addition
|
||||||
|
inputManifestFiles = updateImagePullSecretsInManifestFiles(inputManifestFiles, TaskInputParameters.imagePullSecrets);
|
||||||
// deployment
|
// deployment
|
||||||
const deployedManifestFiles = deployManifests(inputManifestFiles, kubectl, isCanaryDeploymentStrategy(deploymentStrategy));
|
const deployedManifestFiles = deployManifests(inputManifestFiles, kubectl, isCanaryDeploymentStrategy(deploymentStrategy));
|
||||||
// check manifest stability
|
// check manifest stability
|
||||||
@ -100,37 +101,49 @@ function checkManifestStability(kubectl, resources) {
|
|||||||
yield KubernetesManifestUtility.checkManifestStability(kubectl, resources);
|
yield KubernetesManifestUtility.checkManifestStability(kubectl, resources);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function updateResourceObjects(filePaths, imagePullSecrets, containers) {
|
function updateContainerImagesInManifestFiles(filePaths, containers) {
|
||||||
const newObjectsList = [];
|
if (!!containers && containers.length > 0) {
|
||||||
const updateResourceObject = (inputObject) => {
|
const newFilePaths = [];
|
||||||
if (!!imagePullSecrets && imagePullSecrets.length > 0) {
|
const tempDirectory = fileHelper.getTempDirectory();
|
||||||
KubernetesObjectUtility.updateImagePullSecrets(inputObject, imagePullSecrets, false);
|
filePaths.forEach((filePath) => {
|
||||||
}
|
let contents = fs.readFileSync(filePath).toString();
|
||||||
if (!!containers && containers.length > 0) {
|
containers.forEach((container) => {
|
||||||
KubernetesObjectUtility.updateImageDetails(inputObject, containers);
|
let imageName = container.split(':')[0];
|
||||||
}
|
if (imageName.indexOf('@') > 0) {
|
||||||
};
|
imageName = imageName.split('@')[0];
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
else if (string_comparison_1.isEqual(kind, 'list', string_comparison_1.StringComparer.OrdinalIgnoreCase)) {
|
if (contents.indexOf(imageName) > 0) {
|
||||||
let items = inputObject.items;
|
contents = utils.substituteImageNameInSpecFile(contents, imageName, container);
|
||||||
if (items.length > 0) {
|
|
||||||
items.forEach((item) => updateResourceObject(item));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
newObjectsList.push(inputObject);
|
});
|
||||||
}
|
const fileName = path.join(tempDirectory, path.basename(filePath));
|
||||||
|
fs.writeFileSync(path.join(fileName), contents);
|
||||||
|
newFilePaths.push(fileName);
|
||||||
});
|
});
|
||||||
});
|
return newFilePaths;
|
||||||
core.debug('New K8s objects after addin imagePullSecrets are :' + JSON.stringify(newObjectsList));
|
}
|
||||||
const newFilePaths = fileHelper.writeObjectsToFile(newObjectsList);
|
return filePaths;
|
||||||
return newFilePaths;
|
}
|
||||||
|
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) {
|
function isCanaryDeploymentStrategy(deploymentStrategy) {
|
||||||
return deploymentStrategy != null && deploymentStrategy.toUpperCase() === canaryDeploymentHelper.CANARY_DEPLOYMENT_STRATEGY.toUpperCase();
|
return deploymentStrategy != null && deploymentStrategy.toUpperCase() === canaryDeploymentHelper.CANARY_DEPLOYMENT_STRATEGY.toUpperCase();
|
||||||
|
|||||||
@ -102,67 +102,6 @@ export function updateImagePullSecrets(inputObject: any, newImagePullSecrets: st
|
|||||||
setImagePullSecrets(inputObject, existingImagePullSecretObjects);
|
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) {
|
export function updateSpecLabels(inputObject: any, newLabels: Map<string, string>, override: boolean) {
|
||||||
if (!inputObject) {
|
if (!inputObject) {
|
||||||
throw ('NullInputObject');
|
throw ('NullInputObject');
|
||||||
|
|||||||
@ -13,7 +13,6 @@ import * as utils from '../manifest-utilities';
|
|||||||
import * as KubernetesManifestUtility from '../manifest-stability-utility';
|
import * as KubernetesManifestUtility from '../manifest-stability-utility';
|
||||||
import * as KubernetesConstants from '../../constants';
|
import * as KubernetesConstants from '../../constants';
|
||||||
import { Kubectl, Resource } from '../../kubectl-object-model';
|
import { Kubectl, Resource } from '../../kubectl-object-model';
|
||||||
import { StringComparer, isEqual } from './../string-comparison';
|
|
||||||
|
|
||||||
import { deployPodCanary } from './pod-canary-deployment-helper';
|
import { deployPodCanary } from './pod-canary-deployment-helper';
|
||||||
import { deploySMICanary } from './smi-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);
|
let inputManifestFiles: string[] = getManifestFiles(manifestFilePaths);
|
||||||
|
|
||||||
// artifact substitution
|
// artifact substitution
|
||||||
inputManifestFiles = updateResourceObjects(inputManifestFiles, TaskInputParameters.containers, TaskInputParameters.imagePullSecrets);
|
inputManifestFiles = updateContainerImagesInManifestFiles(inputManifestFiles, TaskInputParameters.containers);
|
||||||
|
|
||||||
|
// imagePullSecrets addition
|
||||||
|
inputManifestFiles = updateImagePullSecretsInManifestFiles(inputManifestFiles, TaskInputParameters.imagePullSecrets);
|
||||||
|
|
||||||
// deployment
|
// deployment
|
||||||
const deployedManifestFiles = deployManifests(inputManifestFiles, kubectl, isCanaryDeploymentStrategy(deploymentStrategy));
|
const deployedManifestFiles = deployManifests(inputManifestFiles, kubectl, isCanaryDeploymentStrategy(deploymentStrategy));
|
||||||
@ -102,37 +104,56 @@ async function checkManifestStability(kubectl: Kubectl, resources: Resource[]):
|
|||||||
await KubernetesManifestUtility.checkManifestStability(kubectl, resources);
|
await KubernetesManifestUtility.checkManifestStability(kubectl, resources);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateResourceObjects(filePaths: string[], imagePullSecrets: string[], containers: string[]): string[] {
|
function updateContainerImagesInManifestFiles(filePaths: string[], containers: string[]): string[] {
|
||||||
const newObjectsList = [];
|
if (!!containers && containers.length > 0) {
|
||||||
const updateResourceObject = (inputObject) => {
|
const newFilePaths = [];
|
||||||
if (!!imagePullSecrets && imagePullSecrets.length > 0) {
|
const tempDirectory = fileHelper.getTempDirectory();
|
||||||
KubernetesObjectUtility.updateImagePullSecrets(inputObject, imagePullSecrets, false);
|
filePaths.forEach((filePath: string) => {
|
||||||
}
|
let contents = fs.readFileSync(filePath).toString();
|
||||||
if (!!containers && containers.length > 0) {
|
containers.forEach((container: string) => {
|
||||||
KubernetesObjectUtility.updateImageDetails(inputObject, containers);
|
let imageName = container.split(':')[0];
|
||||||
}
|
if (imageName.indexOf('@') > 0) {
|
||||||
}
|
imageName = imageName.split('@')[0];
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
else if (isEqual(kind, 'list', StringComparer.OrdinalIgnoreCase)) {
|
if (contents.indexOf(imageName) > 0) {
|
||||||
let items = inputObject.items;
|
contents = utils.substituteImageNameInSpecFile(contents, imageName, container);
|
||||||
if (items.length > 0) {
|
|
||||||
items.forEach((item) => updateResourceObject(item));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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));
|
return newFilePaths;
|
||||||
const newFilePaths = fileHelper.writeObjectsToFile(newObjectsList);
|
}
|
||||||
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 {
|
function isCanaryDeploymentStrategy(deploymentStrategy: string): boolean {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user