From 58a91755d0ccd1d08448015ada2e3a3c52b42f7b Mon Sep 17 00:00:00 2001 From: Jordon Leach Date: Wed, 31 Jul 2024 14:38:09 -0400 Subject: [PATCH 1/2] Add basic configuration for policy creation --- jest.setup.js | 13 +- .../chart/kubewarden/admission/Basic.vue | 155 +++++++ .../chart/kubewarden/admission/General.vue | 97 ---- .../components/NamespaceNameInput.vue | 414 ++++++++++++++++++ pkg/kubewarden/components/Policies/Config.vue | 2 +- .../components/Policies/PolicyTable.vue | 6 +- pkg/kubewarden/components/Policies/Values.vue | 7 +- pkg/kubewarden/l10n/en-us.yaml | 5 + tests/unit/charts/admission/Basic.spec.ts | 107 +++++ tests/unit/charts/admission/General.spec.ts | 39 +- .../components/Policies/PolicyTable.spec.ts | 16 - 11 files changed, 698 insertions(+), 163 deletions(-) create mode 100644 pkg/kubewarden/chart/kubewarden/admission/Basic.vue create mode 100644 pkg/kubewarden/components/NamespaceNameInput.vue create mode 100644 tests/unit/charts/admission/Basic.spec.ts diff --git a/jest.setup.js b/jest.setup.js index 7d51eddc..ca69ffc1 100644 --- a/jest.setup.js +++ b/jest.setup.js @@ -1,13 +1,13 @@ -import { config } from '@vue/test-utils'; -import { directiveSsr as t } from '@shell/plugins/i18n'; -import { VCleanTooltip } from '@shell/plugins/clean-tooltip-directive'; -import { cleanHtmlDirective } from '@shell/plugins/clean-html-directive'; - import Vue from 'vue'; +import { config } from '@vue/test-utils'; +import i18n from '@shell/plugins/i18n'; +import cleanTooltipDirective from '@shell/directives/clean-tooltip'; +import cleanHtmlDirective from '@shell/directives/clean-html'; Vue.config.productionTip = false; -Vue.directive('clean-tooltip', VCleanTooltip); +Vue.use(i18n); +Vue.directive('clean-tooltip', cleanTooltipDirective); Vue.directive('clean-html', cleanHtmlDirective); beforeAll(() => {}); @@ -16,7 +16,6 @@ beforeEach(() => { jest.restoreAllMocks(); config.mocks['$store'] = { getters: { 'i18n/t': jest.fn() } }; - config.directives = { t }; }); afterEach(() => {}); diff --git a/pkg/kubewarden/chart/kubewarden/admission/Basic.vue b/pkg/kubewarden/chart/kubewarden/admission/Basic.vue new file mode 100644 index 00000000..dfe28bc1 --- /dev/null +++ b/pkg/kubewarden/chart/kubewarden/admission/Basic.vue @@ -0,0 +1,155 @@ + + + diff --git a/pkg/kubewarden/chart/kubewarden/admission/General.vue b/pkg/kubewarden/chart/kubewarden/admission/General.vue index 3074acd9..16269d62 100644 --- a/pkg/kubewarden/chart/kubewarden/admission/General.vue +++ b/pkg/kubewarden/chart/kubewarden/admission/General.vue @@ -4,9 +4,7 @@ import isEmpty from 'lodash/isEmpty'; import { _CREATE } from '@shell/config/query-params'; import { set } from '@shell/utils/object'; -import LabeledSelect from '@shell/components/form/LabeledSelect'; import Loading from '@shell/components/Loading'; -import NameNsDescription from '@shell/components/form/NameNsDescription'; import { Banner } from '@components/Banner'; import { LabeledInput } from '@components/Form/LabeledInput'; import { RadioGroup } from '@components/Form/Radio'; @@ -23,10 +21,6 @@ export default { type: String, default: _CREATE }, - targetNamespace: { - type: String, - required: true - }, isCustom: { type: Boolean, default: false @@ -38,9 +32,7 @@ export default { }, components: { - LabeledSelect, Loading, - NameNsDescription, Banner, LabeledInput, RadioGroup @@ -73,62 +65,23 @@ export default { policy = this.value || {}; } - // fix for https://github.com/rancher/kubewarden-ui/issues/672 - // enforce `default` as namespace for creation of AP's - if ( this.mode === _CREATE && this.chartType === KUBEWARDEN.ADMISSION_POLICY ) { - set(policy.metadata, 'namespace', 'default'); - } - return { policy, initialPolicyMode: null, - isNamespaceNew: false }; }, - watch: { - isNamespaceNew(neu) { - this.$set(this.value, 'isNamespaceNew', neu); - } - }, - created() { if ( this.policyMode ) { this.initialPolicyMode = this.policyMode; } }, - beforeUpdate() { - this.$nextTick(() => { - // In order to fix the layout of the NameNsDescription component - // we need to adjust the classes of the child elements - const wrapper = this.$refs?.nameNsDescriptionWrapper; - - const children = wrapper?.querySelectorAll('.row.mb-20 > .col.span-3'); - - if ( this.isGlobal ) { - if ( children?.length === 1 ) { - children[0].classList.remove('span-3'); - children[0].classList.add('span-12'); - } - } else if ( children?.length === 2 ) { - children[0].classList.remove('span-3'); - children[0].classList.add('span-4'); - children[1].classList.remove('span-3'); - children[1].classList.add('span-8'); - } - }); - }, - computed: { isCreate() { return this.mode === _CREATE; }, - isGlobal() { - return this.chartType === KUBEWARDEN.CLUSTER_ADMISSION_POLICY; - }, - modeDisabled() { // Kubewarden doesn't allow switching a policy from 'protect' to 'monitor' if ( !this.isCreate ) { @@ -142,22 +95,6 @@ export default { return this.value?.policy?.spec?.mode; }, - policyServers() { - return this.$store.getters['cluster/all'](KUBEWARDEN.POLICY_SERVER); - }, - - policyServerOptions() { - if ( this.policyServers?.length > 0 ) { - const out = []; - - this.policyServers.map(p => out.push(p.id)); - - return out; - } - - return this.policyServers || []; - }, - showModeBanner() { if ( !this.isCreate && ( this.initialPolicyMode === 'monitor' && this.policyMode === 'protect' ) ) { return true; @@ -172,33 +109,6 @@ export default { - - \ No newline at end of file diff --git a/pkg/kubewarden/components/NamespaceNameInput.vue b/pkg/kubewarden/components/NamespaceNameInput.vue new file mode 100644 index 00000000..bfbde7a3 --- /dev/null +++ b/pkg/kubewarden/components/NamespaceNameInput.vue @@ -0,0 +1,414 @@ + + + + + diff --git a/pkg/kubewarden/components/Policies/Config.vue b/pkg/kubewarden/components/Policies/Config.vue index b1ece9b4..a0b39d0c 100644 --- a/pkg/kubewarden/components/Policies/Config.vue +++ b/pkg/kubewarden/components/Policies/Config.vue @@ -98,7 +98,7 @@ export default {
-