-
Notifications
You must be signed in to change notification settings - Fork 770
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
Handle Headless Services when no ports are present #157
Conversation
When I tried that I got error:
When I removed |
what compose file did you give it ? |
|
I've done some digging around to figure out where PortalIP is coming from, because PortalIP is old deprecated name for ClusterIP. Because of OpenShift we are using Kubernetes from openshift/kubernetes. We need to figure the way how to use upstream Kubernetes for Kubernetes conversion. But I don't have idea how to do it :-( OpenShift is not doing import rewrite so it includes k8s.io/kubernetes but expect this to be their fork of k8s from openshift/kubernetes :-( |
func CreateHeadlessService(name string, service kobject.ServiceConfig, objects []runtime.Object) *api.Service { | ||
svc := InitSvc(name, service) | ||
|
||
servicePorts := []api.ServicePort{} |
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 believe a tab is missing here (needs to be ran through gofmt)
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.
fixing in next push, thanks
And #200 is merged! |
and we are stuck on my CLA, even though I can probably override this... |
I will rebase tomorrow anyway |
1c2ea54
to
34676e4
Compare
@sebgoa could you check the failed test-cases ? That would be great to introduce handless svc support at kubecon talk. |
ok tests fixed |
@@ -230,7 +230,7 @@ func convertToVersion(obj runtime.Object, groupVersion unversioned.GroupVersion) | |||
|
|||
func (k *Kubernetes) PortsExist(name string, service kobject.ServiceConfig) bool { | |||
if len(service.Port) == 0 { | |||
logrus.Warningf("[%s] Service cannot be created because of missing port.", name) | |||
logrus.Warningf("[%s] No ports defined, we will create a Headless service.", 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.
Logging output could be better. If I was the user, I wouldn't understand what "headless" means. I don't think it should be capitalized either. http://kubernetes.io/docs/user-guide/services/#headless-services
Perhaps: No ports are defined. A headless service will be created. Load-balancing will not be enabled and cluster IP will be set to 'None'.
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 should do this also for openshift.
Right now it displays warning that headless service will be created but no service is actually created.
Adding the same three lines to openshfit.go
as in kubernetes.go
should fix it.
+ } else {
+ svc := o.CreateHeadlessService(name, service, objects)
+ objects = append(objects, svc)
👍 @kadel Could you add an unit test for this ? |
Of course |
import "testing" | ||
|
||
func TestCompareUpAndConvert(t *testing.T) { | ||
} |
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.
blank test, wut
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.
removing :-) that mistake, you were faster than me :-)
@@ -258,7 +258,7 @@ func convertToVersion(obj runtime.Object, groupVersion unversioned.GroupVersion) | |||
// PortsExist checks if service has ports defined | |||
func (k *Kubernetes) PortsExist(name string, service kobject.ServiceConfig) bool { | |||
if len(service.Port) == 0 { | |||
logrus.Warningf("[%s] Service cannot be created because of missing port.", name) | |||
logrus.Warningf("[%s] No ports defined, we will create a Headless service.", 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.
Still need to be fixed :( I think the log can be more explicit.
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 know :-( But I don't have anything short, that might be more helpful :-(
Ideally it should be just one sentence.
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.
Does user even cares about this?
Maybe we can get rid of this message completely.
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.
@kadel I agree. Removing the log would be best, or adding it to Debug instead. If a port isn't passed, it's assumed to be headless anyways.
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,
changed to debug
@@ -282,6 +282,27 @@ func (k *Kubernetes) CreateService(name string, service kobject.ServiceConfig, o | |||
return svc | |||
} | |||
|
|||
// CreateHeadlessService creates a k8s headless service | |||
func (k *Kubernetes) CreateHeadlessService(name string, service kobject.ServiceConfig, objects []runtime.Object) *api.Service { |
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 is a 'Headless' service? I know what it means, but perhaps adding a comment to the kubernetes documentation may help.
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.
Update, I've tried explain why we use Headless services in comment
t.Error(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.
👍
svc.ObjectMeta.Annotations = annotations | ||
|
||
return svc | ||
} |
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.
❓
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.
woops, that was suppose to be a 👍
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.
ok 😉
f3146a2
to
2af2427
Compare
Addresses #146