Skip to content

Commit

Permalink
Merge pull request #169 from arangodb/bugfix/remove-service-stickyness
Browse files Browse the repository at this point in the history
Remove service stickyness
  • Loading branch information
ewoutp authored Jun 11, 2018
2 parents 1aa8ce3 + 5a3c5c1 commit 7876070
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
13 changes: 4 additions & 9 deletions pkg/deployment/resources/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,15 @@ func (r *Resources) EnsureServices() error {
if single {
role = "single"
}
sessionAffinity := v1.ServiceAffinityClientIP
if err := r.ensureExternalAccessServices(eaServiceName, ns, role, "database", k8sutil.ArangoPort, false, sessionAffinity, spec.ExternalAccess, apiObject, log, kubecli); err != nil {
if err := r.ensureExternalAccessServices(eaServiceName, ns, role, "database", k8sutil.ArangoPort, false, spec.ExternalAccess, apiObject, log, kubecli); err != nil {
return maskAny(err)
}

if spec.Sync.IsEnabled() {
// External (and internal) Sync master service
eaServiceName := k8sutil.CreateSyncMasterClientServiceName(apiObject.GetName())
role := "syncmaster"
sessionAffinity := v1.ServiceAffinityNone
if err := r.ensureExternalAccessServices(eaServiceName, ns, role, "sync", k8sutil.ArangoSyncMasterPort, true, sessionAffinity, spec.Sync.ExternalAccess.ExternalAccessSpec, apiObject, log, kubecli); err != nil {
if err := r.ensureExternalAccessServices(eaServiceName, ns, role, "sync", k8sutil.ArangoSyncMasterPort, true, spec.Sync.ExternalAccess.ExternalAccessSpec, apiObject, log, kubecli); err != nil {
return maskAny(err)
}
status := r.context.GetStatus()
Expand All @@ -103,7 +101,7 @@ func (r *Resources) EnsureServices() error {
}

// EnsureServices creates all services needed to service the deployment
func (r *Resources) ensureExternalAccessServices(eaServiceName, ns, svcRole, title string, port int, noneIsClusterIP bool, sessionAffinity v1.ServiceAffinity, spec api.ExternalAccessSpec, apiObject k8sutil.APIObject, log zerolog.Logger, kubecli kubernetes.Interface) error {
func (r *Resources) ensureExternalAccessServices(eaServiceName, ns, svcRole, title string, port int, noneIsClusterIP bool, spec api.ExternalAccessSpec, apiObject k8sutil.APIObject, log zerolog.Logger, kubecli kubernetes.Interface) error {
// Database external access service
createExternalAccessService := false
deleteExternalAccessService := false
Expand Down Expand Up @@ -170,10 +168,7 @@ func (r *Resources) ensureExternalAccessServices(eaServiceName, ns, svcRole, tit
// Let's create or update the database external access service
nodePort := spec.GetNodePort()
loadBalancerIP := spec.GetLoadBalancerIP()
if eaServiceType == v1.ServiceTypeLoadBalancer {
sessionAffinity = v1.ServiceAffinityNone
}
_, newlyCreated, err := k8sutil.CreateExternalAccessService(kubecli, eaServiceName, svcRole, apiObject, eaServiceType, port, nodePort, loadBalancerIP, sessionAffinity, apiObject.AsOwner())
_, newlyCreated, err := k8sutil.CreateExternalAccessService(kubecli, eaServiceName, svcRole, apiObject, eaServiceType, port, nodePort, loadBalancerIP, apiObject.AsOwner())
if err != nil {
log.Debug().Err(err).Msgf("Failed to create %s external access service", title)
return maskAny(err)
Expand Down
13 changes: 5 additions & 8 deletions pkg/util/k8sutil/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ func CreateHeadlessService(kubecli kubernetes.Interface, deployment metav1.Objec
},
}
publishNotReadyAddresses := false
sessionAffinity := v1.ServiceAffinityNone
serviceType := v1.ServiceTypeClusterIP
newlyCreated, err := createService(kubecli, svcName, deploymentName, deployment.GetNamespace(), ClusterIPNone, "", serviceType, ports, "", publishNotReadyAddresses, sessionAffinity, owner)
newlyCreated, err := createService(kubecli, svcName, deploymentName, deployment.GetNamespace(), ClusterIPNone, "", serviceType, ports, "", publishNotReadyAddresses, owner)
if err != nil {
return "", false, maskAny(err)
}
Expand Down Expand Up @@ -98,9 +97,8 @@ func CreateDatabaseClientService(kubecli kubernetes.Interface, deployment metav1
role = "coordinator"
}
publishNotReadyAddresses := true
sessionAffinity := v1.ServiceAffinityClientIP
serviceType := v1.ServiceTypeClusterIP
newlyCreated, err := createService(kubecli, svcName, deploymentName, deployment.GetNamespace(), "", role, serviceType, ports, "", publishNotReadyAddresses, sessionAffinity, owner)
newlyCreated, err := createService(kubecli, svcName, deploymentName, deployment.GetNamespace(), "", role, serviceType, ports, "", publishNotReadyAddresses, owner)
if err != nil {
return "", false, maskAny(err)
}
Expand All @@ -111,7 +109,7 @@ func CreateDatabaseClientService(kubecli kubernetes.Interface, deployment metav1
// If the service already exists, nil is returned.
// If another error occurs, that error is returned.
// The returned bool is true if the service is created, or false when the service already existed.
func CreateExternalAccessService(kubecli kubernetes.Interface, svcName, role string, deployment metav1.Object, serviceType v1.ServiceType, port, nodePort int, loadBalancerIP string, sessionAffinity v1.ServiceAffinity, owner metav1.OwnerReference) (string, bool, error) {
func CreateExternalAccessService(kubecli kubernetes.Interface, svcName, role string, deployment metav1.Object, serviceType v1.ServiceType, port, nodePort int, loadBalancerIP string, owner metav1.OwnerReference) (string, bool, error) {
deploymentName := deployment.GetName()
ports := []v1.ServicePort{
v1.ServicePort{
Expand All @@ -122,7 +120,7 @@ func CreateExternalAccessService(kubecli kubernetes.Interface, svcName, role str
},
}
publishNotReadyAddresses := true
newlyCreated, err := createService(kubecli, svcName, deploymentName, deployment.GetNamespace(), "", role, serviceType, ports, loadBalancerIP, publishNotReadyAddresses, sessionAffinity, owner)
newlyCreated, err := createService(kubecli, svcName, deploymentName, deployment.GetNamespace(), "", role, serviceType, ports, loadBalancerIP, publishNotReadyAddresses, owner)
if err != nil {
return "", false, maskAny(err)
}
Expand All @@ -134,7 +132,7 @@ func CreateExternalAccessService(kubecli kubernetes.Interface, svcName, role str
// If another error occurs, that error is returned.
// The returned bool is true if the service is created, or false when the service already existed.
func createService(kubecli kubernetes.Interface, svcName, deploymentName, ns, clusterIP, role string, serviceType v1.ServiceType,
ports []v1.ServicePort, loadBalancerIP string, publishNotReadyAddresses bool, sessionAffinity v1.ServiceAffinity, owner metav1.OwnerReference) (bool, error) {
ports []v1.ServicePort, loadBalancerIP string, publishNotReadyAddresses bool, owner metav1.OwnerReference) (bool, error) {
labels := LabelsForDeployment(deploymentName, role)
svc := &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -153,7 +151,6 @@ func createService(kubecli kubernetes.Interface, svcName, deploymentName, ns, cl
Selector: labels,
ClusterIP: clusterIP,
PublishNotReadyAddresses: publishNotReadyAddresses,
SessionAffinity: sessionAffinity,
LoadBalancerIP: loadBalancerIP,
},
}
Expand Down

0 comments on commit 7876070

Please sign in to comment.