-
Notifications
You must be signed in to change notification settings - Fork 772
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
Conversation
if |
5e21507
to
94f4352
Compare
@@ -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:""` |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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!
There was a problem hiding this 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:""` |
There was a problem hiding this comment.
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.
replicas
keys in v3replicas
keys in v3
deb7f00
to
ebd4b0b
Compare
@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 { |
There was a problem hiding this comment.
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 {
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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!
replicas
keys in v3replicas
keys in v3
ebd4b0b
to
f09ecce
Compare
@cdrage added changes as per your suggestions, please review :) |
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
resolves kubernetes#644 `replicas` key
f09ecce
to
041d7f7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
resolves #644
replicas
key