diff --git a/pkg/odo/cli/deploy/deploy.go b/pkg/odo/cli/deploy/deploy.go index 01a61373036..3a696a19d23 100644 --- a/pkg/odo/cli/deploy/deploy.go +++ b/pkg/odo/cli/deploy/deploy.go @@ -105,28 +105,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 diff --git a/pkg/odo/cli/dev/dev.go b/pkg/odo/cli/dev/dev.go index d4d26743e06..2c4bacf4458 100644 --- a/pkg/odo/cli/dev/dev.go +++ b/pkg/odo/cli/dev/dev.go @@ -148,6 +148,10 @@ 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) @@ -155,26 +159,24 @@ func (o *DevOptions) Complete(cmdline cmdline.Cmdline, args []string) error { 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