[kind/bug]
odo version: master$ odo service -h
Perform service catalog operations
Usage:
odo service [flags]
odo service [command]
Examples:
# Create new postgresql service from service catalog using dev plan and name my-postgresql-db.
odo service create dh-postgresql-apb my-postgresql-db --plan dev -p postgresql_user=luke -p postgresql_password=secret
# Delete the service named 'mysql-persistent'
odo service delete mysql-persistent
# List all services in the application
odo service list
Available Commands:
create Create a new service from service catalog using the plan defined and deploy it on OpenShift.
delete Delete an existing service
list List all services in the current application
Flags:
-h, --help Help for service
Global Flags:
--skip-connection-check Skip cluster check
-v, --v Level Log level for V logs. Level varies from 0 to 9 (default 0).
--vmodule moduleSpec Comma-separated list of pattern=N settings for file-filtered logging
Use "odo service [command] --help" for more information about a command.
flag support is not available
Support should be added
/priority high
ping @mohammedzee1000 @kadel
Issue title talks about odo service create but the description covers odo service. Going by the issue title, odo service create command does have --project flag but does not have the --context flag.
$ odo service create -h
Create a new service from service catalog using the plan defined and deploy it on OpenShift.
A --plan must be passed along with the service type. Parameters to configure the service are passed as key=value pairs.
For a full list of service types, use: 'odo catalog list services'
Usage:
odo service create <service_type> --plan <plan_name> [service_name] [flags]
Examples:
# Create new postgresql service from service catalog using dev plan and name my-postgresql-db.
odo service create dh-postgresql-apb my-postgresql-db --plan dev -p postgresql_user=luke -p postgresql_password=secret
Flags:
--app string Application, defaults to active application
-h, --help Help for create
-p, --parameters stringSlice Parameters of the plan where a parameter is expressed as <key>=<value
--plan string The name of the plan of the service to be created
--project string Project, defaults to active project
-w, --wait Wait until the service is ready
Global Flags:
--skip-connection-check Skip cluster check
-v, --v Level Log level for V logs. Level varies from 0 to 9 (default 0).
--vmodule moduleSpec Comma-separated list of pattern=N settings for file-filtered logging
/state ready
ping @kadel
odo service create can have --context flag, but it should only read the project and application name from the component config if flags are not specified.
We don't need to write any information about the service that is being created into the component config.
This will be handled by odo link command later.
odo service createcan have--contextflag, but it should only read the project and application name from the component config if flags are not specified.
If I understand correctly, we should follow below rules:
odo service create works if and only if called from inside a directory containing a pre-defined component.odo service create --context /path/to/dir works from anywhere on system as long as /path/to/dir contains a valid context.odo service create --app myapp --project myproj works from anywhere on the system. Do we create an app and/or project of the mentioned names if one doesn't exist already?odo service create would fail with appropriate error message. For example, these invocations would fail:$ odo service create --context /path/to/dir --proj myproj
# error mentions that --context and --proje flags can't be used together
$ odo service create --app myapp
# error mentions that --proj flag is required
$ odo service create --proj myproj
# error mentions that --app flag is required
```
app or project fields from the corresponding .odo/config.yaml?We don't need to write any information about the service that is being created into the component config.
This will be handled byodo linkcommand later.
Ack, makes sense.
If I understand correctly, we should follow below rules:
odo service createworks if and only if called from inside a directory containing a pre-defined component.
yes
odo service create --context /path/to/dirworks from anywhere on system as long as/path/to/dircontains a valid context.
yes
odo service create --app myapp --project myprojworks from anywhere on the system. Do we create an app and/or project of the mentioned names if one doesn't exist already?
Yes. The application doesn't have to be created as it is just a label value. Project shoul be created automatically if doesn't exist.
All other combinations of
odo service createwould fail with appropriate error message. For example, these invocations would fail:
```shell
$ odo service create --context /path/to/dir --app myapperror mentions that --context and --app flags can't be used together
$ odo service create --context /path/to/dir --proj myproj
error mentions that --context and --proje flags can't be used together
$ odo service create --app myapp
error mentions that --proj flag is required
This is valid. If the project is not specified, than the one that is set as active in KUBECONFIG should be used.
$ odo service create --proj myproj
# error mentions that --app flag is required
```
- What if the last two invocations mentioned in 4th point are called from a directory containing pre-defined context? Should we use the
apporprojectfields from the corresponding.odo/config.yaml?
In that case, the flag only overwrites what is in the context.
odo service create --app myapp in the context will use all the setting from the local config accept the application.
All other combinations of odo service create would fail with appropriate error message. For example, these invocations would fail:
```
$ odo service create --context /path/to/dir --app myapperror mentions that --context and --app flags can't be used together
$ odo service create --context /path/to/dir --proj myproj
error mentions that --context and --proje flags can't be used together
```
@kadel I pushed this commit (https://github.com/dharmit/odo/commit/11b479cfae117d6881524aa873328a135ec13da9) to add --context flag to odo service create command.
But the way this function works: https://github.com/openshift/odo/blob/91e0862892ed46eb810444cb5dc4e15c3db38c78/pkg/odo/genericclioptions/context.go#L249-L292
it overwrites the value of Application and Project if --app or --project flags are provided on the cli. So when I do:
$ odo service create --context /path/to/dir --app myapp
it uses the application myapp even if the context within /path/to/dir/.odo/config.yaml uses the application app.
This function is used everywhere for getting a context and I'm a bit lost as to how to achieve what we need here.
Strictly from code point of view, should we add some check like: https://github.com/openshift/odo/blob/91e0862892ed46eb810444cb5dc4e15c3db38c78/pkg/odo/genericclioptions/context.go#L123-L162
so that when we're working on odo service create, it doesn't overwrite the values for Application and Project?
it uses the application
myappeven if the context within/path/to/dir/.odo/config.yamluses the applicationapp.
I think thats expected as we assume if the user provides it then they know what they are doing
it overwrites the value of
ApplicationandProjectif--appor--projectflags are provided on the cli. So when I do:$ odo service create --context /path/to/dir --app myappit uses the application
myappeven if the context within/path/to/dir/.odo/config.yamluses the applicationapp.
this is actually what we want. This is how it works everywhere else. Sorry I missed this in your original comment where you mentioned that it should error out. It should not error out but use values from flags.