lordgamez commented on a change in pull request #1270:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1270#discussion_r816814201



##########
File path: docker/test/integration/minifi/core/KindProxy.py
##########
@@ -0,0 +1,112 @@
+# 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.
+
+
+import glob
+import os
+import stat
+import subprocess
+import time
+from textwrap import dedent
+
+
+class KindProxy:
+    REPOSITORY = 'minifi-kubernetes-test'
+    TAG = 'v1'
+
+    def __init__(self, temp_directory):
+        self.temp_directory = temp_directory
+        self.kind_binary_path = os.path.join(self.temp_directory, 'kind')
+        self.kind_config_path = os.path.join(self.temp_directory, 
'kind-config.yml')
+        self.__download_kind()
+
+    def __download_kind(self):
+        if subprocess.run(['curl', '-Lo', self.kind_binary_path, 
'https://kind.sigs.k8s.io/dl/v0.11.1/kind-linux-amd64']).returncode != 0:
+            raise Exception("Could not download kind")
+        os.chmod(self.kind_binary_path, stat.S_IXUSR)
+
+    def create_config(self, volumes):
+        kind_config = dedent("""\
+                apiVersion: kind.x-k8s.io/v1alpha4
+                kind: Cluster
+                nodes:
+                   - role: control-plane
+                """)
+
+        if volumes:
+            kind_config += "     extraMounts:\n"
+
+        for host_path, container_path in volumes.items():
+            kind_config += "      - hostPath: {path}\n".format(path=host_path)
+            kind_config += "        containerPath: 
{path}\n".format(path=container_path['bind'])
+            if container_path['mode'] != 'rw':
+                kind_config += "        readOnly: true\n"
+
+        with open(self.kind_config_path, 'wb') as config_file:
+            config_file.write(kind_config.encode('utf-8'))
+
+    def start_cluster(self):
+        subprocess.run([self.kind_binary_path, 'delete', 'cluster'])
+
+        if subprocess.run([self.kind_binary_path, 'create', 'cluster', 
'--config=' + self.kind_config_path]).returncode != 0:
+            raise Exception("Could not start the kind cluster")
+
+    def load_docker_image(self, image_store):
+        image_store.get_image('minifi-cpp-in-kubernetes')
+
+        if subprocess.run([self.kind_binary_path, 'load', 'docker-image', 
KindProxy.REPOSITORY + ':' + KindProxy.TAG]).returncode != 0:
+            raise Exception("Could not load the minifi docker image into the 
kind cluster")
+
+    def create_objects(self):
+        test_dir = os.environ['TEST_DIRECTORY']
+        resources_directory = os.path.join(test_dir, 'resources', 
'kubernetes', 'pods-etc')
+
+        self.__wait_for_default_service_account('default')
+        namespaces = self.__create_objects_of_type(resources_directory, 
'namespace')
+        for namespace in namespaces:
+            self.__wait_for_default_service_account(namespace)
+
+        self.__create_objects_of_type(resources_directory, 'pod')
+        self.__create_objects_of_type(resources_directory, 'clusterrole')
+        self.__create_objects_of_type(resources_directory, 
'clusterrolebinding')
+
+    def __wait_for_default_service_account(self, namespace):
+        for _ in range(120):
+            if subprocess.run(['docker', 'exec', 'kind-control-plane', 
'kubectl', '-n', namespace, 'get', 'serviceaccount', 'default']).returncode == 
0:

Review comment:
       It may be better to instantiate a python docker client to get the 
container and call `exec_run` on it to execute commands inside the container.

##########
File path: docker/test/integration/minifi/core/KubernetesRunner.py
##########
@@ -0,0 +1,55 @@
+# 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.
+
+
+import logging
+import os
+import shutil
+from .KindProxy import KindProxy
+from .MinifiContainer import MinifiContainer
+
+
+class KubernetesRunner(MinifiContainer):

Review comment:
       I think this should be renamed to reflect that this runs a minifi 
container inside a kubernetes environment, KubernetesRunner seems too generic 
opposed to the function of the class.

##########
File path: docker/test/integration/minifi/core/DockerTestCluster.py
##########
@@ -34,6 +34,15 @@ def get_stdout_encoding():
         return encoding
 
     def get_app_log(self, container_name):
+        type = self.containers[container_name].type()
+        if type == 'docker container':
+            return self.__get_app_log_from_docker_container(container_name)
+        elif type == 'direct':
+            return self.containers[container_name].get_app_log()
+        else:
+            raise Exception("Unexpected container type '%s'" % type)

Review comment:
       I would either change the method name from `type()` to `log_source()` or 
the type `direct` to `kind cluster container` or something similar to be more 
clearer, because `direct` doesn't really name a type. Also maybe a class could 
be added with const members for these literals to be used from a single place 
like
   
   ```
   class ContainerType:
     DOCKER_CONTAINER = "docker container"
     KIND_CLUSTER_CONTAINER = "kind cluster container"
   ```

##########
File path: docker/test/integration/minifi/core/KindProxy.py
##########
@@ -0,0 +1,112 @@
+# 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.
+
+
+import glob
+import os
+import stat
+import subprocess
+import time
+from textwrap import dedent
+
+
+class KindProxy:
+    REPOSITORY = 'minifi-kubernetes-test'
+    TAG = 'v1'
+
+    def __init__(self, temp_directory):
+        self.temp_directory = temp_directory
+        self.kind_binary_path = os.path.join(self.temp_directory, 'kind')
+        self.kind_config_path = os.path.join(self.temp_directory, 
'kind-config.yml')
+        self.__download_kind()
+
+    def __download_kind(self):
+        if subprocess.run(['curl', '-Lo', self.kind_binary_path, 
'https://kind.sigs.k8s.io/dl/v0.11.1/kind-linux-amd64']).returncode != 0:
+            raise Exception("Could not download kind")
+        os.chmod(self.kind_binary_path, stat.S_IXUSR)
+
+    def create_config(self, volumes):
+        kind_config = dedent("""\
+                apiVersion: kind.x-k8s.io/v1alpha4
+                kind: Cluster
+                nodes:
+                   - role: control-plane
+                """)
+
+        if volumes:
+            kind_config += "     extraMounts:\n"
+
+        for host_path, container_path in volumes.items():
+            kind_config += "      - hostPath: {path}\n".format(path=host_path)
+            kind_config += "        containerPath: 
{path}\n".format(path=container_path['bind'])
+            if container_path['mode'] != 'rw':
+                kind_config += "        readOnly: true\n"
+
+        with open(self.kind_config_path, 'wb') as config_file:
+            config_file.write(kind_config.encode('utf-8'))
+
+    def start_cluster(self):
+        subprocess.run([self.kind_binary_path, 'delete', 'cluster'])
+
+        if subprocess.run([self.kind_binary_path, 'create', 'cluster', 
'--config=' + self.kind_config_path]).returncode != 0:
+            raise Exception("Could not start the kind cluster")
+
+    def load_docker_image(self, image_store):
+        image_store.get_image('minifi-cpp-in-kubernetes')

Review comment:
       I think the image name should be a parameter, we could load other images 
as well if we want to test them with minifi in kubernetes later

##########
File path: docker/test/integration/minifi/core/ImageStore.py
##########
@@ -84,6 +87,18 @@ def __build_minifi_cpp_image(self):
 
         return self.__build_image(dockerfile)
 
+    def __build_simple_minifi_cpp_image_with_root(self):

Review comment:
       Because of the specific tag, this may need to be renamed to 
`__build_minifi_cpp_image_for_kind_proxy_with_root` or something similar to 
contain the intent of use.




-- 
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-unsubscr...@nifi.apache.org

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


Reply via email to