From d2264dc9ed9fab0f6140fd66ea218a5804e007b4 Mon Sep 17 00:00:00 2001 From: Cody Jackson Date: Mon, 15 Jun 2020 10:13:47 -0700 Subject: [PATCH] Ensuring apiGroups have an empty value OPA Constraints don't work unless there's an apiGroup present even if it's empty. This ensures that the empty apiGroup is present if no apiGroups were specified. rancher/dashboard#764 --- shared/gatekeeper-constraint.vue | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/shared/gatekeeper-constraint.vue b/shared/gatekeeper-constraint.vue index c7a2f46e7b8..e8148ad10d2 100644 --- a/shared/gatekeeper-constraint.vue +++ b/shared/gatekeeper-constraint.vue @@ -147,12 +147,22 @@ export default { }, async created() { + this.registerBeforeHook(this.willSave, 'willSave'); if (!this.value.save) { this.$emit('input', merge(await this.createConstraint(), this.value, this.emptyDefaults)); } }, methods: { + willSave() { + this.value.spec.match.kinds.forEach((kind) => { + const apiGroups = kind.apiGroups || []; + + if (apiGroups.length === 0) { + kind.apiGroups = ['*']; + } + }); + }, async createConstraint() { const constraint = await this.$store.dispatch('cluster/create', { type: this.templateOptions[0].value });