{{ shortDescription }} diff --git a/pkg/kubewarden/components/Policies/Create.vue b/pkg/kubewarden/components/Policies/Create.vue index 06c04ed2..24ef06c5 100644 --- a/pkg/kubewarden/components/Policies/Create.vue +++ b/pkg/kubewarden/components/Policies/Create.vue @@ -21,7 +21,8 @@ import { KUBEWARDEN_PRODUCT_NAME, VALUES_STATE, ARTIFACTHUB_PKG_ANNOTATION, - DEFAULT_POLICY + DEFAULT_POLICY, + KUBEWARDEN_KIND } from '../../types'; import { removeEmptyAttrs } from '../../utils/object'; import { handleGrowl } from '../../utils/handle-growl'; @@ -56,8 +57,6 @@ export default ({ Values }, - inject: ['chartType'], - mixins: [CreateEditView], async fetch() { @@ -295,11 +294,17 @@ export default ({ out = this.chartValues?.policy ? this.chartValues.policy : jsyaml.load(this.yamlValues); } + const resourceType = this.chartValues?.policy?.kind; + const schemaType = resourceType === KUBEWARDEN_KIND.ADMISSION_POLICY ? KUBEWARDEN.ADMISSION_POLICY : KUBEWARDEN.CLUSTER_ADMISSION_POLICY; + + // Set policy type to be saved + this.$set(out, 'type', schemaType); + removeEmptyAttrs(out); // Clean up empty values from questions merge(this.value, out); // If create new namespace option is selected, create the ns before saving the policy - if ( this.chartType === KUBEWARDEN.ADMISSION_POLICY && this.chartValues?.isNamespaceNew ) { + if ( schemaType === KUBEWARDEN.ADMISSION_POLICY && this.chartValues?.isNamespaceNew ) { await this.createNamespace(this.value?.metadata?.namespace); } diff --git a/pkg/kubewarden/components/Policies/PolicyTable.vue b/pkg/kubewarden/components/Policies/PolicyTable.vue index 59acce58..d53e65a0 100644 --- a/pkg/kubewarden/components/Policies/PolicyTable.vue +++ b/pkg/kubewarden/components/Policies/PolicyTable.vue @@ -33,8 +33,6 @@ export default { } }, - inject: ['chartType'], - components: { Checkbox, LabeledSelect, LabeledInput, SortableTableWrapper }, @@ -73,10 +71,6 @@ export default { return false; // Exclude pre-releases if showPreRelease is false } - if ( this.chartType === KUBEWARDEN.ADMISSION_POLICY ) { - return !isGlobalPolicy(artifactHubPackage, this.allSchemas); - } - return true; }); diff --git a/pkg/kubewarden/components/Policies/Values.vue b/pkg/kubewarden/components/Policies/Values.vue index 39d2002d..01fbecd3 100644 --- a/pkg/kubewarden/components/Policies/Values.vue +++ b/pkg/kubewarden/components/Policies/Values.vue @@ -12,7 +12,11 @@ import ResourceCancelModal from '@shell/components/ResourceCancelModal'; import Tabbed from '@shell/components/Tabbed'; import YamlEditor, { EDITOR_MODES } from '@shell/components/YamlEditor'; -import { KUBEWARDEN_CHARTS, VALUES_STATE, YAML_OPTIONS, RANCHER_NS_MATCH_EXPRESSION } from '../../types'; +import { + KUBEWARDEN, KUBEWARDEN_KIND, KUBEWARDEN_CHARTS, VALUES_STATE, YAML_OPTIONS, RANCHER_NS_MATCH_EXPRESSION +} from '../../types'; + +import Basic from '../../chart/kubewarden/admission/Basic'; export default { name: 'Values', @@ -41,7 +45,16 @@ export default { }, components: { - ButtonGroup, Loading, ResourceCancelModal, Tabbed, YamlEditor + Basic, ButtonGroup, Loading, ResourceCancelModal, Tabbed, YamlEditor + }, + + provide() { + const values = this.chartValues?.policy ? this.chartValues.policy : this.chartValues || {}; + + const resourceKind = values?.kind; + const schemaType = resourceKind === KUBEWARDEN_KIND.ADMISSION_POLICY ? KUBEWARDEN.ADMISSION_POLICY : KUBEWARDEN.CLUSTER_ADMISSION_POLICY; + + return { chartType: schemaType }; }, async fetch() { @@ -180,6 +193,9 @@ export default { active-class="bg-primary btn-sm" />