Exemplo n.º 1
0
 def test_version_no_until(self):
     checker = ApiDeprecationChecker("1.10.6")
     checker.deprecated_versions = {
         "test/v1": {
             "Deployment": {
                 "since": "1.8.0",
                 "until": "",
             },
         }
     }
     self.assertTrue(checker._is_deprecated("test/v1", "Deployment"))
Exemplo n.º 2
0
 def test_version_not_in_list(self):
     checker = ApiDeprecationChecker("1.9.7")
     checker.deprecated_versions = {
         "test/v1": {
             "Deployment": {
                 "since": "1.8.0",
                 "until": "1.10.0",
             },
         }
     }
     self.assertFalse(checker._is_deprecated("test/v2", "Deployment"))
Exemplo n.º 3
0
def _handler_provision(command, resources, priority_evaluator, use_kubeconfig,
                       sync_mode, show_logs):
    kubeconfig_namespace = None

    if priority_evaluator.environment_deprecated():
        log.warning(
            "K8S_HOST and K8S_CA environment variables support is deprecated "
            "and will be discontinued in the future. Use K8S_MASTER_URI and K8S_CA_BASE64 instead."
        )

    # INFO rvadim: https://github.com/kubernetes-client/python/issues/430#issuecomment-359483997
    if use_kubeconfig:
        try:
            load_kube_config()
            kubeconfig_namespace = list_kube_config_contexts()[1].get(
                'context').get('namespace')
        except Exception as e:
            raise RuntimeError(e)
    else:
        client.Configuration.set_default(
            priority_evaluator.k8s_client_configuration())

    settings.K8S_NAMESPACE = priority_evaluator.k8s_namespace_default(
        kubeconfig_namespace)
    log.info('Default namespace "{}"'.format(settings.K8S_NAMESPACE))

    if not settings.K8S_NAMESPACE:
        log.info(
            "Default namespace is not set. "
            "This may lead to provisioning error, if namespace is not set for each resource."
        )

    try:
        deprecation_checker = ApiDeprecationChecker(
            client.VersionApi().get_code().git_version[1:])
        available_checker = ResourceAvailabilityChecker(
            make_resource_getters_list())

        for resource in resources:
            deprecation_checker.run(resource)
            available_checker.run(resource)
    except client.exceptions.ApiException:
        log.warning(
            "Error while getting API version, deprecation check will be skipped."
        )

    if command == COMMAND_DIFF:
        executor = Diff()
    else:
        executor = Provisioner(command, sync_mode, show_logs)

    for resource in resources:
        executor.run(resource)
Exemplo n.º 4
0
 def test_version_is_deprecated(self):
     checker = ApiDeprecationChecker("1.9.9")
     checker.deprecated_versions = {
         "test/v1": {
             "since": "1.8.0",
             "until": "1.10.0",
             "resources": [
                 "Deployment",
             ],
         }
     }
     self.assertTrue(checker._is_deprecated("test/v1", "Deployment"))
Exemplo n.º 5
0
 def test_kind_not_in_list(self):
     checker = ApiDeprecationChecker("1.9.7")
     checker.deprecated_versions = {
         "test/v1": {
             "since": "1.8.0",
             "until": "1.10.0",
             "resources": [
                 "Deployment",
             ],
         }
     }
     self.assertFalse(checker._is_deprecated("test/v1", "StatefulSet"))
Exemplo n.º 6
0
 def test_version_is_unsupported(self):
     checker = ApiDeprecationChecker("1.10.6")
     checker.deprecated_versions = {
         "test/v1": {
             "since": "1.8.0",
             "until": "1.10.0",
             "resources": [
                 "Deployment",
             ],
         }
     }
     with self.assertRaises(DeprecationError):
         checker._is_deprecated("test/v1", "Deployment")