From daf620d3047c6fa4033b78e81af6726be16d7cf0 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Fri, 19 Nov 2021 16:35:04 -0500 Subject: [PATCH 1/3] [Kubernetes] will generate match labels of the form "app=heron,topology=topology-name". --- .../heron/scheduler/kubernetes/V1Controller.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/heron/schedulers/src/java/org/apache/heron/scheduler/kubernetes/V1Controller.java b/heron/schedulers/src/java/org/apache/heron/scheduler/kubernetes/V1Controller.java index 761d6152db8..21d54f45073 100644 --- a/heron/schedulers/src/java/org/apache/heron/scheduler/kubernetes/V1Controller.java +++ b/heron/schedulers/src/java/org/apache/heron/scheduler/kubernetes/V1Controller.java @@ -839,4 +839,14 @@ protected V1ConfigMap getConfigMap(String configMapName) { throw new TopologySubmissionException(String.format("%s: %s", message, e.getMessage())); } } + + /** + * Generates the Selector match labels with which resources in this topology can be found. + * @return A label of the form app=heron,topology=topology-name. + */ + private String createTopologySelectorLabels() { + return String.format("%s=%s,%s=%s", + KubernetesConstants.LABEL_APP, KubernetesConstants.LABEL_APP_VALUE, + KubernetesConstants.LABEL_TOPOLOGY, getTopologyName()); + } } From ea427c1f22ff30ec3df1ab068ae13a40bac94f09 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Fri, 19 Nov 2021 16:38:24 -0500 Subject: [PATCH 2/3] [Kubernetes] will shutdown a topology by deleting its associated Pods. --- .../scheduler/kubernetes/V1Controller.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/heron/schedulers/src/java/org/apache/heron/scheduler/kubernetes/V1Controller.java b/heron/schedulers/src/java/org/apache/heron/scheduler/kubernetes/V1Controller.java index 21d54f45073..305b5d27611 100644 --- a/heron/schedulers/src/java/org/apache/heron/scheduler/kubernetes/V1Controller.java +++ b/heron/schedulers/src/java/org/apache/heron/scheduler/kubernetes/V1Controller.java @@ -156,12 +156,23 @@ boolean killTopology() { return true; } + /** + * Restarts a topology by deleting the Pods associated with it using Selector Labels. + * @param shardId Not used but required because of interface. + * @return Indicator of successful submission of restart request to Kubernetes cluster. + */ @Override boolean restart(int shardId) { - final String message = "Restarting the whole topology is not supported yet. " - + "Please kill and resubmit the topology."; - LOG.log(Level.SEVERE, message); - return false; + try { + coreClient.deleteCollectionNamespacedPod(getNamespace(), null, null, null, null, + 0, createTopologySelectorLabels(), null, null, null, null, + null, null, null); + LOG.log(Level.WARNING, String.format("Restarting topology '%s'...", getTopologyName())); + } catch (ApiException e) { + LOG.log(Level.SEVERE, String.format("Failed to restart topology '%s'...", getTopologyName())); + return false; + } + return true; } @Override From 44b61c3d48cf16f216d44e06e68b1757f9d7f840 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Fri, 19 Nov 2021 18:20:52 -0500 Subject: [PATCH 3/3] [Kubernetes] Deployments Updated Helm chart for Pod permission: - deletecollection --- deploy/kubernetes/helm/templates/tools.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/deploy/kubernetes/helm/templates/tools.yaml b/deploy/kubernetes/helm/templates/tools.yaml index 7cb572b4587..08b0707c125 100644 --- a/deploy/kubernetes/helm/templates/tools.yaml +++ b/deploy/kubernetes/helm/templates/tools.yaml @@ -296,6 +296,12 @@ rules: - patch - update - watch +- apiGroups: + - "" + resources: + - pods + verbs: + - deletecollection - apiGroups: - "" resources: