From 74c87c4f1a9329e745c0cdf59d3e8a7f30d0ff09 Mon Sep 17 00:00:00 2001 From: Abinand P Date: Sat, 14 Sep 2024 03:30:31 +0000 Subject: [PATCH 1/8] Added time stamps and unmarshalled the json to store the current time in the string formt and used them to store the history --- cyclops-ctrl/api/v1alpha1/module_types.go | 3 + .../crd/bases/cyclops-ui.com_modules.yaml | 7 ++ .../modulecontroller/module_controller.go | 91 +++++++++++++------ 3 files changed, 71 insertions(+), 30 deletions(-) diff --git a/cyclops-ctrl/api/v1alpha1/module_types.go b/cyclops-ctrl/api/v1alpha1/module_types.go index 8a3f460e..1a625e47 100644 --- a/cyclops-ctrl/api/v1alpha1/module_types.go +++ b/cyclops-ctrl/api/v1alpha1/module_types.go @@ -19,6 +19,7 @@ package v1alpha1 import ( apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "time" ) // EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! @@ -66,6 +67,7 @@ type ReconciliationStatus struct { Reason string `json:"reason,omitempty"` // +kubebuilder:validation:Optional Errors []string `json:"errors"` + FinishedAt string `json:"finishedAt"` } type GroupVersionResource struct { @@ -94,6 +96,7 @@ type HistoryEntry struct { Generation int64 `json:"generation"` TemplateRef HistoryTemplateRef `json:"template"` Values apiextensionsv1.JSON `json:"values"` + FinishedAt string `json:"finishedAt"` } //+kubebuilder:object:root=true diff --git a/cyclops-ctrl/config/crd/bases/cyclops-ui.com_modules.yaml b/cyclops-ctrl/config/crd/bases/cyclops-ui.com_modules.yaml index 0da88077..98076e43 100644 --- a/cyclops-ctrl/config/crd/bases/cyclops-ui.com_modules.yaml +++ b/cyclops-ctrl/config/crd/bases/cyclops-ui.com_modules.yaml @@ -29,6 +29,8 @@ spec: history: items: properties: + finishedAt: + type: string generation: format: int64 type: integer @@ -48,6 +50,7 @@ spec: values: x-kubernetes-preserve-unknown-fields: true required: + - finishedAt - generation - template - values @@ -113,6 +116,8 @@ spec: items: type: string type: array + finishedAt: + type: string reason: type: string status: @@ -122,6 +127,8 @@ spec: - succeeded - failed type: string + required: + - finishedAt type: object templateResolvedVersion: type: string diff --git a/cyclops-ctrl/internal/modulecontroller/module_controller.go b/cyclops-ctrl/internal/modulecontroller/module_controller.go index ae432845..c003d92e 100644 --- a/cyclops-ctrl/internal/modulecontroller/module_controller.go +++ b/cyclops-ctrl/internal/modulecontroller/module_controller.go @@ -406,36 +406,67 @@ 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 - } + 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 +} +func (r *ReconciliationStatus) UnmarshalJSON(data []byte) error { + type Alias ReconciliationStatus + aux := &struct { + FinishedAt string `json:"finishedAt"` + *Alias + }{ + Alias: (*Alias)(r), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + // Parse the FinishedAt string to time.Time + finishedAt, err := time.Parse(time.RFC3339, aux.FinishedAt) + if err != nil { + return err + } + r.FinishedAt = finishedAt.Format(time.RFC3339) // Store as string + return nil +} - return nil +func (r *ReconciliationStatus) MarshalJSON() ([]byte, error) { + type Alias ReconciliationStatus + return json.Marshal(&struct { + FinishedAt string `json:"finishedAt"` + *Alias + }{ + Alias: (*Alias)(r), + FinishedAt: r.FinishedAt, + }) } From 62b82b0bbba35a30bfe325f4702c9d74338b511d Mon Sep 17 00:00:00 2001 From: Abinand P Date: Mon, 16 Sep 2024 09:43:18 +0530 Subject: [PATCH 2/8] Update module_types.go --- cyclops-ctrl/api/v1alpha1/module_types.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cyclops-ctrl/api/v1alpha1/module_types.go b/cyclops-ctrl/api/v1alpha1/module_types.go index 1a625e47..18538478 100644 --- a/cyclops-ctrl/api/v1alpha1/module_types.go +++ b/cyclops-ctrl/api/v1alpha1/module_types.go @@ -19,7 +19,6 @@ package v1alpha1 import ( apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "time" ) // EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! From 3112b32ee45401bce65359b91268907770936d03 Mon Sep 17 00:00:00 2001 From: Abinand P Date: Mon, 16 Sep 2024 08:53:50 +0000 Subject: [PATCH 3/8] Improved some minor changes and added verified teh build of the module_controller file --- .../modulecontroller/module_controller.go | 29 ------------------- 1 file changed, 29 deletions(-) diff --git a/cyclops-ctrl/internal/modulecontroller/module_controller.go b/cyclops-ctrl/internal/modulecontroller/module_controller.go index c003d92e..aea6fcd7 100644 --- a/cyclops-ctrl/internal/modulecontroller/module_controller.go +++ b/cyclops-ctrl/internal/modulecontroller/module_controller.go @@ -440,33 +440,4 @@ func (r *ModuleReconciler) setStatus( return nil } -func (r *ReconciliationStatus) UnmarshalJSON(data []byte) error { - type Alias ReconciliationStatus - aux := &struct { - FinishedAt string `json:"finishedAt"` - *Alias - }{ - Alias: (*Alias)(r), - } - if err := json.Unmarshal(data, &aux); err != nil { - return err - } - // Parse the FinishedAt string to time.Time - finishedAt, err := time.Parse(time.RFC3339, aux.FinishedAt) - if err != nil { - return err - } - r.FinishedAt = finishedAt.Format(time.RFC3339) // Store as string - return nil -} -func (r *ReconciliationStatus) MarshalJSON() ([]byte, error) { - type Alias ReconciliationStatus - return json.Marshal(&struct { - FinishedAt string `json:"finishedAt"` - *Alias - }{ - Alias: (*Alias)(r), - FinishedAt: r.FinishedAt, - }) -} From c025b985ba1d9599525c6ef3255b95f7a0b97d90 Mon Sep 17 00:00:00 2001 From: Abinand P Date: Tue, 17 Sep 2024 05:09:47 +0000 Subject: [PATCH 4/8] Formatted the code and added optional for the FinishedAt struct values --- .../modulecontroller/module_controller.go | 65 +++++++++---------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/cyclops-ctrl/internal/modulecontroller/module_controller.go b/cyclops-ctrl/internal/modulecontroller/module_controller.go index aea6fcd7..0841c2d0 100644 --- a/cyclops-ctrl/internal/modulecontroller/module_controller.go +++ b/cyclops-ctrl/internal/modulecontroller/module_controller.go @@ -406,38 +406,37 @@ 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, - 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 -} + 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 +} From 7c40271c49401f0a48d29c2ac96d0a9cd3bf06f0 Mon Sep 17 00:00:00 2001 From: Abinand P Date: Tue, 17 Sep 2024 05:10:41 +0000 Subject: [PATCH 5/8] formatted the code --- cyclops-ctrl/api/v1alpha1/module_types.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cyclops-ctrl/api/v1alpha1/module_types.go b/cyclops-ctrl/api/v1alpha1/module_types.go index 18538478..2f7aa0c2 100644 --- a/cyclops-ctrl/api/v1alpha1/module_types.go +++ b/cyclops-ctrl/api/v1alpha1/module_types.go @@ -65,8 +65,8 @@ type ReconciliationStatus struct { // +kubebuilder:validation:Optional Reason string `json:"reason,omitempty"` // +kubebuilder:validation:Optional - Errors []string `json:"errors"` - FinishedAt string `json:"finishedAt"` + Errors []string `json:"errors"` + FinishedAt string `json:"finishedAt,omitempty"` } type GroupVersionResource struct { @@ -95,7 +95,7 @@ type HistoryEntry struct { Generation int64 `json:"generation"` TemplateRef HistoryTemplateRef `json:"template"` Values apiextensionsv1.JSON `json:"values"` - FinishedAt string `json:"finishedAt"` + FinishedAt string `json:"finishedAt,omitempty"` } //+kubebuilder:object:root=true From 4c1d46bb055f8d1148dd8bfa456b5c90ca88ef38 Mon Sep 17 00:00:00 2001 From: Abinand P Date: Tue, 17 Sep 2024 10:43:57 +0530 Subject: [PATCH 6/8] Update cyclops-ui.com_modules.yaml --- cyclops-ctrl/config/crd/bases/cyclops-ui.com_modules.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/cyclops-ctrl/config/crd/bases/cyclops-ui.com_modules.yaml b/cyclops-ctrl/config/crd/bases/cyclops-ui.com_modules.yaml index 98076e43..9320088a 100644 --- a/cyclops-ctrl/config/crd/bases/cyclops-ui.com_modules.yaml +++ b/cyclops-ctrl/config/crd/bases/cyclops-ui.com_modules.yaml @@ -50,7 +50,6 @@ spec: values: x-kubernetes-preserve-unknown-fields: true required: - - finishedAt - generation - template - values @@ -128,8 +127,6 @@ spec: - failed type: string required: - - finishedAt - type: object templateResolvedVersion: type: string required: From eaf932de44fb8a7ad516a6ebc9219d40d6790bee Mon Sep 17 00:00:00 2001 From: Abinand P Date: Wed, 18 Sep 2024 21:50:16 +0530 Subject: [PATCH 7/8] Added kubebuilderComment --- cyclops-ctrl/api/v1alpha1/module_types.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cyclops-ctrl/api/v1alpha1/module_types.go b/cyclops-ctrl/api/v1alpha1/module_types.go index 2f7aa0c2..54c64560 100644 --- a/cyclops-ctrl/api/v1alpha1/module_types.go +++ b/cyclops-ctrl/api/v1alpha1/module_types.go @@ -66,6 +66,7 @@ type ReconciliationStatus struct { Reason string `json:"reason,omitempty"` // +kubebuilder:validation:Optional Errors []string `json:"errors"` + // +kubebuilder:validation:Optional FinishedAt string `json:"finishedAt,omitempty"` } @@ -95,6 +96,7 @@ type HistoryEntry struct { Generation int64 `json:"generation"` TemplateRef HistoryTemplateRef `json:"template"` Values apiextensionsv1.JSON `json:"values"` + // +kubebuilder:validation:Optional FinishedAt string `json:"finishedAt,omitempty"` } From f015da645422af187b4ce0ed4300e6f9176c11b4 Mon Sep 17 00:00:00 2001 From: petar-cvit Date: Sat, 21 Sep 2024 18:46:45 +0200 Subject: [PATCH 8/8] make manifests --- cyclops-ctrl/config/crd/bases/cyclops-ui.com_modules.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cyclops-ctrl/config/crd/bases/cyclops-ui.com_modules.yaml b/cyclops-ctrl/config/crd/bases/cyclops-ui.com_modules.yaml index 9320088a..6d694d33 100644 --- a/cyclops-ctrl/config/crd/bases/cyclops-ui.com_modules.yaml +++ b/cyclops-ctrl/config/crd/bases/cyclops-ui.com_modules.yaml @@ -126,7 +126,7 @@ spec: - succeeded - failed type: string - required: + type: object templateResolvedVersion: type: string required: