From 044892622722cafcb65cb7225235bb2cb3f032d2 Mon Sep 17 00:00:00 2001 From: Noam Gal Date: Tue, 29 Jun 2021 11:35:46 +0300 Subject: [PATCH] CR-5154 - wait until events is synced (#15) * wait until events is synced * updated workflows to v3.1.1 --- Makefile | 2 +- cmd/commands/runtime.go | 145 +++++++++----------- docs/commands/cli-v2_runtime_create.md | 14 +- docs/releases/release_notes.md | 7 + go.mod | 3 +- go.sum | 4 +- manifests/argo-workflows/kustomization.yaml | 2 +- pkg/store/store.go | 3 + 8 files changed, 86 insertions(+), 94 deletions(-) diff --git a/Makefile b/Makefile index 434c7f2c7..3f59bbbbf 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION=v0.0.19 +VERSION=v0.0.20 OUT_DIR=dist YEAR?=$(shell date +"%Y") diff --git a/cmd/commands/runtime.go b/cmd/commands/runtime.go index d82b591ea..cabd70931 100644 --- a/cmd/commands/runtime.go +++ b/cmd/commands/runtime.go @@ -17,7 +17,7 @@ package commands import ( "context" "fmt" - "io/ioutil" + "time" "github.com/codefresh-io/cli-v2/pkg/cdUtils" "github.com/codefresh-io/cli-v2/pkg/eventUtils" @@ -32,10 +32,12 @@ import ( "github.com/argoproj-labs/argocd-autopilot/pkg/git" "github.com/argoproj-labs/argocd-autopilot/pkg/kube" apstore "github.com/argoproj-labs/argocd-autopilot/pkg/store" + aputil "github.com/argoproj-labs/argocd-autopilot/pkg/util" argocdv1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" wf "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow" wfv1alpha1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1" "github.com/ghodss/yaml" + "github.com/go-git/go-billy/v5/memfs" "github.com/spf13/cobra" v1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" @@ -44,11 +46,11 @@ import ( type ( RuntimeCreateOptions struct { - RuntimeName string - KubeContext string - KubeFactory kube.Factory - insCreateOpts *apcmd.RepoCreateOptions - gsCreateOpts *apcmd.RepoCreateOptions + RuntimeName string + KubeContext string + KubeFactory kube.Factory + insCloneOpts *git.CloneOptions + gsCloneOpts *git.CloneOptions } ) @@ -70,9 +72,9 @@ func NewRuntimeCommand() *cobra.Command { func NewRuntimeCreateCommand() *cobra.Command { var ( - f kube.Factory - insCreateOpts *apcmd.RepoCreateOptions - gsCreateOpts *apcmd.RepoCreateOptions + f kube.Factory + insCloneOpts *git.CloneOptions + gsCloneOpts *git.CloneOptions ) cmd := &cobra.Command{ @@ -92,120 +94,103 @@ func NewRuntimeCreateCommand() *cobra.Command { runtime create runtime-name --install-owner owner --install-name gitops_repo `), - RunE: func(cmd *cobra.Command, args []string) error { - opts := &RuntimeCreateOptions{ - KubeContext: "", - KubeFactory: f, - insCreateOpts: insCreateOpts, - gsCreateOpts: gsCreateOpts, + PreRun: func(_ *cobra.Command, _ []string) { + if gsCloneOpts.Auth.Password == "" { + gsCloneOpts.Auth.Password = insCloneOpts.Auth.Password + } + + insCloneOpts.Parse() + if gsCloneOpts.Repo == "" { + host, orgRepo, _, _, _, suffix, _ := aputil.ParseGitUrl(insCloneOpts.Repo) + gsCloneOpts.Repo = host + orgRepo + "_git_source" + suffix } + + gsCloneOpts.Parse() + }, + RunE: func(cmd *cobra.Command, args []string) error { if len(args) < 1 { log.G().Fatal("must enter runtime name") } - opts.RuntimeName = args[0] - insCreateOpts.Public = false - return RunRuntimeCreate(cmd.Context(), opts) + return RunRuntimeCreate(cmd.Context(), &RuntimeCreateOptions{ + RuntimeName: args[0], + KubeContext: "", + KubeFactory: f, + insCloneOpts: insCloneOpts, + gsCloneOpts: gsCloneOpts, + }) }, } - insCreateOpts = apcmd.AddRepoCreateFlags(cmd, "install") - gsCreateOpts = apcmd.AddRepoCreateFlags(cmd, "git-src") + insCloneOpts = git.AddFlags(cmd, &git.AddFlagsOptions{ + Prefix: "install", + CreateIfNotExist: true, + FS: memfs.New(), + }) + gsCloneOpts = git.AddFlags(cmd, &git.AddFlagsOptions{ + Prefix: "git-src", + Optional: true, + CreateIfNotExist: true, + FS: memfs.New(), + }) f = kube.AddFlags(cmd.Flags()) return cmd } func RunRuntimeCreate(ctx context.Context, opts *RuntimeCreateOptions) error { - insCloneOpts, err := apcmd.RunRepoCreate(ctx, opts.insCreateOpts) - if err != nil { - return err - } - - // var err error - // installOpts := &git.CloneOptions{ - // Repo: "github.com/noam-codefresh/demo", - // Auth: git.Auth{ - // Password: "", - // }, - // FS: fs.Create(memfs.New()), - // } - // installOpts.Parse() - - insCloneOpts.Progress = ioutil.Discard - err = apcmd.RunRepoBootstrap(ctx, &apcmd.RepoBootstrapOptions{ + err := apcmd.RunRepoBootstrap(ctx, &apcmd.RepoBootstrapOptions{ AppSpecifier: store.Get().ArgoCDManifestsURL, Namespace: opts.RuntimeName, KubeContext: opts.KubeContext, KubeFactory: opts.KubeFactory, - CloneOptions: insCloneOpts, + CloneOptions: opts.insCloneOpts, }) if err != nil { return err } err = apcmd.RunProjectCreate(ctx, &apcmd.ProjectCreateOptions{ - CloneOpts: insCloneOpts, + CloneOpts: opts.insCloneOpts, ProjectName: opts.RuntimeName, }) if err != nil { return err } - if err = createApp(ctx, insCloneOpts, opts.RuntimeName, "events", store.Get().ArgoEventsManifestsURL, application.AppTypeKustomize, opts.RuntimeName); err != nil { - return fmt.Errorf("failed to create events application: %w", err) - } - - if err = createApp(ctx, insCloneOpts, opts.RuntimeName, "rollouts", store.Get().ArgoRolloutsManifestsURL, application.AppTypeKustomize, opts.RuntimeName); err != nil { + if err = createApp(ctx, opts.KubeFactory, opts.insCloneOpts, opts.RuntimeName, "rollouts", store.Get().ArgoRolloutsManifestsURL, application.AppTypeKustomize, opts.RuntimeName, false); err != nil { return fmt.Errorf("failed to create rollouts application: %w", err) } - if err = createApp(ctx, insCloneOpts, opts.RuntimeName, "workflows", store.Get().ArgoWorkflowsManifestsURL, application.AppTypeKustomize, opts.RuntimeName); err != nil { + if err = createApp(ctx, opts.KubeFactory, opts.insCloneOpts, opts.RuntimeName, "workflows", store.Get().ArgoWorkflowsManifestsURL, application.AppTypeKustomize, opts.RuntimeName, false); err != nil { return fmt.Errorf("failed to create workflows application: %w", err) } - if err = createComponentsReporter(ctx, insCloneOpts, opts); err != nil { - return fmt.Errorf("failed to create components-reporter: %w", err) - } - - if opts.gsCreateOpts.Owner == "" { - opts.gsCreateOpts.Owner = opts.insCreateOpts.Owner - } - - if opts.gsCreateOpts.Repo == "" { - opts.gsCreateOpts.Repo = opts.insCreateOpts.Repo + "-git-source" - } - - if opts.gsCreateOpts.Token == "" { - opts.gsCreateOpts.Token = opts.insCreateOpts.Token + if err = createApp(ctx, opts.KubeFactory, opts.insCloneOpts, opts.RuntimeName, "events", store.Get().ArgoEventsManifestsURL, application.AppTypeKustomize, opts.RuntimeName, true); err != nil { + return fmt.Errorf("failed to create events application: %w", err) } - gsCloneOpts, err := apcmd.RunRepoCreate(ctx, opts.gsCreateOpts) - if err != nil { - return err + if err = createComponentsReporter(ctx, opts.insCloneOpts, opts); err != nil { + return fmt.Errorf("failed to create components-reporter: %w", err) } - // gsCloneOpts := &git.CloneOptions{ - // Repo: "github.com/noam-codefresh/git-source", - // Auth: git.Auth{ - // Password: gsCreateOpts.Token, - // }, - // FS: fs.Create(memfs.New()), - // } - // gsCloneOpts.Parse() - - if err = createDemoWorkflowTemplate(ctx, gsCloneOpts, store.Get().GitSourceName, opts.RuntimeName); err != nil { + if err = createDemoWorkflowTemplate(ctx, opts.gsCloneOpts, store.Get().GitSourceName, opts.RuntimeName); err != nil { return err } - if err = createGitSource(ctx, insCloneOpts, gsCloneOpts, store.Get().GitSourceName, opts.RuntimeName); err != nil { + if err = createGitSource(ctx, opts.insCloneOpts, opts.gsCloneOpts, store.Get().GitSourceName, opts.RuntimeName); err != nil { return fmt.Errorf("failed to create `%s`: %w", store.Get().GitSourceName, err) } return nil } -func createApp(ctx context.Context, cloneOpts *git.CloneOptions, projectName, appName, appURL, appType, namespace string) error { +func createApp(ctx context.Context, f kube.Factory, cloneOpts *git.CloneOptions, projectName, appName, appURL, appType, namespace string, wait bool) error { + timeout := time.Duration(0) + if wait { + timeout = store.Get().WaitTimeout + } + return apcmd.RunAppCreate(ctx, &apcmd.AppCreateOptions{ CloneOpts: cloneOpts, AppsCloneOpts: &git.CloneOptions{}, @@ -216,6 +201,8 @@ func createApp(ctx context.Context, cloneOpts *git.CloneOptions, projectName, ap AppType: appType, DestNamespace: namespace, }, + KubeFactory: f, + Timeout: timeout, }) } @@ -230,11 +217,11 @@ func createComponentsReporter(ctx context.Context, cloneOpts *git.CloneOptions, } resPath := cloneOpts.FS.Join(apstore.Default.AppsDir, store.Get().ComponentsReporterName, opts.RuntimeName, "resources") - if err := createApp(ctx, cloneOpts, opts.RuntimeName, store.Get().ComponentsReporterName, cloneOpts.URL()+"/"+resPath, application.AppTypeDirectory, opts.RuntimeName); err != nil { + if err := createApp(ctx, opts.KubeFactory, cloneOpts, opts.RuntimeName, store.Get().ComponentsReporterName, cloneOpts.URL()+"/"+resPath, application.AppTypeDirectory, opts.RuntimeName, false); err != nil { return err } - r, repofs, err := cloneOpts.Clone(ctx) + r, repofs, err := cloneOpts.GetRepo(ctx) if err != nil { return err } @@ -419,7 +406,7 @@ func createSensor(repofs fs.FS, name, path, namespace, eventSourceName string) e } func createDemoWorkflowTemplate(ctx context.Context, gsCloneOpts *git.CloneOptions, gsName, runtimeName string) error { - gsRepo, gsFs, err := gsCloneOpts.Clone(ctx) + gsRepo, gsFs, err := gsCloneOpts.GetRepo(ctx) if err != nil { return err } @@ -462,7 +449,7 @@ func createDemoWorkflowTemplate(ctx context.Context, gsCloneOpts *git.CloneOptio func createGitSource(ctx context.Context, insCloneOpts *git.CloneOptions, gsCloneOpts *git.CloneOptions, gsName, runtimeName string) error { var err error - insRepo, insFs, err := insCloneOpts.Clone(ctx) + insRepo, insFs, err := insCloneOpts.GetRepo(ctx) if err != nil { return err } @@ -604,7 +591,7 @@ func createGitSource(ctx context.Context, insCloneOpts *git.CloneOptions, gsClon } fullResPath := insFs.Join(insFs.Root(), resPath) - if err = createApp(ctx, insCloneOpts, runtimeName, gsName, insCloneOpts.URL()+fullResPath, application.AppTypeDirectory, runtimeName); err != nil { + if err = createApp(ctx, nil, insCloneOpts, runtimeName, gsName, insCloneOpts.URL()+fullResPath, application.AppTypeDirectory, runtimeName, false); err != nil { return fmt.Errorf("failed to create git-source: %w", err) } diff --git a/docs/commands/cli-v2_runtime_create.md b/docs/commands/cli-v2_runtime_create.md index cf591546f..9055ad2ef 100644 --- a/docs/commands/cli-v2_runtime_create.md +++ b/docs/commands/cli-v2_runtime_create.md @@ -37,19 +37,13 @@ cli-v2 runtime create [runtime_name] [flags] --cluster string The name of the kubeconfig cluster to use --context string The name of the kubeconfig context to use --git-src-git-token string Your git provider api token [GIT_SRC_GIT_TOKEN] - --git-src-host string The git provider address (for on-premise git providers) - --git-src-name string The name of the repository - --git-src-owner string The name of the owner or organization - --git-src-provider string The git provider, one of: github (default "github") - --git-src-public If true, will create the repository as public (default is false) + --git-src-provider string The git provider, one of: github + --git-src-repo string Repository URL [GIT_SRC_GIT_REPO] -h, --help help for create --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure --install-git-token string Your git provider api token [INSTALL_GIT_TOKEN] - --install-host string The git provider address (for on-premise git providers) - --install-name string The name of the repository - --install-owner string The name of the owner or organization - --install-provider string The git provider, one of: github (default "github") - --install-public If true, will create the repository as public (default is false) + --install-provider string The git provider, one of: github + --install-repo string Repository URL [INSTALL_GIT_REPO] --kubeconfig string Path to the kubeconfig file to use for CLI requests. -n, --namespace string If present, the namespace scope for this CLI request -s, --server string The address and port of the Kubernetes API server diff --git a/docs/releases/release_notes.md b/docs/releases/release_notes.md index e7a6ef7f0..bc18583e2 100644 --- a/docs/releases/release_notes.md +++ b/docs/releases/release_notes.md @@ -1,3 +1,10 @@ +### Installed Applications: +* Argo CD [v2.0.4](https://github.com/argoproj/argo-cd/releases/tag/v2.0.4) + * Argo CD ApplicationSet Controller [2c62537a8e5a](https://github.com/argoproj-labs/applicationset/commit/2c62537a8e5a3d5aecad87b843870789b74bdf89) +* Argo Events [d403c441bc1d](https://github.com/argoproj/argo-events/commit/d403c441bc1d4032daff4e54b496f9342cc5cd57) +* Argo Rollouts [v1.0.2](https://github.com/argoproj/argo-rollouts/releases/tag/v1.0.2) +* Argo Workflows [v3.1.1](https://github.com/argoproj/argo-workflows/releases/tag/v3.1.1) + ### Linux ```bash # get the latest version or change to a specific version diff --git a/go.mod b/go.mod index 14a718d83..c59f56d42 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.16 require ( github.com/argoproj-labs/applicationset v0.1.0 - github.com/argoproj-labs/argocd-autopilot v0.2.7 + github.com/argoproj-labs/argocd-autopilot v0.2.8 github.com/argoproj/argo-cd/v2 v2.0.3 github.com/argoproj/argo-events v1.3.1 github.com/argoproj/argo-workflows/v3 v3.1.0 @@ -12,6 +12,7 @@ require ( github.com/codefresh-io/go-sdk v0.26.2 github.com/fatih/color v1.12.0 github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 + github.com/go-git/go-billy/v5 v5.3.1 github.com/gobuffalo/packr v1.30.1 github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a github.com/lunixbochs/vtclean v1.0.0 // indirect diff --git a/go.sum b/go.sum index 4fba8aada..17584daf1 100644 --- a/go.sum +++ b/go.sum @@ -164,8 +164,8 @@ github.com/ardielle/ardielle-go v1.5.2/go.mod h1:I4hy1n795cUhaVt/ojz83SNVCYIGsAF github.com/ardielle/ardielle-tools v1.5.4/go.mod h1:oZN+JRMnqGiIhrzkRN9l26Cej9dEx4jeNG6A+AdkShk= github.com/argoproj-labs/applicationset v0.0.0-20210614145856-2c62537a8e5a h1:8Nm2KtOu/G7NtoAgucj4TkX8rghzwgFJGXNrAmuz7gc= github.com/argoproj-labs/applicationset v0.0.0-20210614145856-2c62537a8e5a/go.mod h1:5rxggh8ymYXedQDIYylNzIHe6jdshDNasIBCVJuR1iU= -github.com/argoproj-labs/argocd-autopilot v0.2.7 h1:wUBNIMxqozl5heGSB2AO81Bu6gW90FV3DqvM98B1YOA= -github.com/argoproj-labs/argocd-autopilot v0.2.7/go.mod h1:mFkBpj09ofv0oe4K7LcN3Ds1pAXUEOLum/Lk8KUJXH0= +github.com/argoproj-labs/argocd-autopilot v0.2.8 h1:whsV51FygB5OI2qGgLui0aHTVt/V+9M0VgOfz1U+m3I= +github.com/argoproj-labs/argocd-autopilot v0.2.8/go.mod h1:mFkBpj09ofv0oe4K7LcN3Ds1pAXUEOLum/Lk8KUJXH0= github.com/argoproj/argo-cd v1.8.1/go.mod h1:Vfl7OGgBC83dVWgq58wU6UR3kG864h0dtHEIQ8xqw4s= github.com/argoproj/argo-cd v1.8.7 h1:CkIu8p/gcTY/fOZWM2tHuSCIAV2HggXjJftrT1IIT3k= github.com/argoproj/argo-cd v1.8.7/go.mod h1:tqFZW5Lr9KBCDsvOaE5Fh8M1eJ1ThvR58pyyLv8Zqvs= diff --git a/manifests/argo-workflows/kustomization.yaml b/manifests/argo-workflows/kustomization.yaml index 95babb86e..3bc50b9ac 100644 --- a/manifests/argo-workflows/kustomization.yaml +++ b/manifests/argo-workflows/kustomization.yaml @@ -1,4 +1,4 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization resources: - - https://raw.githubusercontent.com/argoproj/argo-workflows/v3.1.0/manifests/install.yaml + - https://raw.githubusercontent.com/argoproj/argo-workflows/v3.1.1/manifests/install.yaml diff --git a/pkg/store/store.go b/pkg/store/store.go index 231698670..18f0190af 100644 --- a/pkg/store/store.go +++ b/pkg/store/store.go @@ -17,6 +17,7 @@ package store import ( "fmt" "runtime" + "time" ) var s Store @@ -59,6 +60,7 @@ type Store struct { EventReportingEndpoint string GitSourceName string Version Version + WaitTimeout time.Duration } // Get returns the global store @@ -83,6 +85,7 @@ func init() { s.EventBusName = "codefresh-eventbus" s.EventReportingEndpoint = "/argo/api/events" s.GitSourceName = "default-git-source" + s.WaitTimeout = 5 * time.Minute initVersion() }