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

Set sesion affinity for coordinator #40

Merged
merged 2 commits into from
Mar 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions pkg/util/k8sutil/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ func CreateHeadlessService(kubecli kubernetes.Interface, deployment metav1.Objec
},
}
publishNotReadyAddresses := false
if err := createService(kubecli, svcName, deploymentName, deployment.GetNamespace(), ClusterIPNone, "", ports, publishNotReadyAddresses, owner); err != nil {
sessionAffinity := v1.ServiceAffinityNone
if err := createService(kubecli, svcName, deploymentName, deployment.GetNamespace(), ClusterIPNone, "", ports, publishNotReadyAddresses, sessionAffinity, owner); err != nil {
return "", maskAny(err)
}
return svcName, nil
Expand All @@ -87,7 +88,8 @@ func CreateDatabaseClientService(kubecli kubernetes.Interface, deployment metav1
role = "coordinator"
}
publishNotReadyAddresses := true
if err := createService(kubecli, svcName, deploymentName, deployment.GetNamespace(), "", role, ports, publishNotReadyAddresses, owner); err != nil {
sessionAffinity := v1.ServiceAffinityClientIP
if err := createService(kubecli, svcName, deploymentName, deployment.GetNamespace(), "", role, ports, publishNotReadyAddresses, sessionAffinity, owner); err != nil {
return "", maskAny(err)
}
return svcName, nil
Expand All @@ -107,7 +109,8 @@ func CreateSyncMasterClientService(kubecli kubernetes.Interface, deployment meta
},
}
publishNotReadyAddresses := true
if err := createService(kubecli, svcName, deploymentName, deployment.GetNamespace(), "", "syncmaster", ports, publishNotReadyAddresses, owner); err != nil {
sessionAffinity := v1.ServiceAffinityNone
if err := createService(kubecli, svcName, deploymentName, deployment.GetNamespace(), "", "syncmaster", ports, publishNotReadyAddresses, sessionAffinity, owner); err != nil {
return "", maskAny(err)
}
return svcName, nil
Expand All @@ -116,7 +119,8 @@ func CreateSyncMasterClientService(kubecli kubernetes.Interface, deployment meta
// createService prepares and creates a service in k8s.
// If the service already exists, nil is returned.
// If another error occurs, that error is returned.
func createService(kubecli kubernetes.Interface, svcName, deploymentName, ns, clusterIP, role string, ports []v1.ServicePort, publishNotReadyAddresses bool, owner metav1.OwnerReference) error {
func createService(kubecli kubernetes.Interface, svcName, deploymentName, ns, clusterIP, role string,
ports []v1.ServicePort, publishNotReadyAddresses bool, sessionAffinity v1.ServiceAffinity, owner metav1.OwnerReference) error {
labels := LabelsForDeployment(deploymentName, role)
svc := &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -134,6 +138,7 @@ func createService(kubecli kubernetes.Interface, svcName, deploymentName, ns, cl
Selector: labels,
ClusterIP: clusterIP,
PublishNotReadyAddresses: publishNotReadyAddresses,
SessionAffinity: sessionAffinity,
},
}
addOwnerRefToObject(svc.GetObjectMeta(), &owner)
Expand Down