Skip to content

Commit

Permalink
Don't save component name in env.yaml
Browse files Browse the repository at this point in the history
<!--
Thank you for opening a PR! Here are some things you need to know before submitting:

1. Please read our developer guideline: https://github.com/redhat-developer/odo/wiki/Dev:-odo-Dev-Guidelines
2. Label this PR accordingly with the '/kind' line
3. Ensure you have written and ran the appropriate tests: https://github.com/redhat-developer/odo/wiki/Dev:-Writing-and-running-tests
4. Read how we approve and LGTM each PR: https://github.com/redhat-developer/odo/wiki/Pull-Requests:-Review-guideline

Documentation:

If you are pushing a change to documentation, please read: https://github.com/redhat-developer/odo/wiki/Documentation:-Contributing
-->

**What type of PR is this:**

<!--
Add one of the following kinds:
/kind feature
/kind cleanup
/kind tests
/kind documentation

Feel free to use other [labels](https://github.com/redhat-developer/odo/labels) as needed. However one of the above labels must be present or the PR will not be reviewed. This instruction is for reviewers as well.
-->
/kind bug

**What does this PR do / why we need it:**

By default we should be saving the namespace / project name, not the app name /
component name

**Which issue(s) this PR fixes:**
<!--
Specifying the issue will automatically close it when this PR is merged
-->

Fixes #5780

**PR acceptance criteria:**

- [ ] Unit test

- [ ] Integration test

- [ ] Documentation

**How to test changes / Special notes to the reviewer:**

Signed-off-by: Charlie Drage <charlie@charliedrage.com>
  • Loading branch information
cdrage committed Jun 27, 2022
1 parent 47caa79 commit 116fdd2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
27 changes: 16 additions & 11 deletions pkg/odo/cli/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,28 +103,33 @@ func (o *DeployOptions) Complete(cmdline cmdline.Cmdline, args []string) (err er
return err
}

envFileInfo, err := envinfo.NewEnvSpecificInfo(o.contextDir)
// ENV.YAML
//
// Set the appropriate variables in the env.yaml file
//
envfileinfo, err := envinfo.NewEnvSpecificInfo("")
if err != nil {
return fmt.Errorf("unable to retrieve configuration information: %w", err)
return fmt.Errorf("unable to retrieve configuration information: %v", err)
}
if !envFileInfo.Exists() {
var cmpName string
cmpName, err = component.GatherName(o.EnvSpecificInfo.GetDevfileObj(), o.GetDevfilePath())
if err != nil {
return fmt.Errorf("unable to retrieve component name: %w", err)
}
err = envFileInfo.SetComponentSettings(envinfo.ComponentSettings{Name: cmpName, Project: o.GetProject(), AppName: "app"})

// If the env.yaml does not exist, we will save the project name
if !envfileinfo.Exists() {
err = envfileinfo.SetComponentSettings(envinfo.ComponentSettings{Project: o.GetProject()})
if err != nil {
return fmt.Errorf("failed to write new env.yaml file: %w", err)
}
}

} else if envFileInfo.GetComponentSettings().Project != o.GetProject() {
err = envFileInfo.SetConfiguration("project", o.GetProject())
// If the env.yaml exists and the project is set incorrectly, we'll override it.
if envfileinfo.Exists() && envfileinfo.GetComponentSettings().Project != o.GetProject() {
err = envfileinfo.SetConfiguration("project", o.GetProject())
if err != nil {
return fmt.Errorf("failed to update project in env.yaml file: %w", err)
}
}

// END ENV.YAML

// this ensures that odo deploy uses the namespace set in env.yaml
o.clientset.KubernetesClient.SetNamespace(o.GetProject())
return
Expand Down
24 changes: 13 additions & 11 deletions pkg/odo/cli/dev/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,33 +138,35 @@ func (o *DevOptions) Complete(cmdline cmdline.Cmdline, args []string) error {
return fmt.Errorf("unable to create context: %v", err)
}

// ENV.YAML
//
// Set the appropriate variables in the env.yaml file
//
envfileinfo, err := envinfo.NewEnvSpecificInfo("")
if err != nil {
return fmt.Errorf("unable to retrieve configuration information: %v", err)
}

o.initialDevfileObj = o.Context.EnvSpecificInfo.GetDevfileObj()

// If the env.yaml does not exist, we will save the project name
if !envfileinfo.Exists() {
// if env.yaml doesn't exist, get component name from the devfile.yaml
var cmpName string
cmpName, err = component.GatherName(o.EnvSpecificInfo.GetDevfileObj(), o.GetDevfilePath())
if err != nil {
return fmt.Errorf("unable to retrieve component name: %w", err)
}
// create env.yaml file with component, project/namespace and application info
// TODO - store only namespace into env.yaml, we don't want to track component or application name via env.yaml
err = envfileinfo.SetComponentSettings(envinfo.ComponentSettings{Name: cmpName, Project: o.GetProject(), AppName: "app"})
err = envfileinfo.SetComponentSettings(envinfo.ComponentSettings{Project: o.GetProject()})
if err != nil {
return fmt.Errorf("failed to write new env.yaml file: %w", err)
}
} else if envfileinfo.GetComponentSettings().Project != o.GetProject() {
// set namespace if the evn.yaml exists; that's the only piece we care about in env.yaml
}

// If the env.yaml exists and the project is set incorrectly, we'll override it.
if envfileinfo.Exists() && envfileinfo.GetComponentSettings().Project != o.GetProject() {
err = envfileinfo.SetConfiguration("project", o.GetProject())
if err != nil {
return fmt.Errorf("failed to update project in env.yaml file: %w", err)
}
}

// END ENV.YAML

o.clientset.KubernetesClient.SetNamespace(o.GetProject())

// 3 steps to evaluate the paths to be ignored when "watching" the pwd/cwd for changes
Expand Down

0 comments on commit 116fdd2

Please sign in to comment.