-
Notifications
You must be signed in to change notification settings - Fork 769
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
Failing when port is specified with labels #590
Conversation
pkg/loader/compose/compose.go
Outdated
@@ -358,6 +358,12 @@ func (c *Compose) LoadFile(files []string) (kobject.KomposeObject, error) { | |||
} | |||
} | |||
|
|||
if len(serviceConfig.Port) == 0 { | |||
if composeServiceConfig.Labels["kompose.service.type"] == "NodePort" || composeServiceConfig.Labels["kompose.service.type"] == "LoadBalancer" { |
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.
Why are there nested if's?
Shouldn't it be: if len(serviceConfig.Port) == 0 && composeServiceConfig.Labels["kompose.service.type"] == "NodePort" || composeServiceConfig.Labels["kompose.service.type"] == "LoadBalancer"
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.
done
pkg/loader/compose/compose.go
Outdated
@@ -358,6 +358,11 @@ func (c *Compose) LoadFile(files []string) (kobject.KomposeObject, error) { | |||
} | |||
} | |||
|
|||
if len(serviceConfig.Port) == 0 && composeServiceConfig.Labels["kompose.service.type"] == "NodePort" || composeServiceConfig.Labels["kompose.service.type"] == "LoadBalancer" { | |||
log.Fatal("Failed to proceed as Nodeport or loadbalancer is defined without ports") |
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.
Was just thinking again (sorry for asking for another change) that this could be better:
log.Fatal("%s defined with no ports present. Issues may occur when bringing up artifacts.", composeServiceConfig.Labels["kompose.service.type"])
And also change this log to warning instead? What do you think @kadel ?
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.
log message is okay but giving warning instead of FATAL is of no use
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.
@surajnarwade I think it should still convert.. Let's wait for @kadel 's opinion 👍
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 think @kadel made it clear that we should fail here #522 (comment)
yes, that makes sense, we should fail, as it doesn't make sense to use NodePort or LoadBalancer without port defined.
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.
Please update the messge though!
pkg/loader/compose/compose.go
Outdated
@@ -358,6 +358,11 @@ func (c *Compose) LoadFile(files []string) (kobject.KomposeObject, error) { | |||
} | |||
} | |||
|
|||
if len(serviceConfig.Port) == 0 && composeServiceConfig.Labels["kompose.service.type"] == "NodePort" || composeServiceConfig.Labels["kompose.service.type"] == "LoadBalancer" { | |||
log.Fatal("Failed to proceed as Nodeport or loadbalancer is defined without ports") | |||
|
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.
nit: remove blank line
@surajnarwade tests and docs update |
pkg/loader/compose/compose.go
Outdated
@@ -358,6 +358,10 @@ func (c *Compose) LoadFile(files []string) (kobject.KomposeObject, error) { | |||
} | |||
} | |||
|
|||
if len(serviceConfig.Port) == 0 && composeServiceConfig.Labels["kompose.service.type"] == "NodePort" || composeServiceConfig.Labels["kompose.service.type"] == "LoadBalancer" { | |||
log.Fatalf("%s defined with no ports present. Issues may occur when bringing up artifacts.", composeServiceConfig.Labels["kompose.service.type"]) |
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.
Also this one does not tell which docker-compose service has that label and no port defined together?
pkg/loader/compose/compose.go
Outdated
@@ -358,6 +358,10 @@ func (c *Compose) LoadFile(files []string) (kobject.KomposeObject, error) { | |||
} | |||
} | |||
|
|||
if len(serviceConfig.Port) == 0 && composeServiceConfig.Labels["kompose.service.type"] == "NodePort" || composeServiceConfig.Labels["kompose.service.type"] == "LoadBalancer" { | |||
log.Fatalf("In %s service, %s defined with no ports present. Issues may occur when bringing up artifacts.", name, composeServiceConfig.Labels["kompose.service.type"]) |
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.
In %s service
isn't grammatically correct.
My previous comment may work a bit better:
log.Fatal("%s defined in service %s with no ports present. Issues may occur when bringing up artifacts.", composeServiceConfig.Labels["kompose.service.type"], name)
a825926
to
8198246
Compare
LGTM 👍 |
@surajnarwade tests and docs update |
Would it be better if it return error here and leave the Fatalf() work to upper layer? |
@gitlawr , |
@surajnarwade
instead of
|
pkg/loader/compose/compose.go
Outdated
@@ -359,6 +359,10 @@ func (c *Compose) LoadFile(files []string) (kobject.KomposeObject, error) { | |||
} | |||
} | |||
|
|||
err = checkLabelsPorts(len(serviceConfig.Port), composeServiceConfig.Labels["kompose.service.type"], name) | |||
if err != nil { | |||
log.Fatal(err) |
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.
Let's not use log.Fatal
, instead wrap the error and pass it up the call stack. Use errors.Wrap
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.
what @containscafeine said ;-)
pkg/loader/compose/compose.go
Outdated
|
||
func checkLabelsPorts(noOfPort int, labels string, svcName string) error { | ||
if noOfPort == 0 && labels == "NodePort" || labels == "LoadBalancer" { | ||
return errors.Errorf("%s defined in service %s with no ports present. Issues may occur when bringing up artifacts.", labels, svcName) |
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.
Let's wrap it using errors.Wrap
to maintain consistency throughout the code.
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.
@surajnarwade if there is nothing to wrap, use errors.New()
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.
@containscafeine , I have variable in my error message. so I used errors.Errorf()
instead of errors.New()
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.
Gotcha
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.
Let's change message a bit. It is not possible to create Headless service with type NodePort or LoadBalancer.
The Message should be more definite.
For example something in those lines:
"kompose.service.type can't be set if service doesn't expose any ports."
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.
added message
6e07ead
to
8a8ac81
Compare
@surajssd , needs review on this |
@surajnarwade bear with me, also please add functional tests! so when I meant tests == (unit tests and functional tests) |
pkg/loader/compose/compose.go
Outdated
@@ -363,6 +363,10 @@ func (c *Compose) LoadFile(files []string) (kobject.KomposeObject, error) { | |||
} | |||
} | |||
|
|||
err1 := checkLabelsPorts(len(serviceConfig.Port), composeServiceConfig.Labels["kompose.service.type"], name) |
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.
err1? that's not a good name for a variable. Please use err
.
pkg/loader/compose/compose.go
Outdated
@@ -363,6 +363,10 @@ func (c *Compose) LoadFile(files []string) (kobject.KomposeObject, error) { | |||
} | |||
} | |||
|
|||
err1 := checkLabelsPorts(len(serviceConfig.Port), composeServiceConfig.Labels["kompose.service.type"], name) | |||
if err1 != nil { | |||
return kobject.KomposeObject{}, errors.Wrap(err, err1.Error()) |
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.
what's going on here? for errors.Wrap it should be `errors.Wrap(err, "Your error message here") or something along the lines.
pkg/loader/compose/compose.go
Outdated
@@ -359,6 +359,10 @@ func (c *Compose) LoadFile(files []string) (kobject.KomposeObject, error) { | |||
} | |||
} | |||
|
|||
err = checkLabelsPorts(len(serviceConfig.Port), composeServiceConfig.Labels["kompose.service.type"], name) | |||
if err != nil { | |||
log.Fatal(err) |
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.
what @containscafeine said ;-)
pkg/loader/compose/compose.go
Outdated
|
||
func checkLabelsPorts(noOfPort int, labels string, svcName string) error { | ||
if noOfPort == 0 && labels == "NodePort" || labels == "LoadBalancer" { | ||
return errors.Errorf("%s defined in service %s with no ports present. Issues may occur when bringing up artifacts.", labels, svcName) |
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.
Let's change message a bit. It is not possible to create Headless service with type NodePort or LoadBalancer.
The Message should be more definite.
For example something in those lines:
"kompose.service.type can't be set if service doesn't expose any ports."
docs/user-guide.md
Outdated
|
||
#### Warning about Labels | ||
|
||
`kompose.service.type` label should be defined with `ports` only, otherwise `kompose` will fail. |
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 should be added under the labels
section, not at the end of the user-guide file, otherwise, PR LGTM.
642406a
to
5ccc7cd
Compare
@cdrage review please :) |
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!
docs/user-guide.md
Outdated
@@ -401,3 +402,5 @@ If the Docker Compose file has a volume specified for a service, the Deployment | |||
If the Docker Compose file has service name with `_` in it (eg.`web_service`), then it will be replaced by `-` and the service name will be renamed accordingly (eg.`web-service`). Kompose does this because "Kubernetes" doesn't allow `_` in object name. | |||
|
|||
Please note that changing service name might break some `docker-compose` files. | |||
|
|||
|
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.
Remove extra newlines, update PR, then go-ahead and merge!
Resolves kubernetes#522 Kompose will give FATAL error if labels are given but ports are not defined
Resolves #522
Kompose will give FATAL error if labels are given but ports are not defined