Skip to content

Commit

Permalink
Add metadata for top-level and nested variables
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Büringer buringerst@vmware.com
  • Loading branch information
sbueringer committed Jun 18, 2024
1 parent dc757d2 commit 806728f
Show file tree
Hide file tree
Showing 10 changed files with 516 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ issues:
# should be removed as the referenced deprecated item is removed from the project.
- linters:
- staticcheck
text: "SA1019: (bootstrapv1.ClusterStatus|KubeadmConfigSpec.UseExperimentalRetryJoin|scope.Config.Spec.UseExperimentalRetryJoin|DockerMachine.Spec.Bootstrapped|machineStatus.Bootstrapped|c.TopologyPlan) is deprecated"
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"
# Specific exclude rules for deprecated packages that are still part of the codebase. These
# should be removed as the referenced deprecated packages are removed from the project.
- linters:
Expand Down
28 changes: 28 additions & 0 deletions api/v1beta1/clusterclass_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,9 @@ type ClusterClassVariable struct {
// Metadata is the metadata of a variable.
// It can be used to add additional data for higher level tools to
// a ClusterClassVariable.
//
// Deprecated: This field is deprecated and is going to be removed in the next apiVersion. Please use XMetadata in JSONSchemaProps instead.
//
// +optional
Metadata ClusterClassVariableMetadata `json:"metadata,omitempty"`

Expand All @@ -406,6 +409,8 @@ type ClusterClassVariable struct {
// ClusterClassVariableMetadata is the metadata of a variable.
// It can be used to add additional data for higher level tools to
// a ClusterClassVariable.
//
// Deprecated: This struct is deprecated and is going to be removed in the next apiVersion.
type ClusterClassVariableMetadata struct {
// Map of string keys and values that can be used to organize and categorize
// (scope and select) variables.
Expand Down Expand Up @@ -551,6 +556,26 @@ type JSONSchemaProps struct {
// NOTE: Can be set for all types.
// +optional
Default *apiextensionsv1.JSON `json:"default,omitempty"`

// XMetadata is the metadata of a variable or a nested field within a variable.
// It can be used to add additional data for higher level tools.
// +optional
XMetadata *VariableSchemaMetadata `json:"x-metadata,omitempty"`
}

// VariableSchemaMetadata is the metadata of a variable or a nested field within a variable.
// It can be used to add additional data for higher level tools.
type VariableSchemaMetadata struct {
// Map of string keys and values that can be used to organize and categorize
// (scope and select) variables.
// +optional
Labels map[string]string `json:"labels,omitempty"`

// Annotations is an unstructured key value map that can be used to store and
// retrieve arbitrary metadata.
// They are not queryable.
// +optional
Annotations map[string]string `json:"annotations,omitempty"`
}

// ClusterClassPatch defines a patch which is applied to customize the referenced templates.
Expand Down Expand Up @@ -769,6 +794,9 @@ type ClusterClassStatusVariableDefinition struct {
// Metadata is the metadata of a variable.
// It can be used to add additional data for higher level tools to
// a ClusterClassVariable.
//
// Deprecated: This field is deprecated and is going to be removed in the next apiVersion.
//
// +optional
Metadata ClusterClassVariableMetadata `json:"metadata,omitempty"`

Expand Down
34 changes: 34 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 57 additions & 4 deletions api/v1beta1/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions config/crd/bases/cluster.x-k8s.io_clusterclasses.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions internal/controllers/clusterclass/clusterclass_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ func TestClusterClassReconciler_reconcile(t *testing.T) {
Schema: clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "integer",
XMetadata: &clusterv1.VariableSchemaMetadata{
Labels: map[string]string{
"some-label": "some-label-value",
},
Annotations: map[string]string{
"some-annotation": "some-annotation-value",
},
},
},
},
Metadata: clusterv1.ClusterClassVariableMetadata{
Expand Down Expand Up @@ -408,6 +416,14 @@ func TestReconciler_reconcileVariables(t *testing.T) {
Schema: clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "integer",
XMetadata: &clusterv1.VariableSchemaMetadata{
Labels: map[string]string{
"some-label": "some-label-value",
},
Annotations: map[string]string{
"some-annotation": "some-annotation-value",
},
},
},
},
Metadata: clusterv1.ClusterClassVariableMetadata{
Expand Down Expand Up @@ -448,6 +464,14 @@ func TestReconciler_reconcileVariables(t *testing.T) {
Schema: clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "integer",
XMetadata: &clusterv1.VariableSchemaMetadata{
Labels: map[string]string{
"some-label": "some-label-value",
},
Annotations: map[string]string{
"some-annotation": "some-annotation-value",
},
},
},
},
Metadata: clusterv1.ClusterClassVariableMetadata{
Expand Down Expand Up @@ -512,6 +536,14 @@ func TestReconciler_reconcileVariables(t *testing.T) {
Schema: clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "string",
XMetadata: &clusterv1.VariableSchemaMetadata{
Labels: map[string]string{
"some-label": "some-label-value",
},
Annotations: map[string]string{
"some-annotation": "some-annotation-value",
},
},
},
},
Metadata: clusterv1.ClusterClassVariableMetadata{
Expand All @@ -535,6 +567,14 @@ func TestReconciler_reconcileVariables(t *testing.T) {
Schema: clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "integer",
XMetadata: &clusterv1.VariableSchemaMetadata{
Labels: map[string]string{
"some-label": "some-label-value",
},
Annotations: map[string]string{
"some-annotation": "some-annotation-value",
},
},
},
},
Metadata: clusterv1.ClusterClassVariableMetadata{
Expand Down Expand Up @@ -565,6 +605,14 @@ func TestReconciler_reconcileVariables(t *testing.T) {
Schema: clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "string",
XMetadata: &clusterv1.VariableSchemaMetadata{
Labels: map[string]string{
"some-label": "some-label-value",
},
Annotations: map[string]string{
"some-annotation": "some-annotation-value",
},
},
},
},
Metadata: clusterv1.ClusterClassVariableMetadata{
Expand Down
Loading

0 comments on commit 806728f

Please sign in to comment.