Skip to content

Commit e815602

Browse files
Cr 5532 (#35)
* added cf base url to runtime cm
1 parent 5e3d3c0 commit e815602

File tree

5 files changed

+37
-22
lines changed

5 files changed

+37
-22
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.40
1+
VERSION=v0.0.41
22
OUT_DIR=dist
33
YEAR?=$(shell date +"%Y")
44

cmd/commands/runtime.go

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type (
5656
gsCloneOpts *git.CloneOptions
5757
insCloneOpts *git.CloneOptions
5858
KubeFactory kube.Factory
59+
commonConfig *runtime.CommonConfig
5960
}
6061

6162
RuntimeUninstallOptions struct {
@@ -66,9 +67,10 @@ type (
6667
}
6768

6869
RuntimeUpgradeOptions struct {
69-
RuntimeName string
70-
Version *semver.Version
71-
CloneOpts *git.CloneOptions
70+
RuntimeName string
71+
Version *semver.Version
72+
CloneOpts *git.CloneOptions
73+
commonConfig *runtime.CommonConfig
7274
}
7375
)
7476

@@ -152,6 +154,9 @@ func NewRuntimeInstallCommand() *cobra.Command {
152154
gsCloneOpts: gsCloneOpts,
153155
insCloneOpts: insCloneOpts,
154156
KubeFactory: f,
157+
commonConfig: &runtime.CommonConfig{
158+
CodefreshBaseURL: cfConfig.GetCurrentContext().URL,
159+
},
155160
})
156161
},
157162
}
@@ -210,7 +215,7 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
210215
}
211216
}
212217

213-
if err = persistRuntime(ctx, opts.insCloneOpts, rt); err != nil {
218+
if err = persistRuntime(ctx, opts.insCloneOpts, rt, opts.commonConfig); err != nil {
214219
return fmt.Errorf("failed to create codefresh-cm: %w", err)
215220
}
216221

@@ -222,7 +227,8 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
222227
return fmt.Errorf("failed to create demo workflowTemplate: %w", err)
223228
}
224229

225-
if err = createGitSource(ctx, opts.insCloneOpts, opts.gsCloneOpts, store.Get().GitSourceName, opts.RuntimeName); err != nil {
230+
if err = createGitSource(ctx, opts.insCloneOpts, opts.gsCloneOpts, store.Get().GitSourceName, opts.RuntimeName,
231+
opts.commonConfig.CodefreshBaseURL); err != nil {
226232
return fmt.Errorf("failed to create `%s`: %w", store.Get().GitSourceName, err)
227233
}
228234

@@ -408,6 +414,9 @@ func NewRuntimeUpgradeCommand() *cobra.Command {
408414
RuntimeName: args[0],
409415
Version: version,
410416
CloneOpts: cloneOpts,
417+
commonConfig: &runtime.CommonConfig{
418+
CodefreshBaseURL: cfConfig.GetCurrentContext().URL,
419+
},
411420
})
412421
},
413422
}
@@ -444,7 +453,7 @@ func RunRuntimeUpgrade(ctx context.Context, opts *RuntimeUpgradeOptions) error {
444453
return fmt.Errorf("must upgrade to version > %s", curRt.Spec.Version)
445454
}
446455

447-
newComponents, err := curRt.Upgrade(fs, newRt)
456+
newComponents, err := curRt.Upgrade(fs, newRt, opts.commonConfig)
448457
if err != nil {
449458
return fmt.Errorf("failed to upgrade runtime: %w", err)
450459
}
@@ -463,13 +472,13 @@ func RunRuntimeUpgrade(ctx context.Context, opts *RuntimeUpgradeOptions) error {
463472
return nil
464473
}
465474

466-
func persistRuntime(ctx context.Context, cloneOpts *git.CloneOptions, rt *runtime.Runtime) error {
475+
func persistRuntime(ctx context.Context, cloneOpts *git.CloneOptions, rt *runtime.Runtime, rtConf *runtime.CommonConfig) error {
467476
r, fs, err := cloneOpts.GetRepo(ctx)
468477
if err != nil {
469478
return err
470479
}
471480

472-
if err = rt.Save(fs, fs.Join(apstore.Default.BootsrtrapDir, store.Get().RuntimeFilename)); err != nil {
481+
if err = rt.Save(fs, fs.Join(apstore.Default.BootsrtrapDir, store.Get().RuntimeFilename), rtConf); err != nil {
473482
return err
474483
}
475484

@@ -516,7 +525,8 @@ func createComponentsReporter(ctx context.Context, cloneOpts *git.CloneOptions,
516525
return err
517526
}
518527

519-
if err := createSensor(repofs, store.Get().ComponentsReporterName, resPath, opts.RuntimeName, store.Get().ComponentsReporterName); err != nil {
528+
if err := createSensor(repofs, store.Get().ComponentsReporterName, resPath, opts.RuntimeName,
529+
store.Get().ComponentsReporterName, opts.commonConfig.CodefreshBaseURL); err != nil {
520530
return err
521531
}
522532

@@ -668,13 +678,13 @@ func createEventSource(repofs fs.FS, path, namespace string) error {
668678
return repofs.WriteYamls(repofs.Join(path, "event-source.yaml"), eventSource)
669679
}
670680

671-
func createSensor(repofs fs.FS, name, path, namespace, eventSourceName string) error {
681+
func createSensor(repofs fs.FS, name, path, namespace, eventSourceName, cfBaseURL string) error {
672682
sensor := eventsutil.CreateSensor(&eventsutil.CreateSensorOptions{
673683
Name: name,
674684
Namespace: namespace,
675685
EventSourceName: eventSourceName,
676686
EventBusName: store.Get().EventBusName,
677-
TriggerURL: cfConfig.GetCurrentContext().URL + store.Get().EventReportingEndpoint,
687+
TriggerURL: cfBaseURL + store.Get().EventReportingEndpoint,
678688
Triggers: []string{
679689
"components",
680690
"runtime",
@@ -725,7 +735,7 @@ func createDemoWorkflowTemplate(ctx context.Context, gsCloneOpts *git.CloneOptio
725735
return err
726736
}
727737

728-
func createGitSource(ctx context.Context, insCloneOpts *git.CloneOptions, gsCloneOpts *git.CloneOptions, gsName, runtimeName string) error {
738+
func createGitSource(ctx context.Context, insCloneOpts *git.CloneOptions, gsCloneOpts *git.CloneOptions, gsName, runtimeName, cfBaseURL string) error {
729739
var err error
730740

731741
insRepo, insFs, err := insCloneOpts.GetRepo(ctx)
@@ -830,7 +840,7 @@ func createGitSource(ctx context.Context, insCloneOpts *git.CloneOptions, gsClon
830840
Namespace: runtimeName,
831841
EventSourceName: eventSourceName,
832842
EventBusName: store.Get().EventBusName,
833-
TriggerURL: cfConfig.GetCurrentContext().URL + store.Get().EventReportingEndpoint,
843+
TriggerURL: cfBaseURL + store.Get().EventReportingEndpoint,
834844
Triggers: []string{
835845
// "clusterWorkflowTemplate",
836846
"workflowTemplate",

docs/releases/release_notes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
### Linux
99
```bash
1010
# download and extract the binary
11-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.40/cf-linux-amd64.tar.gz | tar zx
11+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.41/cf-linux-amd64.tar.gz | tar zx
1212

1313
# move the binary to your $PATH
1414
mv ./cf-linux-amd64 /usr/local/bin/cf
@@ -20,7 +20,7 @@ cf version
2020
### Mac
2121
```bash
2222
# download and extract the binary
23-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.40/cf-darwin-amd64.tar.gz | tar zx
23+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.41/cf-darwin-amd64.tar.gz | tar zx
2424

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

manifests/runtime.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
namespace: "{{ namespace }}"
66
spec:
77
defVersion: 1.0.0
8-
version: 0.0.40
8+
version: 0.0.41
99
bootstrapSpecifier: github.com/codefresh-io/cli-v2/manifests/argo-cd
1010
components:
1111
- name: events

pkg/runtime/runtime.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ type (
5555
Components []AppDef `json:"components"`
5656
}
5757

58+
CommonConfig struct {
59+
CodefreshBaseURL string `json:"baseUrl"`
60+
}
61+
5862
AppDef struct {
5963
Name string `json:"name"`
6064
Type string `json:"type"`
@@ -114,8 +118,8 @@ func Load(fs fs.FS, filename string) (*Runtime, error) {
114118
return runtime, yaml.Unmarshal([]byte(data), runtime)
115119
}
116120

117-
func (r *Runtime) Save(fs fs.FS, filename string) error {
118-
data, err := yaml.Marshal(r)
121+
func (r *Runtime) Save(fs fs.FS, filename string, config *CommonConfig) error {
122+
runtimeData, err := yaml.Marshal(r)
119123
if err != nil {
120124
return err
121125
}
@@ -134,20 +138,21 @@ func (r *Runtime) Save(fs fs.FS, filename string) error {
134138
},
135139
},
136140
Data: map[string]string{
137-
"runtime": string(data),
141+
"runtime": string(runtimeData),
142+
"base-url": config.CodefreshBaseURL,
138143
},
139144
}
140145

141146
return fs.WriteYamls(filename, cm)
142147
}
143148

144-
func (r *Runtime) Upgrade(fs fs.FS, newRt *Runtime) ([]AppDef, error) {
149+
func (r *Runtime) Upgrade(fs fs.FS, newRt *Runtime, config *CommonConfig) ([]AppDef, error) {
145150
newComponents, err := r.Spec.upgrade(fs, &newRt.Spec)
146151
if err != nil {
147152
return nil, err
148153
}
149154

150-
if err := newRt.Save(fs, fs.Join(apstore.Default.BootsrtrapDir, store.Get().RuntimeFilename)); err != nil {
155+
if err := newRt.Save(fs, fs.Join(apstore.Default.BootsrtrapDir, store.Get().RuntimeFilename), config); err != nil {
151156
return nil, fmt.Errorf("failed to save runtime definition: %w", err)
152157
}
153158

0 commit comments

Comments
 (0)