Skip to content

Commit fe09842

Browse files
committed
add status proxy for namespace scoped access only
Signed-off-by: Britania Rodriguez Reyes <[email protected]>
1 parent 2aaa087 commit fe09842

6 files changed

+885
-2
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Placement Status Proxy API Implementation
2+
3+
## Final Implementation Status - COMPLETED ✅
4+
5+
### API Implementation Complete
6+
-**PlacementStatusProxy Resource**: Namespaced resource that mirrors ClusterResourcePlacement status
7+
-**PlacementStatusProxyList**: List type for the proxy resource
8+
-**EnableStatusProxy Field**: Boolean field in ClusterResourcePlacementSpec to enable proxy creation
9+
-**Kubebuilder Annotations**: Proper annotations for CRD generation
10+
-**Documentation**: Comprehensive comments explaining usage and naming convention
11+
-**Code Generation**: DeepCopyObject methods generated successfully
12+
-**Schema Registration**: Types properly registered in SchemeBuilder
13+
-**Compile Validation**: No compilation errors
14+
15+
### Naming Convention Implemented
16+
- **Template**: `<clusterResourcePlacementName>-status`
17+
- **Example**: CRP named "my-app-crp" creates proxy named "my-app-crp-status"
18+
- **Rationale**: Shorter than original proposal, clear identification of source CRP
19+
20+
### Enhanced Documentation Features
21+
- **Multi-CRP Namespace Support**: Clear explanation of how multiple CRPs in same namespace are distinguished
22+
- **Status Field Clarity**: Documentation explains namespace and resource information display
23+
- **Usage Examples**: Concrete examples of naming patterns
24+
25+
## Completed TODO Checklist ✅
26+
- [x] Task 1.1: Analyze existing PlacementStatus structure
27+
- [x] Task 1.2: Design the new namespaced resource structure
28+
- [x] Task 1.3: Define naming convention and template
29+
- [x] Task 1.4: Add appropriate kubebuilder annotations
30+
- [x] Task 2.1: Create the new resource type definition
31+
- [x] Task 2.2: Add proper documentation and comments
32+
- [x] Task 2.3: Register the new type in scheme
33+
- [x] Task 2.4: Add EnableStatusProxy boolean field to ClusterResourcePlacementSpec
34+
- [x] Task 3.1: Run code generation to ensure API is valid
35+
- [x] Task 3.2: Verify CRD generation works properly
36+
37+
## Implementation Journey
38+
39+
### Design Evolution
40+
1. **Initial Design**: Complex spec with namespace targeting field
41+
2. **Simplified Design**: Removed spec portion as CRP name provides identification
42+
3. **Naming Optimization**: Changed from `<CRP_NAME>-placement-status` to `<crp-name>-status`
43+
4. **Field Design**: Changed from `StatusProxyNamespace *string` to `EnableStatusProxy bool`
44+
5. **Documentation Enhancement**: Added clarity about namespace and resource information
45+
46+
### Final API Structure
47+
```go
48+
type PlacementStatusProxy struct {
49+
metav1.TypeMeta `json:",inline"`
50+
metav1.ObjectMeta `json:"metadata,omitempty"`
51+
Status PlacementStatus `json:"status,omitempty"`
52+
}
53+
54+
type PlacementSpec struct {
55+
// ... existing fields ...
56+
EnableStatusProxy bool `json:"enableStatusProxy,omitempty"`
57+
}
58+
```
59+
60+
## Success Criteria - ALL MET ✅
61+
- [x] New namespaced resource is defined with proper structure
62+
- [x] Resource includes PlacementStatus from ClusterResourcePlacement
63+
- [x] Naming template is documented in comments
64+
- [x] Kubebuilder annotations are correctly applied
65+
- [x] Code generation produces valid CRDs
66+
- [x] Resource is properly registered in scheme
67+
- [x] No compilation errors
68+
- [x] Multiple CRP support in same namespace clearly documented
69+
70+
## Next Steps for Controller Implementation
71+
The API is complete and ready for controller implementation. Future work would involve:
72+
1. Creating a controller to watch ClusterResourcePlacement objects
73+
2. Creating/updating PlacementStatusProxy objects when EnableStatusProxy=true
74+
3. Managing lifecycle and cleanup of proxy objects
75+
4. Handling status synchronization between CRP and proxy objects

apis/placement/v1beta1/clusterresourceplacement_types.go

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,14 @@ type PlacementSpec struct {
148148
// +kubebuilder:default=10
149149
// +kubebuilder:validation:Optional
150150
RevisionHistoryLimit *int32 `json:"revisionHistoryLimit,omitempty"`
151+
152+
// EnableStatusProxy indicates whether a PlacementStatusProxy object should be created to mirror the placement status.
153+
// When enabled, PlacementStatusProxy objects will be created in the same namespaces selected by the ResourceSelectors.
154+
// This allows namespace-scoped access to the cluster-scoped ClusterResourcePlacement status.
155+
// Defaults to false.
156+
// +kubebuilder:default=false
157+
// +kubebuilder:validation:Optional
158+
EnableStatusProxy bool `json:"enableStatusProxy,omitempty"`
151159
}
152160

153161
// Tolerations returns tolerations for PlacementSpec to handle nil policy case.
@@ -1495,6 +1503,61 @@ func (rpl *ResourcePlacementList) GetPlacementObjs() []PlacementObj {
14951503
return objs
14961504
}
14971505

1506+
// +genclient
1507+
// +genclient:Namespaced
1508+
// +kubebuilder:object:root=true
1509+
// +kubebuilder:resource:scope="Namespaced",shortName=psp,categories={fleet,fleet-placement}
1510+
// +kubebuilder:subresource:status
1511+
// +kubebuilder:storageversion
1512+
// +kubebuilder:printcolumn:JSONPath=`.status.observedResourceIndex`,name="Resource-Index",type=string
1513+
// +kubebuilder:printcolumn:JSONPath=`.metadata.creationTimestamp`,name="Age",type=date
1514+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
1515+
1516+
// PlacementStatusProxy is a namespaced resource that mirrors the PlacementStatus of a corresponding
1517+
// ClusterResourcePlacement object. This allows namespace-scoped access to cluster-scoped placement status.
1518+
//
1519+
// This object will be created within the target namespace that contains resources being managed by the CRP.
1520+
// When multiple ClusterResourcePlacements target the same namespace, each PlacementStatusProxy within that
1521+
// namespace is uniquely identified by its object name, which corresponds to the specific ClusterResourcePlacement
1522+
// that created it.
1523+
//
1524+
// The name of this object should follow the template: <clusterResourcePlacementName>-status
1525+
// where <clusterResourcePlacementName> is the name of the corresponding ClusterResourcePlacement.
1526+
//
1527+
// For example, if you have a ClusterResourcePlacement named "my-app-crp", the corresponding
1528+
// PlacementStatusProxy should be named "my-app-crp-status".
1529+
type PlacementStatusProxy struct {
1530+
metav1.TypeMeta `json:",inline"`
1531+
metav1.ObjectMeta `json:"metadata,omitempty"`
1532+
1533+
// The observed status of PlacementStatusProxy which mirrors the PlacementStatus of the corresponding ClusterResourcePlacement.
1534+
// This includes information about the namespace and resources within that namespace that are being managed by the placement.
1535+
// The status will show placement details for resources selected by the ClusterResourcePlacement's ResourceSelectors.
1536+
// +kubebuilder:validation:Optional
1537+
Status PlacementStatus `json:"status,omitempty"`
1538+
}
1539+
1540+
// PlacementStatusProxyList contains a list of PlacementStatusProxy.
1541+
// +kubebuilder:resource:scope="Namespaced"
1542+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
1543+
type PlacementStatusProxyList struct {
1544+
metav1.TypeMeta `json:",inline"`
1545+
metav1.ListMeta `json:"metadata,omitempty"`
1546+
Items []PlacementStatusProxy `json:"items"`
1547+
}
1548+
1549+
// SetConditions sets the conditions of the PlacementStatusProxy.
1550+
func (m *PlacementStatusProxy) SetConditions(conditions ...metav1.Condition) {
1551+
for _, c := range conditions {
1552+
meta.SetStatusCondition(&m.Status.Conditions, c)
1553+
}
1554+
}
1555+
1556+
// GetCondition returns the condition of the PlacementStatusProxy objects.
1557+
func (m *PlacementStatusProxy) GetCondition(conditionType string) *metav1.Condition {
1558+
return meta.FindStatusCondition(m.Status.Conditions, conditionType)
1559+
}
1560+
14981561
func init() {
1499-
SchemeBuilder.Register(&ClusterResourcePlacement{}, &ClusterResourcePlacementList{}, &ResourcePlacement{}, &ResourcePlacementList{})
1562+
SchemeBuilder.Register(&ClusterResourcePlacement{}, &ClusterResourcePlacementList{}, &ResourcePlacement{}, &ResourcePlacementList{}, &PlacementStatusProxy{}, &PlacementStatusProxyList{})
15001563
}

apis/placement/v1beta1/zz_generated.deepcopy.go

Lines changed: 59 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/placement.kubernetes-fleet.io_clusterresourceplacements.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,14 @@ spec:
11441144
spec:
11451145
description: The desired state of ClusterResourcePlacement.
11461146
properties:
1147+
enableStatusProxy:
1148+
default: false
1149+
description: |-
1150+
EnableStatusProxy indicates whether a PlacementStatusProxy object should be created to mirror the placement status.
1151+
When enabled, PlacementStatusProxy objects will be created in the same namespaces selected by the ResourceSelectors.
1152+
This allows namespace-scoped access to the cluster-scoped ClusterResourcePlacement status.
1153+
Defaults to false.
1154+
type: boolean
11471155
policy:
11481156
description: |-
11491157
Policy defines how to select member clusters to place the selected resources.

0 commit comments

Comments
 (0)