You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sh...@apache.org on 2019/06/14 09:42:48 UTC

[ignite] branch master updated: IGNITE-11771: adding the option to include pods with a not-ready state. - Fixes #6486

This is an automated email from the ASF dual-hosted git repository.

shroman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new 3a8ea33  IGNITE-11771: adding the option to include pods with a not-ready state. - Fixes #6486
3a8ea33 is described below

commit 3a8ea330dd5732579097788bba85eae0d1a98f33
Author: Balazs Peterfi <ba...@betvictor.com>
AuthorDate: Fri Jun 14 18:41:35 2019 +0900

    IGNITE-11771: adding the option to include pods with a not-ready state. - Fixes #6486
    
    Signed-off-by: shroman <rs...@yahoo.com>
---
 .../kubernetes/TcpDiscoveryKubernetesIpFinder.java | 70 +++++++++++++---------
 1 file changed, 43 insertions(+), 27 deletions(-)

diff --git a/modules/kubernetes/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/kubernetes/TcpDiscoveryKubernetesIpFinder.java b/modules/kubernetes/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/kubernetes/TcpDiscoveryKubernetesIpFinder.java
index e5f05ba..b24a972 100644
--- a/modules/kubernetes/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/kubernetes/TcpDiscoveryKubernetesIpFinder.java
+++ b/modules/kubernetes/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/kubernetes/TcpDiscoveryKubernetesIpFinder.java
@@ -17,6 +17,17 @@
 
 package org.apache.ignite.spi.discovery.tcp.ipfinder.kubernetes;
 
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.internal.IgniteInterruptedCheckedException;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.resources.LoggerResource;
+import org.apache.ignite.spi.IgniteSpiException;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinderAdapter;
+
+import javax.net.ssl.*;
 import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.net.URL;
@@ -29,21 +40,6 @@ import java.util.Collection;
 import java.util.List;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.atomic.AtomicBoolean;
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSession;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.X509TrustManager;
-import org.apache.ignite.IgniteLogger;
-import org.apache.ignite.internal.IgniteInterruptedCheckedException;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.resources.LoggerResource;
-import org.apache.ignite.spi.IgniteSpiException;
-import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinderAdapter;
 
 /**
  * IP finder for automatic lookup of Ignite nodes running in Kubernetes environment. All Ignite nodes have to deployed
@@ -69,6 +65,7 @@ import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinderAdapter;
  *      <li>The Kubernetes service namespace for IP addresses lookup (see {@link #setNamespace(String)}</li>
  *      <li>The host name of the Kubernetes API server (see {@link #setMasterUrl(String)})</li>
  *      <li>Path to the service token (see {@link #setAccountToken(String)}</li>
+ *      <li>To include not-ready pods (see {@link #includeNotReadyAddresses(boolean)}</li>
  * </ul>
  * <p>
  * Both {@link #registerAddresses(Collection)} and {@link #unregisterAddresses(Collection)} have no effect.
@@ -124,6 +121,9 @@ public class TcpDiscoveryKubernetesIpFinder extends TcpDiscoveryIpFinderAdapter
     /** SSL context */
     private SSLContext ctx;
 
+    /** Whether addresses of pods in not-ready state should be included. */
+    private boolean includeNotReadyAddresses;
+
     /**
      * Creates an instance of Kubernetes IP finder.
      */
@@ -153,19 +153,12 @@ public class TcpDiscoveryKubernetesIpFinder extends TcpDiscoveryIpFinderAdapter
 
             Endpoints endpoints = mapper.readValue(conn.getInputStream(), Endpoints.class);
 
-            if (endpoints != null) {
-                if (endpoints.subsets != null && !endpoints.subsets.isEmpty()) {
-                    for (Subset subset : endpoints.subsets) {
-
-                        if (subset.addresses != null && !subset.addresses.isEmpty()) {
-                            for (Address address : subset.addresses) {
-                                addrs.add(new InetSocketAddress(address.ip, 0));
+            if (endpoints != null && endpoints.subsets != null && !endpoints.subsets.isEmpty()) {
+                for (Subset subset : endpoints.subsets) {
+                    addrs.addAll(parseAddresses(subset.addresses));
 
-                                if (log.isDebugEnabled())
-                                    log.debug("Added an address to the list: " + address.ip);
-                            }
-                        }
-                    }
+                    if (includeNotReadyAddresses)
+                        addrs.addAll(parseAddresses(subset.notReadyAddresses));
                 }
             }
         }
@@ -176,6 +169,19 @@ public class TcpDiscoveryKubernetesIpFinder extends TcpDiscoveryIpFinderAdapter
         return addrs;
     }
 
+    private Collection<InetSocketAddress> parseAddresses(List<Address> addresses) {
+        Collection<InetSocketAddress> addrs = new ArrayList<>();
+        if (addresses != null && !addresses.isEmpty()) {
+            for (Address address : addresses) {
+                addrs.add(new InetSocketAddress(address.ip, 0));
+
+                if (log.isDebugEnabled())
+                    log.debug("Added an address to the list: " + address.ip);
+            }
+        }
+        return addrs;
+    }
+
     /** {@inheritDoc} */
     @Override public void registerAddresses(Collection<InetSocketAddress> addrs) throws IgniteSpiException {
         // No-op
@@ -228,6 +234,15 @@ public class TcpDiscoveryKubernetesIpFinder extends TcpDiscoveryIpFinderAdapter
     }
 
     /**
+     * Determines whether addresses of not-ready pods should be included. Default is false.
+     *
+     * @param includeNotReadyAddresses Flag to include not-ready pods.
+     */
+    public void includeNotReadyAddresses(boolean includeNotReadyAddresses) {
+        this.includeNotReadyAddresses = includeNotReadyAddresses;
+    }
+
+    /**
      * Kubernetes IP finder initialization.
      *
      * @throws IgniteSpiException In case of error.
@@ -305,6 +320,7 @@ public class TcpDiscoveryKubernetesIpFinder extends TcpDiscoveryIpFinderAdapter
     private static class Subset {
         /** */
         public List<Address> addresses;
+        public List<Address> notReadyAddresses;
     }
 
     /**