Skip to content

Commit

Permalink
Ensuring apiGroups have an empty value
Browse files Browse the repository at this point in the history
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.

#764
  • Loading branch information
codyrancher committed Jun 15, 2020
1 parent 9f99cea commit d2264dc
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions shared/gatekeeper-constraint.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down

0 comments on commit d2264dc

Please sign in to comment.