Skip to content

Commit

Permalink
Create reconcile.go
Browse files Browse the repository at this point in the history
The reconcilation file
  • Loading branch information
Abiji-2020 authored Sep 29, 2024
1 parent 7f19618 commit e46adaf
Showing 1 changed file with 59 additions and 0 deletions.
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)

}

0 comments on commit e46adaf

Please sign in to comment.