Skip to content

Commit

Permalink
Cr 5532 (#35)
Browse files Browse the repository at this point in the history
* added cf base url to runtime cm
  • Loading branch information
daniel-codefresh authored Aug 2, 2021
1 parent 5e3d3c0 commit e815602
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=v0.0.40
VERSION=v0.0.41
OUT_DIR=dist
YEAR?=$(shell date +"%Y")

Expand Down
36 changes: 23 additions & 13 deletions cmd/commands/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type (
gsCloneOpts *git.CloneOptions
insCloneOpts *git.CloneOptions
KubeFactory kube.Factory
commonConfig *runtime.CommonConfig
}

RuntimeUninstallOptions struct {
Expand All @@ -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
}
)

Expand Down Expand Up @@ -152,6 +154,9 @@ func NewRuntimeInstallCommand() *cobra.Command {
gsCloneOpts: gsCloneOpts,
insCloneOpts: insCloneOpts,
KubeFactory: f,
commonConfig: &runtime.CommonConfig{
CodefreshBaseURL: cfConfig.GetCurrentContext().URL,
},
})
},
}
Expand Down Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand Down Expand Up @@ -408,6 +414,9 @@ func NewRuntimeUpgradeCommand() *cobra.Command {
RuntimeName: args[0],
Version: version,
CloneOpts: cloneOpts,
commonConfig: &runtime.CommonConfig{
CodefreshBaseURL: cfConfig.GetCurrentContext().URL,
},
})
},
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions docs/releases/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion manifests/runtime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions pkg/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
}

Expand Down

0 comments on commit e815602

Please sign in to comment.