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

Handle Headless Services when no ports are present #157

Merged
merged 4 commits into from
Jan 25, 2017

Conversation

sebgoa
Copy link
Contributor

@sebgoa sebgoa commented Sep 16, 2016

Addresses #146

@kadel
Copy link
Member

kadel commented Sep 19, 2016

When I tried that I got error:

time="2016-09-19T13:47:10+02:00" level=warning msg="[redis] No ports defined, we will create a Headless service." 
error validating "STDIN": error validating data: found invalid field portalIP for v1.ServiceSpec; if you choose to ignore these errors, turn validation off with --validate=false

When I removed portalIP from generated service everything worked fine.

@sebgoa
Copy link
Contributor Author

sebgoa commented Sep 19, 2016

what compose file did you give it ?

@kadel
Copy link
Member

kadel commented Sep 19, 2016

version: "2"

services:
    web:
      image: tuna/docker-counter23
      ports:
        - "5000:5000"
      links:
        - redis
      networks:
        - default

    redis:
      image: redis:3.0
      networks: 
        - default

@kadel
Copy link
Member

kadel commented Sep 27, 2016

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.
Problem is that they added this for backward compatibility :-(
Result of this is that Services with PortalIP can be deployed to OpenShift but it fails on 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{}
Copy link
Member

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)

Copy link
Contributor Author

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

@kadel
Copy link
Member

kadel commented Oct 17, 2016

I just tested this with newer openshift version and PortalIP is gone.
OpenShift and K8S upgrade is part of #200. As soon as #200 get merged we can merge this.

@surajssd
Copy link
Member

And #200 is merged!

@sebgoa
Copy link
Contributor Author

sebgoa commented Oct 18, 2016

and we are stuck on my CLA, even though I can probably override this...

@sebgoa
Copy link
Contributor Author

sebgoa commented Oct 18, 2016

I will rebase tomorrow anyway

@sebgoa sebgoa force-pushed the headless branch 2 times, most recently from 1c2ea54 to 34676e4 Compare October 19, 2016 15:09
@ngtuna
Copy link
Contributor

ngtuna commented Nov 2, 2016

@sebgoa could you check the failed test-cases ? That would be great to introduce handless svc support at kubecon talk.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Nov 29, 2016
@sebgoa
Copy link
Contributor Author

sebgoa commented Nov 29, 2016

@kadel @surajssd you want to have a look at this ? I fixed the headless stuff, it is rebased...

@sebgoa
Copy link
Contributor Author

sebgoa commented Nov 29, 2016

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)
Copy link
Member

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'.

Copy link
Member

@kadel kadel left a 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
Copy link
Member

kadel commented Jan 3, 2017

I've rebased this and added headless services for OpenShift.

ping @sebgoa @ngtuna

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.7%) to 45.9% when pulling 425df63 on sebgoa:headless into b059c44 on kubernetes-incubator:master.

@ngtuna
Copy link
Contributor

ngtuna commented Jan 3, 2017

👍 @kadel Could you add an unit test for this ?

@kadel
Copy link
Member

kadel commented Jan 4, 2017

Of course

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.7%) to 45.9% when pulling ff8d656 on sebgoa:headless into 6e260ba on kubernetes-incubator:master.

import "testing"

func TestCompareUpAndConvert(t *testing.T) {
}
Copy link
Member

Choose a reason for hiding this comment

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

blank test, wut

Copy link
Member

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)
Copy link
Member

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.

Copy link
Member

@kadel kadel Jan 23, 2017

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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 {
Copy link
Member

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.

Copy link
Member

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)
}

}
Copy link
Member

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
}
Copy link
Member

@cdrage cdrage Jan 23, 2017

Choose a reason for hiding this comment

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

👍

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

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 👍

Copy link
Member

Choose a reason for hiding this comment

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

ok 😉

@kadel kadel force-pushed the headless branch 4 times, most recently from f3146a2 to 2af2427 Compare January 25, 2017 09:23
@kadel kadel merged commit 5383914 into kubernetes:master Jan 25, 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 review needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants