Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--provider global flag for kompose #182

Merged
merged 1 commit into from
Oct 6, 2016

Conversation

surajssd
Copy link
Member

@surajssd surajssd commented Oct 3, 2016

Now a user can select a provider using global flag --provider=openshift to select openshift provider
or --provider-kubernetes to select kubernetes provider if nothing is provided kubernetes is the default provider.

Fixes #179

Copy link
Member

@kadel kadel left a comment

Choose a reason for hiding this comment

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

I think that it is not really user friendly to show options for all providers.

When you do kompose --provider kubernetes convert --h it should show only options that are valid for Kubernetes and when you do kompose --provider openshift convert --h user should see only options for OpenShift

@kadel
Copy link
Member

kadel commented Oct 3, 2016

Today on train to Berlin I've worked on same thing as part of work on kompose up for openshift. :-)

Because I wanted --help to show only options that are valid for given provider, I've done this slightly differently.

I've used app.Before to add Commands depending on specified provider.
You can see my wip in branch openshift-up in my fork master...kadel:openshift-up

I don't know how much time I'm going to have this week to clean it up and finish. But If you want to have provider flag sooner, look at my branch and you can use it ;-)

@surajssd
Copy link
Member Author

surajssd commented Oct 4, 2016

@kadel thanks for pointers, this helps with the missing point I had!

@surajssd
Copy link
Member Author

surajssd commented Oct 4, 2016

@kadel addressed the issues you mentioned!

Now output looks like this:

for openshift

$ kompose --provider=openshift convert -h
NAME:
   kompose convert - Convert Docker Compose file (e.g. docker-compose.yml) to Kubernetes objects

USAGE:
   kompose convert [command options] [arguments...]

OPTIONS:
   --out, -o                    Specify file name in order to save objects into [$OUTPUT_FILE]
   --replicas "1"               Specify the number of replicas in the generated resource spec (default 1)
   --chart, -c                  Create a chart deployment
   --yaml, -y                   Generate resource file in yaml format
   --stdout                     Print converted objects to stdout
   --deploymentconfig, --dc     Generate a DeploymentConfig for OpenShift

for k8s

$ kompose convert -h
NAME:
   kompose convert - Convert Docker Compose file (e.g. docker-compose.yml) to Kubernetes objects

USAGE:
   kompose convert [command options] [arguments...]

OPTIONS:
   --out, -o                            Specify file name in order to save objects into [$OUTPUT_FILE]
   --replicas "1"                       Specify the number of replicas in the generated resource spec (default 1)
   --chart, -c                          Create a chart deployment
   --yaml, -y                           Generate resource file in yaml format
   --stdout                             Print converted objects to stdout
   --deployment, -d                     Generate a deployment resource file (default on)
   --daemonset, --ds                    Generate a daemonset resource file
   --replicationcontroller, --rc        Generate a replication controller resource file

Copy link
Member

@kadel kadel left a comment

Choose a reason for hiding this comment

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

Thank you @surajssd.
Just couple suggestions ;-)

if !opt.CreateD && !opt.CreateDS && !opt.CreateRC {
opt.CreateD = true
}
if opt.CreateDeploymentConfig {
Copy link
Member

Choose a reason for hiding this comment

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

this check is not needed, this can never happen

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh yes, now this is not needed since command line handling will take care of it :)

// create deploymentconfig by default if no controller has been set
if !opt.CreateDeploymentConfig {
opt.CreateDeploymentConfig = true
}
if opt.CreateD {
Copy link
Member

Choose a reason for hiding this comment

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

this check is not needed, this can never happen same for CreateDS and CreateRS

provider := strings.ToLower(c.GlobalString("provider"))
switch provider {
case "kubernetes":
k8sControllers := []cli.Flag{
Copy link
Member

@kadel kadel Oct 4, 2016

Choose a reason for hiding this comment

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

can we create whole new cli.Command here? So we can set usage help for every provider independently?
Or set commands.Usage here

If I run kompose --provider openshift convert -h It is still displaying usage mentioning Kubernetes

NAME:
   kompose convert - Convert Docker Compose file (e.g. docker-compose.yml) to Kubernetes objects
....

This is also relying on ConvertCommand always being first in that slice :-( This might lead to errors in the future. At least there should be comment in app.Commands

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes sure we can create new cli.Command, and nice catch of that usage string BTW!

@@ -33,7 +32,7 @@ func main() {
app.Author = "Skippbox Kompose Contributors"
app.Email = "https://github.com/skippbox/kompose"
app.EnableBashCompletion = true
app.Before = cliApp.BeforeApp
app.Before = command.BeforeApp
app.Flags = append(command.CommonFlags())
app.Commands = []cli.Command{
command.ConvertCommand(),
Copy link
Member

Choose a reason for hiding this comment

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

in command.BeforeApp you are counting on ConvertCommand being always in the first place here.
If you want it like that, here should be comment explaining that this cannot be moved.

Copy link
Member Author

Choose a reason for hiding this comment

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

I stuck to the way you did it, add the command itself in BeforeApp function, so this is not needed I think.

@surajssd
Copy link
Member Author

surajssd commented Oct 5, 2016

Changed it now to have new cli.Command altogether, so usage is changed, added new function that returns common flags.

$ kompose --provider=openshift convert -h
NAME:
    - Convert Docker Compose file (e.g. docker-compose.yml) to OpenShift objects

USAGE:
    [command options] [arguments...]

OPTIONS:
   --deploymentconfig, --dc     Generate a OpenShift DeploymentConfig object
   --out, -o                    Specify file name in order to save objects into [$OUTPUT_FILE]
   --replicas "1"               Specify the number of replicas in the generated resource spec (default 1)
   --yaml, -y                   Generate resource file in yaml format
   --stdout                     Print converted objects to stdout

Copy link
Member

@kadel kadel left a comment

Choose a reason for hiding this comment

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

LGTM. Great work @surajssd 🎉

It would be great if @sebgoa or @ngtuna also look at this before it gets merged.

return command
}

func commonConvertFlags() []cli.Flag {
Copy link
Member

Choose a reason for hiding this comment

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

👍

@surajssd
Copy link
Member Author

surajssd commented Oct 5, 2016

@kadel sure will wait for @sebgoa or @ngtuna to try it out once! Thanks for reviews and pointers!

@ngtuna
Copy link
Contributor

ngtuna commented Oct 5, 2016

Great work @surajssd 👍 I will try it today. Thanks

@ngtuna
Copy link
Contributor

ngtuna commented Oct 5, 2016

Hey @surajssd, at first test I see $ kompose --help lists out up and down command only. Convert is missing.

$ kompose --help
...
COMMANDS:
    up      Deploy your Dockerized application to Kubernetes (default: creating Kubernetes deployment and service)
    down    Delete instantiated services/deployments from kubernetes
...

@ngtuna
Copy link
Contributor

ngtuna commented Oct 5, 2016

Otherwise LGTM. I like the idea of changing usage between providers 💯

@ngtuna
Copy link
Contributor

ngtuna commented Oct 5, 2016

Then provider owners have their own space to arrange outputs.

Now a user can select a provider using global flag
--provider=openshift to select openshift provider
or --provider-kubernetes to select kubernetes provider
if nothing is provided kubernetes is the default provider.

Fixes kubernetes#179
@surajssd
Copy link
Member Author

surajssd commented Oct 6, 2016

@ngtuna nice catch about convert not being visible. Made changes accordingly here https://github.com/skippbox/kompose/pull/182/files#diff-3145698b159fb0a026984b4a017a8b24R67 also added note here https://github.com/skippbox/kompose/pull/182/files#diff-d9814220427d68b7f7ade416b1440032R38

@surajssd
Copy link
Member Author

surajssd commented Oct 6, 2016

And also it shows up under help

$ kompose -h
NAME:
[SNIP]
   Skippbox Kompose Contributors <https://github.com/skippbox/kompose> 

COMMANDS:
    convert     Convert Docker Compose file (e.g. docker-compose.yml) to Kubernetes/OpenShift objects
    up          Deploy your Dockerized application to Kubernetes (default: creating Kubernetes deployment and service)
    down        Delete instantiated services/deployments from kubernetes

GLOBAL OPTIONS:
[SNIP]

@ngtuna
Copy link
Contributor

ngtuna commented Oct 6, 2016

Thanks @surajssd . Merging now for the release tonight.

@ngtuna ngtuna merged commit fbfdb75 into kubernetes:master Oct 6, 2016
@surajssd
Copy link
Member Author

surajssd commented Oct 7, 2016

Thanks @ngtuna !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants