From 5dba291112ece573f6905828f708a3c1d20d1d19 Mon Sep 17 00:00:00 2001 From: killianmuldoon Date: Tue, 24 Jan 2023 15:04:06 +0000 Subject: [PATCH] Add API types for DiscoverVariables hook --- .../api/v1alpha1/topologymutation_types.go | 36 ++++++ .../api/v1alpha1/zz_generated.deepcopy.go | 58 ++++++++++ .../api/v1alpha1/zz_generated.openapi.go | 105 ++++++++++++++++++ 3 files changed, 199 insertions(+) diff --git a/exp/runtime/hooks/api/v1alpha1/topologymutation_types.go b/exp/runtime/hooks/api/v1alpha1/topologymutation_types.go index c6a353671d7e..4a3f2fd0bf51 100644 --- a/exp/runtime/hooks/api/v1alpha1/topologymutation_types.go +++ b/exp/runtime/hooks/api/v1alpha1/topologymutation_types.go @@ -22,6 +22,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" runtimecatalog "sigs.k8s.io/cluster-api/exp/runtime/catalog" ) @@ -179,6 +180,32 @@ type HolderReference struct { // ValidateTopology validates the Cluster topology after all patches have been applied. func ValidateTopology(*ValidateTopologyRequest, *ValidateTopologyResponse) {} +// DiscoverVariablesRequest is the request of the DiscoverVariables hook. +// +kubebuilder:object:root=true +type DiscoverVariablesRequest struct { + metav1.TypeMeta `json:",inline"` + + // CommonRequest contains Settings field common to all request types. + CommonRequest `json:",inline"` +} + +// DiscoverVariablesResponse is the response of the DiscoverVariables hook. +// +kubebuilder:object:root=true +type DiscoverVariablesResponse struct { + metav1.TypeMeta `json:",inline"` + + // CommonResponse contains Status and Message fields common to all response types. + CommonResponse `json:",inline"` + + // Variables are variable schemas for variables defined by the DiscoverVariables hook. + Variables []clusterv1.ClusterClassVariable `json:"variables"` +} + +var _ ResponseObject = &DiscoverVariablesResponse{} + +// DiscoverVariables returns variable schemas defined by a Runtime Extension. +func DiscoverVariables(*DiscoverVariablesRequest, *DiscoverVariablesResponse) {} + func init() { catalogBuilder.RegisterHook(GeneratePatches, &runtimecatalog.HookMeta{ Tags: []string{"Topology Mutation Hook"}, @@ -203,4 +230,13 @@ func init() { "- The call's request contains all templates, the global variables and the template-specific variables used while computing patches\n" + "- The response must contain the result of the validation", }) + + catalogBuilder.RegisterHook(DiscoverVariables, &runtimecatalog.HookMeta{ + Tags: []string{"Topology Mutation Hook"}, + Summary: "Cluster API Runtime will call this hook when ClusterClass variables are being computed", + Description: "Cluster API Runtime will call this hook when ClusterClass variables are being computed " + + "during the ClusterClass reconcile loop." + + "Notes:\n" + + "- The response must contain the schemas of all variables defined by the patch.", + }) } diff --git a/exp/runtime/hooks/api/v1alpha1/zz_generated.deepcopy.go b/exp/runtime/hooks/api/v1alpha1/zz_generated.deepcopy.go index c9c01155cfcd..a4979390ee29 100644 --- a/exp/runtime/hooks/api/v1alpha1/zz_generated.deepcopy.go +++ b/exp/runtime/hooks/api/v1alpha1/zz_generated.deepcopy.go @@ -23,6 +23,7 @@ package v1alpha1 import ( "k8s.io/apimachinery/pkg/runtime" + "sigs.k8s.io/cluster-api/api/v1beta1" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -384,6 +385,63 @@ func (in *CommonRetryResponse) DeepCopy() *CommonRetryResponse { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DiscoverVariablesRequest) DeepCopyInto(out *DiscoverVariablesRequest) { + *out = *in + out.TypeMeta = in.TypeMeta + in.CommonRequest.DeepCopyInto(&out.CommonRequest) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DiscoverVariablesRequest. +func (in *DiscoverVariablesRequest) DeepCopy() *DiscoverVariablesRequest { + if in == nil { + return nil + } + out := new(DiscoverVariablesRequest) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *DiscoverVariablesRequest) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DiscoverVariablesResponse) DeepCopyInto(out *DiscoverVariablesResponse) { + *out = *in + out.TypeMeta = in.TypeMeta + out.CommonResponse = in.CommonResponse + if in.Variables != nil { + in, out := &in.Variables, &out.Variables + *out = make([]v1beta1.ClusterClassVariable, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DiscoverVariablesResponse. +func (in *DiscoverVariablesResponse) DeepCopy() *DiscoverVariablesResponse { + if in == nil { + return nil + } + out := new(DiscoverVariablesResponse) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *DiscoverVariablesResponse) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *DiscoveryRequest) DeepCopyInto(out *DiscoveryRequest) { *out = *in diff --git a/exp/runtime/hooks/api/v1alpha1/zz_generated.openapi.go b/exp/runtime/hooks/api/v1alpha1/zz_generated.openapi.go index b5b523a17a05..1486a6fdd83d 100644 --- a/exp/runtime/hooks/api/v1alpha1/zz_generated.openapi.go +++ b/exp/runtime/hooks/api/v1alpha1/zz_generated.openapi.go @@ -45,6 +45,8 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1.CommonRequest": schema_runtime_hooks_api_v1alpha1_CommonRequest(ref), "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1.CommonResponse": schema_runtime_hooks_api_v1alpha1_CommonResponse(ref), "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1.CommonRetryResponse": schema_runtime_hooks_api_v1alpha1_CommonRetryResponse(ref), + "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1.DiscoverVariablesRequest": schema_runtime_hooks_api_v1alpha1_DiscoverVariablesRequest(ref), + "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1.DiscoverVariablesResponse": schema_runtime_hooks_api_v1alpha1_DiscoverVariablesResponse(ref), "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1.DiscoveryRequest": schema_runtime_hooks_api_v1alpha1_DiscoveryRequest(ref), "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1.DiscoveryResponse": schema_runtime_hooks_api_v1alpha1_DiscoveryResponse(ref), "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1.ExtensionHandler": schema_runtime_hooks_api_v1alpha1_ExtensionHandler(ref), @@ -804,6 +806,109 @@ func schema_runtime_hooks_api_v1alpha1_CommonRetryResponse(ref common.ReferenceC } } +func schema_runtime_hooks_api_v1alpha1_DiscoverVariablesRequest(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "DiscoverVariablesRequest is the request of the DiscoverVariables hook.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "kind": { + SchemaProps: spec.SchemaProps{ + Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", + Type: []string{"string"}, + Format: "", + }, + }, + "apiVersion": { + SchemaProps: spec.SchemaProps{ + Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", + Type: []string{"string"}, + Format: "", + }, + }, + "settings": { + SchemaProps: spec.SchemaProps{ + Description: "Settings defines key value pairs to be passed to the call.", + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Allows: true, + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + }, + }, + }, + } +} + +func schema_runtime_hooks_api_v1alpha1_DiscoverVariablesResponse(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "DiscoverVariablesResponse is the response of the DiscoverVariables hook.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "kind": { + SchemaProps: spec.SchemaProps{ + Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", + Type: []string{"string"}, + Format: "", + }, + }, + "apiVersion": { + SchemaProps: spec.SchemaProps{ + Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", + Type: []string{"string"}, + Format: "", + }, + }, + "status": { + SchemaProps: spec.SchemaProps{ + Description: "Status of the call. One of \"Success\" or \"Failure\".\n\nPossible enum values:\n - `\"Failure\"` represents a failure response.\n - `\"Success\"` represents a success response.", + Default: "", + Type: []string{"string"}, + Format: "", + Enum: []interface{}{"Failure", "Success"}}, + }, + "message": { + SchemaProps: spec.SchemaProps{ + Description: "A human-readable description of the status of the call.", + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "variables": { + SchemaProps: spec.SchemaProps{ + Description: "Variables are variable schemas for variables defined by the DiscoverVariables hook.", + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("sigs.k8s.io/cluster-api/api/v1beta1.ClusterClassVariable"), + }, + }, + }, + }, + }, + }, + Required: []string{"status", "message", "variables"}, + }, + }, + Dependencies: []string{ + "sigs.k8s.io/cluster-api/api/v1beta1.ClusterClassVariable"}, + } +} + func schema_runtime_hooks_api_v1alpha1_DiscoveryRequest(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{