@@ -23,128 +23,14 @@ package api
23
23
24
24
import (
25
25
"context"
26
- "fmt"
27
26
28
- apiextensionsv1 " k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1 "
27
+ runtimehooksv1 "sigs. k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1 "
29
28
)
30
29
31
30
// Generator defines a component that can generate patches for ClusterClass templates.
32
31
type Generator interface {
33
32
// Generate generates patches for templates.
34
- // GenerateRequest contains templates and the corresponding variables.
35
- // GenerateResponse contains the patches which should be applied to the templates of the GenerateRequest.
36
- Generate (ctx context.Context , request * GenerateRequest ) (* GenerateResponse , error )
37
- }
38
-
39
- // GenerateRequest defines the input for a Generate request.
40
- type GenerateRequest struct {
41
- // Variables is a name/value map containing variables.
42
- Variables map [string ]apiextensionsv1.JSON
43
-
44
- // Items contains the list of templates to generate patches for.
45
- Items []* GenerateRequestTemplate
46
- }
47
-
48
- // GenerateRequestTemplate defines one of the ClusterClass templates to generate patches for.
49
- type GenerateRequestTemplate struct {
50
- // TemplateRef identifies a template to generate patches for;
51
- // the same TemplateRef must be used when specifying to which template a generated patch should be applied to.
52
- TemplateRef TemplateRef
53
-
54
- // Variables is a name/value map containing variables specifically for the current template.
55
- // For example some builtin variables like MachineDeployment replicas and version are context-sensitive
56
- // and thus are only added to templates for MachineDeployments and with values which correspond to the
57
- // current MachineDeployment.
58
- Variables map [string ]apiextensionsv1.JSON
59
-
60
- // Template contains the template.
61
- Template apiextensionsv1.JSON
62
- }
63
-
64
- // TemplateRef identifies one of the ClusterClass templates to generate patches for;
65
- // the same TemplateRef must be used when specifying where a generated patch should apply to.
66
- type TemplateRef struct {
67
- // APIVersion of the current template.
68
- APIVersion string
69
-
70
- // Kind of the current template.
71
- Kind string
72
-
73
- // TemplateType defines where the template is used.
74
- TemplateType TemplateType
75
-
76
- // MachineDeployment specifies the MachineDeployment in which the template is used.
77
- // This field is only set if the template is used in the context of a MachineDeployment.
78
- MachineDeploymentRef MachineDeploymentRef
79
- }
80
-
81
- func (t TemplateRef ) String () string {
82
- ret := fmt .Sprintf ("%s %s/%s" , t .TemplateType , t .APIVersion , t .Kind )
83
- if t .MachineDeploymentRef .TopologyName != "" {
84
- ret = fmt .Sprintf ("%s, MachineDeployment topology %s" , ret , t .MachineDeploymentRef .TopologyName )
85
- }
86
- if t .MachineDeploymentRef .Class != "" {
87
- ret = fmt .Sprintf ("%s, MachineDeployment class %s" , ret , t .MachineDeploymentRef .Class )
88
- }
89
- return ret
90
- }
91
-
92
- // MachineDeploymentRef specifies the MachineDeployment in which the template is used.
93
- type MachineDeploymentRef struct {
94
- // TopologyName is the name of the MachineDeploymentTopology.
95
- TopologyName string
96
-
97
- // Class is the name of the MachineDeploymentClass.
98
- Class string
99
- }
100
-
101
- // TemplateType define the type for target types enum.
102
- type TemplateType string
103
-
104
- const (
105
- // InfrastructureClusterTemplateType identifies a template for the InfrastructureCluster object.
106
- InfrastructureClusterTemplateType TemplateType = "InfrastructureClusterTemplate"
107
-
108
- // ControlPlaneTemplateType identifies a template for the ControlPlane object.
109
- ControlPlaneTemplateType TemplateType = "ControlPlaneTemplate"
110
-
111
- // ControlPlaneInfrastructureMachineTemplateType identifies a template for the InfrastructureMachines to be used for the ControlPlane object.
112
- ControlPlaneInfrastructureMachineTemplateType TemplateType = "ControlPlane/InfrastructureMachineTemplate"
113
-
114
- // MachineDeploymentBootstrapConfigTemplateType identifies a template for the BootstrapConfig to be used for a MachineDeployment object.
115
- MachineDeploymentBootstrapConfigTemplateType TemplateType = "MachineDeployment/BootstrapConfigTemplate"
116
-
117
- // MachineDeploymentInfrastructureMachineTemplateType identifies a template for the InfrastructureMachines to be used for a MachineDeployment object.
118
- MachineDeploymentInfrastructureMachineTemplateType TemplateType = "MachineDeployment/InfrastructureMachineTemplate"
119
- )
120
-
121
- // PatchType define the type for patch types enum.
122
- type PatchType string
123
-
124
- const (
125
- // JSONPatchType identifies a https://datatracker.ietf.org/doc/html/rfc6902 json patch.
126
- JSONPatchType PatchType = "JSONPatch"
127
-
128
- // JSONMergePatchType identifies a https://datatracker.ietf.org/doc/html/rfc7386 json merge patch.
129
- JSONMergePatchType PatchType = "JSONMergePatch"
130
- )
131
-
132
- // GenerateResponse defines the response of a Generate request.
133
- // NOTE: Patches defined in GenerateResponse will be applied in the same order to the original
134
- // GenerateRequest object, thus adding changes on templates across all the subsequent Generate calls.
135
- type GenerateResponse struct {
136
- // Items contains the list of generated patches.
137
- Items []GenerateResponsePatch
138
- }
139
-
140
- // GenerateResponsePatch defines a Patch targeting a specific GenerateRequestTemplate.
141
- type GenerateResponsePatch struct {
142
- // TemplateRef identifies the template the patch should apply to.
143
- TemplateRef TemplateRef
144
-
145
- // Patch contains the patch.
146
- Patch apiextensionsv1.JSON
147
-
148
- // Patch defines the type of the JSON patch.
149
- PatchType PatchType
33
+ // GeneratePatchesRequest contains templates and the corresponding variables.
34
+ // GeneratePatchesResponse contains the patches which should be applied to the templates of the GenerateRequest.
35
+ Generate (context.Context , * runtimehooksv1.GeneratePatchesRequest ) * runtimehooksv1.GeneratePatchesResponse
150
36
}
0 commit comments