Skip to content
Open
40 changes: 40 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug Jest Tests",
"type": "node",
"request": "launch",
"runtimeArgs": [
"--inspect-brk",
"${workspaceRoot}/node_modules/.bin/jest",
"--runInBand",
"--watch"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
},
{
"name": "Debug Jest Tests relativeFile",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
},
"runtimeArgs": [
"--inspect-brk",
"${workspaceRoot}/node_modules/.bin/jest",
"--runInBand",
"--watch"
],
"args": ["${relativeFile}"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
}
]

}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"dependencies": {
"@kubernetes/client-node": "^1.3.0",
"@rancher/components": "^0.3.0-alpha.1",
"@rancher/components": "^0.3.0-alpha.2",
"@rancher/shell": "^3.0.4",
"vue": "^3.5.13",
"vue-router": "^4.5.0",
Expand Down
28 changes: 28 additions & 0 deletions pkg/kubewarden/chart/kubewarden/policy-server/General.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useStore } from 'vuex';

import { _CREATE } from '@shell/config/query-params';
import { CATALOG, FLEET } from '@shell/config/types';
import { PRIORITY_CLASS } from '@kubewarden/config/contstants';

import { DEFAULT_POLICY_SERVER } from '@kubewarden/models/policies.kubewarden.io.policyserver';
import { getPolicyServerModule, isFleetDeployment } from '@kubewarden/modules/fleet';
Expand All @@ -21,11 +22,13 @@ import {
} from '@kubewarden/types';
import { findCompatibleDefaultsChart } from '@kubewarden/utils/chart';

import ResourceLabeledSelect from '@shell/components/form/ResourceLabeledSelect';
import { Banner } from '@components/Banner';
import { LabeledInput } from '@components/Form/LabeledInput';
import { RadioGroup } from '@components/Form/Radio';
import Loading from '@shell/components/Loading';
import ServiceNameSelect from '@shell/components/form/ServiceNameSelect';
import { RcButton } from '@components/RcButton';

const props = defineProps<{
mode?: string;
Expand Down Expand Up @@ -259,5 +262,30 @@ watchEffect(() => {
/>
</div>
</div>
<div class="row mt-20">
<div class="col span-6">
<!-- Reduce is required as the component maps to object.value if any -->
<h3>
{{ t('kubewarden.policyServerConfig.priorityClassName.label') }}
</h3>
<div style="display:flex; gap: 8px">
<ResourceLabeledSelect
v-model:value="value.spec.priorityClassName"
data-testid="ps-config-priority-class-name-select"
:clearable="true"
:mode="mode"
:resource-type="PRIORITY_CLASS"
:label="t('kubewarden.policyServerConfig.priorityClassName.label')"
option-label="metadata.name"
:reduce="(priorityClassName: any) => priorityClassName.metadata.name"
/>
<RcButton
secondary
data-testid="ps-config-priority-class-name-clear"
@click="value.spec.priorityClassName = ''"
>{{ t("generic.clear") }}</RcButton>
</div>
</div>
</div>
</div>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ const defaultMountOptions = {
template: '<div />',
props: ['modelValue', 'options']
},
Banner: { template: '<span />' },
LabeledInput: { template: '<span />' },
LabeledTooltip: { template: '<span />' },
RadioGroup: { template: '<span />' }
Banner: { template: '<span />' },
ResourceLabeledSelect: true,
LabeledInput: { template: '<span />' },
LabeledTooltip: { template: '<span />' },
RadioGroup: { template: '<span />' }
}
}
};
Expand Down Expand Up @@ -116,6 +117,43 @@ describe('component: General', () => {
expect(selector.props('options')).toStrictEqual(['sa-1', 'sa-2', 'sa-3']);
});

it('displays priorityClassName', () => {
const expectation = 'whatever';
const wrapper = createWrapper({
props: {
value: {
...DEFAULT_POLICY_SERVER,
spec: {
...DEFAULT_POLICY_SERVER.spec,
priorityClassName: expectation
}
}
}
});
const selector = wrapper.find('[data-testid="ps-config-priority-class-name-select"]');

expect(selector.exists()).toBe(true);
expect(selector.attributes('value')).toBe(expectation);
});

it('can clear priorityClassName', () => {
const wrapper = createWrapper({
props: {
value: {
...DEFAULT_POLICY_SERVER,
spec: {
...DEFAULT_POLICY_SERVER.spec,
priorityClassName: 'whatever'
}
}
}
});

wrapper.find('[data-testid="ps-config-priority-class-name-clear"]').element.click();

expect(wrapper.vm.value.spec.priorityClassName).toBe('');
});

it('displays correct service account when existing', async() => {
const policyServer = {
...DEFAULT_POLICY_SERVER,
Expand Down
1 change: 1 addition & 0 deletions pkg/kubewarden/config/contstants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const PRIORITY_CLASS = 'scheduling.k8s.io.priorityclass';
6 changes: 6 additions & 0 deletions pkg/kubewarden/config/table-headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ export const POLICY_SERVER_HEADERS = [
formatter: 'PolicyServerDeployment',
canBeVariable: true,
},
{
name: 'priorityClassName',
label: 'Priority Class Name',
value: 'spec.priorityClassName',
sort: ['spec.priorityClassName']
},
{
name: 'kubewardenPolicyServers',
label: 'Image',
Expand Down
2 changes: 2 additions & 0 deletions pkg/kubewarden/l10n/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ kubewarden:
label: Image URL
tooltip: This is the container image the policy server.
replicas: Replicas
priorityClassName:
label: Priority Class Name
registry:
description: The PolicyServer allows you to pull policies from OCI registries and HTTP servers, by default HTTPS is enforced with host TLS verification. You can interact with registries using untrusted certificates or even without TLS by using the `insecureSources` setting. This approach is highly discouraged in environments closer to production. More information on configuring custom certificate authorities can be found <a href="https://docs.kubewarden.io/next/howtos/policy-servers/custom-cas" target="_blank" rel="noopener noreferrer nofollow">here</a>.
insecureSources:
Expand Down
1 change: 1 addition & 0 deletions pkg/kubewarden/types/kubewarden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export interface PolicyServer {
env: V1EnvVar[];
image?: string;
replicas?: number;
priorityClassName?: string;
securityContexts?: {
container?: V1SecurityContext;
pod?: V1PodSecurityContext;
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3312,10 +3312,10 @@
resolved "https://registry.npmjs.org/@popperjs/core/-/core-2.11.8.tgz#6b79032e760a0899cd4204710beede972a3a185f"
integrity sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==

"@rancher/components@^0.3.0-alpha.1":
version "0.3.0-alpha.1"
resolved "https://registry.npmjs.org/@rancher/components/-/components-0.3.0-alpha.1.tgz#86f570be89f84ab271bd3ca392b7bc57827e33c1"
integrity sha512-wqplnnHD4RUY1KO1zl9IZ8pZvVfY2MhgRWHsNaqAd17Y0Chylk9egsFveRJb0VBPOCwa3iu0ttFvl9mLIjvpHw==
"@rancher/components@^0.3.0-alpha.2":
version "0.3.0-alpha.2"
resolved "https://registry.npmjs.org/@rancher/components/-/components-0.3.0-alpha.2.tgz#aad9b3eddccf3602422d4628275d6ee4cc687ee1"
integrity sha512-bOr+BeTJSrOlXaIaZpVBRHTN9CxPpUNxvSBAaX6c2cGzZFgU2XUaUBY35t6azt0FFkrsVTkjTzKBaJBYTFSUsQ==
dependencies:
lodash.debounce "4.0.8"

Expand Down