Skip to content

Commit c60b65a

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

6 files changed

+907
-2
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Placement Status Proxy API Implementation
2+
## TODO Checklist
3+
- [x] Task 1.1: Analyze existing PlacementStatus structure
4+
- [x] Task 1.2: Design the new namespaced resource structure
5+
- [x] Task 1.3: Define naming convention and template
6+
- [x] Task 1.4: Add appropriate kubebuilder annotations
7+
- [x] Task 2.1: Create the new resource type definition
8+
- [x] Task 2.2: Add proper documentation and comments
9+
- [x] Task 2.3: Register the new type in scheme
10+
- [x] Task 2.4: Add EnableStatusProxy boolean field to ClusterResourcePlacementSpec
11+
- [ ] Task 3.1: Run code generation to ensure API is valid
12+
- [ ] Task 3.2: Verify CRD generation works properly
13+
14+
## Implementation Status
15+
- ✅ Added PlacementStatusProxy and PlacementStatusProxyList types
16+
- ✅ Added proper kubebuilder annotations and documentation
17+
- ✅ Included naming template in comments: `<clusterResourcePlacementName>-status`
18+
- ✅ Added finalizer constant
19+
- ✅ Registered types in scheme
20+
- ✅ Added EnableStatusProxy boolean field to PlacementSpec to enable/disable proxy creation
21+
- ✅ Enhanced Status field comment to clarify namespace and resource information display
22+
- ⚠️ Need to run code generation for DeepCopyObject methods
23+
24+
## Field Design Change
25+
- **Changed from**: `StatusProxyNamespace *string` - specified target namespace
26+
- **Changed to**: `EnableStatusProxy bool` - simple enable/disable flag
27+
- **Rationale**: Namespace is already specified in ResourceSelectors, so we just need a boolean to enable the feature
28+
- **Behavior**: When enabled, PlacementStatusProxy objects are created in namespaces containing selected resources
29+
30+
## Status Field Enhancement
31+
- Added clarifying comment that the Status field includes information about the namespace and resources within that namespace
32+
- Explains that placement details are shown for resources selected by the ClusterResourcePlacement's ResourceSelectors to create a namespaced object that will take the PlacementStatus of a corresponding ClusterResourcePlacement. This will serve as a proxy or mirror of the cluster-scoped CRP status in a namespace-scoped resource.
33+
34+
## Requirements Analysis
35+
1. Create a new namespaced custom resource
36+
2. The resource should contain PlacementStatus from corresponding ClusterResourcePlacement
37+
3. The name should follow a template that includes the ClusterResourcePlacement name
38+
4. Only implement the API (no controllers needed for now)
39+
5. Add appropriate documentation as comments
40+
41+
## Implementation Plan
42+
43+
### Phase 1: API Design
44+
- **Task 1.1**: Analyze existing PlacementStatus structure
45+
- **Task 1.2**: Design the new namespaced resource structure
46+
- **Task 1.3**: Define naming convention and template
47+
- **Task 1.4**: Add appropriate kubebuilder annotations
48+
49+
### Phase 2: API Implementation
50+
- **Task 2.1**: Create the new resource type definition
51+
- **Task 2.2**: Add proper documentation and comments
52+
- **Task 2.3**: Register the new type in scheme
53+
- **Task 2.4**: Verify code generation markers
54+
55+
### Phase 3: Validation
56+
- **Task 3.1**: Run code generation to ensure API is valid
57+
- **Task 3.2**: Verify CRD generation works properly
58+
59+
## Success Criteria
60+
- [ ] New namespaced resource is defined with proper structure
61+
- [ ] Resource includes PlacementStatus from ClusterResourcePlacement
62+
- [ ] Naming template is documented in comments
63+
- [ ] Kubebuilder annotations are correctly applied
64+
- [ ] Code generation produces valid CRDs
65+
- [ ] Resource is properly registered in scheme
66+
67+
## Naming Convention
68+
The object name template should be: `<crp-name>-status`
69+
This will be documented in the API comments.
70+
71+
Updated from the original `<crp-name>-placement-status` to be shorter and more concise.
72+
73+
## TODO Checklist
74+
- [x] Task 1.1: Analyze existing PlacementStatus structure
75+
- [x] Task 1.2: Design the new namespaced resource structure
76+
- [x] Task 1.3: Define naming convention and template
77+
- [x] Task 1.4: Add appropriate kubebuilder annotations
78+
- [x] Task 2.1: Create the new resource type definition
79+
- [x] Task 2.2: Add proper documentation and comments
80+
- [x] Task 2.3: Register the new type in scheme
81+
- [ ] Task 2.4: Verify code generation markers
82+
- [ ] Task 3.1: Run code generation to ensure API is valid
83+
- [ ] Task 3.2: Verify CRD generation works properly
84+
85+
## Implementation Status
86+
- ✅ Added PlacementStatusProxy and PlacementStatusProxyList types
87+
- ✅ Added proper kubebuilder annotations and documentation
88+
- ✅ Included naming template in comments: `<clusterResourcePlacementName>-placement-status`
89+
- ✅ Added finalizer constant
90+
- ✅ Registered types in scheme
91+
- ⚠️ Need to run code generation for DeepCopyObject methods

apis/placement/v1beta1/clusterresourceplacement_types.go

Lines changed: 70 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,67 @@ func (rpl *ResourcePlacementList) GetPlacementObjs() []PlacementObj {
14951503
return objs
14961504
}
14971505

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

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)