From e81560237eaa6bcb66727aac8aad6c4d316427af Mon Sep 17 00:00:00 2001 From: daniel-codefresh <69415974+daniel-codefresh@users.noreply.github.com> Date: Mon, 2 Aug 2021 14:27:21 +0300 Subject: [PATCH] Cr 5532 (#35) * added cf base url to runtime cm --- Makefile | 2 +- cmd/commands/runtime.go | 36 ++++++++++++++++++++++------------ docs/releases/release_notes.md | 4 ++-- manifests/runtime.yaml | 2 +- pkg/runtime/runtime.go | 15 +++++++++----- 5 files changed, 37 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index b510c9083..379efb028 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION=v0.0.40 +VERSION=v0.0.41 OUT_DIR=dist YEAR?=$(shell date +"%Y") diff --git a/cmd/commands/runtime.go b/cmd/commands/runtime.go index 041839bd2..28b1d3309 100644 --- a/cmd/commands/runtime.go +++ b/cmd/commands/runtime.go @@ -56,6 +56,7 @@ type ( gsCloneOpts *git.CloneOptions insCloneOpts *git.CloneOptions KubeFactory kube.Factory + commonConfig *runtime.CommonConfig } RuntimeUninstallOptions struct { @@ -66,9 +67,10 @@ type ( } RuntimeUpgradeOptions struct { - RuntimeName string - Version *semver.Version - CloneOpts *git.CloneOptions + RuntimeName string + Version *semver.Version + CloneOpts *git.CloneOptions + commonConfig *runtime.CommonConfig } ) @@ -152,6 +154,9 @@ func NewRuntimeInstallCommand() *cobra.Command { gsCloneOpts: gsCloneOpts, insCloneOpts: insCloneOpts, KubeFactory: f, + commonConfig: &runtime.CommonConfig{ + CodefreshBaseURL: cfConfig.GetCurrentContext().URL, + }, }) }, } @@ -210,7 +215,7 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error { } } - if err = persistRuntime(ctx, opts.insCloneOpts, rt); err != nil { + if err = persistRuntime(ctx, opts.insCloneOpts, rt, opts.commonConfig); err != nil { return fmt.Errorf("failed to create codefresh-cm: %w", err) } @@ -222,7 +227,8 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error { return fmt.Errorf("failed to create demo workflowTemplate: %w", err) } - if err = createGitSource(ctx, opts.insCloneOpts, opts.gsCloneOpts, store.Get().GitSourceName, opts.RuntimeName); err != nil { + if err = createGitSource(ctx, opts.insCloneOpts, opts.gsCloneOpts, store.Get().GitSourceName, opts.RuntimeName, + opts.commonConfig.CodefreshBaseURL); err != nil { return fmt.Errorf("failed to create `%s`: %w", store.Get().GitSourceName, err) } @@ -408,6 +414,9 @@ func NewRuntimeUpgradeCommand() *cobra.Command { RuntimeName: args[0], Version: version, CloneOpts: cloneOpts, + commonConfig: &runtime.CommonConfig{ + CodefreshBaseURL: cfConfig.GetCurrentContext().URL, + }, }) }, } @@ -444,7 +453,7 @@ func RunRuntimeUpgrade(ctx context.Context, opts *RuntimeUpgradeOptions) error { return fmt.Errorf("must upgrade to version > %s", curRt.Spec.Version) } - newComponents, err := curRt.Upgrade(fs, newRt) + newComponents, err := curRt.Upgrade(fs, newRt, opts.commonConfig) if err != nil { return fmt.Errorf("failed to upgrade runtime: %w", err) } @@ -463,13 +472,13 @@ func RunRuntimeUpgrade(ctx context.Context, opts *RuntimeUpgradeOptions) error { return nil } -func persistRuntime(ctx context.Context, cloneOpts *git.CloneOptions, rt *runtime.Runtime) error { +func persistRuntime(ctx context.Context, cloneOpts *git.CloneOptions, rt *runtime.Runtime, rtConf *runtime.CommonConfig) error { r, fs, err := cloneOpts.GetRepo(ctx) if err != nil { return err } - if err = rt.Save(fs, fs.Join(apstore.Default.BootsrtrapDir, store.Get().RuntimeFilename)); err != nil { + if err = rt.Save(fs, fs.Join(apstore.Default.BootsrtrapDir, store.Get().RuntimeFilename), rtConf); err != nil { return err } @@ -516,7 +525,8 @@ func createComponentsReporter(ctx context.Context, cloneOpts *git.CloneOptions, return err } - if err := createSensor(repofs, store.Get().ComponentsReporterName, resPath, opts.RuntimeName, store.Get().ComponentsReporterName); err != nil { + if err := createSensor(repofs, store.Get().ComponentsReporterName, resPath, opts.RuntimeName, + store.Get().ComponentsReporterName, opts.commonConfig.CodefreshBaseURL); err != nil { return err } @@ -668,13 +678,13 @@ func createEventSource(repofs fs.FS, path, namespace string) error { return repofs.WriteYamls(repofs.Join(path, "event-source.yaml"), eventSource) } -func createSensor(repofs fs.FS, name, path, namespace, eventSourceName string) error { +func createSensor(repofs fs.FS, name, path, namespace, eventSourceName, cfBaseURL string) error { sensor := eventsutil.CreateSensor(&eventsutil.CreateSensorOptions{ Name: name, Namespace: namespace, EventSourceName: eventSourceName, EventBusName: store.Get().EventBusName, - TriggerURL: cfConfig.GetCurrentContext().URL + store.Get().EventReportingEndpoint, + TriggerURL: cfBaseURL + store.Get().EventReportingEndpoint, Triggers: []string{ "components", "runtime", @@ -725,7 +735,7 @@ func createDemoWorkflowTemplate(ctx context.Context, gsCloneOpts *git.CloneOptio return err } -func createGitSource(ctx context.Context, insCloneOpts *git.CloneOptions, gsCloneOpts *git.CloneOptions, gsName, runtimeName string) error { +func createGitSource(ctx context.Context, insCloneOpts *git.CloneOptions, gsCloneOpts *git.CloneOptions, gsName, runtimeName, cfBaseURL string) error { var err error insRepo, insFs, err := insCloneOpts.GetRepo(ctx) @@ -830,7 +840,7 @@ func createGitSource(ctx context.Context, insCloneOpts *git.CloneOptions, gsClon Namespace: runtimeName, EventSourceName: eventSourceName, EventBusName: store.Get().EventBusName, - TriggerURL: cfConfig.GetCurrentContext().URL + store.Get().EventReportingEndpoint, + TriggerURL: cfBaseURL + store.Get().EventReportingEndpoint, Triggers: []string{ // "clusterWorkflowTemplate", "workflowTemplate", diff --git a/docs/releases/release_notes.md b/docs/releases/release_notes.md index 494db7872..f080e6020 100644 --- a/docs/releases/release_notes.md +++ b/docs/releases/release_notes.md @@ -8,7 +8,7 @@ ### Linux ```bash # download and extract the binary -curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.40/cf-linux-amd64.tar.gz | tar zx +curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.41/cf-linux-amd64.tar.gz | tar zx # move the binary to your $PATH mv ./cf-linux-amd64 /usr/local/bin/cf @@ -20,7 +20,7 @@ cf version ### Mac ```bash # download and extract the binary -curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.40/cf-darwin-amd64.tar.gz | tar zx +curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.41/cf-darwin-amd64.tar.gz | tar zx # move the binary to your $PATH mv ./cf-darwin-amd64 /usr/local/bin/cf diff --git a/manifests/runtime.yaml b/manifests/runtime.yaml index 3076dad9b..252a02cd2 100644 --- a/manifests/runtime.yaml +++ b/manifests/runtime.yaml @@ -5,7 +5,7 @@ metadata: namespace: "{{ namespace }}" spec: defVersion: 1.0.0 - version: 0.0.40 + version: 0.0.41 bootstrapSpecifier: github.com/codefresh-io/cli-v2/manifests/argo-cd components: - name: events diff --git a/pkg/runtime/runtime.go b/pkg/runtime/runtime.go index c176abb8c..4075faf0e 100644 --- a/pkg/runtime/runtime.go +++ b/pkg/runtime/runtime.go @@ -55,6 +55,10 @@ type ( Components []AppDef `json:"components"` } + CommonConfig struct { + CodefreshBaseURL string `json:"baseUrl"` + } + AppDef struct { Name string `json:"name"` Type string `json:"type"` @@ -114,8 +118,8 @@ func Load(fs fs.FS, filename string) (*Runtime, error) { return runtime, yaml.Unmarshal([]byte(data), runtime) } -func (r *Runtime) Save(fs fs.FS, filename string) error { - data, err := yaml.Marshal(r) +func (r *Runtime) Save(fs fs.FS, filename string, config *CommonConfig) error { + runtimeData, err := yaml.Marshal(r) if err != nil { return err } @@ -134,20 +138,21 @@ func (r *Runtime) Save(fs fs.FS, filename string) error { }, }, Data: map[string]string{ - "runtime": string(data), + "runtime": string(runtimeData), + "base-url": config.CodefreshBaseURL, }, } return fs.WriteYamls(filename, cm) } -func (r *Runtime) Upgrade(fs fs.FS, newRt *Runtime) ([]AppDef, error) { +func (r *Runtime) Upgrade(fs fs.FS, newRt *Runtime, config *CommonConfig) ([]AppDef, error) { newComponents, err := r.Spec.upgrade(fs, &newRt.Spec) if err != nil { return nil, err } - if err := newRt.Save(fs, fs.Join(apstore.Default.BootsrtrapDir, store.Get().RuntimeFilename)); err != nil { + if err := newRt.Save(fs, fs.Join(apstore.Default.BootsrtrapDir, store.Get().RuntimeFilename), config); err != nil { return nil, fmt.Errorf("failed to save runtime definition: %w", err) }