Skip to content

Commit 888e09b

Browse files
CR-14126 support bitbucket cloud (#549)
* support bitbucket cloud * bump * generic retry * lint fix * lint fix
1 parent 869f4fb commit 888e09b

16 files changed

+279
-91
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.492
1+
VERSION=v0.0.493
22

33
OUT_DIR=dist
44
YEAR?=$(shell date +"%Y")

cmd/commands/git-source.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ func createDemoGitPipeline(opts *gitSourceGitDemoPipelineOptions) error {
761761
return createDemoGitlabPipeline(opts)
762762
case "bitbucket-server":
763763
return createDemoBitbucketServerPipeline(opts)
764+
case "bitbucket":
765+
return nil
764766
default:
765767
return fmt.Errorf("demo git pipeline is not yet supported for provider %s", gitProviderType)
766768
}

cmd/commands/integrations.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type (
4141
)
4242

4343
var gitProvidersByName = map[string]model.GitProviders{
44+
"bitbucket": model.GitProvidersBitbucket,
4445
"bitbucket-server": model.GitProvidersBitbucketServer,
4546
"github": model.GitProvidersGithub,
4647
"gitlab": model.GitProvidersGitlab,
@@ -222,7 +223,7 @@ func NewGitIntegrationAddCommand(client *sdk.AppProxyAPI) *cobra.Command {
222223
},
223224
}
224225

225-
cmd.Flags().StringVar(&provider, "provider", "github", "One of bitbucket-server|github|gitlab")
226+
cmd.Flags().StringVar(&provider, "provider", "github", "One of bitbucket|bitbucket-server|github|gitlab")
226227
cmd.Flags().StringVar(&apiURL, "api-url", "", "Git provider API Url")
227228
cmd.Flags().BoolVar(&accountAdminsOnly, "account-admins-only", false,
228229
"If true, this integration would only be visible to account admins (default: false)")

cmd/commands/runtime_install.go

Lines changed: 77 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func NewRuntimeInstallCommand() *cobra.Command {
204204
cmd.Flags().StringToStringVar(&installationOpts.NamespaceLabels, "namespace-labels", nil, "Optional labels that will be set on the namespace resource. (e.g. \"key1=value1,key2=value2\"")
205205
cmd.Flags().StringToStringVar(&installationOpts.InternalIngressAnnotation, "internal-ingress-annotation", nil, "Add annotations to the internal ingress")
206206
cmd.Flags().StringToStringVar(&installationOpts.ExternalIngressAnnotation, "external-ingress-annotation", nil, "Add annotations to the external ingress")
207-
cmd.Flags().BoolVar(&installationOpts.EnableGitProviders, "enable-git-providers", false, "Enable git providers (bitbucket-server|gitlab)")
207+
cmd.Flags().BoolVar(&installationOpts.EnableGitProviders, "enable-git-providers", false, "Enable git providers (bitbucket|bitbucket-server|gitlab)")
208208

209209
installationOpts.InsCloneOpts = apu.AddCloneFlags(cmd, &apu.CloneFlagsOptions{
210210
CreateIfNotExist: true,
@@ -586,13 +586,15 @@ func runRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
586586
return err
587587
}
588588

589+
provider := model.GitProviders(gitProvider)
590+
589591
repoURL := opts.InsCloneOpts.URL()
590592
token, iv, err := createRuntimeOnPlatform(ctx, &model.RuntimeInstallationArgs{
591593
RuntimeName: opts.RuntimeName,
592594
Cluster: server,
593595
RuntimeVersion: runtimeVersion,
594596
IngressHost: &opts.IngressHost,
595-
GitProvider: model.GitProviders(gitProvider),
597+
GitProvider: &provider,
596598
InternalIngressHost: &opts.InternalIngressHost,
597599
IngressClass: &opts.IngressClass,
598600
IngressController: &ingressControllerName,
@@ -672,14 +674,21 @@ func runRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
672674
return util.DecorateErrorWithDocsLink(fmt.Errorf("failed to create project: %w", err))
673675
}
674676

675-
// persists codefresh-cm, this must be created before events-reporter eventsource
676-
// otherwise it will not start and no events will get to the platform.
677-
if !opts.FromRepo {
678-
err = persistRuntime(ctx, opts.InsCloneOpts, rt, opts.CommonConfig)
679-
} else {
680-
// in case of runtime recovery we only update the existing cm
681-
err = updateCodefreshCM(ctx, opts, rt, server)
682-
}
677+
// bitbucket cloud take more time to push a commit
678+
// all coming retries perpuse is to avoid issues of cloning before pervious commit was pushed
679+
err = util.Retry(ctx, &util.RetryOptions{
680+
Func: func() error {
681+
// persists codefresh-cm, this must be created before events-reporter eventsource
682+
// otherwise it will not start and no events will get to the platform.
683+
if !opts.FromRepo {
684+
return persistRuntime(ctx, opts.InsCloneOpts, rt, opts.CommonConfig)
685+
} else {
686+
// in case of runtime recovery we only update the existing cm
687+
return updateCodefreshCM(ctx, opts, rt, server)
688+
}
689+
},
690+
Sleep: 2,
691+
})
683692
handleCliStep(reporter.InstallStepCreateOrUpdateConfigMap, "Creating/Updating codefresh-cm", err, false, true)
684693
if err != nil {
685694
return util.DecorateErrorWithDocsLink(fmt.Errorf("failed to create or update codefresh-cm: %w", err))
@@ -1008,13 +1017,23 @@ you can try to create it manually by running:
10081017
func installComponents(ctx context.Context, opts *RuntimeInstallOptions, rt *runtime.Runtime) error {
10091018
var err error
10101019

1020+
// bitbucket cloud take more time to push a commit
1021+
// all coming retries perpuse is to avoid issues of cloning before pervious commit was pushed
10111022
if !store.Get().SkipIngress && rt.Spec.IngressController != string(ingressutil.IngressControllerALB) {
1012-
if err = createWorkflowsIngress(ctx, opts, rt); err != nil {
1023+
if err = util.Retry(ctx, &util.RetryOptions{
1024+
Func: func() error {
1025+
return createWorkflowsIngress(ctx, opts, rt)
1026+
},
1027+
}); err != nil {
10131028
return fmt.Errorf("failed to patch Argo-Workflows ingress: %w", err)
10141029
}
10151030
}
10161031

1017-
if err = configureAppProxy(ctx, opts, rt); err != nil {
1032+
if err = util.Retry(ctx, &util.RetryOptions{
1033+
Func: func() error {
1034+
return configureAppProxy(ctx, opts, rt)
1035+
},
1036+
}); err != nil {
10181037
return fmt.Errorf("failed to patch App-Proxy ingress: %w", err)
10191038
}
10201039

@@ -1799,23 +1818,29 @@ func createEventsReporter(ctx context.Context, cloneOpts *apgit.CloneOptions, op
17991818
return err
18001819
}
18011820

1802-
r, repofs, err := cloneOpts.GetRepo(ctx)
1803-
if err != nil {
1804-
return err
1805-
}
1821+
// bitbucket cloud take more time to push a commit
1822+
// all coming retries perpuse is to avoid issues of cloning before pervious commit was pushed
1823+
return util.Retry(ctx, &util.RetryOptions{
1824+
Func: func() error {
1825+
r, repofs, err := opts.InsCloneOpts.GetRepo(ctx)
1826+
if err != nil {
1827+
return err
1828+
}
18061829

1807-
if err := createEventsReporterEventSource(repofs, resPath, opts.RuntimeName, opts.Insecure); err != nil {
1808-
return err
1809-
}
1830+
if err = createEventsReporterEventSource(repofs, resPath, opts.RuntimeName, opts.Insecure); err != nil {
1831+
return err
1832+
}
1833+
eventsReporterTriggers := []string{"events"}
18101834

1811-
eventsReporterTriggers := []string{"events"}
1812-
if err := createSensor(repofs, store.Get().EventsReporterName, resPath, opts.RuntimeName, store.Get().EventsReporterName, eventsReporterTriggers, "data"); err != nil {
1813-
return err
1814-
}
1835+
if err = createSensor(repofs, store.Get().EventsReporterName, resPath, opts.RuntimeName, store.Get().EventsReporterName, eventsReporterTriggers, "data"); err != nil {
1836+
return err
1837+
}
18151838

1816-
log.G(ctx).Info("Pushing Event Reporter manifests")
1839+
log.G(ctx).Info("Pushing Event Reporter manifests")
1840+
return apu.PushWithMessage(ctx, r, "Created Codefresh Event Reporter")
1841+
},
1842+
})
18171843

1818-
return apu.PushWithMessage(ctx, r, "Created Codefresh Event Reporter")
18191844
}
18201845

18211846
func createReporter(ctx context.Context, cloneOpts *apgit.CloneOptions, opts *RuntimeInstallOptions, reporterCreateOpts reporterCreateOptions) error {
@@ -1839,34 +1864,40 @@ func createReporter(ctx context.Context, cloneOpts *apgit.CloneOptions, opts *Ru
18391864
return err
18401865
}
18411866

1842-
r, repofs, err := cloneOpts.GetRepo(ctx)
1843-
if err != nil {
1844-
return err
1845-
}
1867+
// bitbucket cloud take more time to push a commit
1868+
// all coming retries perpuse is to avoid issues of cloning before pervious commit was pushed
1869+
return util.Retry(ctx, &util.RetryOptions{
1870+
Func: func() error {
1871+
r, repofs, err := opts.InsCloneOpts.GetRepo(ctx)
18461872

1847-
if err := createReporterRBAC(repofs, resPath, opts.RuntimeName, reporterCreateOpts.saName, reporterCreateOpts.clusterScope); err != nil {
1848-
return err
1849-
}
1873+
if err != nil {
1874+
return err
1875+
}
18501876

1851-
if err := createReporterEventSource(repofs, resPath, opts.RuntimeName, reporterCreateOpts, reporterCreateOpts.clusterScope); err != nil {
1852-
return err
1853-
}
1877+
if err = createReporterRBAC(repofs, resPath, opts.RuntimeName, reporterCreateOpts.saName, reporterCreateOpts.clusterScope); err != nil {
1878+
return err
1879+
}
18541880

1855-
var triggerNames []string
1856-
for _, gvr := range reporterCreateOpts.gvr {
1857-
triggerNames = append(triggerNames, gvr.resourceName)
1858-
}
1881+
if err = createReporterEventSource(repofs, resPath, opts.RuntimeName, reporterCreateOpts, reporterCreateOpts.clusterScope); err != nil {
1882+
return err
1883+
}
1884+
var triggerNames []string
1885+
for _, gvr := range reporterCreateOpts.gvr {
1886+
triggerNames = append(triggerNames, gvr.resourceName)
1887+
}
18591888

1860-
if err := createSensor(repofs, reporterCreateOpts.reporterName, resPath, opts.RuntimeName, reporterCreateOpts.reporterName, triggerNames, "data.object"); err != nil {
1861-
return err
1862-
}
1889+
if err = createSensor(repofs, reporterCreateOpts.reporterName, resPath, opts.RuntimeName, reporterCreateOpts.reporterName, triggerNames, "data.object"); err != nil {
1890+
return err
1891+
}
18631892

1864-
titleCase := cases.Title(language.AmericanEnglish)
1865-
log.G(ctx).Info("Pushing Codefresh ", titleCase.String(reporterCreateOpts.reporterName), " manifests")
1893+
titleCase := cases.Title(language.AmericanEnglish)
1894+
log.G(ctx).Info("Pushing Codefresh ", titleCase.String(reporterCreateOpts.reporterName), " manifests")
18661895

1867-
pushMessage := "Created Codefresh" + titleCase.String(reporterCreateOpts.reporterName) + "Reporter"
1896+
pushMessage := "Created Codefresh" + titleCase.String(reporterCreateOpts.reporterName) + "Reporter"
18681897

1869-
return apu.PushWithMessage(ctx, r, pushMessage)
1898+
return apu.PushWithMessage(ctx, r, pushMessage)
1899+
},
1900+
})
18701901
}
18711902

18721903
func updateProject(repofs fs.FS, rt *runtime.Runtime) error {

docs/commands/cli-v2_git-source_edit.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ cli-v2 git-source edit RUNTIME_NAME GITSOURCE_NAME [flags]
2020
--exclude string files to exclude. can be either filenames or a glob
2121
--git-src-git-token string Your git provider api token [GIT_SRC_GIT_TOKEN]
2222
--git-src-git-user string Your git provider user name [GIT_SRC_GIT_USER] (not required in GitHub)
23-
--git-src-provider string The git provider, one of: azure|bitbucket-server|gitea|github|gitlab
23+
--git-src-provider string The git provider, one of: azure|bitbucket|bitbucket-server|gitea|github|gitlab
2424
--git-src-repo string Repository URL [GIT_SRC_GIT_REPO]
2525
-t, --git-token string Your git provider api token [GIT_TOKEN]
2626
-u, --git-user string Your git provider user name [GIT_USER] (not required in GitHub)
2727
-h, --help help for edit
2828
--include string files to include. can be either filenames or a glob
29-
--provider string The git provider, one of: azure|bitbucket-server|gitea|github|gitlab
29+
--provider string The git provider, one of: azure|bitbucket|bitbucket-server|gitea|github|gitlab
3030
--repo string Repository URL [GIT_REPO]
3131
-b, --upsert-branch If true will try to checkout the specified branch and create it if it doesn't exist
3232
```

docs/commands/cli-v2_integration_git_add.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ cli-v2 integration git add [NAME] [flags]
1212
--account-admins-only If true, this integration would only be visible to account admins (default: false)
1313
--api-url string Git provider API Url
1414
-h, --help help for add
15-
--provider string One of bitbucket-server|github|gitlab (default "github")
15+
--provider string One of bitbucket|bitbucket-server|github|gitlab (default "github")
1616
```
1717

1818
### Options inherited from parent commands

docs/commands/cli-v2_runtime_install.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ cli-v2 runtime install [runtime_name] [flags]
4545
-n, --namespace string If present, the namespace scope for this CLI request
4646
--namespace-labels stringToString Optional labels that will be set on the namespace resource. (e.g. "key1=value1,key2=value2" (default [])
4747
--personal-git-token string The Personal git token for your user
48-
--provider string The git provider, one of: azure|bitbucket-server|gitea|github|gitlab
48+
--provider string The git provider, one of: azure|bitbucket|bitbucket-server|gitea|github|gitlab
4949
--provider-api-url string Git provider API url
5050
--repo string Repository URL [GIT_REPO]
5151
--set-default-resources If true, will set default requests and limits on all of the runtime components

docs/releases/release_notes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ cf version
2323

2424
```bash
2525
# download and extract the binary
26-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.492/cf-linux-amd64.tar.gz | tar zx
26+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.493/cf-linux-amd64.tar.gz | tar zx
2727

2828
# move the binary to your $PATH
2929
mv ./cf-linux-amd64 /usr/local/bin/cf
@@ -36,7 +36,7 @@ cf version
3636

3737
```bash
3838
# download and extract the binary
39-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.492/cf-darwin-amd64.tar.gz | tar zx
39+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.493/cf-darwin-amd64.tar.gz | tar zx
4040

4141
# move the binary to your $PATH
4242
mv ./cf-darwin-amd64 /usr/local/bin/cf

go.mod

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ go 1.18
44

55
require (
66
github.com/Masterminds/semver/v3 v3.1.1
7-
github.com/argoproj-labs/argocd-autopilot v0.4.4
7+
github.com/argoproj-labs/argocd-autopilot v0.4.5
88
github.com/argoproj/applicationset v0.4.1
99
github.com/argoproj/argo-cd/v2 v2.4.6
1010
github.com/argoproj/argo-events v0.17.1-0.20220327045437-70eaafe9afec
1111
github.com/argoproj/argo-workflows/v3 v3.3.1
1212
github.com/briandowns/spinner v1.18.1
13-
github.com/codefresh-io/go-sdk v0.46.0
13+
github.com/codefresh-io/go-sdk v0.47.1
1414
github.com/fatih/color v1.13.0
1515
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
1616
github.com/go-git/go-billy/v5 v5.3.1
@@ -52,7 +52,7 @@ require (
5252
github.com/Masterminds/goutils v1.1.1 // indirect
5353
github.com/Masterminds/semver v1.5.0 // indirect
5454
github.com/Masterminds/sprig v2.22.0+incompatible // indirect
55-
github.com/Microsoft/go-winio v0.4.17 // indirect
55+
github.com/Microsoft/go-winio v0.5.0 // indirect
5656
github.com/PagerDuty/go-pagerduty v1.5.0 // indirect
5757
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect
5858
github.com/PuerkitoBio/purell v1.1.1 // indirect
@@ -149,6 +149,7 @@ require (
149149
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
150150
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
151151
github.com/klauspost/compress v1.14.4 // indirect
152+
github.com/ktrysmt/go-bitbucket v0.9.49 // indirect
152153
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
153154
github.com/lunixbochs/vtclean v1.0.0 // indirect
154155
github.com/magiconair/properties v1.8.5 // indirect
@@ -203,7 +204,7 @@ require (
203204
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
204205
github.com/whilp/git-urls v0.0.0-20191001220047-6db9661140c0 // indirect
205206
github.com/xanzy/go-gitlab v0.71.0 // indirect
206-
github.com/xanzy/ssh-agent v0.3.0 // indirect
207+
github.com/xanzy/ssh-agent v0.3.1 // indirect
207208
github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca // indirect
208209
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c // indirect
209210
github.com/yuin/gopher-lua v0.0.0-20210529063254-f4c35e4016d9 // indirect

0 commit comments

Comments
 (0)