Skip to content

Commit 41ad875

Browse files
committed
temp changes adding conditions
1 parent 57b20ba commit 41ad875

File tree

3 files changed

+45
-30
lines changed

3 files changed

+45
-30
lines changed

api/v1alpha1/conditions.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,6 @@ type ConditionType string
2424

2525
func (c ConditionType) String() string { return string(c) }
2626

27-
const (
28-
// ResourceGraphDefinitionConditionTypeGraphVerified indicates the state of the directed
29-
// acyclic graph (DAG) that kro uses to manage the resources in a
30-
// ResourceGraphDefinition.
31-
ResourceGraphDefinitionConditionTypeGraphVerified ConditionType = "GraphVerified"
32-
// ResourceGraphDefinitionConditionTypeCustomResourceDefinitionSynced indicates the state of the
33-
// CustomResourceDefinition (CRD) that kro uses to manage the resources in a
34-
// ResourceGraphDefinition.
35-
ResourceGraphDefinitionConditionTypeCustomResourceDefinitionSynced ConditionType = "CustomResourceDefinitionSynced"
36-
// ResourceGraphDefinitionConditionTypeReconcilerReady indicates the state of the reconciler.
37-
// Whenever an ResourceGraphDefinition resource is created, kro will spin up a
38-
// reconciler for that resource. This condition indicates the state of the
39-
// reconciler.
40-
ResourceGraphDefinitionConditionTypeReconcilerReady ConditionType = "ReconcilerReady"
41-
)
42-
4327
// Condition is the common struct used by all CRDs managed by ACK service
4428
// controllers to indicate terminal states of the CR and its backend AWS
4529
// service API resource

pkg/controller/resourcegraphdefinition/controller.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,38 +155,46 @@ func (r *ResourceGraphDefinitionReconciler) findRGDsForCRD(ctx context.Context,
155155
}
156156
}
157157

158-
func (r *ResourceGraphDefinitionReconciler) Reconcile(ctx context.Context, o *v1alpha1.ResourceGraphDefinition) (res ctrl.Result, reconcileErr error) {
158+
func (r *ResourceGraphDefinitionReconciler) Reconcile(ctx context.Context, o *v1alpha1.ResourceGraphDefinition) (res ctrl.Result, err error) {
159159
var topologicalOrder []string
160160
var resourcesInformation []v1alpha1.ResourceInformation
161161
// defer function will ensure any errors that occur during reconcile will eventually be
162162
// patched to the resource
163163
defer func() {
164164
// if the updateStatus error is a k8s NotFound error we want to skip it.
165165
// If not, we will merge it to the returned error
166-
if err := r.updateStatus(ctx, o, topologicalOrder, resourcesInformation); err != nil {
167-
// we don't want to reconcile if resource is deleted
168-
if !apierrors.IsNotFound(err) {
169-
reconcileErr = errors.Join(reconcileErr, err)
166+
if patchErr := r.updateStatus(ctx, o, topologicalOrder, resourcesInformation); patchErr != nil {
167+
if apierrors.IsNotFound(patchErr) {
168+
// we don't want to return an error and requeue if
169+
// rgd is not found (deleted)
170+
err = nil
170171
} else {
171-
reconcileErr = nil
172+
err = errors.Join(patchErr, err)
172173
}
173174
}
174175
}()
176+
mark := NewConditionsMarkerFor(o)
175177
if !o.DeletionTimestamp.IsZero() {
176178
if err := r.cleanupResourceGraphDefinition(ctx, o); err != nil {
179+
mark.ResourceGraphNotCleanedUp(err.Error())
177180
return ctrl.Result{}, err
178181
}
182+
mark.ResourceGraphCleanedUp()
179183
if err := r.setUnmanaged(ctx, o); err != nil {
184+
mark.ResourceGraphUnfinalized(err.Error())
180185
return ctrl.Result{}, err
181186
}
187+
mark.ResourceGraphFinalized("removed")
182188
return ctrl.Result{}, nil
183189
}
184190

185191
if err := r.setManaged(ctx, o); err != nil {
192+
mark.ResourceGraphUnfinalized(err.Error())
186193
return ctrl.Result{}, err
187194
}
195+
mark.ResourceGraphFinalized("added")
188196

189-
topologicalOrder, resourcesInformation, reconcileErr = r.reconcileResourceGraphDefinition(ctx, o)
197+
topologicalOrder, resourcesInformation, err = r.reconcileResourceGraphDefinition(ctx, o)
190198

191-
return ctrl.Result{}, reconcileErr
199+
return ctrl.Result{}, err
192200
}

pkg/controller/resourcegraphdefinition/controller_status.go

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,21 +106,24 @@ func (r *ResourceGraphDefinitionReconciler) setUnmanaged(ctx context.Context, rg
106106
}
107107

108108
const (
109-
Ready = "Ready"
110-
ResourceGraphAccepted = "ResourceGraphAccepted"
111-
KindReady = "KindReady"
112-
ControllerReady = "ControllerReady"
109+
Ready = "Ready"
110+
ResourceGraphAccepted = "ResourceGraphAccepted"
111+
KindReady = "KindReady"
112+
ControllerReady = "ControllerReady"
113+
ResourceGraphFinalized = "ResourceGraphFinalized"
114+
ResourceGraphCleanedUp = "ResourceGraphCleanedUp"
113115
)
114116

115-
var rgdConditionTypes = apis.NewReadyConditions(ResourceGraphAccepted, KindReady, ControllerReady)
117+
var rgdConditionTypes = apis.NewReadyConditions(ResourceGraphAccepted, KindReady, ControllerReady, ResourceGraphFinalized)
116118

117119
// NewConditionsMarkerFor creates a marker to manage conditions and sub-conditions for ResourceGraphDefinitions.
118120
//
119121
// ```
120122
// Ready
121123
// ├─ ResourceGraphAccepted - This controller has accepted the spec.schema and spec.resources.
122124
// ├─ KindReady - The CRD status created on behalf of this RGD.
123-
// └─ ControllerReady - The status of the controller thread reconciling this resource.
125+
// ├─ ControllerReady - The status of the controller thread reconciling this resource.
126+
// └─ ResourceGraphFinalized - The RGD was successfully finalized
124127
// ```
125128

126129
func NewConditionsMarkerFor(o apis.Object) *ConditionsMarker {
@@ -159,6 +162,26 @@ func (m *ConditionsMarker) KindReady(kind string) {
159162
m.cs.SetTrueWithReason(KindReady, "Ready", fmt.Sprintf("kind %s has been accepted and ready", kind))
160163
}
161164

165+
// ResourceGraphUnfinalized signals the RGD finalizer failed to add/remove
166+
func (m *ConditionsMarker) ResourceGraphUnfinalized(msg string) {
167+
m.cs.SetFalse(ResourceGraphFinalized, "Failed", msg)
168+
}
169+
170+
// ResourceGraphFinalized signals the RGD finalizer was successfully added/removed
171+
func (m *ConditionsMarker) ResourceGraphFinalized(addedOrRemoved string) {
172+
m.cs.SetTrueWithReason(ResourceGraphFinalized, "Success", fmt.Sprintf("resourcegraph finalizer has been successfully %s", addedOrRemoved))
173+
}
174+
175+
// ResourceGraphCleanedUp signals the RGD was cleaned up successfully
176+
func (m *ConditionsMarker) ResourceGraphCleanedUp() {
177+
m.cs.SetTrueWithReason(ResourceGraphCleanedUp, "Success", "resourcegraph cleaned up successfully")
178+
}
179+
180+
// ResourceGraphNotCleanedUp signals the RGD failed to cleanup successfully
181+
func (m *ConditionsMarker) ResourceGraphNotCleanedUp(msg string) {
182+
m.cs.SetFalse(ResourceGraphCleanedUp, "Failed", msg)
183+
}
184+
162185
// ControllerFailedToStart signals the microcontroller had an issue when starting.
163186
func (m *ConditionsMarker) ControllerFailedToStart(msg string) {
164187
m.cs.SetFalse(ControllerReady, "FailedToStart", msg)

0 commit comments

Comments
 (0)