From e46adaf0ca0c0359f5e66744b8b3f6601f7151c4 Mon Sep 17 00:00:00 2001 From: Abinand P Date: Sun, 29 Sep 2024 19:15:47 +0530 Subject: [PATCH] Create reconcile.go The reconcilation file --- cyctl/cmd/reconcile.go | 59 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 cyctl/cmd/reconcile.go diff --git a/cyctl/cmd/reconcile.go b/cyctl/cmd/reconcile.go new file mode 100644 index 00000000..9d19f2b8 --- /dev/null +++ b/cyctl/cmd/reconcile.go @@ -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 ` +) + +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) + +}