Skip to content

Commit 73d78e4

Browse files
committed
Add metadata for top-level and nested variables
Signed-off-by: Stefan Büringer [email protected]
1 parent ada2764 commit 73d78e4

File tree

10 files changed

+542
-6
lines changed

10 files changed

+542
-6
lines changed

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ issues:
234234
# should be removed as the referenced deprecated item is removed from the project.
235235
- linters:
236236
- staticcheck
237-
text: "SA1019: (bootstrapv1.ClusterStatus|KubeadmConfigSpec.UseExperimentalRetryJoin|scope.Config.Spec.UseExperimentalRetryJoin|DockerMachine.Spec.Bootstrapped|machineStatus.Bootstrapped|c.TopologyPlan) is deprecated"
237+
text: "SA1019: (bootstrapv1.ClusterStatus|KubeadmConfigSpec.UseExperimentalRetryJoin|scope.Config.Spec.UseExperimentalRetryJoin|DockerMachine.Spec.Bootstrapped|machineStatus.Bootstrapped|c.TopologyPlan|clusterv1.ClusterClassVariableMetadata|(variable|currentDefinition|specVar|newVariableDefinition|statusVarDefinition).Metadata) is deprecated"
238238
# Specific exclude rules for deprecated packages that are still part of the codebase. These
239239
# should be removed as the referenced deprecated packages are removed from the project.
240240
- linters:

api/v1beta1/clusterclass_types.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,9 @@ type ClusterClassVariable struct {
396396
// Metadata is the metadata of a variable.
397397
// It can be used to add additional data for higher level tools to
398398
// a ClusterClassVariable.
399+
//
400+
// Deprecated: This field is deprecated and is going to be removed in the next apiVersion. Please use XMetadata in JSONSchemaProps instead.
401+
//
399402
// +optional
400403
Metadata ClusterClassVariableMetadata `json:"metadata,omitempty"`
401404

@@ -406,6 +409,8 @@ type ClusterClassVariable struct {
406409
// ClusterClassVariableMetadata is the metadata of a variable.
407410
// It can be used to add additional data for higher level tools to
408411
// a ClusterClassVariable.
412+
//
413+
// Deprecated: This struct is deprecated and is going to be removed in the next apiVersion.
409414
type ClusterClassVariableMetadata struct {
410415
// Map of string keys and values that can be used to organize and categorize
411416
// (scope and select) variables.
@@ -569,6 +574,26 @@ type JSONSchemaProps struct {
569574
// +listType=map
570575
// +listMapKey=rule
571576
XValidations []ValidationRule `json:"x-kubernetes-validations,omitempty"`
577+
578+
// XMetadata is the metadata of a variable or a nested field within a variable.
579+
// It can be used to add additional data for higher level tools.
580+
// +optional
581+
XMetadata *VariableSchemaMetadata `json:"x-metadata,omitempty"`
582+
}
583+
584+
// VariableSchemaMetadata is the metadata of a variable or a nested field within a variable.
585+
// It can be used to add additional data for higher level tools.
586+
type VariableSchemaMetadata struct {
587+
// Map of string keys and values that can be used to organize and categorize
588+
// (scope and select) variables.
589+
// +optional
590+
Labels map[string]string `json:"labels,omitempty"`
591+
592+
// Annotations is an unstructured key value map that can be used to store and
593+
// retrieve arbitrary metadata.
594+
// They are not queryable.
595+
// +optional
596+
Annotations map[string]string `json:"annotations,omitempty"`
572597
}
573598

574599
// ValidationRule describes a validation rule written in the CEL expression language.
@@ -897,6 +922,9 @@ type ClusterClassStatusVariableDefinition struct {
897922
// Metadata is the metadata of a variable.
898923
// It can be used to add additional data for higher level tools to
899924
// a ClusterClassVariable.
925+
//
926+
// Deprecated: This field is deprecated and is going to be removed in the next apiVersion.
927+
//
900928
// +optional
901929
Metadata ClusterClassVariableMetadata `json:"metadata,omitempty"`
902930

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta1/zz_generated.openapi.go

Lines changed: 56 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/cluster.x-k8s.io_clusterclasses.yaml

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/controllers/clusterclass/clusterclass_controller_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ func TestClusterClassReconciler_reconcile(t *testing.T) {
114114
Schema: clusterv1.VariableSchema{
115115
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
116116
Type: "integer",
117+
XMetadata: &clusterv1.VariableSchemaMetadata{
118+
Labels: map[string]string{
119+
"some-label": "some-label-value",
120+
},
121+
Annotations: map[string]string{
122+
"some-annotation": "some-annotation-value",
123+
},
124+
},
117125
},
118126
},
119127
Metadata: clusterv1.ClusterClassVariableMetadata{
@@ -408,6 +416,14 @@ func TestReconciler_reconcileVariables(t *testing.T) {
408416
Schema: clusterv1.VariableSchema{
409417
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
410418
Type: "integer",
419+
XMetadata: &clusterv1.VariableSchemaMetadata{
420+
Labels: map[string]string{
421+
"some-label": "some-label-value",
422+
},
423+
Annotations: map[string]string{
424+
"some-annotation": "some-annotation-value",
425+
},
426+
},
411427
},
412428
},
413429
Metadata: clusterv1.ClusterClassVariableMetadata{
@@ -448,6 +464,14 @@ func TestReconciler_reconcileVariables(t *testing.T) {
448464
Schema: clusterv1.VariableSchema{
449465
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
450466
Type: "integer",
467+
XMetadata: &clusterv1.VariableSchemaMetadata{
468+
Labels: map[string]string{
469+
"some-label": "some-label-value",
470+
},
471+
Annotations: map[string]string{
472+
"some-annotation": "some-annotation-value",
473+
},
474+
},
451475
},
452476
},
453477
Metadata: clusterv1.ClusterClassVariableMetadata{
@@ -512,6 +536,14 @@ func TestReconciler_reconcileVariables(t *testing.T) {
512536
Schema: clusterv1.VariableSchema{
513537
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
514538
Type: "string",
539+
XMetadata: &clusterv1.VariableSchemaMetadata{
540+
Labels: map[string]string{
541+
"some-label": "some-label-value",
542+
},
543+
Annotations: map[string]string{
544+
"some-annotation": "some-annotation-value",
545+
},
546+
},
515547
},
516548
},
517549
Metadata: clusterv1.ClusterClassVariableMetadata{
@@ -535,6 +567,14 @@ func TestReconciler_reconcileVariables(t *testing.T) {
535567
Schema: clusterv1.VariableSchema{
536568
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
537569
Type: "integer",
570+
XMetadata: &clusterv1.VariableSchemaMetadata{
571+
Labels: map[string]string{
572+
"some-label": "some-label-value",
573+
},
574+
Annotations: map[string]string{
575+
"some-annotation": "some-annotation-value",
576+
},
577+
},
538578
},
539579
},
540580
Metadata: clusterv1.ClusterClassVariableMetadata{
@@ -565,6 +605,14 @@ func TestReconciler_reconcileVariables(t *testing.T) {
565605
Schema: clusterv1.VariableSchema{
566606
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
567607
Type: "string",
608+
XMetadata: &clusterv1.VariableSchemaMetadata{
609+
Labels: map[string]string{
610+
"some-label": "some-label-value",
611+
},
612+
Annotations: map[string]string{
613+
"some-annotation": "some-annotation-value",
614+
},
615+
},
568616
},
569617
},
570618
Metadata: clusterv1.ClusterClassVariableMetadata{

0 commit comments

Comments
 (0)