-
Notifications
You must be signed in to change notification settings - Fork 593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug 1878700: Fix Add Pipeline Trigger for Pipeline Operator 1.1 #6612
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import { k8sList } from '@console/internal/module/k8s'; | ||
import { ClusterServiceVersionKind } from '@console/operator-lifecycle-manager'; | ||
import { getPipelineOperatorVersion } from '../pipeline-operator'; | ||
|
||
jest.mock('@console/internal/module/k8s', () => ({ | ||
k8sList: jest.fn(), | ||
})); | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
const k8sListMock = k8sList as jest.Mock; | ||
|
||
describe('getPipelineOperatorVersion', () => { | ||
it('should fetch the ClusterServiceVersion from the api', async () => { | ||
const csvs = [ | ||
{ | ||
metadata: { name: 'openshift-pipelines-operator.v1.0.1' }, | ||
spec: { version: '1.0.1' }, | ||
status: { phase: 'Succeeded' }, | ||
} as ClusterServiceVersionKind, | ||
]; | ||
k8sListMock.mockReturnValueOnce(Promise.resolve(csvs)); | ||
|
||
const version = await getPipelineOperatorVersion('unit-test'); | ||
|
||
expect(version.raw).toBe('1.0.1'); | ||
expect(version.major).toBe(1); | ||
expect(version.minor).toBe(0); | ||
expect(version.patch).toBe(1); | ||
expect(k8sList).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should return the active ClusterServiceVersion if multiple returns', async () => { | ||
const csvs = [ | ||
{ | ||
metadata: { name: 'openshift-pipelines-operator.v1.0.1' }, | ||
spec: { version: '1.0.1' }, | ||
status: { phase: 'Succeeded' }, | ||
} as ClusterServiceVersionKind, | ||
{ | ||
metadata: { name: 'openshift-pipelines-operator.v1.1.1' }, | ||
spec: { version: '1.1.1' }, | ||
status: { phase: 'Pending' }, | ||
} as ClusterServiceVersionKind, | ||
]; | ||
k8sListMock.mockReturnValueOnce(Promise.resolve(csvs)); | ||
|
||
const version = await getPipelineOperatorVersion('unit-test'); | ||
|
||
expect(version.raw).toBe('1.0.1'); | ||
expect(version.major).toBe(1); | ||
expect(version.minor).toBe(0); | ||
expect(version.patch).toBe(1); | ||
expect(k8sList).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should fetch the latest (highest) ClusterServiceVersion from the api', async () => { | ||
const csvs = [ | ||
{ | ||
metadata: { name: 'openshift-pipelines-operator.v1.0.1' }, | ||
spec: { version: '1.0.1' }, | ||
status: { phase: 'Succeeded' }, | ||
} as ClusterServiceVersionKind, | ||
{ | ||
metadata: { name: 'openshift-pipelines-operator.v10.11.12' }, | ||
spec: { version: '10.11.12' }, | ||
status: { phase: 'Succeeded' }, | ||
} as ClusterServiceVersionKind, | ||
{ | ||
metadata: { name: 'openshift-pipelines-operator.v1.1.1' }, | ||
spec: { version: '1.1.1' }, | ||
status: { phase: 'Succeeded' }, | ||
} as ClusterServiceVersionKind, | ||
]; | ||
k8sListMock.mockReturnValueOnce(Promise.resolve(csvs)); | ||
|
||
const version = await getPipelineOperatorVersion('unit-test'); | ||
|
||
expect(version.raw).toBe('10.11.12'); | ||
expect(version.major).toBe(10); | ||
expect(version.minor).toBe(11); | ||
expect(version.patch).toBe(12); | ||
expect(k8sList).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should return null if there is no ClusterServiceVersion available', async () => { | ||
k8sListMock.mockReturnValueOnce(Promise.resolve([])); | ||
await expect(getPipelineOperatorVersion('unit-test')).resolves.toBe(null); | ||
expect(k8sList).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should return null if there is no pipeline operator at all', async () => { | ||
const csvs = [ | ||
{ | ||
metadata: { name: 'another-operator' }, | ||
spec: { version: '1.0.0' }, | ||
status: { phase: 'Succeeded' }, | ||
} as ClusterServiceVersionKind, | ||
]; | ||
k8sListMock.mockReturnValueOnce(Promise.resolve(csvs)); | ||
await expect(getPipelineOperatorVersion('unit-test')).resolves.toBe(null); | ||
expect(k8sList).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should return null if there is no matching ClusterServiceVersion available', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you write one more test for valid items but not including a Pipeline Operator? I think you covered both sides (none and mixed), but I think there is still valid test possible here for just invalid ones. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added new test, it should return null if there is no pipeline operator at all |
||
const csvs = [ | ||
{ | ||
metadata: { name: 'another-operator' }, | ||
spec: { version: '1.0.0' }, | ||
status: { phase: 'Succeeded' }, | ||
} as ClusterServiceVersionKind, | ||
{ | ||
metadata: { name: 'openshift-pipelines-operator.v1.1.1' }, | ||
spec: { version: '1.1.1' }, | ||
status: { phase: 'Installing' }, | ||
} as ClusterServiceVersionKind, | ||
]; | ||
k8sListMock.mockReturnValueOnce(Promise.resolve(csvs)); | ||
await expect(getPipelineOperatorVersion('unit-test')).resolves.toBe(null); | ||
expect(k8sList).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,25 @@ | ||||||
import { compare, parse, SemVer } from 'semver'; | ||||||
import { | ||||||
ClusterServiceVersionKind, | ||||||
ClusterServiceVersionModel, | ||||||
ClusterServiceVersionPhase, | ||||||
} from '@console/operator-lifecycle-manager'; | ||||||
import { k8sList } from '@console/internal/module/k8s'; | ||||||
|
||||||
export const getPipelineOperatorVersion = async (namespace: string): Promise<SemVer | null> => { | ||||||
const allCSVs: ClusterServiceVersionKind[] = await k8sList(ClusterServiceVersionModel, { | ||||||
ns: namespace, | ||||||
}); | ||||||
const matchingCSVs = allCSVs.filter( | ||||||
(csv) => | ||||||
csv.metadata?.name?.startsWith('openshift-pipelines-operator') && | ||||||
csv.status?.phase === ClusterServiceVersionPhase.CSVPhaseSucceeded, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @andrewballantyne @christianvogt Does it makes sense to check the status.phase of the Pipeline Operator to get the right version? If this is not required I could use |
||||||
); | ||||||
const versions = matchingCSVs.map((csv) => parse(csv.spec.version)).filter(Boolean); | ||||||
// Orders from small (oldest) to highest (newest) version | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm confused by this comment vs the tests.
Suggested change
You're grabbing the last one, the earliest version based on your tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The order after this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I was confused by your test... I didn't read the |
||||||
versions.sort(compare); | ||||||
if (versions.length > 0) { | ||||||
return versions[versions.length - 1]; | ||||||
} | ||||||
return null; | ||||||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if we might be able to use
keyof
here, or would it become too verbose? Especially sincename
is deprecated.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't know what the solution looks like then. But the usage in triggers.ts works fine with name and at least VScode shows these deprecated hint. But I'm open to see and try an example here. /me open the TS keyof definition :)