Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To add reconciliation time stamps #572

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cyclops-ctrl/api/v1alpha1/module_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type ReconciliationStatus struct {
Reason string `json:"reason,omitempty"`
// +kubebuilder:validation:Optional
Errors []string `json:"errors"`
FinishedAt string `json:"finishedAt"`
Abiji-2020 marked this conversation as resolved.
Show resolved Hide resolved
}

type GroupVersionResource struct {
Expand Down Expand Up @@ -94,6 +95,7 @@ type HistoryEntry struct {
Generation int64 `json:"generation"`
TemplateRef HistoryTemplateRef `json:"template"`
Values apiextensionsv1.JSON `json:"values"`
FinishedAt string `json:"finishedAt"`
Abiji-2020 marked this conversation as resolved.
Show resolved Hide resolved
}

//+kubebuilder:object:root=true
Expand Down
7 changes: 7 additions & 0 deletions cyclops-ctrl/config/crd/bases/cyclops-ui.com_modules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ spec:
history:
items:
properties:
finishedAt:
type: string
generation:
format: int64
type: integer
Expand All @@ -48,6 +50,7 @@ spec:
values:
x-kubernetes-preserve-unknown-fields: true
required:
- finishedAt
- generation
- template
- values
Expand Down Expand Up @@ -113,6 +116,8 @@ spec:
items:
type: string
type: array
finishedAt:
type: string
reason:
type: string
status:
Expand All @@ -122,6 +127,8 @@ spec:
- succeeded
- failed
type: string
required:
- finishedAt
type: object
templateResolvedVersion:
type: string
Expand Down
64 changes: 33 additions & 31 deletions cyclops-ctrl/internal/modulecontroller/module_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,36 +406,38 @@ func (r *ModuleReconciler) mergeChildrenGVRs(existing, current []cyclopsv1alpha1
}

func (r *ModuleReconciler) setStatus(
ctx context.Context,
module cyclopsv1alpha1.Module,
namespacedName types.NamespacedName,
status cyclopsv1alpha1.ReconciliationStatusState,
templateResolvedVersion string,
reason string,
installErrors []string,
childrenResources []cyclopsv1alpha1.GroupVersionResource,
iconURL string,
ctx context.Context,
module cyclopsv1alpha1.Module,
namespacedName types.NamespacedName,
status cyclopsv1alpha1.ReconciliationStatusState,
templateResolvedVersion string,
reason string,
installErrors []string,
childrenResources []cyclopsv1alpha1.GroupVersionResource,
iconURL string,
) error {
trv := module.Status.TemplateResolvedVersion
if len(trv) == 0 {
trv = templateResolvedVersion
}

module.Status = cyclopsv1alpha1.ModuleStatus{
ReconciliationStatus: cyclopsv1alpha1.ReconciliationStatus{
Status: status,
Reason: reason,
Errors: installErrors,
},
ManagedGVRs: r.mergeChildrenGVRs(module.Status.ManagedGVRs, childrenResources),
TemplateResolvedVersion: templateResolvedVersion,
IconURL: iconURL,
}

if err := r.Status().Update(ctx, &module); err != nil {
r.logger.Error(err, "error updating module status", "namespaced name", namespacedName)
return err
}

return nil
trv := module.Status.TemplateResolvedVersion
if len(trv) == 0 {
trv = templateResolvedVersion
}

module.Status = cyclopsv1alpha1.ModuleStatus{
ReconciliationStatus: cyclopsv1alpha1.ReconciliationStatus{
Status: status,
Reason: reason,
Errors: installErrors,
FinishedAt: time.Now().Format(time.RFC3339), // Convert time to string format
},
ManagedGVRs: r.mergeChildrenGVRs(module.Status.ManagedGVRs, childrenResources),
TemplateResolvedVersion: templateResolvedVersion,
IconURL: iconURL,
}

if err := r.Status().Update(ctx, &module); err != nil {
r.logger.Error(err, "error updating module status", "namespaced name", namespacedName)
return err
}

return nil
}

Loading