Beispiel #1
0
    def test_nuclio_config_spec_env(self, db: Session, client: TestClient):
        function = self._generate_runtime(self.runtime_kind)

        name = "env1"
        secret = "shh"
        secret_key = "open sesame"
        function.set_env_from_secret(name, secret=secret, secret_key=secret_key)

        name2 = "env2"
        value2 = "value2"
        function.set_env(name2, value2)

        expected_env_vars = [
            {
                "name": name,
                "valueFrom": {"secretKeyRef": {"key": secret_key, "name": secret}},
            },
            {"name": name2, "value": value2},
        ]

        function_name, project_name, config = compile_function_config(function)
        for expected_env_var in expected_env_vars:
            assert expected_env_var in config["spec"]["env"]
        assert isinstance(function.spec.env[0], kubernetes.client.V1EnvVar)
        assert isinstance(function.spec.env[1], kubernetes.client.V1EnvVar)

        # simulating sending to API - serialization through dict
        function = function.from_dict(function.to_dict())
        function_name, project_name, config = compile_function_config(function)
        for expected_env_var in expected_env_vars:
            assert expected_env_var in config["spec"]["env"]
Beispiel #2
0
 def test_enrich_with_ingress_never(self, db: Session, client: TestClient):
     """
     Expect no ingress to be created automatically as the configuration templated ingress mode is "never"
     """
     function = self._generate_runtime("nuclio")
     function_name, project_name, config = compile_function_config(function)
     service_type = "DoesNotMatter"
     enrich_function_with_ingress(
         config, NuclioIngressAddTemplatedIngressModes.never, service_type)
     ingresses = resolve_function_ingresses(config["spec"])
     assert ingresses == []
Beispiel #3
0
 def test_enrich_with_ingress_always(self, db: Session, client: TestClient):
     """
     Expect ingress template to be created as the configuration templated ingress mode is "always"
     """
     function = self._generate_runtime("nuclio")
     function_name, project_name, config = compile_function_config(function)
     service_type = "NodePort"
     enrich_function_with_ingress(
         config, NuclioIngressAddTemplatedIngressModes.always, service_type)
     ingresses = resolve_function_ingresses(config["spec"])
     assert ingresses[0]["hostTemplate"] != ""
Beispiel #4
0
 def test_enrich_with_ingress_on_cluster_ip(self, db: Session, client: TestClient):
     """
     Expect ingress template to be created as the configuration templated ingress mode is "onClusterIP" while the
     function service type is ClusterIP
     """
     function = self._generate_runtime(self.runtime_kind)
     function_name, project_name, config = compile_function_config(function)
     service_type = "ClusterIP"
     enrich_function_with_ingress(
         config, NuclioIngressAddTemplatedIngressModes.on_cluster_ip, service_type,
     )
     ingresses = resolve_function_ingresses(config["spec"])
     assert ingresses[0]["hostTemplate"] != ""
Beispiel #5
0
    def test_enrich_with_ingress_no_overriding(self, db: Session, client: TestClient):
        """
        Expect no ingress template to be created, thought its mode is "always",
        since the function already have a pre-configured ingress
        """
        function = self._generate_runtime(self.runtime_kind)

        # both ingress and node port
        ingress_host = "something.com"
        function.with_http(host=ingress_host, paths=["/"], port=30030)
        function_name, project_name, config = compile_function_config(function)
        service_type = "NodePort"
        enrich_function_with_ingress(
            config, NuclioIngressAddTemplatedIngressModes.always, service_type
        )
        ingresses = resolve_function_ingresses(config["spec"])
        assert len(ingresses) > 0, "Expected one ingress to be created"
        for ingress in ingresses:
            assert "hostTemplate" not in ingress, "No host template should be added"
            assert ingress["host"] == ingress_host