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

Reconcilation #593

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion cyclops-ctrl/api/v1alpha1/module_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ type ReconciliationStatus struct {
// +kubebuilder:validation:Optional
Reason string `json:"reason,omitempty"`
// +kubebuilder:validation:Optional
Errors []string `json:"errors"`
Errors []string `json:"errors"`
// +kubebuilder:validation:Optional
FinishedAt string `json:"finishedAt,omitempty"`
}

type GroupVersionResource struct {
Expand Down Expand Up @@ -94,6 +96,8 @@ type HistoryEntry struct {
Generation int64 `json:"generation"`
TemplateRef HistoryTemplateRef `json:"template"`
Values apiextensionsv1.JSON `json:"values"`
// +kubebuilder:validation:Optional
FinishedAt string `json:"finishedAt,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
4 changes: 4 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 Down Expand Up @@ -113,6 +115,8 @@ spec:
items:
type: string
type: array
finishedAt:
type: string
reason:
type: string
status:
Expand Down
7 changes: 4 additions & 3 deletions cyclops-ctrl/internal/modulecontroller/module_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,10 @@ func (r *ModuleReconciler) setStatus(

module.Status = cyclopsv1alpha1.ModuleStatus{
ReconciliationStatus: cyclopsv1alpha1.ReconciliationStatus{
Status: status,
Reason: reason,
Errors: installErrors,
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,
Expand Down
59 changes: 59 additions & 0 deletions cyctl/cmd/reconcile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package cmd

import (
"fmt"

"github.com/cyclops-ui/cyclops/cyclops-ctrl/api/v1alpha1/client"
"github.com/cyclops-ui/cycops-cyctl/internal/kubeconfig"
"github.com/spf13/cobra"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"time"
)

func reconcileModule(clientset *client.CyclopsV1Alpha1Client, moduleName string) {
module, err := clientset.Modules("cyclops").Get(moduleName)
if err != nil {
fmt.Println("Failed to fetch the module ", err)
return
}
annotations := module.GetAnnotations()
if annotations == nil {
annotations = make(map[string]string)
}
annotations["cyclops/reconciled-at"] = time.Now().Format(time.RFC3339)
module.SetAnnotations(annotations)
module.TypeMeta = v1.TypeMeta{
APIVersion: "cyclops-ui.com/v1alpha1",
Kind: "Module",
}

_, err = clientset.Modules("cyclops").Update(module)
if err != nil {
fmt.Println("failed to update module: ", err)
return
}
fmt.Printf("successfully reconciled %v", moduleName)

}

var (
reconcileExample = `# Reconcile the Module
cyctl reconcile <modulename>`
)

var reconcileCMD = &cobra.Command{
Use: "reconcile",
Short: "Will reconcile the Module and update the current TimeStamp",
Long: "Will reconcile the Module and update the current TimeStamp",
Example: reconcileExample,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
moduleName := args[0]
reconcileModule(kubeconfig.Moduleset, moduleName)
},
}

func init() {
RootCmd.AddCommand(reconcileCMD)

}