Skip to content

Commit 0448926

Browse files
authored
CR-5154 - wait until events is synced (#15)
* wait until events is synced * updated workflows to v3.1.1
1 parent 4f003f3 commit 0448926

File tree

8 files changed

+86
-94
lines changed

8 files changed

+86
-94
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.0.19
1+
VERSION=v0.0.20
22
OUT_DIR=dist
33
YEAR?=$(shell date +"%Y")
44

cmd/commands/runtime.go

Lines changed: 66 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package commands
1717
import (
1818
"context"
1919
"fmt"
20-
"io/ioutil"
20+
"time"
2121

2222
"github.com/codefresh-io/cli-v2/pkg/cdUtils"
2323
"github.com/codefresh-io/cli-v2/pkg/eventUtils"
@@ -32,10 +32,12 @@ import (
3232
"github.com/argoproj-labs/argocd-autopilot/pkg/git"
3333
"github.com/argoproj-labs/argocd-autopilot/pkg/kube"
3434
apstore "github.com/argoproj-labs/argocd-autopilot/pkg/store"
35+
aputil "github.com/argoproj-labs/argocd-autopilot/pkg/util"
3536
argocdv1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
3637
wf "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow"
3738
wfv1alpha1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
3839
"github.com/ghodss/yaml"
40+
"github.com/go-git/go-billy/v5/memfs"
3941
"github.com/spf13/cobra"
4042
v1 "k8s.io/api/core/v1"
4143
rbacv1 "k8s.io/api/rbac/v1"
@@ -44,11 +46,11 @@ import (
4446

4547
type (
4648
RuntimeCreateOptions struct {
47-
RuntimeName string
48-
KubeContext string
49-
KubeFactory kube.Factory
50-
insCreateOpts *apcmd.RepoCreateOptions
51-
gsCreateOpts *apcmd.RepoCreateOptions
49+
RuntimeName string
50+
KubeContext string
51+
KubeFactory kube.Factory
52+
insCloneOpts *git.CloneOptions
53+
gsCloneOpts *git.CloneOptions
5254
}
5355
)
5456

@@ -70,9 +72,9 @@ func NewRuntimeCommand() *cobra.Command {
7072

7173
func NewRuntimeCreateCommand() *cobra.Command {
7274
var (
73-
f kube.Factory
74-
insCreateOpts *apcmd.RepoCreateOptions
75-
gsCreateOpts *apcmd.RepoCreateOptions
75+
f kube.Factory
76+
insCloneOpts *git.CloneOptions
77+
gsCloneOpts *git.CloneOptions
7678
)
7779

7880
cmd := &cobra.Command{
@@ -92,120 +94,103 @@ func NewRuntimeCreateCommand() *cobra.Command {
9294
9395
<BIN> runtime create runtime-name --install-owner owner --install-name gitops_repo
9496
`),
95-
RunE: func(cmd *cobra.Command, args []string) error {
96-
opts := &RuntimeCreateOptions{
97-
KubeContext: "",
98-
KubeFactory: f,
99-
insCreateOpts: insCreateOpts,
100-
gsCreateOpts: gsCreateOpts,
97+
PreRun: func(_ *cobra.Command, _ []string) {
98+
if gsCloneOpts.Auth.Password == "" {
99+
gsCloneOpts.Auth.Password = insCloneOpts.Auth.Password
100+
}
101+
102+
insCloneOpts.Parse()
103+
if gsCloneOpts.Repo == "" {
104+
host, orgRepo, _, _, _, suffix, _ := aputil.ParseGitUrl(insCloneOpts.Repo)
105+
gsCloneOpts.Repo = host + orgRepo + "_git_source" + suffix
101106
}
107+
108+
gsCloneOpts.Parse()
109+
},
110+
RunE: func(cmd *cobra.Command, args []string) error {
102111
if len(args) < 1 {
103112
log.G().Fatal("must enter runtime name")
104113
}
105114

106-
opts.RuntimeName = args[0]
107-
insCreateOpts.Public = false
108-
return RunRuntimeCreate(cmd.Context(), opts)
115+
return RunRuntimeCreate(cmd.Context(), &RuntimeCreateOptions{
116+
RuntimeName: args[0],
117+
KubeContext: "",
118+
KubeFactory: f,
119+
insCloneOpts: insCloneOpts,
120+
gsCloneOpts: gsCloneOpts,
121+
})
109122
},
110123
}
111124

112-
insCreateOpts = apcmd.AddRepoCreateFlags(cmd, "install")
113-
gsCreateOpts = apcmd.AddRepoCreateFlags(cmd, "git-src")
125+
insCloneOpts = git.AddFlags(cmd, &git.AddFlagsOptions{
126+
Prefix: "install",
127+
CreateIfNotExist: true,
128+
FS: memfs.New(),
129+
})
130+
gsCloneOpts = git.AddFlags(cmd, &git.AddFlagsOptions{
131+
Prefix: "git-src",
132+
Optional: true,
133+
CreateIfNotExist: true,
134+
FS: memfs.New(),
135+
})
114136
f = kube.AddFlags(cmd.Flags())
115137

116138
return cmd
117139
}
118140

119141
func RunRuntimeCreate(ctx context.Context, opts *RuntimeCreateOptions) error {
120-
insCloneOpts, err := apcmd.RunRepoCreate(ctx, opts.insCreateOpts)
121-
if err != nil {
122-
return err
123-
}
124-
125-
// var err error
126-
// installOpts := &git.CloneOptions{
127-
// Repo: "github.com/noam-codefresh/demo",
128-
// Auth: git.Auth{
129-
// Password: "<TOKEN>",
130-
// },
131-
// FS: fs.Create(memfs.New()),
132-
// }
133-
// installOpts.Parse()
134-
135-
insCloneOpts.Progress = ioutil.Discard
136-
err = apcmd.RunRepoBootstrap(ctx, &apcmd.RepoBootstrapOptions{
142+
err := apcmd.RunRepoBootstrap(ctx, &apcmd.RepoBootstrapOptions{
137143
AppSpecifier: store.Get().ArgoCDManifestsURL,
138144
Namespace: opts.RuntimeName,
139145
KubeContext: opts.KubeContext,
140146
KubeFactory: opts.KubeFactory,
141-
CloneOptions: insCloneOpts,
147+
CloneOptions: opts.insCloneOpts,
142148
})
143149
if err != nil {
144150
return err
145151
}
146152

147153
err = apcmd.RunProjectCreate(ctx, &apcmd.ProjectCreateOptions{
148-
CloneOpts: insCloneOpts,
154+
CloneOpts: opts.insCloneOpts,
149155
ProjectName: opts.RuntimeName,
150156
})
151157
if err != nil {
152158
return err
153159
}
154160

155-
if err = createApp(ctx, insCloneOpts, opts.RuntimeName, "events", store.Get().ArgoEventsManifestsURL, application.AppTypeKustomize, opts.RuntimeName); err != nil {
156-
return fmt.Errorf("failed to create events application: %w", err)
157-
}
158-
159-
if err = createApp(ctx, insCloneOpts, opts.RuntimeName, "rollouts", store.Get().ArgoRolloutsManifestsURL, application.AppTypeKustomize, opts.RuntimeName); err != nil {
161+
if err = createApp(ctx, opts.KubeFactory, opts.insCloneOpts, opts.RuntimeName, "rollouts", store.Get().ArgoRolloutsManifestsURL, application.AppTypeKustomize, opts.RuntimeName, false); err != nil {
160162
return fmt.Errorf("failed to create rollouts application: %w", err)
161163
}
162164

163-
if err = createApp(ctx, insCloneOpts, opts.RuntimeName, "workflows", store.Get().ArgoWorkflowsManifestsURL, application.AppTypeKustomize, opts.RuntimeName); err != nil {
165+
if err = createApp(ctx, opts.KubeFactory, opts.insCloneOpts, opts.RuntimeName, "workflows", store.Get().ArgoWorkflowsManifestsURL, application.AppTypeKustomize, opts.RuntimeName, false); err != nil {
164166
return fmt.Errorf("failed to create workflows application: %w", err)
165167
}
166168

167-
if err = createComponentsReporter(ctx, insCloneOpts, opts); err != nil {
168-
return fmt.Errorf("failed to create components-reporter: %w", err)
169-
}
170-
171-
if opts.gsCreateOpts.Owner == "" {
172-
opts.gsCreateOpts.Owner = opts.insCreateOpts.Owner
173-
}
174-
175-
if opts.gsCreateOpts.Repo == "" {
176-
opts.gsCreateOpts.Repo = opts.insCreateOpts.Repo + "-git-source"
177-
}
178-
179-
if opts.gsCreateOpts.Token == "" {
180-
opts.gsCreateOpts.Token = opts.insCreateOpts.Token
169+
if err = createApp(ctx, opts.KubeFactory, opts.insCloneOpts, opts.RuntimeName, "events", store.Get().ArgoEventsManifestsURL, application.AppTypeKustomize, opts.RuntimeName, true); err != nil {
170+
return fmt.Errorf("failed to create events application: %w", err)
181171
}
182172

183-
gsCloneOpts, err := apcmd.RunRepoCreate(ctx, opts.gsCreateOpts)
184-
if err != nil {
185-
return err
173+
if err = createComponentsReporter(ctx, opts.insCloneOpts, opts); err != nil {
174+
return fmt.Errorf("failed to create components-reporter: %w", err)
186175
}
187176

188-
// gsCloneOpts := &git.CloneOptions{
189-
// Repo: "github.com/noam-codefresh/git-source",
190-
// Auth: git.Auth{
191-
// Password: gsCreateOpts.Token,
192-
// },
193-
// FS: fs.Create(memfs.New()),
194-
// }
195-
// gsCloneOpts.Parse()
196-
197-
if err = createDemoWorkflowTemplate(ctx, gsCloneOpts, store.Get().GitSourceName, opts.RuntimeName); err != nil {
177+
if err = createDemoWorkflowTemplate(ctx, opts.gsCloneOpts, store.Get().GitSourceName, opts.RuntimeName); err != nil {
198178
return err
199179
}
200180

201-
if err = createGitSource(ctx, insCloneOpts, gsCloneOpts, store.Get().GitSourceName, opts.RuntimeName); err != nil {
181+
if err = createGitSource(ctx, opts.insCloneOpts, opts.gsCloneOpts, store.Get().GitSourceName, opts.RuntimeName); err != nil {
202182
return fmt.Errorf("failed to create `%s`: %w", store.Get().GitSourceName, err)
203183
}
204184

205185
return nil
206186
}
207187

208-
func createApp(ctx context.Context, cloneOpts *git.CloneOptions, projectName, appName, appURL, appType, namespace string) error {
188+
func createApp(ctx context.Context, f kube.Factory, cloneOpts *git.CloneOptions, projectName, appName, appURL, appType, namespace string, wait bool) error {
189+
timeout := time.Duration(0)
190+
if wait {
191+
timeout = store.Get().WaitTimeout
192+
}
193+
209194
return apcmd.RunAppCreate(ctx, &apcmd.AppCreateOptions{
210195
CloneOpts: cloneOpts,
211196
AppsCloneOpts: &git.CloneOptions{},
@@ -216,6 +201,8 @@ func createApp(ctx context.Context, cloneOpts *git.CloneOptions, projectName, ap
216201
AppType: appType,
217202
DestNamespace: namespace,
218203
},
204+
KubeFactory: f,
205+
Timeout: timeout,
219206
})
220207
}
221208

@@ -230,11 +217,11 @@ func createComponentsReporter(ctx context.Context, cloneOpts *git.CloneOptions,
230217
}
231218

232219
resPath := cloneOpts.FS.Join(apstore.Default.AppsDir, store.Get().ComponentsReporterName, opts.RuntimeName, "resources")
233-
if err := createApp(ctx, cloneOpts, opts.RuntimeName, store.Get().ComponentsReporterName, cloneOpts.URL()+"/"+resPath, application.AppTypeDirectory, opts.RuntimeName); err != nil {
220+
if err := createApp(ctx, opts.KubeFactory, cloneOpts, opts.RuntimeName, store.Get().ComponentsReporterName, cloneOpts.URL()+"/"+resPath, application.AppTypeDirectory, opts.RuntimeName, false); err != nil {
234221
return err
235222
}
236223

237-
r, repofs, err := cloneOpts.Clone(ctx)
224+
r, repofs, err := cloneOpts.GetRepo(ctx)
238225
if err != nil {
239226
return err
240227
}
@@ -419,7 +406,7 @@ func createSensor(repofs fs.FS, name, path, namespace, eventSourceName string) e
419406
}
420407

421408
func createDemoWorkflowTemplate(ctx context.Context, gsCloneOpts *git.CloneOptions, gsName, runtimeName string) error {
422-
gsRepo, gsFs, err := gsCloneOpts.Clone(ctx)
409+
gsRepo, gsFs, err := gsCloneOpts.GetRepo(ctx)
423410
if err != nil {
424411
return err
425412
}
@@ -462,7 +449,7 @@ func createDemoWorkflowTemplate(ctx context.Context, gsCloneOpts *git.CloneOptio
462449
func createGitSource(ctx context.Context, insCloneOpts *git.CloneOptions, gsCloneOpts *git.CloneOptions, gsName, runtimeName string) error {
463450
var err error
464451

465-
insRepo, insFs, err := insCloneOpts.Clone(ctx)
452+
insRepo, insFs, err := insCloneOpts.GetRepo(ctx)
466453
if err != nil {
467454
return err
468455
}
@@ -604,7 +591,7 @@ func createGitSource(ctx context.Context, insCloneOpts *git.CloneOptions, gsClon
604591
}
605592

606593
fullResPath := insFs.Join(insFs.Root(), resPath)
607-
if err = createApp(ctx, insCloneOpts, runtimeName, gsName, insCloneOpts.URL()+fullResPath, application.AppTypeDirectory, runtimeName); err != nil {
594+
if err = createApp(ctx, nil, insCloneOpts, runtimeName, gsName, insCloneOpts.URL()+fullResPath, application.AppTypeDirectory, runtimeName, false); err != nil {
608595
return fmt.Errorf("failed to create git-source: %w", err)
609596
}
610597

docs/commands/cli-v2_runtime_create.md

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,13 @@ cli-v2 runtime create [runtime_name] [flags]
3737
--cluster string The name of the kubeconfig cluster to use
3838
--context string The name of the kubeconfig context to use
3939
--git-src-git-token string Your git provider api token [GIT_SRC_GIT_TOKEN]
40-
--git-src-host string The git provider address (for on-premise git providers)
41-
--git-src-name string The name of the repository
42-
--git-src-owner string The name of the owner or organization
43-
--git-src-provider string The git provider, one of: github (default "github")
44-
--git-src-public If true, will create the repository as public (default is false)
40+
--git-src-provider string The git provider, one of: github
41+
--git-src-repo string Repository URL [GIT_SRC_GIT_REPO]
4542
-h, --help help for create
4643
--insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure
4744
--install-git-token string Your git provider api token [INSTALL_GIT_TOKEN]
48-
--install-host string The git provider address (for on-premise git providers)
49-
--install-name string The name of the repository
50-
--install-owner string The name of the owner or organization
51-
--install-provider string The git provider, one of: github (default "github")
52-
--install-public If true, will create the repository as public (default is false)
45+
--install-provider string The git provider, one of: github
46+
--install-repo string Repository URL [INSTALL_GIT_REPO]
5347
--kubeconfig string Path to the kubeconfig file to use for CLI requests.
5448
-n, --namespace string If present, the namespace scope for this CLI request
5549
-s, --server string The address and port of the Kubernetes API server

docs/releases/release_notes.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
### Installed Applications:
2+
* Argo CD [v2.0.4](https://github.com/argoproj/argo-cd/releases/tag/v2.0.4)
3+
* Argo CD ApplicationSet Controller [2c62537a8e5a](https://github.com/argoproj-labs/applicationset/commit/2c62537a8e5a3d5aecad87b843870789b74bdf89)
4+
* Argo Events [d403c441bc1d](https://github.com/argoproj/argo-events/commit/d403c441bc1d4032daff4e54b496f9342cc5cd57)
5+
* Argo Rollouts [v1.0.2](https://github.com/argoproj/argo-rollouts/releases/tag/v1.0.2)
6+
* Argo Workflows [v3.1.1](https://github.com/argoproj/argo-workflows/releases/tag/v3.1.1)
7+
18
### Linux
29
```bash
310
# get the latest version or change to a specific version

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ go 1.16
44

55
require (
66
github.com/argoproj-labs/applicationset v0.1.0
7-
github.com/argoproj-labs/argocd-autopilot v0.2.7
7+
github.com/argoproj-labs/argocd-autopilot v0.2.8
88
github.com/argoproj/argo-cd/v2 v2.0.3
99
github.com/argoproj/argo-events v1.3.1
1010
github.com/argoproj/argo-workflows/v3 v3.1.0
1111
github.com/briandowns/spinner v1.13.0
1212
github.com/codefresh-io/go-sdk v0.26.2
1313
github.com/fatih/color v1.12.0
1414
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
15+
github.com/go-git/go-billy/v5 v5.3.1
1516
github.com/gobuffalo/packr v1.30.1
1617
github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a
1718
github.com/lunixbochs/vtclean v1.0.0 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ github.com/ardielle/ardielle-go v1.5.2/go.mod h1:I4hy1n795cUhaVt/ojz83SNVCYIGsAF
164164
github.com/ardielle/ardielle-tools v1.5.4/go.mod h1:oZN+JRMnqGiIhrzkRN9l26Cej9dEx4jeNG6A+AdkShk=
165165
github.com/argoproj-labs/applicationset v0.0.0-20210614145856-2c62537a8e5a h1:8Nm2KtOu/G7NtoAgucj4TkX8rghzwgFJGXNrAmuz7gc=
166166
github.com/argoproj-labs/applicationset v0.0.0-20210614145856-2c62537a8e5a/go.mod h1:5rxggh8ymYXedQDIYylNzIHe6jdshDNasIBCVJuR1iU=
167-
github.com/argoproj-labs/argocd-autopilot v0.2.7 h1:wUBNIMxqozl5heGSB2AO81Bu6gW90FV3DqvM98B1YOA=
168-
github.com/argoproj-labs/argocd-autopilot v0.2.7/go.mod h1:mFkBpj09ofv0oe4K7LcN3Ds1pAXUEOLum/Lk8KUJXH0=
167+
github.com/argoproj-labs/argocd-autopilot v0.2.8 h1:whsV51FygB5OI2qGgLui0aHTVt/V+9M0VgOfz1U+m3I=
168+
github.com/argoproj-labs/argocd-autopilot v0.2.8/go.mod h1:mFkBpj09ofv0oe4K7LcN3Ds1pAXUEOLum/Lk8KUJXH0=
169169
github.com/argoproj/argo-cd v1.8.1/go.mod h1:Vfl7OGgBC83dVWgq58wU6UR3kG864h0dtHEIQ8xqw4s=
170170
github.com/argoproj/argo-cd v1.8.7 h1:CkIu8p/gcTY/fOZWM2tHuSCIAV2HggXjJftrT1IIT3k=
171171
github.com/argoproj/argo-cd v1.8.7/go.mod h1:tqFZW5Lr9KBCDsvOaE5Fh8M1eJ1ThvR58pyyLv8Zqvs=
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
apiVersion: kustomize.config.k8s.io/v1beta1
22
kind: Kustomization
33
resources:
4-
- https://raw.githubusercontent.com/argoproj/argo-workflows/v3.1.0/manifests/install.yaml
4+
- https://raw.githubusercontent.com/argoproj/argo-workflows/v3.1.1/manifests/install.yaml

pkg/store/store.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package store
1717
import (
1818
"fmt"
1919
"runtime"
20+
"time"
2021
)
2122

2223
var s Store
@@ -59,6 +60,7 @@ type Store struct {
5960
EventReportingEndpoint string
6061
GitSourceName string
6162
Version Version
63+
WaitTimeout time.Duration
6264
}
6365

6466
// Get returns the global store
@@ -83,6 +85,7 @@ func init() {
8385
s.EventBusName = "codefresh-eventbus"
8486
s.EventReportingEndpoint = "/argo/api/events"
8587
s.GitSourceName = "default-git-source"
88+
s.WaitTimeout = 5 * time.Minute
8689
initVersion()
8790
}
8891

0 commit comments

Comments
 (0)