-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prevent fetch of policy reports if controller app version is not 1.11 (…
…#650) Co-authored-by: Alexandre Alves <[email protected]>
- Loading branch information
Showing
5 changed files
with
161 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Store } from 'vuex'; | ||
|
||
import { CATALOG } from '@shell/config/types'; | ||
import { CATALOG as CATALOG_ANNOTATIONS } from '@shell/config/labels-annotations'; | ||
|
||
import { KUBEWARDEN_APPS, CatalogApp } from '../types'; | ||
|
||
export const fetchControllerApp = async(store: Store<any>): Promise<CatalogApp | undefined> => { | ||
if ( store.getters['cluster/schemaFor'](CATALOG.APP) ) { | ||
const allApps: CatalogApp[] = await store.dispatch('cluster/findAll', { type: CATALOG.APP }); | ||
|
||
const controllerApp = allApps?.find(app => ( | ||
app.spec?.chart?.metadata?.annotations?.[CATALOG_ANNOTATIONS.RELEASE_NAME] === KUBEWARDEN_APPS.RANCHER_CONTROLLER | ||
)); | ||
|
||
if ( controllerApp ) { | ||
store.dispatch('kubewarden/updateControllerApp', controllerApp); | ||
|
||
return controllerApp; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { CatalogApp } from '@kubewarden/types'; | ||
|
||
export const mockControllerApp: CatalogApp = { | ||
id: 'cattle-kubewarden-system/rancher-kubewarden-controller', | ||
type: 'app', | ||
apiVersion: 'catalog.cattle.io/v1', | ||
kind: 'App', | ||
metadata: { | ||
annotations: {}, | ||
labels: {}, | ||
name: 'rancher-kubewarden-controller', | ||
namespace: 'cattle-kubewarden-system' | ||
}, | ||
spec: { | ||
chart: { | ||
metadata: { | ||
annotations: { | ||
'catalog.cattle.io/auto-install': 'kubewarden-crds=1.4.5', | ||
'catalog.cattle.io/certified': 'rancher', | ||
'catalog.cattle.io/display-name': 'Kubewarden', | ||
'catalog.cattle.io/namespace': 'cattle-kubewarden-system', | ||
'catalog.cattle.io/os': 'linux', | ||
'catalog.cattle.io/provides-gvr': 'policyservers.policies.kubewarden.io/v1', | ||
'catalog.cattle.io/rancher-version': '>= 2.6.0-0 <= 2.8.100-0', | ||
'catalog.cattle.io/release-name': 'rancher-kubewarden-controller', | ||
'catalog.cattle.io/requests-cpu': '250m', | ||
'catalog.cattle.io/requests-memory': '50Mi', | ||
'catalog.cattle.io/type': 'cluster-tool', | ||
'catalog.cattle.io/ui-component': 'kubewarden', | ||
'catalog.cattle.io/ui-source-repo': 'kubewarden-charts', | ||
'catalog.cattle.io/ui-source-repo-type': 'cluster', | ||
'catalog.cattle.io/upstream-version': '2.0.9' | ||
}, | ||
apiVersion: 'v2', | ||
appVersion: 'v1.11.0', | ||
name: 'kubewarden-controller', | ||
type: 'application', | ||
version: '2.0.9' | ||
}, | ||
values: {} | ||
}, | ||
info: { status: 'deployed' }, | ||
name: 'rancher-kubewarden-controller', | ||
namespace: 'cattle-kubewarden-system', | ||
resources: [], | ||
values: {} | ||
}, | ||
status: { summary: { state: 'deployed' } } | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { CATALOG } from '@shell/config/labels-annotations'; | ||
import { KUBEWARDEN_APPS } from '@kubewarden/types'; | ||
import { fetchControllerApp } from '@kubewarden/modules/kubewardenController'; | ||
|
||
const mockStore = { | ||
getters: { 'cluster/schemaFor': jest.fn() }, | ||
dispatch: jest.fn(), | ||
}; | ||
|
||
beforeEach(() => { // | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe('fetchControllerApp', () => { | ||
it('should fetch and return the controller app when found', async() => { | ||
const expectedControllerApp = { spec: { chart: { metadata: { annotations: { [CATALOG.RELEASE_NAME]: KUBEWARDEN_APPS.RANCHER_CONTROLLER } } } } }; | ||
|
||
mockStore.getters['cluster/schemaFor'].mockReturnValue(true); | ||
mockStore.dispatch.mockResolvedValue([expectedControllerApp]); | ||
|
||
const result = await fetchControllerApp(mockStore); | ||
|
||
expect(result).toEqual(expectedControllerApp); | ||
expect(mockStore.dispatch).toHaveBeenCalledWith('kubewarden/updateControllerApp', expectedControllerApp); | ||
}); | ||
|
||
it('should return undefined if the controller app is not found', async() => { | ||
mockStore.getters['cluster/schemaFor'].mockReturnValue(true); | ||
mockStore.dispatch.mockResolvedValue([]); | ||
|
||
const result = await fetchControllerApp(mockStore); | ||
|
||
expect(result).toBeUndefined(); | ||
expect(mockStore.dispatch).not.toHaveBeenCalledWith('kubewarden/updateControllerApp', expect.anything()); | ||
}); | ||
|
||
it('should not proceed if the schema for CATALOG.APP is not found', async() => { | ||
mockStore.getters['cluster/schemaFor'].mockReturnValue(false); | ||
|
||
const result = await fetchControllerApp(mockStore); | ||
|
||
expect(result).toBeUndefined(); | ||
expect(mockStore.dispatch).not.toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters