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

Added support for replicas keys in v3 #664

Merged
merged 1 commit into from
Jul 6, 2017

Conversation

surajnarwade
Copy link
Contributor

resolves #644 replicas key

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 22, 2017
@surajnarwade
Copy link
Contributor Author

if replica is not mentioned in docker-compose file, it will look for --replicas

@surajnarwade surajnarwade force-pushed the add-replicas-v3 branch 2 times, most recently from 5e21507 to 94f4352 Compare June 22, 2017 05:18
@surajnarwade
Copy link
Contributor Author

@cdrage @kadel @procrypt, needs review :)

@@ -92,6 +92,7 @@ type ServiceConfig struct {
MemLimit yaml.MemStringorInt `compose:"mem_limit" bundle:""`
TmpFs []string `compose:"tmpfs" bundle:""`
Dockerfile string `compose:"dockerfile" bundle:""`
Replicas int `compose:"replicas" bundle:""`
Copy link
Member

Choose a reason for hiding this comment

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

We want to replicate how we do it similarly with kobject in libcompose / docker/cli.

I ask that you create a separate struct, similar to https://github.com/docker/cli/blob/master/cli/compose/types/types.go#L159 in order to implement the Deploy key.

Copy link
Member

Choose a reason for hiding this comment

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

Actually... this would be more difficult than it's worth. Ignore me! Leave this as it is 👍 Just add a test for testing replicas within deploy.

@@ -489,15 +489,21 @@ func (k *Kubernetes) ConfigEnvs(name string, service kobject.ServiceConfig) []ap
// CreateKubernetesObjects generates a Kubernetes artifact for each input type service
func (k *Kubernetes) CreateKubernetesObjects(name string, service kobject.ServiceConfig, opt kobject.ConvertOptions) []runtime.Object {
var objects []runtime.Object
var replica int
if service.Replicas == 0 {
replica = opt.Replicas
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't make sense. We should check to see if the default replicas value has been changed, rather than checking for 0.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't get it?

Copy link
Member

@cdrage cdrage Jun 23, 2017

Choose a reason for hiding this comment

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

We need to check if --replicas = VALUE has been passed in (which would override what we do here).

@@ -160,7 +160,7 @@
}
},
"spec": {
"replicas": 1,
"replicas": 6,
Copy link
Member

Choose a reason for hiding this comment

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

no need to change previous test. please include a NEW test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but its failing, that's why, changed. but it's replicas=6 in docker-compose v3 file ?

Copy link
Member

Choose a reason for hiding this comment

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

ah crap, i didn't realize that. thanks!

Copy link
Member

@cdrage cdrage left a comment

Choose a reason for hiding this comment

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

needs tests!

@@ -92,6 +92,7 @@ type ServiceConfig struct {
MemLimit yaml.MemStringorInt `compose:"mem_limit" bundle:""`
TmpFs []string `compose:"tmpfs" bundle:""`
Dockerfile string `compose:"dockerfile" bundle:""`
Replicas int `compose:"replicas" bundle:""`
Copy link
Member

Choose a reason for hiding this comment

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

Actually... this would be more difficult than it's worth. Ignore me! Leave this as it is 👍 Just add a test for testing replicas within deploy.

@surajnarwade surajnarwade changed the title Added support for replicas keys in v3 [WIP]Added support for replicas keys in v3 Jun 23, 2017
@surajnarwade surajnarwade force-pushed the add-replicas-v3 branch 3 times, most recently from deb7f00 to ebd4b0b Compare June 27, 2017 06:30
@surajnarwade
Copy link
Contributor Author

@cdrage review please as tests are added

@@ -192,6 +192,11 @@ func dockerComposeToKomposeMapping(composeObject *types.Config) (kobject.Kompose
serviceConfig.Command = composeServiceConfig.Entrypoint
serviceConfig.Args = composeServiceConfig.Command

//Handling replicas
if composeServiceConfig.Deploy.Replicas != nil {
Copy link
Member

Choose a reason for hiding this comment

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

no need to add != nil. Just leave as if composeServiceConfig.Deploy.Replicas {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cdrage thats not working as composeServiceConfig.Deploy.Replicas is not boolean but it's pointer

Copy link
Member

Choose a reason for hiding this comment

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

Ah, okay.

@@ -489,15 +489,23 @@ func (k *Kubernetes) ConfigEnvs(name string, service kobject.ServiceConfig) []ap
// CreateKubernetesObjects generates a Kubernetes artifact for each input type service
func (k *Kubernetes) CreateKubernetesObjects(name string, service kobject.ServiceConfig, opt kobject.ConvertOptions) []runtime.Object {
var objects []runtime.Object
var replica int
if opt.Replicas > 1 {
Copy link
Member

Choose a reason for hiding this comment

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

like what I mentioned before, would be better to do:

if opt.IsReplicaSetFlag {
  replica = opt.Replicas
}

So that means that if it has been changed from the default value, it'd pick it up, even if the user puts replicas=1.

You will have to add another flag similar to the other ones here: https://github.com/kubernetes-incubator/kompose/blob/master/cmd/convert.go#L84

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you mean something like this,

kompose convert --replicas=1 --replica-set

I am confused because, --replicas is int flag and what you are suggesting is boolean flag

Copy link
Member

@cdrage cdrage Jun 28, 2017

Choose a reason for hiding this comment

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

Yes, it is a boolean flag. We are checking if the default value has been changed, and if it has been changed, we MAKE SURE that we use opt.Replicas.

Currently, opt.Replicas only checks > 1. What if the user sets --replicas=1, but in the docker-compose.yaml file it has it set otherwise? The value from --replicas won't be used.

By checking to see if the default value has been changed, see: https://github.com/kubernetes-incubator/kompose/blob/master/cmd/convert.go#L84 we can make sure that the CLI paramter takes priority over the contents of the docker-compose.yaml file.


//replicas
var replica int
if opt.Replicas > 1 {
Copy link
Member

Choose a reason for hiding this comment

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

Similar to above comment in regards to kubernetes.go, make the changes here as well!

@surajnarwade surajnarwade changed the title [WIP]Added support for replicas keys in v3 Added support for replicas keys in v3 Jun 27, 2017
@surajnarwade
Copy link
Contributor Author

@cdrage added changes as per your suggestions, please review :)

Copy link
Member

@cdrage cdrage left a comment

Choose a reason for hiding this comment

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

Thanks for the changes!!!

LGTM!

@@ -489,15 +489,21 @@ func (k *Kubernetes) ConfigEnvs(name string, service kobject.ServiceConfig) []ap
// CreateKubernetesObjects generates a Kubernetes artifact for each input type service
func (k *Kubernetes) CreateKubernetesObjects(name string, service kobject.ServiceConfig, opt kobject.ConvertOptions) []runtime.Object {
var objects []runtime.Object
var replica int
if opt.IsReplicaSetFlag || service.Replicas == 0 {
replica = opt.Replicas
Copy link
Member

Choose a reason for hiding this comment

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

👍

@surajnarwade
Copy link
Contributor Author

@kadel @surajssd needed one more +1 here :)

Copy link
Member

@surajssd surajssd left a comment

Choose a reason for hiding this comment

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

LGTM

@surajssd surajssd merged commit 06543f7 into kubernetes:master Jul 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tracking card for new deploy keys in v3
4 participants