Skip to content

Commit fc53d73

Browse files
runtime-mutation-using-input-type (#110)
* bump sdk * removed redundant * createOnPlatform Options * removed redundant * removed replace * bump * without local sdk * sdk * installationArgs: opts * type update * removed redundant * sdk bump * tidy * type fix and store use * bump * better error handling * make codegen * opts arg
1 parent a808952 commit fc53d73

File tree

4 files changed

+36
-26
lines changed

4 files changed

+36
-26
lines changed

cmd/commands/runtime.go

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,16 @@ import (
6161

6262
type (
6363
RuntimeInstallOptions struct {
64-
RuntimeName string
65-
RuntimeToken string
66-
IngressHost string
67-
Insecure bool
68-
Version *semver.Version
69-
GsCloneOpts *git.CloneOptions
70-
InsCloneOpts *git.CloneOptions
71-
KubeFactory kube.Factory
72-
CommonConfig *runtime.CommonConfig
64+
RuntimeName string
65+
RuntimeToken string
66+
IngressHost string
67+
Insecure bool
68+
Version *semver.Version
69+
GsCloneOpts *git.CloneOptions
70+
InsCloneOpts *git.CloneOptions
71+
KubeFactory kube.Factory
72+
CommonConfig *runtime.CommonConfig
7373
}
74-
7574
RuntimeUninstallOptions struct {
7675
RuntimeName string
7776
Timeout time.Duration
@@ -209,24 +208,27 @@ func NewRuntimeInstallCommand() *cobra.Command {
209208
func getComponents(rt *runtime.Runtime, opts *RuntimeInstallOptions) []string {
210209
var componentNames []string
211210
for _, component := range rt.Spec.Components {
212-
componentNames = append(componentNames, fmt.Sprintf("%s-%s", opts.RuntimeName, component.Name))
211+
componentFullName := fmt.Sprintf("%s-%s", opts.RuntimeName, component.Name)
212+
componentNames = append(componentNames, componentFullName)
213213
}
214214

215215
// should find a more dynamic way to get these additional components
216216
additionalComponents := []string{"events-reporter", "workflow-reporter"}
217217
for _, additionalComponentName := range additionalComponents {
218-
componentNames = append(componentNames, fmt.Sprintf("%s-%s", opts.RuntimeName, additionalComponentName))
218+
componentFullName := fmt.Sprintf("%s-%s", opts.RuntimeName, additionalComponentName)
219+
componentNames = append(componentNames, componentFullName)
219220
}
220-
componentNames = append(componentNames, "argo-cd")
221+
argoCDFullName := store.Get().ArgoCD
222+
componentNames = append(componentNames, argoCDFullName)
221223

222224
return componentNames
223225
}
224226

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, runtimeName, server, runtimeVersion, ingressHost, componentNames)
227+
func createRuntimeOnPlatform(ctx context.Context, opts *model.RuntimeInstallationArgs) (string, error) {
228+
runtimeCreationResponse, err := cfConfig.NewClient().V2().Runtime().Create(ctx, opts)
227229

228-
if runtimeCreationResponse.ErrorMessage != nil {
229-
return runtimeCreationResponse.NewAccessToken, fmt.Errorf("failed to create a new runtime: %s. Error: %w", *runtimeCreationResponse.ErrorMessage, err)
230+
if err != nil {
231+
return "", fmt.Errorf("failed to create a new runtime: %s. Error: %w", opts.RuntimeName, err)
230232
}
231233

232234
return runtimeCreationResponse.NewAccessToken, nil
@@ -254,7 +256,13 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
254256

255257
componentNames := getComponents(rt, opts)
256258

257-
token, err := createRuntimeOnPlatform(ctx, opts.RuntimeName, server, runtimeVersion, opts.IngressHost, componentNames)
259+
token, err := createRuntimeOnPlatform(ctx, &model.RuntimeInstallationArgs{
260+
RuntimeName: opts.RuntimeName,
261+
Cluster: server,
262+
RuntimeVersion: runtimeVersion,
263+
IngressHost: &opts.IngressHost,
264+
ComponentNames: componentNames,
265+
})
258266

259267
if err != nil {
260268
return fmt.Errorf("failed to create a new runtime: %w", err)
@@ -326,11 +334,11 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
326334
fullGsPath := opts.GsCloneOpts.FS.Join(opts.GsCloneOpts.FS.Root(), gsPath)[1:]
327335

328336
if err = RunGitSourceCreate(ctx, &GitSourceCreateOptions{
329-
InsCloneOpts: opts.InsCloneOpts,
330-
GsCloneOpts: opts.GsCloneOpts,
331-
GsName: store.Get().GitSourceName,
332-
RuntimeName: opts.RuntimeName,
333-
FullGsPath: fullGsPath,
337+
InsCloneOpts: opts.InsCloneOpts,
338+
GsCloneOpts: opts.GsCloneOpts,
339+
GsName: store.Get().GitSourceName,
340+
RuntimeName: opts.RuntimeName,
341+
FullGsPath: fullGsPath,
334342
}); err != nil {
335343
return fmt.Errorf("failed to create `%s`: %w", store.Get().GitSourceName, err)
336344
}

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.5
13+
github.com/codefresh-io/go-sdk v0.34.7
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
@@ -266,8 +266,8 @@ github.com/clusterhq/flocker-go v0.0.0-20160920122132-2b8b7259d313/go.mod h1:P1w
266266
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
267267
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
268268
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
269-
github.com/codefresh-io/go-sdk v0.34.5 h1:9ZPVd1bZgExRRXfttNd0XqB9CIWdDK6qRSQLpjLXIWY=
270-
github.com/codefresh-io/go-sdk v0.34.5/go.mod h1:CcoVmTFWHGkbrSW8LyOGB/vJe5Vzr3iC/pNE2QIBTyg=
269+
github.com/codefresh-io/go-sdk v0.34.7 h1:KyVAHuYmlwp5hqTzEKc95CqggDZDcBRwfsL22fIxGIc=
270+
github.com/codefresh-io/go-sdk v0.34.7/go.mod h1:CcoVmTFWHGkbrSW8LyOGB/vJe5Vzr3iC/pNE2QIBTyg=
271271
github.com/colinmarc/hdfs v1.1.4-0.20180802165501-48eb8d6c34a9/go.mod h1:0DumPviB681UcSuJErAbDIOx6SIaJWj463TymfZG02I=
272272
github.com/colinmarc/hdfs v1.1.4-0.20180805212432-9746310a4d31/go.mod h1:vSBumefK4HA5uiRSwNP+3ofgrEoScpCS2MMWcWXEuQ4=
273273
github.com/container-storage-interface/spec v1.3.0/go.mod h1:6URME8mwIBbpVyZV93Ce5St17xBiQJQY67NDsuohiy4=

pkg/store/store.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ type Store struct {
8888
CronExampleEventName string
8989
CronExampleTriggerTemplateName string
9090
CronExampleDependencyName string
91+
ArgoCD string
9192
}
9293

9394
// Get returns the global store
@@ -138,6 +139,7 @@ func init() {
138139
s.CronExampleEventName = "example-with-interval"
139140
s.CronExampleTriggerTemplateName = "hello-world"
140141
s.CronExampleDependencyName = "calendar-dep"
142+
s.ArgoCD = "argo-cd"
141143
initVersion()
142144
}
143145

0 commit comments

Comments
 (0)