Skip to content

Commit c37b4ce

Browse files
CR-6312-runtime-install-mutation (#95)
* bump and added params for runtime create mutation * with ingresshost * to use updated go-sdk * without local go-sdk * without local go-sdk * with installationStatus * with INSTALLATION_STATUS header * removed redundant * tested with installation status enum * with Get instead of List as post validation logic * better component list * tested: cli blocks until installation is complete * commented out preInstallationChecks to test validation by runtime token * tested: added logic to remove token as part of uninstall * doc flags fix * back to original pre installation checks - instead of using token * bump * bump use of newer sdk * without comment * with merged go-sdk * codegen * without gocyclo * reduce cyclomatic
1 parent 162c761 commit c37b4ce

File tree

4 files changed

+59
-24
lines changed

4 files changed

+59
-24
lines changed

cmd/commands/runtime.go

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ func NewRuntimeInstallCommand() *cobra.Command {
123123
# To run this command you need to create a personal access token for your git provider
124124
# and provide it using:
125125
126-
export INSTALL_GIT_TOKEN=<token>
126+
export GIT_TOKEN=<token>
127127
128128
# or with the flag:
129129
130-
--install-git-token <token>
130+
--git-token <token>
131131
132132
# Adds a new runtime
133133
134-
<BIN> runtime install runtime-name --install-repo gitops_repo
134+
<BIN> runtime install runtime-name --repo gitops_repo
135135
`),
136136
PreRun: func(_ *cobra.Command, _ []string) {
137137
if gsCloneOpts.Auth.Password == "" {
@@ -206,6 +206,32 @@ func NewRuntimeInstallCommand() *cobra.Command {
206206
return cmd
207207
}
208208

209+
func getComponents(rt *runtime.Runtime, opts *RuntimeInstallOptions) []string {
210+
var componentNames []string
211+
for _, component := range rt.Spec.Components {
212+
componentNames = append(componentNames, fmt.Sprintf("%s-%s", opts.RuntimeName, component.Name))
213+
}
214+
215+
// should find a more dynamic way to get these additional components
216+
additionalComponents := []string{"events-reporter", "workflow-reporter"}
217+
for _, additionalComponentName := range additionalComponents {
218+
componentNames = append(componentNames, fmt.Sprintf("%s-%s", opts.RuntimeName, additionalComponentName))
219+
}
220+
componentNames = append(componentNames, "argo-cd")
221+
222+
return componentNames
223+
}
224+
225+
func createRuntimeOnPlatform(ctx context.Context, runtimeName string, server string, runtimeVersion string, ingressHost string, componentNames []string) (string, error) {
226+
runtimeCreationResponse, err := cfConfig.NewClient().V2().Runtime().Create(ctx, runtimeVersion, server, runtimeVersion, ingressHost, componentNames)
227+
228+
if runtimeCreationResponse.ErrorMessage != nil {
229+
return runtimeCreationResponse.NewAccessToken, fmt.Errorf("failed to create a new runtime: %s. Error: %w", *runtimeCreationResponse.ErrorMessage, err)
230+
}
231+
232+
return runtimeCreationResponse.NewAccessToken, nil
233+
}
234+
209235
func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
210236
if err := preInstallationChecks(ctx, opts); err != nil {
211237
return fmt.Errorf("pre installation checks failed: %w", err)
@@ -216,17 +242,26 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
216242
return fmt.Errorf("failed to download runtime definition: %w", err)
217243
}
218244

219-
runtimeCreationResponse, err := cfConfig.NewClient().V2().Runtime().Create(ctx, opts.RuntimeName)
220-
if err != nil {
221-
return fmt.Errorf("failed to create a new runtime: %w", err)
245+
runtimeVersion := "v99.99.99"
246+
if rt.Spec.Version != nil { // in dev mode
247+
runtimeVersion = rt.Spec.Version.String()
222248
}
223249

224-
opts.RuntimeToken = runtimeCreationResponse.NewAccessToken
225250
server, err := util.CurrentServer()
226251
if err != nil {
227252
return fmt.Errorf("failed to get current server address: %w", err)
228253
}
229254

255+
componentNames := getComponents(rt, opts)
256+
257+
token, err := createRuntimeOnPlatform(ctx, opts.RuntimeName, server, runtimeVersion, opts.IngressHost, componentNames)
258+
259+
if err != nil {
260+
return fmt.Errorf("failed to create a new runtime: %w", err)
261+
}
262+
263+
opts.RuntimeToken = token
264+
230265
rt.Spec.Cluster = server
231266
rt.Spec.IngressHost = opts.IngressHost
232267

@@ -388,20 +423,18 @@ func intervalCheckIsRuntimePersisted(milliseconds int, ctx context.Context, runt
388423
for retries := 20; retries > 0; <-ticker.C {
389424
retries--
390425
fmt.Println("waiting for the runtime installation to complete...")
391-
var runtimes []model.Runtime
392-
runtimes, err = cfConfig.NewClient().V2().Runtime().List(ctx)
426+
runtime, err := cfConfig.NewClient().V2().Runtime().Get(ctx, runtimeName)
393427
if err != nil {
394-
continue
428+
return fmt.Errorf("failed to complete the runtime installation. Error: %w", err)
395429
}
396430

397-
for _, rt := range runtimes {
398-
if rt.Metadata.Name == runtimeName {
399-
wg.Done()
400-
ticker.Stop()
401-
return nil
402-
}
431+
if runtime.InstallationStatus != model.InstallationStatusCompleted {
432+
continue
403433
}
404434

435+
wg.Done()
436+
ticker.Stop()
437+
return nil
405438
}
406439

407440
return fmt.Errorf("failed to complete the runtime installation due to timeout. Error: %w", err)
@@ -431,7 +464,7 @@ func RunRuntimeList(ctx context.Context) error {
431464
}
432465

433466
tb := ansiterm.NewTabWriter(os.Stdout, 0, 0, 4, ' ', 0)
434-
_, err = fmt.Fprintln(tb, "NAME\tNAMESPACE\tCLUSTER\tVERSION\tSYNC_STATUS\tHEALTH_STATUS\tHEALTH_MESSAGE")
467+
_, err = fmt.Fprintln(tb, "NAME\tNAMESPACE\tCLUSTER\tVERSION\tSYNC_STATUS\tHEALTH_STATUS\tHEALTH_MESSAGE\tINSTALLATION_STATUS")
435468
if err != nil {
436469
return err
437470
}
@@ -444,6 +477,7 @@ func RunRuntimeList(ctx context.Context) error {
444477
syncStatus := rt.SyncStatus
445478
healthStatus := rt.HealthStatus
446479
healthMessage := "N/A"
480+
installationStatus := rt.InstallationStatus
447481

448482
if rt.Metadata.Namespace != nil {
449483
namespace = *rt.Metadata.Namespace
@@ -461,14 +495,15 @@ func RunRuntimeList(ctx context.Context) error {
461495
healthMessage = *rt.HealthMessage
462496
}
463497

464-
_, err = fmt.Fprintf(tb, "%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
498+
_, err = fmt.Fprintf(tb, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
465499
name,
466500
namespace,
467501
cluster,
468502
version,
469503
syncStatus,
470504
healthStatus,
471505
healthMessage,
506+
installationStatus,
472507
)
473508
if err != nil {
474509
return err

docs/commands/cli-v2_runtime_install.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ cli-v2 runtime install [runtime_name] [flags]
1313
# To run this command you need to create a personal access token for your git provider
1414
# and provide it using:
1515
16-
export INSTALL_GIT_TOKEN=<token>
16+
export GIT_TOKEN=<token>
1717
1818
# or with the flag:
1919
20-
--install-git-token <token>
20+
--git-token <token>
2121
2222
# Adds a new runtime
2323
24-
cli-v2 runtime install runtime-name --install-repo gitops_repo
24+
cli-v2 runtime install runtime-name --repo gitops_repo
2525
2626
```
2727

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/argoproj/argo-events v1.4.0
1111
github.com/argoproj/argo-workflows/v3 v3.1.6
1212
github.com/briandowns/spinner v1.16.0
13-
github.com/codefresh-io/go-sdk v0.34.2
13+
github.com/codefresh-io/go-sdk v0.34.4
1414
github.com/fatih/color v1.12.0
1515
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
1616
github.com/go-git/go-billy/v5 v5.3.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGX
268268
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
269269
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
270270
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
271-
github.com/codefresh-io/go-sdk v0.34.2 h1:tdkCTr9622ZE4yeT3E4wQaUDOnaQeftAwQS0DeQPC3s=
272-
github.com/codefresh-io/go-sdk v0.34.2/go.mod h1:CcoVmTFWHGkbrSW8LyOGB/vJe5Vzr3iC/pNE2QIBTyg=
271+
github.com/codefresh-io/go-sdk v0.34.4 h1:qwEQwE7v/43lkQiE/6t28vSaon04t5vWO8in//BxzH4=
272+
github.com/codefresh-io/go-sdk v0.34.4/go.mod h1:CcoVmTFWHGkbrSW8LyOGB/vJe5Vzr3iC/pNE2QIBTyg=
273273
github.com/colinmarc/hdfs v1.1.4-0.20180802165501-48eb8d6c34a9/go.mod h1:0DumPviB681UcSuJErAbDIOx6SIaJWj463TymfZG02I=
274274
github.com/colinmarc/hdfs v1.1.4-0.20180805212432-9746310a4d31/go.mod h1:vSBumefK4HA5uiRSwNP+3ofgrEoScpCS2MMWcWXEuQ4=
275275
github.com/container-storage-interface/spec v1.3.0/go.mod h1:6URME8mwIBbpVyZV93Ce5St17xBiQJQY67NDsuohiy4=

0 commit comments

Comments
 (0)