Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

cli: provide environment override capability #4019

Merged
merged 1 commit into from
Aug 23, 2021

Conversation

shashankram
Copy link
Member

Description:
Provides the capability to override default namespace
and commands in osm cli. This is required to provide
a better experience of osm cli in managed environments,
where users can be advised to use a config file to to override
defaults.

It works as follows:

  1. If osm config file is present, either in $HOME/.osm/config
    or specified via the OSM_CONFIG env var, this file will be
    used for environment defaults. This works similar to
    KUBECONFIG where the env variable overrides the static
    file if present.
  2. If osm config file is not present, defaults values are
    used for the environment configurations.
  3. If the install kind is set to managed in the config file,
    then install/uninstall/upgrade/dashboard commands which
    are only meant for self-hosted environments are disabled.

Part of #3978

Testing done:

  1. When no config file is specified via OSM_CONFIG env var or $HOME/.osm/config:
$ osm env
--- 
install:
  kind: self-hosted
  distribution: ""
  namespace: osm-system

$ osm -h | grep osm-namespace
      --osm-namespace string   namespace for osm control plane (default "osm-system")
  1. When OSM_CONFIG env var is used to specify a config file:
$ cat /tmp/osmconfig.yaml 
install:
  kind: managed
  distribution: AKS
  namespace: kube-system

$ OSM_CONFIG=/tmp/osmconfig.yaml osm env
--- 
install:
  kind: managed
  distribution: AKS
  namespace: kube-system

$ OSM_CONFIG=/tmp/osmconfig.yaml osm -h | grep osm-namespace
      --osm-namespace string   namespace for osm control plane (default "kube-system")
  1. When $HOME/.osm/config is present and OSM_CONFIG env var is not set:
 cat ~/.osm/config.yaml
install:
  kind: self-hosted
  distribution: Kind
  namespace: osm-system

$ osm env
--- 
install:
  kind: self-hosted
  distribution: Kind
  namespace: osm-system

$ osm -h | grep osm-namespace
      --osm-namespace string   namespace for osm control plane (default "osm-system")

Affected area:

Functional Area
CLI Tool [X]

Please answer the following questions with yes/no.

  1. Does this change contain code from or inspired by another project? no

    • Did you notify the maintainers and provide attribution?
  2. Is this a breaking change? no

@shashankram shashankram requested a review from a team as a code owner August 20, 2021 22:45
Comment on lines +131 to +136
// envFromConfig returns the environment information from the config file.
// The config file is looked up as follows:
// 1. Look for config file specified in OSM_CONFIG env var. If set, use it.
// 2. If 1. is not applicable, look for a file in $HOME/.osm/config; if file exists use it
// 3. If neither of 1. and 2. apply, use system defaults.
func envFromConfig() (*EnvConfig, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is excellent! Thank you!

@allenlsy
Copy link
Contributor

I feel the solution is coupled with how a managed environment works. Suppose we have another managed environment using a new way of automation, we then need to provide more options.

But for now, this is the way to go.

@shashankram
Copy link
Member Author

I feel the solution is coupled with how a managed environment works. Suppose we have another managed environment using a new way of automation, we then need to provide more options.

But for now, this is the way to go.

I don't understand this comment. If the install is managed (as specified in the config file), then there is no reason to give the users the option to install. What's the concern here?

Provides the capability to override default namespace
and commands in osm cli. This is required to provide
a better experience of osm cli in managed environments.

It works as follows:
1. If osm config file is present, either in $HOME/.osm/config
   or specified via the OSM_CONFIG env var, this file will be
   used for environment defaults. This works similar to
   KUBECONFIG where the env variable overrides the static
   file if present.
2. If osm config file is not present, defaults values are
   used for the environment configurations.
3. If the install kind is set to `managed` in the config file,
   then install/uninstall/upgrade/dashboard commands which
   are only meant for self-hosted environments are disabled.

Resolves openservicemesh#3978

Signed-off-by: Shashank Ram <[email protected]>
@shashankram shashankram merged commit 4dcc321 into openservicemesh:main Aug 23, 2021
@shashankram shashankram deleted the cli-def branch August 23, 2021 15:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants