Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CR-5154 - wait until events is synced #15

Merged
merged 4 commits into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=v0.0.19
VERSION=v0.0.20
OUT_DIR=dist
YEAR?=$(shell date +"%Y")

Expand Down
145 changes: 66 additions & 79 deletions cmd/commands/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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
}
)

Expand All @@ -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{
Expand All @@ -92,120 +94,103 @@ func NewRuntimeCreateCommand() *cobra.Command {

<BIN> 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: "<TOKEN>",
// },
// 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
noam-codefresh marked this conversation as resolved.
Show resolved Hide resolved
}

return apcmd.RunAppCreate(ctx, &apcmd.AppCreateOptions{
CloneOpts: cloneOpts,
AppsCloneOpts: &git.CloneOptions{},
Expand All @@ -216,6 +201,8 @@ func createApp(ctx context.Context, cloneOpts *git.CloneOptions, projectName, ap
AppType: appType,
DestNamespace: namespace,
},
KubeFactory: f,
Timeout: timeout,
})
}

Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}

Expand Down
14 changes: 4 additions & 10 deletions docs/commands/cli-v2_runtime_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions docs/releases/release_notes.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ 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
github.com/briandowns/spinner v1.13.0
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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion manifests/argo-workflows/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions pkg/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package store
import (
"fmt"
"runtime"
"time"
)

var s Store
Expand Down Expand Up @@ -59,6 +60,7 @@ type Store struct {
EventReportingEndpoint string
GitSourceName string
Version Version
WaitTimeout time.Duration
}

// Get returns the global store
Expand All @@ -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()
}

Expand Down