Skip to content

Commit

Permalink
feat: Application generation strategies and clusters generation (argo…
Browse files Browse the repository at this point in the history
…proj#8263)

feat: Application generation strategies and clusters generation (argoproj#8263)

Signed-off-by: pashavictorovich <pavel@codefresh.io>
  • Loading branch information
pasha-codefresh authored Jan 24, 2022
1 parent c3b3521 commit b7bdb8f
Show file tree
Hide file tree
Showing 17 changed files with 589 additions and 338 deletions.
76 changes: 0 additions & 76 deletions hack/gen-resources/cmd/commands/all.go

This file was deleted.

59 changes: 0 additions & 59 deletions hack/gen-resources/cmd/commands/application.go

This file was deleted.

132 changes: 132 additions & 0 deletions hack/gen-resources/cmd/commands/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package commands

import (
"context"
"log"

"github.com/spf13/cobra"

generator "github.com/argoproj/argo-cd/v2/hack/gen-resources/generators"
"github.com/argoproj/argo-cd/v2/util/db"
"github.com/argoproj/argo-cd/v2/util/settings"

cmdutil "github.com/argoproj/argo-cd/v2/cmd/util"
"github.com/argoproj/argo-cd/v2/hack/gen-resources/util"
"github.com/argoproj/argo-cd/v2/util/cli"
)

const (
cliName = "argocd-generator"
)

func init() {
cobra.OnInitialize(initConfig)
}

func initConfig() {
cli.SetLogFormat(cmdutil.LogFormat)
cli.SetLogLevel(cmdutil.LogLevel)
}

// NewCommand returns a new instance of an argocd command
func NewCommand() *cobra.Command {

var generateOpts util.GenerateOpts

var command = &cobra.Command{
Use: cliName,
Short: "Generator for argocd resources",
Run: func(c *cobra.Command, args []string) {
c.HelpFunc()(c, args)
},
DisableAutoGenTag: true,
}

command.AddCommand(NewGenerateCommand(&generateOpts))
command.AddCommand(NewCleanCommand(&generateOpts))

command.PersistentFlags().StringVar(&generateOpts.Namespace, "kube-namespace", "argocd", "Name of the namespace on which Argo agent should be installed [$KUBE_NAMESPACE]")
return command
}

func NewGenerateCommand(opts *util.GenerateOpts) *cobra.Command {
var file string
var command = &cobra.Command{
Use: "generate [-f file]",
Short: "Generate entities",
Long: "Generate entities",
Run: func(c *cobra.Command, args []string) {
log.Printf("Retrieve configuration from %s", file)
err := util.Parse(opts, file)
if err != nil {
log.Fatalf("Failed to retrieve configuration, %v", err.Error())
}
argoClientSet := util.ConnectToK8sArgoClientSet()
clientSet := util.ConnectToK8sClientSet()

settingsMgr := settings.NewSettingsManager(context.TODO(), clientSet, opts.Namespace)
argoDB := db.NewDB(opts.Namespace, settingsMgr, clientSet)

pg := generator.NewProjectGenerator(argoClientSet)
ag := generator.NewApplicationGenerator(argoClientSet, clientSet, argoDB)
rg := generator.NewRepoGenerator(util.ConnectToK8sClientSet())
cg := generator.NewClusterGenerator(argoDB, util.ConnectToK8sClientSet(), util.ConnectToK8sConfig())

err = pg.Generate(opts)
if err != nil {
log.Fatalf("Failed to generate projects, %v", err.Error())
}
err = rg.Generate(opts)
if err != nil {
log.Fatalf("Failed to generate repositories, %v", err.Error())
}
err = cg.Generate(opts)
if err != nil {
log.Fatalf("Failed to generate clusters, %v", err.Error())
}
err = ag.Generate(opts)
if err != nil {
log.Fatalf("Failed to generate applications, %v", err.Error())
}
},
}
command.Flags().StringVarP(&file, "file", "f", "", "")
return command
}

func NewCleanCommand(opts *util.GenerateOpts) *cobra.Command {
var command = &cobra.Command{
Use: "clean",
Short: "Clean entities",
Long: "Clean entities",
Run: func(c *cobra.Command, args []string) {
argoClientSet := util.ConnectToK8sArgoClientSet()
clientSet := util.ConnectToK8sClientSet()
settingsMgr := settings.NewSettingsManager(context.TODO(), clientSet, opts.Namespace)
argoDB := db.NewDB(opts.Namespace, settingsMgr, clientSet)

pg := generator.NewProjectGenerator(argoClientSet)
ag := generator.NewApplicationGenerator(argoClientSet, clientSet, argoDB)
cg := generator.NewClusterGenerator(argoDB, clientSet, util.ConnectToK8sConfig())
rg := generator.NewRepoGenerator(clientSet)

err := pg.Clean(opts)
if err != nil {
log.Fatalf("Failed to clean projects, %v", err.Error())
}
err = ag.Clean(opts)
if err != nil {
log.Fatalf("Failed to clean applications, %v", err.Error())
}
err = cg.Clean(opts)
if err != nil {
log.Fatalf("Failed to clean clusters, %v", err.Error())
}
err = rg.Clean(opts)
if err != nil {
log.Fatalf("Failed to clean repositores, %v", err.Error())
}
},
}
return command
}
60 changes: 0 additions & 60 deletions hack/gen-resources/cmd/commands/project.go

This file was deleted.

61 changes: 0 additions & 61 deletions hack/gen-resources/cmd/commands/repos.go

This file was deleted.

Loading

0 comments on commit b7bdb8f

Please sign in to comment.