Skip to content

Commit e3f2500

Browse files
committed
unify all types
Signed-off-by: Ryan Zhang <[email protected]>
1 parent 0da7106 commit e3f2500

File tree

4 files changed

+156
-87
lines changed

4 files changed

+156
-87
lines changed

apis/placement/v1beta1/binding_types.go

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package v1beta1
1919
import (
2020
"k8s.io/apimachinery/pkg/api/meta"
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
"sigs.k8s.io/controller-runtime/pkg/client"
2223
)
2324

2425
const (
@@ -246,6 +247,24 @@ type ResourceBindingList struct {
246247
Items []ResourceBinding `json:"items"`
247248
}
248249

250+
// GetBindingObjs returns the binding objects in the list.
251+
func (c *ClusterResourceBindingList) GetBindingObjs() []BindingObj {
252+
objs := make([]BindingObj, 0, len(c.Items))
253+
for i := range c.Items {
254+
objs = append(objs, &c.Items[i])
255+
}
256+
return objs
257+
}
258+
259+
// GetBindingObjs returns the binding objects in the list.
260+
func (r *ResourceBindingList) GetBindingObjs() []BindingObj {
261+
objs := make([]BindingObj, 0, len(r.Items))
262+
for i := range r.Items {
263+
objs = append(objs, &r.Items[i])
264+
}
265+
return objs
266+
}
267+
249268
// SetConditions set the given conditions on the ClusterResourceBinding.
250269
func (b *ClusterResourceBinding) SetConditions(conditions ...metav1.Condition) {
251270
for _, c := range conditions {
@@ -328,6 +347,44 @@ func (b *ResourceBinding) SetBindingStatus(status *ResourceBindingStatus) {
328347
}
329348
}
330349

331-
func init() {
332-
SchemeBuilder.Register(&ClusterResourceBinding{}, &ClusterResourceBindingList{}, &ResourceBinding{}, &ResourceBindingList{})
350+
// make sure the BindingObj and BindingObjList interfaces are implemented by the
351+
// ClusterResourceBinding and ResourceBinding types.
352+
var _ BindingObj = &ClusterResourceBinding{}
353+
var _ BindingObj = &ResourceBinding{}
354+
var _ BindingObjList = &ClusterResourceBindingList{}
355+
var _ BindingObjList = &ResourceBindingList{}
356+
357+
// A BindingSpecGetSetter contains binding spec
358+
// +kubebuilder:object:generate=false
359+
type BindingSpecGetSetter interface {
360+
GetBindingSpec() *ResourceBindingSpec
361+
SetBindingSpec(*ResourceBindingSpec)
362+
}
363+
364+
// A BindingStatusGetSetter contains binding status
365+
// +kubebuilder:object:generate=false
366+
type BindingStatusGetSetter interface {
367+
GetBindingStatus() *ResourceBindingStatus
368+
SetBindingStatus(*ResourceBindingStatus)
369+
}
370+
371+
// A BindingObj is for kubernetes resource binding object.
372+
// +kubebuilder:object:generate=false
373+
type BindingObj interface {
374+
client.Object
375+
BindingSpecGetSetter
376+
BindingStatusGetSetter
377+
}
378+
379+
// A BindingListItemGetter contains binding list items
380+
// +kubebuilder:object:generate=false
381+
type BindingListItemGetter interface {
382+
GetBindingObjs() []BindingObj
383+
}
384+
385+
// A BindingObjList is for kubernetes resource binding list object.
386+
// +kubebuilder:object:generate=false
387+
type BindingObjList interface {
388+
client.ObjectList
389+
BindingListItemGetter
333390
}

apis/placement/v1beta1/interface.go

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -47,88 +47,3 @@ type PlacementObj interface {
4747
PlacementSpecGetSetter
4848
PlacementStatusGetSetter
4949
}
50-
51-
// A BindingSpecGetSetter contains bindingSpec
52-
// +kubebuilder:object:generate=false
53-
type BindingSpecGetSetter interface {
54-
GetBindingSpec() *ResourceBindingSpec
55-
SetBindingSpec(*ResourceBindingSpec)
56-
}
57-
58-
// A BindingStatusGetSetter contains bindingStatus
59-
// +kubebuilder:object:generate=false
60-
type BindingStatusGetSetter interface {
61-
GetBindingStatus() *ResourceBindingStatus
62-
SetBindingStatus(*ResourceBindingStatus)
63-
}
64-
65-
var _ BindingObj = &ClusterResourceBinding{}
66-
var _ BindingObj = &ResourceBinding{}
67-
68-
// A BindingObj is for kubernetes resource binding object.
69-
// +kubebuilder:object:generate=false
70-
type BindingObj interface {
71-
client.Object
72-
BindingSpecGetSetter
73-
BindingStatusGetSetter
74-
}
75-
76-
// A PolicySnapshotSpecGetSetter contains policy snapshot spec
77-
// +kubebuilder:object:generate=false
78-
type PolicySnapshotSpecGetSetter interface {
79-
GetPolicySnapshotSpec() *SchedulingPolicySnapshotSpec
80-
SetPolicySnapshotSpec(*SchedulingPolicySnapshotSpec)
81-
}
82-
83-
// A PolicySnapshotStatusGetSetter contains policy snapshot status
84-
// +kubebuilder:object:generate=false
85-
type PolicySnapshotStatusGetSetter interface {
86-
GetPolicySnapshotStatus() *SchedulingPolicySnapshotStatus
87-
SetPolicySnapshotStatus(*SchedulingPolicySnapshotStatus)
88-
}
89-
90-
// A PolicySnapshotObj is for kubernetes policy snapshot object.
91-
// +kubebuilder:object:generate=false
92-
type PolicySnapshotObj interface {
93-
client.Object
94-
PolicySnapshotSpecGetSetter
95-
PolicySnapshotStatusGetSetter
96-
}
97-
98-
// A PolicySnapshotSpec contains policy snapshot spec
99-
// +kubebuilder:object:generate=false
100-
type PolicySnapshotListItemGetter interface {
101-
GetPolicySnapshotObjs() []PolicySnapshotObj
102-
}
103-
104-
// A PolicySnapshotList is for kubernetes policy snapshot list object.
105-
// +kubebuilder:object:generate=false
106-
type PolicySnapshotList interface {
107-
client.ObjectList
108-
PolicySnapshotListItemGetter
109-
}
110-
111-
// A ResourceSnapshotSpecGetSettter contains resource snapshot spec
112-
// +kubebuilder:object:generate=false
113-
type ResourceSnapshotSpecGetSettter interface {
114-
GetResourceSnapshotSpec() *ResourceSnapshotSpec
115-
SetResourceSnapshotSpec(*ResourceSnapshotSpec)
116-
}
117-
118-
// A ResourceSnapshotStatusGetSetter contains resource snapshot status
119-
// +kubebuilder:object:generate=false
120-
type ResourceSnapshotStatusGetSetter interface {
121-
GetResourceSnapshotStatus() *ResourceSnapshotStatus
122-
SetResourceSnapshotStatus(*ResourceSnapshotStatus)
123-
}
124-
125-
var _ ResourceSnapshotObj = &ClusterResourceSnapshot{}
126-
var _ ResourceSnapshotObj = &ResourceSnapshot{}
127-
128-
// A ResourceSnapshotObj is for kubernetes resource snapshot object.
129-
// +kubebuilder:object:generate=false
130-
type ResourceSnapshotObj interface {
131-
client.Object
132-
ResourceSnapshotSpecGetSettter
133-
ResourceSnapshotStatusGetSetter
134-
}

apis/placement/v1beta1/policysnapshot_types.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package v1beta1
1919
import (
2020
"k8s.io/apimachinery/pkg/api/meta"
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
"sigs.k8s.io/controller-runtime/pkg/client"
2223
)
2324

2425
const (
@@ -251,6 +252,41 @@ type SchedulingPolicySnapshot struct {
251252
Status SchedulingPolicySnapshotStatus `json:"status,omitempty"`
252253
}
253254

255+
// A PolicySnapshotSpecGetSetter contains policy snapshot spec
256+
// +kubebuilder:object:generate=false
257+
type PolicySnapshotSpecGetSetter interface {
258+
GetPolicySnapshotSpec() *SchedulingPolicySnapshotSpec
259+
SetPolicySnapshotSpec(*SchedulingPolicySnapshotSpec)
260+
}
261+
262+
// A PolicySnapshotStatusGetSetter contains policy snapshot status
263+
// +kubebuilder:object:generate=false
264+
type PolicySnapshotStatusGetSetter interface {
265+
GetPolicySnapshotStatus() *SchedulingPolicySnapshotStatus
266+
SetPolicySnapshotStatus(*SchedulingPolicySnapshotStatus)
267+
}
268+
269+
// A PolicySnapshotObj is for kubernetes policy snapshot object.
270+
// +kubebuilder:object:generate=false
271+
type PolicySnapshotObj interface {
272+
client.Object
273+
PolicySnapshotSpecGetSetter
274+
PolicySnapshotStatusGetSetter
275+
}
276+
277+
// A PolicySnapshotSpec contains policy snapshot spec
278+
// +kubebuilder:object:generate=false
279+
type PolicySnapshotListItemGetter interface {
280+
GetPolicySnapshotObjs() []PolicySnapshotObj
281+
}
282+
283+
// A PolicySnapshotList is for kubernetes policy snapshot list object.
284+
// +kubebuilder:object:generate=false
285+
type PolicySnapshotList interface {
286+
client.ObjectList
287+
PolicySnapshotListItemGetter
288+
}
289+
254290
// GetPolicySnapshotSpec returns the policy snapshot spec.
255291
func (m *SchedulingPolicySnapshot) GetPolicySnapshotSpec() *SchedulingPolicySnapshotSpec {
256292
return &m.Spec

apis/placement/v1beta1/resourcesnapshot_types.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"k8s.io/apimachinery/pkg/api/meta"
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2222
"k8s.io/apimachinery/pkg/runtime"
23+
"sigs.k8s.io/controller-runtime/pkg/client"
2324
)
2425

2526
const (
@@ -174,6 +175,48 @@ type ResourceSnapshotList struct {
174175
Items []ResourceSnapshot `json:"items"`
175176
}
176177

178+
// make sure the ResourceSnapshotObj and ResourceSnapshotList interfaces are implemented by the
179+
// ClusterResourceSnapshot and ResourceSnapshot types.
180+
var _ ResourceSnapshotObj = &ResourceSnapshot{}
181+
var _ ResourceSnapshotObj = &ResourceSnapshot{}
182+
var _ ResourceSnapshotObjList = &ClusterResourceSnapshotList{}
183+
var _ ResourceSnapshotObjList = &ResourceSnapshotList{}
184+
185+
// A ResourceSnapshotSpecGetSettter contains resource snapshot spec
186+
// +kubebuilder:object:generate=false
187+
type ResourceSnapshotSpecGetSettter interface {
188+
GetResourceSnapshotSpec() *ResourceSnapshotSpec
189+
SetResourceSnapshotSpec(*ResourceSnapshotSpec)
190+
}
191+
192+
// A ResourceSnapshotStatusGetSetter contains resource snapshot status
193+
// +kubebuilder:object:generate=false
194+
type ResourceSnapshotStatusGetSetter interface {
195+
GetResourceSnapshotStatus() *ResourceSnapshotStatus
196+
SetResourceSnapshotStatus(*ResourceSnapshotStatus)
197+
}
198+
199+
// A ResourceSnapshotObj is for kubernetes resource snapshot object.
200+
// +kubebuilder:object:generate=false
201+
type ResourceSnapshotObj interface {
202+
client.Object
203+
ResourceSnapshotSpecGetSettter
204+
ResourceSnapshotStatusGetSetter
205+
}
206+
207+
// A ResourceSnapshotSpec contains resource snapshot spec
208+
// +kubebuilder:object:generate=false
209+
type ResourceSnapshotListItemGetter interface {
210+
GetResourceSnapshotObjs() []ResourceSnapshotObj
211+
}
212+
213+
// A ResourceSnapshotObjList is for kubernetes resource snapshot list object.
214+
// +kubebuilder:object:generate=false
215+
type ResourceSnapshotObjList interface {
216+
client.ObjectList
217+
ResourceSnapshotListItemGetter
218+
}
219+
177220
// SetConditions sets the conditions for a ClusterResourceSnapshot.
178221
func (m *ClusterResourceSnapshot) SetConditions(conditions ...metav1.Condition) {
179222
for _, c := range conditions {
@@ -210,6 +253,15 @@ func (m *ClusterResourceSnapshot) SetResourceSnapshotStatus(status *ResourceSnap
210253
}
211254
}
212255

256+
// ClusterResourceSnapshotList returns the list of ResourceSnapshotObj from the ResourceSnapshotList.
257+
func (c *ClusterResourceSnapshotList) GetResourceSnapshotObjs() []ResourceSnapshotObj {
258+
objs := make([]ResourceSnapshotObj, 0, len(c.Items))
259+
for i := range c.Items {
260+
objs = append(objs, &c.Items[i])
261+
}
262+
return objs
263+
}
264+
213265
// SetConditions sets the conditions for a ResourceSnapshot.
214266
func (m *ResourceSnapshot) SetConditions(conditions ...metav1.Condition) {
215267
for _, c := range conditions {
@@ -246,6 +298,15 @@ func (m *ResourceSnapshot) SetResourceSnapshotStatus(status *ResourceSnapshotSta
246298
}
247299
}
248300

301+
// GetResourceSnapshotObjs returns the list of ResourceSnapshotObj from the ResourceSnapshotList.
302+
func (c *ResourceSnapshotList) GetResourceSnapshotObjs() []ResourceSnapshotObj {
303+
objs := make([]ResourceSnapshotObj, 0, len(c.Items))
304+
for i := range c.Items {
305+
objs = append(objs, &c.Items[i])
306+
}
307+
return objs
308+
}
309+
249310
func init() {
250311
SchemeBuilder.Register(&ClusterResourceSnapshot{}, &ClusterResourceSnapshotList{})
251312
SchemeBuilder.Register(&ResourceSnapshot{}, &ResourceSnapshotList{})

0 commit comments

Comments
 (0)