Skip to content

Commit 6a86d57

Browse files
committed
feat: add datadependency v1alpha1 API definitions
Add API definitions for the datadependency v1alpha1 API group: - DataSource: represents a cached query result for data sources in federated environment - DataSourceClaim: represents a claim for data source resources Signed-off-by: FanXu <[email protected]>
1 parent f562f82 commit 6a86d57

File tree

3 files changed

+292
-0
lines changed

3 files changed

+292
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
Copyright 2025 The Volcano Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package v1alpha1 contains API Schema definitions for the datadependency v1alpha1 API group
18+
// +k8s:deepcopy-gen=package,register
19+
// +groupName=datadependency.volcano.sh
20+
package v1alpha1
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
Copyright 2025 The Volcano Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
"k8s.io/apimachinery/pkg/runtime"
22+
"k8s.io/apimachinery/pkg/runtime/schema"
23+
)
24+
25+
const (
26+
// GroupName is the group name used in this package.
27+
GroupName = "datadependency.volcano.sh"
28+
)
29+
30+
// SchemeGroupVersion is group version used to register these objects.
31+
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha1"}
32+
33+
// Kind takes an unqualified kind and returns back a Group qualified GroupKind.
34+
func Kind(kind string) schema.GroupKind {
35+
return SchemeGroupVersion.WithKind(kind).GroupKind()
36+
}
37+
38+
// Resource takes an unqualified resource and returns a Group qualified GroupResource.
39+
func Resource(resource string) schema.GroupResource {
40+
return SchemeGroupVersion.WithResource(resource).GroupResource()
41+
}
42+
43+
var (
44+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
45+
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
46+
// AddToScheme adds the types in this group-version to the given scheme.
47+
AddToScheme = SchemeBuilder.AddToScheme
48+
)
49+
50+
// Adds the list of known types to Scheme.
51+
func addKnownTypes(scheme *runtime.Scheme) error {
52+
scheme.AddKnownTypes(SchemeGroupVersion,
53+
&DataSource{},
54+
&DataSourceList{},
55+
&DataSourceClaim{},
56+
&DataSourceClaimList{},
57+
)
58+
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
59+
return nil
60+
}
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
/*
2+
Copyright 2025 The Volcano Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
corev1 "k8s.io/api/core/v1"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
)
23+
24+
// +genclient
25+
// +genclient:nonNamespaced
26+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
27+
// +k8s:openapi-gen=true
28+
// +kubebuilder:subresource:status
29+
30+
// DataSource represents a cached query result for data sources in the federated environment.
31+
// It is a cluster-scoped resource.
32+
type DataSource struct {
33+
metav1.TypeMeta `json:",inline"`
34+
metav1.ObjectMeta `json:"metadata,omitempty"`
35+
36+
Spec DataSourceSpec `json:"spec,omitempty"`
37+
Status DataSourceStatus `json:"status,omitempty"`
38+
}
39+
40+
// DataSourceSpec defines the desired state of DataSource.
41+
type DataSourceSpec struct {
42+
// System specifies the underlying data system.
43+
// This provides context for the 'name' and 'attributes' fields.
44+
// e.g., "hive", "s3", "hdfs".
45+
// +required
46+
System string `json:"system"`
47+
48+
// Type specifies the category of the data source within the system.
49+
// e.g., for system="hive", type could be "table", "view".
50+
// e.g., for system="s3", type could be "bucket", "object", "prefix".
51+
// +required
52+
Type string `json:"type"`
53+
54+
// Name is the identifier of the data source, its format is interpreted
55+
// in the context of the 'system' and 'type'.
56+
// +required
57+
Name string `json:"name"`
58+
59+
// Locality defines which clusters this data source is available on.
60+
// +required
61+
Locality *DataSourceLocality `json:"locality"`
62+
63+
// Attributes provides extra, non-identifying metadata.
64+
// +optional
65+
Attributes map[string]string `json:"attributes,omitempty"`
66+
67+
// ReclaimPolicy defines what happens to this DataSource when its last bound DataSourceClaim is deleted.
68+
// Defaults to "Retain".
69+
// +optional
70+
ReclaimPolicy DataSourceReclaimPolicy `json:"reclaimPolicy,omitempty"`
71+
}
72+
73+
// DataSourceLocality specifies the cached location information of the data source.
74+
type DataSourceLocality struct {
75+
// ClusterNames is a list of cluster names where the cached data source information indicates availability.
76+
// This provides a simple and direct way to specify cached data source location
77+
// without interfering with user-defined ResourceBinding cluster affinity.
78+
// +required
79+
ClusterNames []string `json:"clusterNames"`
80+
}
81+
82+
// DataSourceStatus defines the observed state of DataSource.
83+
type DataSourceStatus struct {
84+
// ClaimRefs is a list of references to DataSourceClaims that are bound to this DataSource.
85+
// The presence of items in this list indicates the DataSource is in use.
86+
// +optional
87+
ClaimRefs []corev1.ObjectReference `json:"claimRefs,omitempty"`
88+
89+
// BoundClaims counts the number of DataSourceClaims currently bound to this DataSource.
90+
// This provides a quick summary of its usage.
91+
// +optional
92+
BoundClaims int32 `json:"boundClaims,omitempty"`
93+
94+
// Conditions store the available observations of the DataSource's state.
95+
// This is more flexible than a single phase.
96+
// +optional
97+
Conditions []metav1.Condition `json:"conditions,omitempty"`
98+
}
99+
100+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
101+
102+
// DataSourceList contains a list of DataSource.
103+
type DataSourceList struct {
104+
metav1.TypeMeta `json:",inline"`
105+
metav1.ListMeta `json:"metadata,omitempty"`
106+
Items []DataSource `json:"items"`
107+
}
108+
109+
type DataSourceReclaimPolicy string
110+
111+
const (
112+
ReclaimPolicyRetain DataSourceReclaimPolicy = "Retain"
113+
ReclaimPolicyDelete DataSourceReclaimPolicy = "Delete"
114+
)
115+
116+
// ================================== DataSourceClaim ==================================
117+
// +genclient
118+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
119+
// +k8s:openapi-gen=true
120+
// +kubebuilder:subresource:status
121+
122+
// DataSourceClaim is a request for a DataSource by a user.
123+
// It is a namespaced resource.
124+
type DataSourceClaim struct {
125+
metav1.TypeMeta `json:",inline"`
126+
metav1.ObjectMeta `json:"metadata,omitempty"`
127+
128+
Spec DataSourceClaimSpec `json:"spec,omitempty"`
129+
Status DataSourceClaimStatus `json:"status,omitempty"`
130+
}
131+
132+
// WorkloadRef defines a reference to a workload resource that can be used with Dynamic Client.
133+
// It provides the minimal fields needed to precisely identify and retrieve a workload.
134+
type WorkloadRef struct {
135+
// APIVersion is the API version of the workload resource.
136+
// e.g., "apps/v1", "batch.volcano.sh/v1alpha1"
137+
// +required
138+
APIVersion string `json:"apiVersion"`
139+
140+
// Kind is the kind of the workload resource.
141+
// e.g., "Deployment", "Job"
142+
// +required
143+
Kind string `json:"kind"`
144+
145+
// Name is the name of the workload resource.
146+
// +required
147+
Name string `json:"name"`
148+
149+
// Namespace is the namespace of the workload resource.
150+
// If empty, defaults to the namespace of the DataSourceClaim.
151+
// +optional
152+
Namespace string `json:"namespace,omitempty"`
153+
}
154+
155+
// DataSourceClaimSpec defines the desired state of DataSourceClaim.
156+
type DataSourceClaimSpec struct {
157+
// System is the required underlying data system of the data source.
158+
// +required
159+
System string `json:"system"`
160+
161+
// DataSourceType is the required category of the data source within the system.
162+
// +required
163+
DataSourceType string `json:"dataSourceType"`
164+
165+
// DataSourceName specifies the logical name of the cached data source to claim.
166+
// It will be matched against DataSource's spec.name field.
167+
// +required
168+
DataSourceName string `json:"dataSourceName"`
169+
170+
// Workload specifies the workload that this claim is associated with.
171+
// This enables the controller to precisely identify and manage the workload
172+
// using Dynamic Client without requiring complex selectors or UIDs.
173+
// +required
174+
Workload WorkloadRef `json:"workload"`
175+
176+
// Attributes provides extra, non-identifying metadata.
177+
// +optional
178+
Attributes map[string]string `json:"attributes,omitempty"`
179+
}
180+
181+
// DataSourceClaimStatus defines the observed state of DataSourceClaim.
182+
type DataSourceClaimStatus struct {
183+
// Phase indicates the current lifecycle phase of the claim.
184+
// +optional
185+
// +default="Pending"
186+
Phase DSCPhase `json:"phase"`
187+
188+
// BoundDataSource specifies the name of the DataSource object
189+
// that is bound to this claim for scheduling.
190+
// +optional
191+
BoundDataSource string `json:"boundDataSource,omitempty"`
192+
193+
// Conditions store the available observations of the claim's state.
194+
// +optional
195+
Conditions []metav1.Condition `json:"conditions,omitempty"`
196+
}
197+
198+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
199+
200+
// DataSourceClaimList contains a list of DataSourceClaim.
201+
type DataSourceClaimList struct {
202+
metav1.TypeMeta `json:",inline"`
203+
metav1.ListMeta `json:"metadata,omitempty"`
204+
Items []DataSourceClaim `json:"items"`
205+
}
206+
207+
type DSCPhase string
208+
209+
const (
210+
DSCPhasePending DSCPhase = "Pending"
211+
DSCPhaseBound DSCPhase = "Bound"
212+
)

0 commit comments

Comments
 (0)