You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by la...@apache.org on 2015/08/12 13:27:44 UTC

stratos git commit: STRATOS-1495 - create kubernetes services and port mappings once

Repository: stratos
Updated Branches:
  refs/heads/master 0eacfad93 -> ab9fed70a


STRATOS-1495 - create kubernetes services and port mappings once


Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/ab9fed70
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/ab9fed70
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/ab9fed70

Branch: refs/heads/master
Commit: ab9fed70a2cab054d33e346aa0930d3ce1570a17
Parents: 0eacfad
Author: lasinducharith <la...@gmail.com>
Authored: Wed Aug 12 16:57:16 2015 +0530
Committer: lasinducharith <la...@gmail.com>
Committed: Wed Aug 12 16:57:16 2015 +0530

----------------------------------------------------------------------
 .../iaases/kubernetes/KubernetesIaas.java       | 39 +++++++++++++++-----
 1 file changed, 29 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/ab9fed70/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/kubernetes/KubernetesIaas.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/kubernetes/KubernetesIaas.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/kubernetes/KubernetesIaas.java
index 820140b..149ac42 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/kubernetes/KubernetesIaas.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/kubernetes/KubernetesIaas.java
@@ -525,9 +525,18 @@ public class KubernetesIaas extends Iaas {
                 String containerPortName = KubernetesIaasUtil.preparePortNameFromPortMapping(clusterPortMapping);
 
                 try {
-                    // Services need to use minions private IP addresses for creating iptable rules
-                    kubernetesApi.createService(serviceId, serviceLabel, servicePort, serviceType, containerPortName,
-                            containerPort, sessionAffinity);
+                    // If kubernetes service is already created, skip creating a new one
+                    if (kubernetesApi.getService(serviceId) == null) {
+                        // Services need to use minions private IP addresses for creating iptable rules
+                        kubernetesApi.createService(serviceId, serviceLabel, servicePort, serviceType, containerPortName,
+                                containerPort, sessionAffinity);
+                    } else {
+                        if (log.isDebugEnabled()) {
+                            log.debug(String.format("Kubernetes service is already created: [cluster] %s [service] %s " +
+                                            "[protocol] %s [service-port] %d [container-port] %d", clusterId,
+                                    serviceId, clusterPortMapping.getProtocol(), servicePort, containerPort));
+                        }
+                    }
                 } finally {
                     // Persist kubernetes service sequence no
                     CloudControllerContext.getInstance().persist();
@@ -622,15 +631,25 @@ public class KubernetesIaas extends Iaas {
                     String serviceType = portMapping.getKubernetesPortType();
                     clusterPortMapping.setKubernetesServiceType(serviceType);
 
-                    if (serviceType.equals(KubernetesConstants.NODE_PORT)) {
-                        int nextServicePort = kubernetesClusterContext.getNextServicePort();
-                        if (nextServicePort == -1) {
-                            throw new RuntimeException(String.format("Could not generate service port: [cluster-id] %s " +
-                                    "[port] %d", clusterId, portMapping.getPort()));
+                    //If kubernetes service port is already set, skip setting a new one
+                    if (clusterPortMapping.getKubernetesServicePort() == 0) {
+                        if (serviceType.equals(KubernetesConstants.NODE_PORT)) {
+                            int nextServicePort = kubernetesClusterContext.getNextServicePort();
+                            if (nextServicePort == -1) {
+                                throw new RuntimeException(String.format("Could not generate service port: [cluster-id] %s " +
+                                        "[port] %d", clusterId, portMapping.getPort()));
+                            }
+                            clusterPortMapping.setKubernetesServicePort(nextServicePort);
+                        } else {
+                            clusterPortMapping.setKubernetesServicePort(portMapping.getPort());
                         }
-                        clusterPortMapping.setKubernetesServicePort(nextServicePort);
                     } else {
-                        clusterPortMapping.setKubernetesServicePort(portMapping.getPort());
+                        if (log.isDebugEnabled()) {
+                            log.debug(String.format("Kubernetes service port is already set: [application-id] %s " +
+                                            "[cluster-id] %s [port] %d [service-port] %d",
+                                    applicationId, clusterId, clusterPortMapping.getPort(),
+                                    clusterPortMapping.getKubernetesServicePort()));
+                        }
                     }
 
                     // Add port mappings to payload