Skip to content

Commit 5534060

Browse files
authored
Merge pull request #870 from a-hilaly/immutable-group
Make `schema.group` field immutable
2 parents 15a3c32 + e4ff7b3 commit 5534060

File tree

7 files changed

+26
-28
lines changed

7 files changed

+26
-28
lines changed

api/v1alpha1/resourcegraphdefinition_types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,12 @@ type Schema struct {
6262
APIVersion string `json:"apiVersion,omitempty"`
6363
// Group is the API group for the generated CRD. Together with APIVersion and Kind,
6464
// it forms the complete GVK (Group-Version-Kind) identifier.
65-
// If omitted, defaults to "kro.run".
65+
// If omitted, defaults to "kro.run". This field is immutable after creation.
6666
// Example: "mycompany.io", "databases.example.com"
6767
//
6868
// +kubebuilder:validation:Optional
6969
// +kubebuilder:default="kro.run"
70+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="group is immutable"
7071
Group string `json:"group,omitempty"`
7172
// Spec defines the schema for the instance's spec section using SimpleSchema syntax.
7273
// This becomes the OpenAPI schema for instances of the generated CRD.

helm/crds/kro.run_resourcegraphdefinitions.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,12 @@ spec:
223223
description: |-
224224
Group is the API group for the generated CRD. Together with APIVersion and Kind,
225225
it forms the complete GVK (Group-Version-Kind) identifier.
226-
If omitted, defaults to "kro.run".
226+
If omitted, defaults to "kro.run". This field is immutable after creation.
227227
Example: "mycompany.io", "databases.example.com"
228228
type: string
229+
x-kubernetes-validations:
230+
- message: group is immutable
231+
rule: self == oldSelf
229232
kind:
230233
description: |-
231234
Kind is the name of the custom resource type that will be created.

pkg/controller/resourcegraphdefinition/controller_cleanup.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,8 @@ func (r *ResourceGraphDefinitionReconciler) cleanupResourceGraphDefinition(ctx c
4040
return fmt.Errorf("failed to shutdown microcontroller: %w", err)
4141
}
4242

43-
group := rgd.Spec.Schema.Group
44-
if group == "" {
45-
group = v1alpha1.KRODomainName
46-
}
4743
// cleanup CRD
48-
crdName := extractCRDName(group, rgd.Spec.Schema.Kind)
44+
crdName := extractCRDName(rgd.Spec.Schema.Group, rgd.Spec.Schema.Kind)
4945
if err := r.cleanupResourceGraphDefinitionCRD(ctx, crdName); err != nil {
5046
return fmt.Errorf("failed to cleanup CRD %s: %w", crdName, err)
5147
}

pkg/graph/crd/crd.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,12 @@ import (
2121
"github.com/gobuffalo/flect"
2222
extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2323
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24-
25-
"github.com/kubernetes-sigs/kro/api/v1alpha1"
2624
)
2725

2826
// SynthesizeCRD generates a CustomResourceDefinition for a given API version and kind
2927
// with the provided spec and status schemas~
3028
func SynthesizeCRD(group, apiVersion, kind string, spec, status extv1.JSONSchemaProps, statusFieldsOverride bool, additionalPrinterColumns []extv1.CustomResourceColumnDefinition) *extv1.CustomResourceDefinition {
31-
crdGroup := group
32-
if crdGroup == "" {
33-
crdGroup = v1alpha1.KRODomainName
34-
}
35-
return newCRD(crdGroup, apiVersion, kind, newCRDSchema(spec, status, statusFieldsOverride), additionalPrinterColumns)
29+
return newCRD(group, apiVersion, kind, newCRDSchema(spec, status, statusFieldsOverride), additionalPrinterColumns)
3630
}
3731

3832
func newCRD(group, apiVersion, kind string, schema *extv1.JSONSchemaProps, additionalPrinterColumns []extv1.CustomResourceColumnDefinition) *extv1.CustomResourceDefinition {

pkg/graph/crd/crd_test.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import (
2020
"github.com/stretchr/testify/assert"
2121
"github.com/stretchr/testify/require"
2222
extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
23-
24-
"github.com/kubernetes-sigs/kro/api/v1alpha1"
2523
)
2624

2725
func TestSynthesizeCRD(t *testing.T) {
@@ -47,17 +45,6 @@ func TestSynthesizeCRD(t *testing.T) {
4745
expectedName: "widgets.kro.com",
4846
expectedGroup: "kro.com",
4947
},
50-
{
51-
name: "empty group uses default domain",
52-
group: "",
53-
apiVersion: "v1alphav2",
54-
kind: "Service",
55-
spec: extv1.JSONSchemaProps{Type: "object"},
56-
status: extv1.JSONSchemaProps{Type: "object"},
57-
statusFieldsOverride: false,
58-
expectedName: "services." + v1alpha1.KRODomainName,
59-
expectedGroup: v1alpha1.KRODomainName,
60-
},
6148
{
6249
name: "mixes case kind",
6350
group: "kro.com",

test/integration/suites/core/format_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2025 The Kube Resource Orchestrator Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package core_test
216

317
import (

website/static/crds/kro.run_resourcegraphdefinitions.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,12 @@ spec:
223223
description: |-
224224
Group is the API group for the generated CRD. Together with APIVersion and Kind,
225225
it forms the complete GVK (Group-Version-Kind) identifier.
226-
If omitted, defaults to "kro.run".
226+
If omitted, defaults to "kro.run". This field is immutable after creation.
227227
Example: "mycompany.io", "databases.example.com"
228228
type: string
229+
x-kubernetes-validations:
230+
- message: group is immutable
231+
rule: self == oldSelf
229232
kind:
230233
description: |-
231234
Kind is the name of the custom resource type that will be created.

0 commit comments

Comments
 (0)