Skip to content

Commit 3c57183

Browse files
committed
address comments and organize the interface better
Signed-off-by: Ryan Zhang <[email protected]>
1 parent 94e52a8 commit 3c57183

File tree

5 files changed

+242
-230
lines changed

5 files changed

+242
-230
lines changed

apis/placement/v1beta1/binding_types.go

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,48 @@ const (
2828
SchedulerCRBCleanupFinalizer = fleetPrefix + "scheduler-crb-cleanup"
2929
)
3030

31+
// make sure the BindingObj and BindingObjList interfaces are implemented by the
32+
// ClusterResourceBinding and ResourceBinding types.
33+
var _ BindingObj = &ClusterResourceBinding{}
34+
var _ BindingObj = &ResourceBinding{}
35+
var _ BindingObjList = &ClusterResourceBindingList{}
36+
var _ BindingObjList = &ResourceBindingList{}
37+
38+
// A BindingSpecGetterSetter offers binding spec getter and setter methods.
39+
// +kubebuilder:object:generate=false
40+
type BindingSpecGetterSetter interface {
41+
GetBindingSpec() *ResourceBindingSpec
42+
SetBindingSpec(*ResourceBindingSpec)
43+
}
44+
45+
// A BindingStatusGetterSetter offers binding status getter and setter methods.
46+
// +kubebuilder:object:generate=false
47+
type BindingStatusGetterSetter interface {
48+
GetBindingStatus() *ResourceBindingStatus
49+
SetBindingStatus(*ResourceBindingStatus)
50+
}
51+
52+
// A BindingObj offers an abstract way to work with fleet binding objects.
53+
// +kubebuilder:object:generate=false
54+
type BindingObj interface {
55+
client.Object
56+
BindingSpecGetterSetter
57+
BindingStatusGetterSetter
58+
}
59+
60+
// A BindingListItemGetter offers a method to get binding objects from a list.
61+
// +kubebuilder:object:generate=false
62+
type BindingListItemGetter interface {
63+
GetBindingObjs() []BindingObj
64+
}
65+
66+
// A BindingObjList offers an abstract way to work with list binding objects.
67+
// +kubebuilder:object:generate=false
68+
type BindingObjList interface {
69+
client.ObjectList
70+
BindingListItemGetter
71+
}
72+
3173
// +kubebuilder:object:root=true
3274
// +kubebuilder:resource:scope=Cluster,categories={fleet,fleet-placement},shortName=crb
3375
// +kubebuilder:subresource:status
@@ -290,7 +332,7 @@ func (b *ClusterResourceBinding) GetBindingSpec() *ResourceBindingSpec {
290332
// SetBindingSpec sets the binding spec.
291333
func (b *ClusterResourceBinding) SetBindingSpec(spec *ResourceBindingSpec) {
292334
if spec != nil {
293-
b.Spec = *spec
335+
spec.DeepCopyInto(&b.Spec)
294336
}
295337
}
296338

@@ -302,7 +344,7 @@ func (b *ClusterResourceBinding) GetBindingStatus() *ResourceBindingStatus {
302344
// SetBindingStatus sets the binding status.
303345
func (b *ClusterResourceBinding) SetBindingStatus(status *ResourceBindingStatus) {
304346
if status != nil {
305-
b.Status = *status
347+
status.DeepCopyInto(&b.Status)
306348
}
307349
}
308350

@@ -331,7 +373,7 @@ func (b *ResourceBinding) GetBindingSpec() *ResourceBindingSpec {
331373
// SetBindingSpec sets the binding spec.
332374
func (b *ResourceBinding) SetBindingSpec(spec *ResourceBindingSpec) {
333375
if spec != nil {
334-
b.Spec = *spec
376+
spec.DeepCopyInto(&b.Spec)
335377
}
336378
}
337379

@@ -343,52 +385,10 @@ func (b *ResourceBinding) GetBindingStatus() *ResourceBindingStatus {
343385
// SetBindingStatus sets the binding status.
344386
func (b *ResourceBinding) SetBindingStatus(status *ResourceBindingStatus) {
345387
if status != nil {
346-
b.Status = *status
388+
status.DeepCopyInto(&b.Status)
347389
}
348390
}
349391

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
390-
}
391-
392392
func init() {
393393
SchemeBuilder.Register(&ClusterResourceBinding{}, &ClusterResourceBindingList{}, &ResourceBinding{}, &ResourceBindingList{})
394394
}

apis/placement/v1beta1/clusterresourceplacement_types.go

Lines changed: 68 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"k8s.io/apimachinery/pkg/api/meta"
2222
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2323
"k8s.io/apimachinery/pkg/util/intstr"
24+
"sigs.k8s.io/controller-runtime/pkg/client"
2425
)
2526

2627
const (
@@ -33,6 +34,48 @@ const (
3334
SchedulerCRPCleanupFinalizer = fleetPrefix + "scheduler-cleanup"
3435
)
3536

37+
// make sure the PlacementObj and PlacementObjList interfaces are implemented by the
38+
// ClusterResourcePlacement and ResourcePlacement types.
39+
var _ PlacementObj = &ClusterResourcePlacement{}
40+
var _ PlacementObj = &ResourcePlacement{}
41+
var _ PlacementObjList = &ClusterResourcePlacementList{}
42+
var _ PlacementObjList = &ResourcePlacementList{}
43+
44+
// PlacementSpecGetterSetter offers the functionality to work with the PlacementSpecGetterSetter.
45+
// +kubebuilder:object:generate=false
46+
type PlacementSpecGetterSetter interface {
47+
GetPlacementSpec() *PlacementSpec
48+
SetPlacementSpec(*PlacementSpec)
49+
}
50+
51+
// PlacementStatusGetterSetter offers the functionality to work with the PlacementStatusGetterSetter.
52+
// +kubebuilder:object:generate=false
53+
type PlacementStatusGetterSetter interface {
54+
GetPlacementStatus() *PlacementStatus
55+
SetPlacementStatus(*PlacementStatus)
56+
}
57+
58+
// PlacementObj offers the functionality to work with fleet placement object.
59+
// +kubebuilder:object:generate=false
60+
type PlacementObj interface {
61+
client.Object
62+
PlacementSpecGetterSetter
63+
PlacementStatusGetterSetter
64+
}
65+
66+
// PlacementListItemGetter offers the functionality to get a list of PlacementObj items.
67+
// +kubebuilder:object:generate=false
68+
type PlacementListItemGetter interface {
69+
GetPlacementObjs() []PlacementObj
70+
}
71+
72+
// PlacementObjList offers the functionality to work with fleet placement object list.
73+
// +kubebuilder:object:generate=false
74+
type PlacementObjList interface {
75+
client.ObjectList
76+
PlacementListItemGetter
77+
}
78+
3679
// +genclient
3780
// +genclient:nonNamespaced
3881
// +kubebuilder:object:root=true
@@ -1290,6 +1333,15 @@ func (m *ClusterResourcePlacement) SetConditions(conditions ...metav1.Condition)
12901333
}
12911334
}
12921335

1336+
// GetPlacementObjs returns the placement objects in the list.
1337+
func (crpl *ClusterResourcePlacementList) GetPlacementObjs() []PlacementObj {
1338+
objs := make([]PlacementObj, len(crpl.Items))
1339+
for i := range crpl.Items {
1340+
objs[i] = &crpl.Items[i]
1341+
}
1342+
return objs
1343+
}
1344+
12931345
// GetCondition returns the condition of the ClusterResourcePlacement objects.
12941346
func (m *ClusterResourcePlacement) GetCondition(conditionType string) *metav1.Condition {
12951347
return meta.FindStatusCondition(m.Status.Conditions, conditionType)
@@ -1303,7 +1355,7 @@ func (m *ClusterResourcePlacement) GetPlacementSpec() *PlacementSpec {
13031355
// SetPlacementSpec sets the placement spec.
13041356
func (m *ClusterResourcePlacement) SetPlacementSpec(spec *PlacementSpec) {
13051357
if spec != nil {
1306-
m.Spec = *spec
1358+
spec.DeepCopyInto(&m.Spec)
13071359
}
13081360
}
13091361

@@ -1316,14 +1368,14 @@ func (m *ClusterResourcePlacement) GetPlacementStatus() *PlacementStatus {
13161368
// SetPlacementStatus sets the placement status.
13171369
func (m *ClusterResourcePlacement) SetPlacementStatus(status *PlacementStatus) {
13181370
if status != nil {
1319-
m.Status = *status
1371+
status.DeepCopyInto(&m.Status)
13201372
}
13211373
}
13221374

13231375
const (
1324-
// PlacementCleanupFinalizer is a finalizer added by the CRP controller to all CRPs, to make sure
1325-
// that the CRP controller can react to CRP deletions if necessary.
1326-
PlacementCleanupFinalizer = fleetPrefix + "rp-cleanup"
1376+
// ResourcePlacementCleanupFinalizer is a finalizer added by the RP controller to all RPs, to make sure
1377+
// that the RP controller can react to RP deletions if necessary.
1378+
ResourcePlacementCleanupFinalizer = fleetPrefix + "rp-cleanup"
13271379
)
13281380

13291381
// +genclient
@@ -1389,7 +1441,7 @@ func (m *ResourcePlacement) GetPlacementSpec() *PlacementSpec {
13891441
// SetPlacementSpec sets the placement spec.
13901442
func (m *ResourcePlacement) SetPlacementSpec(spec *PlacementSpec) {
13911443
if spec != nil {
1392-
m.Spec = *spec
1444+
spec.DeepCopyInto(&m.Spec)
13931445
}
13941446
}
13951447

@@ -1401,8 +1453,17 @@ func (m *ResourcePlacement) GetPlacementStatus() *PlacementStatus {
14011453
// SetPlacementStatus sets the placement status.
14021454
func (m *ResourcePlacement) SetPlacementStatus(status *PlacementStatus) {
14031455
if status != nil {
1404-
m.Status = *status
1456+
status.DeepCopyInto(&m.Status)
1457+
}
1458+
}
1459+
1460+
// GetPlacementObjs returns the placement objects in the list.
1461+
func (rpl *ResourcePlacementList) GetPlacementObjs() []PlacementObj {
1462+
objs := make([]PlacementObj, len(rpl.Items))
1463+
for i := range rpl.Items {
1464+
objs[i] = &rpl.Items[i]
14051465
}
1466+
return objs
14061467
}
14071468

14081469
func init() {

apis/placement/v1beta1/interface.go

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)