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

Add deploy: mode: global support #771

Merged
merged 1 commit into from Aug 24, 2017
Merged

Conversation

cdrage
Copy link
Member

@cdrage cdrage commented Aug 16, 2017

Adds support for deploy: mode.

For example:

version: "3"

services:
  foo:
    deploy:
      resources:
        mode: global
        replicas: 6
    image: redis

Will only generate replicas: 1 in Kubernetes pods as "global" limits
replicas to only one.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 16, 2017
@kompose-bot
Copy link
Collaborator

@cdrage, thank you for the pull request! We'll request some people to review your PR. @surajnarwade and @procrypt, please review this.

@surajnarwade
Copy link
Contributor

surajnarwade commented Aug 18, 2017

documentation of mode says global spin up exactly one container per swarm node, can we achieve same with kubernetes ?

@cdrage
Copy link
Member Author

cdrage commented Aug 18, 2017

@surajnarwade nope, unless it's a daemonset. For now it's just replicas: 1. I really want to add DaemonSet however.

But you are right.

@@ -496,6 +496,12 @@ func (k *Kubernetes) CreateKubernetesObjects(name string, service kobject.Servic
replica = service.Replicas
}

// Check to see if Docker Compose v3 Deploy.Mode has been set to "global"
if service.DeployMode == "global" {
log.Infof("Deploy mode has been set to global. Setting Kubernetes container replicas to 0 for service %s", name)
Copy link
Member

Choose a reason for hiding this comment

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

Message says replicas to 0 but it sets replicas to 1

services:
foo:
deploy:
resources:
Copy link
Member

Choose a reason for hiding this comment

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

mode: is not under resource but directly under deploy key and the same thing for replicas

# Test deploy mode: global
cmd="kompose convert --stdout -j -f $KOMPOSE_ROOT/script/test/fixtures/v3/docker-compose-deploy-mode.yaml"
sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" "$KOMPOSE_ROOT/script/test/fixtures/v3/output-deploy-mode-k8s-template.json" > /tmp/output-k8s.json
convert::expect_success "kompose convert --stdout -j -f $KOMPOSE_ROOT/script/test/fixtures/v3/docker-compose-deploy-mode.yaml" "/tmp/output-k8s.json"
Copy link
Member

Choose a reason for hiding this comment

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

use convert::expect_success_and_warning to also check warning to avoid false positives with the wrong docker compose file

@cdrage
Copy link
Member Author

cdrage commented Aug 22, 2017

Thanks @kadel I've gone ahead and implemented the changes.

deploy:
mode: global
resources:
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.

there is not replicas in the resources field ;-)

Copy link
Member Author

Choose a reason for hiding this comment

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

Woops, again another error!

@@ -496,6 +496,12 @@ func (k *Kubernetes) CreateKubernetesObjects(name string, service kobject.Servic
replica = service.Replicas
}

// Check to see if Docker Compose v3 Deploy.Mode has been set to "global"
if service.DeployMode == "global" {
log.Infof("Deploy mode has been set to global. Setting Kubernetes container replicas to 1 for service %s", name)
Copy link
Member

Choose a reason for hiding this comment

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

Isn't it a bit confusing to display this message even if replicas are set to 1 or if replicas is not set?

Copy link
Member Author

Choose a reason for hiding this comment

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

By default DeployMode is "replicated" so this will only be shown when "global" is selected. Should we remove this all-together?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I see what you mean now. Updated!

@cdrage cdrage force-pushed the add-global branch 2 times, most recently from 7305018 to 7594b58 Compare August 23, 2017 15:38
@cdrage
Copy link
Member Author

cdrage commented Aug 23, 2017

Again, another mistake and tests failed. But fixed with @kadel 's suggestions.

Ready for another review!

if opt.IsReplicaSetFlag || service.Replicas == 0 {
replica = opt.Replicas
} else {
replica = service.Replicas
}

// Check to see if Docker Compose v3 Deploy.Mode has been set to "global"
if service.DeployMode == "global" {
log.Infof("Global mode has been set. Containers will only be replicated once throughout the cluster")
Copy link
Member

Choose a reason for hiding this comment

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

This message is still weird. It doesn't say what it does.
For kubernetes Kompose is ignoring global mode, Kompose just creates regular Deployment with one replica.

So this is not what global mode should do. Should this message just say that global mode is not supported and that regular deployment will be created?

Copy link
Member Author

Choose a reason for hiding this comment

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

@kadel In the future when we add DaemonSet we could switch it to use that, as that is better reflection on how this should work (one container per node).

Would it be better to output a warning saying that Global is not support, but replicas will be set to 1?

Copy link
Member

Choose a reason for hiding this comment

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

Would it be better to output a warning saying that Global is not support, but replicas will be set to 1?

Yes , I think this would be the best.

We can remove it once we start doing the DaemonSet thing. ( automatically using DaemonSets for services with global mode.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Luckily I doubt many people use global. So for now let's output the warning and put up an issue to eventually have it switch to daemonset

Adds support for deploy: mode.

For example:

```yaml
version: "3"

services:
  foo:
    deploy:
      resources:
        mode: global
        replicas: 6
    image: redis
```

Will only generate replicas: 1 in Kubernetes pods as "global" limits
replicas to only one.
@cdrage
Copy link
Member Author

cdrage commented Aug 23, 2017

@kadel Updated with the new warning message

@kadel kadel merged commit 2ff2d38 into kubernetes:master Aug 24, 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. rebase needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants