Beispiel #1
0
def get_istio_version() -> str:
    """
    Get istio version(e.g. 1.4.5, 1.3.2) from pilot container image
    """
    cmd = "kubectl get pod -n istio-system -l istio=pilot -o jsonpath='{.items[0].spec.containers[0].image}'"
    imageName = command.run_sync(cmd)  # Output Sample: docker.io/istio/pilot:1.4.5
    return imageName[imageName.find(":") + 1:]  # Extract version such as 1.4.5
 def test_gererate(self):
     self.load_templates()
     ns_name = self.workload.generate(3)
     output = command.run_sync("kubectl get svc -n {}".format(ns_name))
     self.assertEqual(len(output.splitlines()), 4)
     print("Delete workloads. Probably takes a little time.")
     self.workload.reset()
Beispiel #3
0
 def wait(self, namespace, resource, condition, timeout="300s"):
     """
     Wait for a specific condition on deployed/deleted resources
     """
     # This function use timeout command. because --timeout option in
     # <kubectl wait> does not mean process timeout.
     # --timeout is interval of sending GET resource to api-server
     cmd = "timeout {timeout} kubectl --namespace {namespace} wait {resource} \
         --for=condition={condition} --selector={label}".format(
         namespace=namespace,
         resource=resource,
         condition=condition,
         label=self.label,
         timeout=timeout,
     )
     command.run_sync(cmd)
Beispiel #4
0
 def reset(self):
     """
     Delete all namespaces generated by this script
     """
     self.logger.info("Delete all namespaces that has {} label".format(
         self.label))
     cmd = "kubectl delete namespace --selector={}".format(self.label)
     resp = command.run_sync(cmd)
     if resp:
         self.logger.debug("Result: {}".format(resp))
Beispiel #5
0
    def __deploy_manifest(self,
                          manifest,
                          namespace=None,
                          resource_type=None,
                          resource_name=None):
        ns = " --namespace {}".format(namespace) if namespace else ""
        cmd = "cat << EOF | kubectl {ns} apply -f -\n{manifest}EOF".format(
            ns=ns, manifest=manifest)

        try:
            resp = command.run_sync(cmd)
        except Exception as e:
            self.logger.error("Failed to create {} {}".format(
                resource_type, resource_name))
            raise e
        self.logger.info("Deploy {} - {}".format(resource_type, resource_name))
        self.logger.debug("Deploy result: {}".format(resp))
Beispiel #6
0
 def __get_prometheus_port(self):
     cmd = "kubectl get svc -n istio-system prometheus -o jsonpath='{.spec.ports[0].port}'"
     port = command.run_sync(cmd)
     return port
Beispiel #7
0
 def test_sync(self):
     self.assertEqual("abcde", command.run_sync("echo abcde"))