@@ -19,56 +19,71 @@ import (
1919 "k8s.io/apimachinery/pkg/runtime"
2020)
2121
22- // ResourceGraphDefinitionSpec defines the desired state of ResourceGraphDefinition
22+ // ResourceGraphDefinitionSpec defines the desired state of ResourceGraphDefinition.
23+ // It contains the schema for instances (defining the CRD structure) and the list of
24+ // Kubernetes resources that make up the graph.
2325type ResourceGraphDefinitionSpec struct {
24- // The schema of the resourcegraphdefinition, which includes the
25- // apiVersion , kind, spec, status, types, and some validation
26- // rules .
26+ // Schema defines the structure of instances created from this ResourceGraphDefinition.
27+ // It specifies the API version , kind, and fields (spec/ status) for the generated CRD.
28+ // Use SimpleSchema syntax to define the instance schema concisely .
2729 //
2830 // +kubebuilder:validation:Required
2931 Schema * Schema `json:"schema,omitempty"`
30- // The resources that are part of the resourcegraphdefinition.
32+ // Resources is the list of Kubernetes resources that will be created and managed
33+ // for each instance. Resources can reference each other using CEL expressions,
34+ // creating a dependency graph that determines creation order.
3135 //
3236 // +kubebuilder:validation:Optional
3337 Resources []* Resource `json:"resources,omitempty"`
3438}
3539
36- // Schema represents the attributes that define an instance of
37- // a resourcegraphdefinition.
40+ // Schema defines the structure and behavior of instances created from a ResourceGraphDefinition.
41+ // It specifies the API group, version, and kind for the generated CRD, along with the
42+ // spec and status schemas using SimpleSchema syntax. You can also define custom types,
43+ // validation rules, and printer columns.
3844type Schema struct {
39- // The kind of the resourcegraphdefinition. This is used to generate
40- // and create the CRD for the resourcegraphdefinition.
45+ // Kind is the name of the custom resource type that will be created.
46+ // This becomes the kind field of the generated CRD and must be a valid Kubernetes kind name
47+ // (PascalCase, starting with a capital letter). This field is immutable after creation.
48+ // Example: "WebApplication", "Database", "MicroService"
4149 //
4250 // +kubebuilder:validation:Required
4351 // +kubebuilder:validation:Pattern=`^[A-Z][a-zA-Z0-9]{0,62}$`
4452 // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="kind is immutable"
4553 Kind string `json:"kind,omitempty"`
46- // The APIVersion of the resourcegraphdefinition. This is used to generate
47- // and create the CRD for the resourcegraphdefinition.
54+ // APIVersion is the version identifier for the generated CRD.
55+ // Must follow Kubernetes versioning conventions (v1, v1alpha1, v1beta1, etc.).
56+ // This field is immutable after creation.
57+ // Example: "v1alpha1", "v1", "v2beta1"
4858 //
4959 // +kubebuilder:validation:Required
5060 // +kubebuilder:validation:Pattern=`^v[0-9]+(alpha[0-9]+|beta[0-9]+)?$`
5161 // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="apiVersion is immutable"
5262 APIVersion string `json:"apiVersion,omitempty"`
53- // The group of the resourcegraphdefinition. This is used to set the API group
54- // of the generated CRD. If omitted, it defaults to "kro.run".
63+ // Group is the API group for the generated CRD. Together with APIVersion and Kind,
64+ // it forms the complete GVK (Group-Version-Kind) identifier.
65+ // If omitted, defaults to "kro.run".
66+ // Example: "mycompany.io", "databases.example.com"
5567 //
5668 // +kubebuilder:validation:Optional
5769 // +kubebuilder:default="kro.run"
5870 Group string `json:"group,omitempty"`
59- // The spec of the resourcegraphdefinition. Typically, this is the spec of
60- // the CRD that the resourcegraphdefinition is managing. This is adhering
61- // to the SimpleSchema spec
71+ // Spec defines the schema for the instance's spec section using SimpleSchema syntax.
72+ // This becomes the OpenAPI schema for instances of the generated CRD.
73+ // Use SimpleSchema's concise syntax to define fields, types, defaults, and validations.
74+ // Example: {"replicas": "integer | default=1 | min=1 | max=10"}
6275 Spec runtime.RawExtension `json:"spec,omitempty"`
6376
64- // Types is a map of custom type definitions. These can be used in the spec
65- // of the resourcegraphdefinition. Each type definition is also adhering to
66- // the SimpleSchema spec.
77+ // Types is a map of custom type definitions that can be referenced in the Spec.
78+ // This allows you to define reusable complex types using SimpleSchema syntax.
79+ // Reference custom types in Spec using the type name.
80+ // Example: {"Server": {"host": "string", "port": "integer"}}
6781 Types runtime.RawExtension `json:"types,omitempty"`
6882
69- // The status of the resourcegraphdefinition. This is the status of the CRD
70- // that the resourcegraphdefinition is managing. This is adhering to the
71- // SimpleSchema spec.
83+ // Status defines the schema for the instance's status section using SimpleSchema syntax.
84+ // Unlike spec, status fields use CEL expressions to project values from underlying resources.
85+ // This allows you to surface important information from managed resources at the instance level.
86+ // Example: {"connectionName": "${database.status.connectionName}", "endpoint": "${service.status.loadBalancer.ingress[0].hostname}"}
7287 Status runtime.RawExtension `json:"status,omitempty"`
7388
7489 // AdditionalPrinterColumns defines additional printer columns
@@ -82,35 +97,75 @@ type Schema struct {
8297}
8398
8499type ExternalRefMetadata struct {
100+ // Name is the name of the external resource to reference.
101+ // This field is required.
102+ //
85103 // +kubebuilder:validation:Required
86104 Name string `json:"name,omitempty"`
87- // Namespace of the external resource. optional, if empty uses instance namespace
105+ // Namespace is the namespace of the external resource.
106+ // If empty, the instance's namespace will be used.
107+ //
88108 // +kubebuilder:validation:Optional
89109 Namespace string `json:"namespace,omitempty"`
90110}
91111
92- // ExternalRef is a reference to an external resource.
93- // It allows the user to specify the Kind, Version, Name and Namespace of the resource
94- // to be read and used in the Graph.
112+ // ExternalRef is a reference to an external resource that already exists in the cluster.
113+ // It allows you to read and use existing resources in your ResourceGraphDefinition
114+ // without creating them. The referenced resource's fields can be accessed using CEL
115+ // expressions in other resources.
95116type ExternalRef struct {
117+ // APIVersion is the API version of the external resource.
118+ // Example: "v1" for core resources, "apps/v1" for Deployments.
119+ //
96120 // +kubebuilder:validation:Required
97121 APIVersion string `json:"apiVersion"`
122+ // Kind is the kind of the external resource.
123+ // Example: "Service", "ConfigMap", "Deployment".
124+ //
98125 // +kubebuilder:validation:Required
99126 Kind string `json:"kind"`
127+ // Metadata contains the name and optional namespace of the external resource.
128+ //
100129 // +kubebuilder:validation:Required
101130 Metadata ExternalRefMetadata `json:"metadata"`
102131}
103132
133+ // Resource represents a Kubernetes resource that is part of the ResourceGraphDefinition.
134+ // Each resource can either be created using a template or reference an existing resource.
135+ // Resources can depend on each other through CEL expressions, creating a dependency graph.
136+ //
104137// +kubebuilder:validation:XValidation:rule="(has(self.template) && !has(self.externalRef)) || (!has(self.template) && has(self.externalRef))",message="exactly one of template or externalRef must be provided"
105138type Resource struct {
139+ // ID is a unique identifier for this resource within the ResourceGraphDefinition.
140+ // It is used to reference this resource in CEL expressions from other resources.
141+ // Example: "deployment", "service", "configmap".
142+ //
106143 // +kubebuilder:validation:Required
107144 ID string `json:"id,omitempty"`
145+ // Template is the Kubernetes resource manifest to create.
146+ // It can contain CEL expressions (using ${...} syntax) that reference other resources.
147+ // Exactly one of template or externalRef must be provided.
148+ //
108149 // +kubebuilder:validation:Optional
109150 Template runtime.RawExtension `json:"template,omitempty"`
151+ // ExternalRef references an existing resource in the cluster instead of creating one.
152+ // This is useful for reading existing resources and using their values in other resources.
153+ // Exactly one of template or externalRef must be provided.
154+ //
110155 // +kubebuilder:validation:Optional
111156 ExternalRef * ExternalRef `json:"externalRef,omitempty"`
157+ // ReadyWhen is a list of CEL expressions that determine when this resource is considered ready.
158+ // All expressions must evaluate to true for the resource to be ready.
159+ // If not specified, the resource is considered ready when it exists.
160+ // Example: ["self.status.phase == 'Running'", "self.status.readyReplicas > 0"]
161+ //
112162 // +kubebuilder:validation:Optional
113163 ReadyWhen []string `json:"readyWhen,omitempty"`
164+ // IncludeWhen is a list of CEL expressions that determine whether this resource should be created.
165+ // All expressions must evaluate to true for the resource to be included.
166+ // If not specified, the resource is always included.
167+ // Example: ["schema.spec.enableMonitoring == true"]
168+ //
114169 // +kubebuilder:validation:Optional
115170 IncludeWhen []string `json:"includeWhen,omitempty"`
116171}
@@ -125,31 +180,41 @@ const (
125180 ResourceGraphDefinitionStateInactive ResourceGraphDefinitionState = "Inactive"
126181)
127182
128- // ResourceGraphDefinitionStatus defines the observed state of ResourceGraphDefinition
183+ // ResourceGraphDefinitionStatus defines the observed state of ResourceGraphDefinition.
184+ // It provides information about the deployment state, resource ordering, and conditions.
129185type ResourceGraphDefinitionStatus struct {
130- // State is the state of the resourcegraphdefinition
186+ // State indicates whether the ResourceGraphDefinition is Active or Inactive.
187+ // Active means the CRD has been created and the controller is running.
188+ // Inactive means the ResourceGraphDefinition has been disabled or encountered an error.
131189 State ResourceGraphDefinitionState `json:"state,omitempty"`
132- // TopologicalOrder is the topological order of the resourcegraphdefinition graph
190+ // TopologicalOrder is the ordered list of resource IDs based on their dependencies.
191+ // Resources are created in this order to ensure dependencies are satisfied.
192+ // Example: ["configmap", "deployment", "service"]
133193 TopologicalOrder []string `json:"topologicalOrder,omitempty"`
134- // Conditions represent the latest available observations of an object's state
194+ // Conditions represent the latest available observations of the ResourceGraphDefinition's state.
195+ // Common condition types include "Ready", "Validated", and "ReconcilerDeployed".
135196 Conditions Conditions `json:"conditions,omitempty"`
136- // Resources represents the resources, and their information (dependencies for now)
197+ // Resources provides detailed information about each resource in the graph,
198+ // including their dependencies.
137199 Resources []ResourceInformation `json:"resources,omitempty"`
138200}
139201
140- // ResourceInformation defines the information about a resource
141- // in the resourcegraphdefinition
202+ // ResourceInformation provides detailed information about a specific resource
203+ // in the ResourceGraphDefinition, particularly its dependencies on other resources.
142204type ResourceInformation struct {
143- // ID represents the id of the resources we're providing information for
205+ // ID is the unique identifier of the resource as defined in the resources list.
144206 ID string `json:"id,omitempty"`
145- // Dependencies represents the resource dependencies of a resource graph definition
207+ // Dependencies lists all resources that this resource depends on.
208+ // A resource depends on another if it references it in a CEL expression.
209+ // These dependencies determine the order of resource creation.
146210 Dependencies []Dependency `json:"dependencies,omitempty"`
147211}
148212
149- // Dependency defines the dependency a resource has observed
150- // from the resources it points to based on expressions
213+ // Dependency represents a dependency relationship between resources.
214+ // When a resource uses CEL expressions to reference another resource,
215+ // a dependency is created to ensure proper ordering.
151216type Dependency struct {
152- // ID represents the id of the dependency resource
217+ // ID is the unique identifier of the resource that this resource depends on.
153218 ID string `json:"id,omitempty"`
154219}
155220
@@ -162,7 +227,11 @@ type Dependency struct {
162227// +kubebuilder:printcolumn:name="AGE",type="date",priority=0,JSONPath=".metadata.creationTimestamp"
163228// +kubebuilder:resource:shortName=rgd,scope=Cluster
164229
165- // ResourceGraphDefinition is the Schema for the resourcegraphdefinitions API
230+ // ResourceGraphDefinition is the core API for defining reusable groups of Kubernetes resources.
231+ // It allows you to create custom resources that manage multiple underlying resources as a cohesive unit.
232+ // When you create a ResourceGraphDefinition, kro automatically generates a CRD and deploys a controller
233+ // to manage instances of your custom resource. Resources can reference each other using CEL expressions,
234+ // and kro ensures they are created in the correct dependency order.
166235type ResourceGraphDefinition struct {
167236 metav1.TypeMeta `json:",inline"`
168237 metav1.ObjectMeta `json:"metadata,omitempty"`
0 commit comments