Skip to content

Commit 1e10d6f

Browse files
fix: simplify status
1 parent af40f0f commit 1e10d6f

File tree

6 files changed

+77
-93
lines changed

6 files changed

+77
-93
lines changed

api/clusters/v1alpha1/accessrequest_types.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,23 @@ type PermissionsRequest struct {
3939

4040
// AccessRequestStatus defines the observed state of AccessRequest
4141
type AccessRequestStatus struct {
42-
CommonStatus `json:",inline"`
42+
// ObservedGeneration is the generation of this resource that was last reconciled by the controller.
43+
ObservedGeneration int64 `json:"observedGeneration"`
44+
45+
// LastReconcileTime is the time when the resource was last reconciled by the controller.
46+
LastReconcileTime metav1.Time `json:"lastReconcileTime"`
47+
48+
// Reason is expected to contain a CamelCased string that provides further information in a machine-readable format.
49+
// +optional
50+
Reason string `json:"reason,omitempty"`
51+
52+
// Message contains further details in a human-readable format.
53+
// +optional
54+
Message string `json:"message,omitempty"`
55+
56+
// Conditions contains the conditions of this resource using the standard Kubernetes condition format.
57+
// +optional
58+
Conditions []metav1.Condition `json:"conditions,omitempty"`
4359

4460
// Phase is the current phase of the request.
4561
// +kubebuilder:default=Pending

api/clusters/v1alpha1/cluster_types.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,23 @@ type K8sConfiguration struct {
5252

5353
// ClusterStatus defines the observed state of Cluster
5454
type ClusterStatus struct {
55-
CommonStatus `json:",inline"`
55+
// ObservedGeneration is the generation of this resource that was last reconciled by the controller.
56+
ObservedGeneration int64 `json:"observedGeneration"`
57+
58+
// LastReconcileTime is the time when the resource was last reconciled by the controller.
59+
LastReconcileTime metav1.Time `json:"lastReconcileTime"`
60+
61+
// Reason is expected to contain a CamelCased string that provides further information in a machine-readable format.
62+
// +optional
63+
Reason string `json:"reason,omitempty"`
64+
65+
// Message contains further details in a human-readable format.
66+
// +optional
67+
Message string `json:"message,omitempty"`
68+
69+
// Conditions contains the conditions of this resource using the standard Kubernetes condition format.
70+
// +optional
71+
Conditions []metav1.Condition `json:"conditions,omitempty"`
5672

5773
// Phase is the current phase of the cluster.
5874
Phase ClusterPhase `json:"phase"`

api/clusters/v1alpha1/clusterrequest_types.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,23 @@ type ClusterRequestSpec struct {
1313

1414
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.cluster) || has(self.cluster)", message="cluster may not be removed once set"
1515
type ClusterRequestStatus struct {
16-
CommonStatus `json:",inline"`
16+
// ObservedGeneration is the generation of this resource that was last reconciled by the controller.
17+
ObservedGeneration int64 `json:"observedGeneration"`
18+
19+
// LastReconcileTime is the time when the resource was last reconciled by the controller.
20+
LastReconcileTime metav1.Time `json:"lastReconcileTime"`
21+
22+
// Reason is expected to contain a CamelCased string that provides further information in a machine-readable format.
23+
// +optional
24+
Reason string `json:"reason,omitempty"`
25+
26+
// Message contains further details in a human-readable format.
27+
// +optional
28+
Message string `json:"message,omitempty"`
29+
30+
// Conditions contains the conditions of this resource using the standard Kubernetes condition format.
31+
// +optional
32+
Conditions []metav1.Condition `json:"conditions,omitempty"`
1733

1834
// Phase is the current phase of the request.
1935
// +kubebuilder:default=Pending

api/clusters/v1alpha1/shared_types.go

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
package v1alpha1
22

3-
import (
4-
"k8s.io/apimachinery/pkg/api/meta"
5-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
6-
)
7-
83
// These are standard condition types that can be used across resources
94
const (
105
// ReadyConditionType indicates whether the resource is ready
@@ -39,60 +34,3 @@ type NamespacedObjectReference struct {
3934
// Namespace is the namespace of the referenced resource.
4035
Namespace string `json:"namespace"`
4136
}
42-
43-
// CommonStatus is a status shared by multiple resources.
44-
// It uses standard Kubernetes conditions for status representation.
45-
type CommonStatus struct {
46-
// ObservedGeneration is the generation of this resource that was last reconciled by the controller.
47-
ObservedGeneration int64 `json:"observedGeneration"`
48-
49-
// LastReconcileTime is the time when the resource was last reconciled by the controller.
50-
LastReconcileTime metav1.Time `json:"lastReconcileTime"`
51-
52-
// Reason is expected to contain a CamelCased string that provides further information in a machine-readable format.
53-
// +optional
54-
Reason string `json:"reason,omitempty"`
55-
56-
// Message contains further details in a human-readable format.
57-
// +optional
58-
Message string `json:"message,omitempty"`
59-
60-
// Conditions contains the conditions of this resource using the standard Kubernetes condition format.
61-
// +optional
62-
Conditions []metav1.Condition `json:"conditions,omitempty"`
63-
}
64-
65-
// GetCondition returns the condition with the provided type.
66-
// Returns nil if the condition is not found.
67-
func (s *CommonStatus) GetCondition(conditionType string) *metav1.Condition {
68-
return meta.FindStatusCondition(s.Conditions, conditionType)
69-
}
70-
71-
// SetCondition sets the status condition. It either overwrites the existing condition or
72-
// creates a new one if the condition wasn't present.
73-
func (s *CommonStatus) SetCondition(condition metav1.Condition) {
74-
meta.SetStatusCondition(&s.Conditions, condition)
75-
}
76-
77-
// RemoveCondition removes the condition with the specified type.
78-
func (s *CommonStatus) RemoveCondition(conditionType string) {
79-
meta.RemoveStatusCondition(&s.Conditions, conditionType)
80-
}
81-
82-
// IsReady returns true if the Ready condition is present and set to True.
83-
func (s *CommonStatus) IsReady() bool {
84-
condition := s.GetCondition(ReadyConditionType)
85-
return condition != nil && condition.Status == metav1.ConditionTrue
86-
}
87-
88-
// IsAvailable returns true if the Available condition is present and set to True.
89-
func (s *CommonStatus) IsAvailable() bool {
90-
condition := s.GetCondition(AvailableConditionType)
91-
return condition != nil && condition.Status == metav1.ConditionTrue
92-
}
93-
94-
// HasReconcileSucceeded returns true if the ReconcileSuccess condition is present and set to True.
95-
func (s *CommonStatus) HasReconcileSucceeded() bool {
96-
condition := s.GetCondition(ReconcileSuccessConditionType)
97-
return condition != nil && condition.Status == metav1.ConditionTrue
98-
}

api/clusters/v1alpha1/zz_generated.deepcopy.go

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

internal/controllers/accessrequest/controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ type AccessRequestReconciler struct {
4040

4141
var _ reconcile.Reconciler = &AccessRequestReconciler{}
4242

43-
type ReconcileResult = ctrlutils.ReconcileResult[*clustersv1alpha1.AccessRequest, clustersv1alpha1.ConditionStatus]
43+
type ReconcileResult = ctrlutils.ReconcileResult[*clustersv1alpha1.AccessRequest, *clustersv1alpha1.AccessRequestStatus]
4444

4545
func (r *AccessRequestReconciler) Reconcile(ctx context.Context, req reconcile.Request) (reconcile.Result, error) {
4646
log := logging.FromContextOrPanic(ctx).WithName(ControllerName)
4747
ctx = logging.NewContext(ctx, log)
4848
log.Info("Starting reconcile")
4949
rr := r.reconcile(ctx, req)
5050
// status update
51-
return ctrlutils.NewStatusUpdaterBuilder[*clustersv1alpha1.AccessRequest, clustersv1alpha1.RequestPhase, clustersv1alpha1.ConditionStatus]().
51+
return ctrlutils.NewStatusUpdaterBuilder[*clustersv1alpha1.AccessRequest, clustersv1alpha1.RequestPhase, clustersv1alpha1.AccessRequestStatus]().
5252
WithNestedStruct("CommonStatus").
5353
WithFieldOverride(ctrlutils.STATUS_FIELD_PHASE, "Phase").
5454
WithoutFields(ctrlutils.STATUS_FIELD_CONDITIONS).

0 commit comments

Comments
 (0)