From 498c225063f99aea6200bc3190970abfc73b667a Mon Sep 17 00:00:00 2001 From: Abinand P Date: Mon, 30 Sep 2024 19:08:10 +0530 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20reconcilation=20command=20?= =?UTF-8?q?line=20=20(#595)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Create reconcile.go The reconcilation file * Modifed the cli outputs --- 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..d52cca65 --- /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 triggered reconcilation for module: %v", moduleName) + +} + +var ( + reconcileExample = `# Reconcile a Module + cyctl reconcile ` +) + +var reconcileCMD = &cobra.Command{ + Use: "reconcile", + Short: "Trigger module reconciliation", + Long: "Trigger module reconciliation", + 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) + +}