Skip to content

Commit 16fb162

Browse files
authored
feat: requirement controller (#16)
* feat: Update RequirementSpec and RequirementStatus with new fields and validation * Implement Requirement Controller with enhanced reconciliation logic and status management - Refactored RequirementReconciler to include a dedicated ReconcileHandler method for better separation of concerns. - Introduced a new RequirementAdapterInterface to facilitate operations during reconciliation. - Added default check interval for requeueing after reconciliation. - Implemented field indexing for Operation resources owned by Requirement. - Enhanced SetupWithManager to register event recorder for Requirement events. - Created utility functions for managing Requirement status conditions, including ClearConditions, IsCacheMissed, and UpdateCondition. - Added unit tests for Requirement status management functions to ensure correctness. - Updated requirement_controller_test.go to cover new reconciliation logic and adapter interactions. - Introduced constants for condition types and reasons to improve readability and maintainability. * fix: Refactor requirement adapter tests to use a constant for operation name * fix: Update validation comments and refactor test to use a constant for requirement UID
1 parent b2e6bc1 commit 16fb162

File tree

11 files changed

+9149
-28
lines changed

11 files changed

+9149
-28
lines changed

api/v1/requirement_types.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,30 @@ type RequirementSpec struct {
2828
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
2929
// Important: Run "make" to regenerate code after modifying this file
3030

31-
// Foo is an example field of Requirement. Edit requirement_types.go to remove/update
32-
Foo string `json:"foo,omitempty"`
31+
// +kubebuilder:validation:Required
32+
Template OperationSpec `json:"template"`
33+
// +kubebuilder:validation:Required
34+
EnableCache bool `json:"enableCache"`
35+
// +kubebuilder:validation:Optional
36+
// +kubebuilder:validation:Pattern:=`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$`
37+
ExpireAt string `json:"expireAt,omitempty"`
3338
}
3439

3540
// RequirementStatus defines the observed state of Requirement.
3641
type RequirementStatus struct {
3742
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
3843
// Important: Run "make" to regenerate code after modifying this file
44+
OperationId string `json:"operationId"`
45+
OperationName string `json:"operationName"`
46+
CacheKey string `json:"originalCacheKey"`
47+
Phase string `json:"phase"`
48+
Conditions []metav1.Condition `json:"conditions"`
3949
}
4050

4151
// +kubebuilder:object:root=true
4252
// +kubebuilder:subresource:status
53+
// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=`.status.phase`
54+
// +kubebuilder:printcolumn:name="OperationId",type="string",JSONPath=`.status.operationId`
4355

4456
// Requirement is the Schema for the requirements API.
4557
type Requirement struct {

api/v1/zz_generated.deepcopy.go

Lines changed: 10 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/app.github.com_requirements.yaml

Lines changed: 7590 additions & 2 deletions
Large diffs are not rendered by default.

internal/controller/mocks/mock_requirement_adapter.go

Lines changed: 117 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)