You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by GitBox <gi...@apache.org> on 2023/01/20 08:08:00 UTC

[GitHub] [hbase] ndimiduk commented on a diff in pull request #4979: HBASE-27574 Implement ClusterManager interface for Kubernetes

ndimiduk commented on code in PR #4979:
URL: https://github.com/apache/hbase/pull/4979#discussion_r1082207440


##########
hbase-it/src/test/java/org/apache/hadoop/hbase/KubernetesClusterManager.java:
##########
@@ -0,0 +1,258 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase;
+
+import com.google.gson.JsonSyntaxException;
+import io.kubernetes.client.openapi.ApiClient;
+import io.kubernetes.client.openapi.ApiException;
+import io.kubernetes.client.openapi.apis.CoreV1Api;
+import io.kubernetes.client.openapi.models.V1ObjectMeta;
+import io.kubernetes.client.openapi.models.V1Pod;
+import io.kubernetes.client.openapi.models.V1PodList;
+import io.kubernetes.client.util.ClientBuilder;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Optional;
+import java.util.Set;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.conf.Configured;
+import org.apache.hadoop.hbase.procedure2.util.StringUtils;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Cluster manager for K8s context. Supports taking destructive actions, and checking for the
+ * presence of a running process. Assumes services are running behind some type of `Deployment` that
+ * will handle starting replacement processes after a destructive action. Requires that the
+ * configuration specify a Kubernetes namespace.
+ * </p>
+ * Note that the k8s java client is a bit dodgy unable to read responses when we call delete (i.e.
+ * kill) and sometimes when checking isRunning; makes for noisy logs and sometimes the operations
+ * overrun each other but generally succeed.
+ */
+@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.CONFIG)
+public class KubernetesClusterManager extends Configured implements ClusterManager {
+  private static final Logger LOG = LoggerFactory.getLogger(KubernetesClusterManager.class);
+
+  private static final String NAMESPACE_CONF_KEY =
+    KubernetesClusterManager.class.getCanonicalName() + ".namespace";
+  private static final String ZOOKEEPER_ROLE_SELECTOR_CONF_KEY =
+    KubernetesClusterManager.class.getCanonicalName() + ".zookeeper_role";
+  private static final String NAMENODE_ROLE_SELECTOR_CONF_KEY =
+    KubernetesClusterManager.class.getCanonicalName() + ".namenode_role";
+  private static final String JOURNALNODE_ROLE_SELECTOR_CONF_KEY =
+    KubernetesClusterManager.class.getCanonicalName() + ".journalnode_role";
+  private static final String DATANODE_ROLE_SELECTOR_CONF_KEY =
+    KubernetesClusterManager.class.getCanonicalName() + ".datanode_role";
+  private static final String MASTER_ROLE_SELECTOR_CONF_KEY =
+    KubernetesClusterManager.class.getCanonicalName() + ".master_role";
+  private static final String REGIONSERVER_ROLE_SELECTOR_CONF_KEY =
+    KubernetesClusterManager.class.getCanonicalName() + ".regionserver_role";
+  private static final Set<ServiceType> SUPPORTED_SERVICE_TYPES = buildSupportedServiceTypesSet();
+
+  private CoreV1Api api;
+  private String namespace;
+
+  private static Set<ServiceType> buildSupportedServiceTypesSet() {
+    final Set<ServiceType> set = new HashSet<>();
+    set.add(ServiceType.ZOOKEEPER_SERVER);
+    set.add(ServiceType.HADOOP_NAMENODE);
+    set.add(ServiceType.HADOOP_JOURNALNODE);
+    set.add(ServiceType.HADOOP_DATANODE);
+    set.add(ServiceType.HBASE_MASTER);
+    set.add(ServiceType.HBASE_REGIONSERVER);
+    return Collections.unmodifiableSet(set);
+  }
+
+  @Override
+  public void setConf(Configuration configuration) {
+    // This is usually called from the constructor (The call to super goes to
+    // Configured which does a setConf in its construction) but the configuration
+    // null at that time. After construction, setConf is called again.
+    // Assume single-thread doing ClusterManager setup.
+    if (configuration == null) {
+      LOG.debug("Skipping because provided configuration=null");
+      return;
+    }
+    if (getConf() != null) {
+      LOG.debug("Skipping because configuration already set, getConf={}", getConf());
+      return;
+    }
+    super.setConf(configuration);
+    this.namespace = configuration.get(NAMESPACE_CONF_KEY);

Review Comment:
   What default namespace would you propose? I guess, `default` ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hbase.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org