Skip to content

Commit

Permalink
Fix trigger annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
divyanshiGupta committed Feb 22, 2021
1 parent cf684ab commit d6df541
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export const createOrUpdateDeployment = (
...annotations,
'alpha.image.policy.openshift.io/resolve-names': '*',
...getTriggerAnnotation(
name,
imgName || name,
imgNamespace || namespace,
imageChange,
Expand Down Expand Up @@ -440,6 +441,7 @@ export const createOrUpdateDeployImageResources = async (
}
const originalAnnotations = appResources?.editAppResource?.data?.metadata?.annotations || {};
const triggerAnnotations = getTriggerAnnotation(
name,
internalImageStreamName || name,
internalImageStreamNamespace || namespace,
imageChange,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,12 @@ export const createOrUpdateDeployment = (

const imageStreamName = imageStream && imageStream.metadata.name;
const defaultLabels = getAppLabels({ name, applicationName, imageStreamName, selectedTag });
const imageName = name;
const annotations = {
...getGitAnnotations(repository, ref),
...getCommonAnnotations(),
'alpha.image.policy.openshift.io/resolve-names': '*',
...getTriggerAnnotation(name, namespace, imageChange),
...getTriggerAnnotation(name, imageName, namespace, imageChange),
};
const podLabels = getPodLabels(name);
const templateLabels = getTemplateLabels(originalDeployment);
Expand Down Expand Up @@ -632,6 +633,7 @@ export const createOrUpdateResources = async (

const originalAnnotations = appResources?.editAppResource?.data?.metadata?.annotations || {};
const triggerAnnotations = getTriggerAnnotation(
name,
generatedImageStreamName || name,
namespace,
imageChange,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mergeData } from '../resource-label-utils';
import { getTriggerAnnotation, mergeData } from '../resource-label-utils';
import {
devfileDeployment,
newBuildConfig,
Expand Down Expand Up @@ -111,4 +111,18 @@ describe('resource-label-utils', () => {
);
});
});
describe('getTriggerAnnotation', () => {
it('should return trigger annotation with proper values', () => {
let annotation = getTriggerAnnotation('test', 'python', 'div', true);
expect(annotation).toEqual({
'image.openshift.io/triggers':
'[{"from":{"kind":"ImageStreamTag","name":"python:latest","namespace":"div"},"fieldPath":"spec.template.spec.containers[?(@.name==\\"test\\")].image","pause":"false"}]',
});
annotation = getTriggerAnnotation('test', 'test', 'div', false);
expect(annotation).toEqual({
'image.openshift.io/triggers':
'[{"from":{"kind":"ImageStreamTag","name":"test:latest","namespace":"div"},"fieldPath":"spec.template.spec.containers[?(@.name==\\"test\\")].image","pause":"true"}]',
});
});
});
});
11 changes: 6 additions & 5 deletions frontend/packages/dev-console/src/utils/resource-label-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,16 @@ export const getCommonAnnotations = () => {
};

export const getTriggerAnnotation = (
name: string,
namespace: string,
containerName: string,
imageName: string,
imageNamespace: string,
imageTrigger: boolean,
tag: string = 'latest',
imageTag: string = 'latest',
) => ({
[TRIGGERS_ANNOTATION]: JSON.stringify([
{
from: { kind: 'ImageStreamTag', name: `${name}:${tag}`, namespace },
fieldPath: `spec.template.spec.containers[?(@.name=="${name}")].image`,
from: { kind: 'ImageStreamTag', name: `${imageName}:${imageTag}`, namespace: imageNamespace },
fieldPath: `spec.template.spec.containers[?(@.name=="${containerName}")].image`,
pause: `${!imageTrigger}`,
},
]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export const getKnativeServiceDepResource = (
...(concurrencylimit && { containerConcurrency: concurrencylimit }),
containers: [
{
name,
image: `${imageStreamUrl}`,
...(contTargetPort && {
ports: [
Expand Down

0 comments on commit d6df541

Please sign in to comment.