Skip to content

Commit

Permalink
feat: make ResourceGroup schema.kind and schema.apiVersion immutable
Browse files Browse the repository at this point in the history
Add CEL validation rules to prevent modifications to the schema `kind` and
`apiVersion` fields after a `ResourceGroup` is created. This ensures schema
stability and  prevents potential issues that could arise from changing
these fundamental identity fields.
  • Loading branch information
a-hilaly committed Nov 11, 2024
1 parent f4e1697 commit 16ad925
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/v1alpha1/resource_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ type Schema struct {
// and create the CRD for the resourcegroup.
//
// +kubebuilder:validation:Required
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="kind is immutable"
Kind string `json:"kind,omitempty"`
// The APIVersion of the resourcegroup. This is used to generate
// and create the CRD for the resourcegroup.
//
// +kubebuilder:validation:Required
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="apiVersion is immutable"
APIVersion string `json:"apiVersion,omitempty"`
// The spec of the resourcegroup. Typically, this is the spec of
// the CRD that the resourcegroup is managing. This is adhering
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/kro.run_resourcegroups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,17 @@ spec:
The APIVersion of the resourcegroup. This is used to generate
and create the CRD for the resourcegroup.
type: string
x-kubernetes-validations:
- message: apiVersion is immutable
rule: self == oldSelf
kind:
description: |-
The kind of the resourcegroup. This is used to generate
and create the CRD for the resourcegroup.
type: string
x-kubernetes-validations:
- message: kind is immutable
rule: self == oldSelf
spec:
description: |-
The spec of the resourcegroup. Typically, this is the spec of
Expand Down

0 comments on commit 16ad925

Please sign in to comment.