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

Propagate underscore into valid name #509

Merged
merged 1 commit into from
Apr 3, 2017

Conversation

procrypt
Copy link
Contributor

@procrypt procrypt commented Mar 24, 2017

Now we can provide service name with _ in docker-compose files and they will by converted as - in the generated artifacts by kompose eg, if the service name in docker-compose file is "foo_bar" then it will be converted into "foo-bar" in the generated artifacts.

docker-compose.yml containing _ in service name.

version: "2"
services:
  web_service:
    image: tuna/docker-counter23:latest
    ports:
      - "5000:5000"
    links:
      - redis_service
  redis_service:
    image: redis:latest
    ports:
      - "6379"
$ kompose up
INFO[0000] Service name in docker-compose has been changed from "redis_service" to "redis-service" 
INFO[0000] Service name in docker-compose has been changed from "web_service" to "web-service" 

We are going to create Kubernetes Deployments, Services and PersistentVolumeClaims for your Dockerized application. 
If you need different kind of resources, use the 'kompose convert' and 'kubectl create -f' commands instead. 

INFO[0000] Successfully created Service: redis-service  
INFO[0000] Successfully created Service: web-service    
INFO[0000] Successfully created Deployment: redis-service 
INFO[0000] Successfully created Deployment: web-service 

Your application has been deployed to Kubernetes. You can run 'kubectl get deployment,svc,pods,pvc' for details.

docker-compose.yml without _ in service name.

version: "2"
services:
  web:
    image: tuna/docker-counter23:latest
    ports:
      - "5000:5000"
    links:
      - redis
  redis:
    image: redis:latest
    ports:
      - "6379"
$ kompose up
We are going to create Kubernetes Deployments, Services and PersistentVolumeClaims for your Dockerized application. 
If you need different kind of resources, use the 'kompose convert' and 'kubectl create -f' commands instead. 

INFO[0000] Successfully created Service: redis          
INFO[0000] Successfully created Service: web            
INFO[0000] Successfully created Deployment: redis       
INFO[0000] Successfully created Deployment: web         

Your application has been deployed to Kubernetes. You can run 'kubectl get deployment,svc,pods,pvc' for details.

cc: @kadel @cdrage
Fixes: #420

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 24, 2017
@procrypt procrypt force-pushed the propagate_underscore branch 2 times, most recently from 8d81b48 to afa0240 Compare March 24, 2017 04:30
@kadel
Copy link
Member

kadel commented Mar 27, 2017

We shouldn't do this in every place where name is used.
This should be fixed when docker-compose file is loaded into KObject. (https://github.com/kubernetes-incubator/kompose/blob/ec897ef50facdd1c2518cd074bf3b5fcc56bae7c/pkg/loader/compose/compose.go#L377)

Than you have to do it only once, and you can be sure that it will be correct in every place after that.

@procrypt procrypt force-pushed the propagate_underscore branch 6 times, most recently from b244494 to 94e6c7f Compare March 27, 2017 18:43
@procrypt
Copy link
Contributor Author

@kadel @surajssd Rebased and updated.

@@ -637,7 +637,7 @@ func (k *Kubernetes) Deploy(komposeObject kobject.KomposeObject, opt kobject.Con
if !opt.EmptyVols {
pvcStr = " and PersistentVolumeClaims "
}
fmt.Println("We are going to create Kubernetes Deployments, Services" + pvcStr + "for your Dockerized application. \n" +
fmt.Println("\nWe are going to create Kubernetes Deployments, Services" + pvcStr + "for your Dockerized application. \n" +
Copy link
Member

Choose a reason for hiding this comment

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

Remove the \n

This may be a good opportunity to change this into a log.Info instead of a Println.

@@ -374,7 +374,10 @@ func (c *Compose) LoadFile(files []string) (kobject.KomposeObject, error) {
serviceConfig.Tty = composeServiceConfig.Tty
serviceConfig.MemLimit = composeServiceConfig.MemLimit
serviceConfig.TmpFs = composeServiceConfig.Tmpfs
komposeObject.ServiceConfigs[name] = serviceConfig
komposeObject.ServiceConfigs[normalizeServiceNames(name)] = serviceConfig
if !reflect.DeepEqual(komposeObject.ServiceConfigs[normalizeServiceNames(name)], komposeObject.ServiceConfigs[name]) {
Copy link
Member

Choose a reason for hiding this comment

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

Should @procrypt add a test for this @kadel ?

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 Test are already there, the function normalizeServiceNames() was written by @surajssd but we never used it.
Tests for normalizeServiceNames().

Copy link
Member

Choose a reason for hiding this comment

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

@procrypt ah, makes sense!

Copy link
Member

Choose a reason for hiding this comment

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

That reflect seems little bit too much :-(
Can same think be done a bit easier without reflect and more readable?
Why compere whole struct? Comparing just names should be enough no?

@procrypt procrypt force-pushed the propagate_underscore branch 2 times, most recently from 4354b4f to 8d1f4bd Compare March 28, 2017 03:52
komposeObject.ServiceConfigs[name] = serviceConfig
komposeObject.ServiceConfigs[normalizeServiceNames(name)] = serviceConfig
if !reflect.DeepEqual(komposeObject.ServiceConfigs[normalizeServiceNames(name)], komposeObject.ServiceConfigs[name]) {
log.Infof("Service name in docker-compose has been changed from %c%s%c to %c%s%c", '"', name, '"', '"', normalizeServiceNames(name), '"')
Copy link
Member

Choose a reason for hiding this comment

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

if you want to print " in the output then you can use format specifier %q and get the same result, so you don't need to do the hack currently done!

Copy link
Member

Choose a reason for hiding this comment

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

This might help https://golang.org/pkg/fmt/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@surajssd 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.

LGTM

@procrypt procrypt force-pushed the propagate_underscore branch 2 times, most recently from faa8091 to fdb4878 Compare March 29, 2017 03:10
@procrypt
Copy link
Contributor Author

@kadel Updated 😉

@@ -374,7 +374,10 @@ func (c *Compose) LoadFile(files []string) (kobject.KomposeObject, error) {
serviceConfig.Tty = composeServiceConfig.Tty
serviceConfig.MemLimit = composeServiceConfig.MemLimit
serviceConfig.TmpFs = composeServiceConfig.Tmpfs
komposeObject.ServiceConfigs[name] = serviceConfig
komposeObject.ServiceConfigs[normalizeServiceNames(name)] = serviceConfig
if komposeObject.ServiceConfigs[normalizeServiceNames(name)].Image != komposeObject.ServiceConfigs[name].Image {
Copy link
Member

Choose a reason for hiding this comment

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

This confuses me a lot.
Why are you comparing Images?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kadel I didn't see that sorry, I have updated the PR.

Now we can provide service name with "_" in docker-compose files and they will by converted as "-" in the generated artifacts by kompose eg, if the service name in docker-compose file is "foo_bar" then it will be converted into "foo-bar" in the generated artifacts
@sylus
Copy link

sylus commented Apr 3, 2017

Excited for this to get in so can properly use kompose :) Thanks so much!

@kadel
Copy link
Member

kadel commented Apr 3, 2017

Excited for this to get in so can properly use kompose :) Thanks so much!

Just beware that in some cases this also renames dns name that points to renamed service. In some cases this can break communication between services :-(

@kadel kadel merged commit a24084d into kubernetes:master Apr 3, 2017
@@ -637,7 +637,7 @@ func (k *Kubernetes) Deploy(komposeObject kobject.KomposeObject, opt kobject.Con
if !opt.EmptyVols {
pvcStr = " and PersistentVolumeClaims "
}
fmt.Println("We are going to create Kubernetes Deployments, Services" + pvcStr + "for your Dockerized application. \n" +
log.Info("We are going to create Kubernetes Deployments, Services" + pvcStr + "for your Dockerized application. " +
Copy link
Member

Choose a reason for hiding this comment

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

IIRC It was purposefully kept as Println

Copy link
Member

Choose a reason for hiding this comment

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

@surajssd Why?

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

6 participants