@@ -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
2627const (
@@ -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.
12941346func (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.
13041356func (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.
13171369func (m * ClusterResourcePlacement ) SetPlacementStatus (status * PlacementStatus ) {
13181370 if status != nil {
1319- m .Status = * status
1371+ status . DeepCopyInto ( & m .Status )
13201372 }
13211373}
13221374
13231375const (
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.
13901442func (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.
14021454func (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
14081469func init () {
0 commit comments