def test_deploy_clears_alpha_beta_annotations(self, put, get, config, app_spec, datadog, prometheus, secrets): old_strongbox_spec = app_spec.strongbox._replace( enabled=True, groups=["group1", "group2"]) old_app_spec = app_spec._replace(replicas=10, strongbox=old_strongbox_spec) old_deployment = create_expected_deployment( config, old_app_spec, add_init_container_annotations=True) get_mock_response = create_autospec(Response) get_mock_response.json.return_value = old_deployment get.side_effect = None get.return_value = get_mock_response expected_deployment = create_expected_deployment(config, app_spec) put_mock_response = create_autospec(Response) put_mock_response.json.return_value = expected_deployment put.side_effect = None put.return_value = put_mock_response deployer = DeploymentDeployer(config, datadog, prometheus, secrets) deployer.deploy(app_spec, SELECTOR, LABELS, False) pytest.helpers.assert_any_call(put, DEPLOYMENTS_URI + "testapp", expected_deployment) datadog.apply.assert_called_once_with(DeploymentMatcher(), app_spec, False) prometheus.apply.assert_called_once_with(DeploymentMatcher(), app_spec) secrets.apply.assert_called_once_with(DeploymentMatcher(), app_spec)
def test_deploy_new_deployment(self, post, config, app_spec, datadog, prometheus, secrets, owner_references): expected_deployment = create_expected_deployment(config, app_spec) mock_response = create_autospec(Response) mock_response.json.return_value = expected_deployment post.side_effect = None post.return_value = mock_response deployer = DeploymentDeployer(config, datadog, prometheus, secrets, owner_references) deployer.deploy(app_spec, SELECTOR, LABELS, False) pytest.helpers.assert_any_call(post, DEPLOYMENTS_URI, expected_deployment) datadog.apply.assert_called_once_with(TypeMatcher(Deployment), app_spec, False) prometheus.apply.assert_called_once_with(TypeMatcher(Deployment), app_spec) secrets.apply.assert_called_once_with(TypeMatcher(Deployment), app_spec) owner_references.apply.assert_called_with(TypeMatcher(Deployment), app_spec)
def test_managed_environment_variables(self, post, config, app_spec, datadog, prometheus, secrets, owner_references): deployer = DeploymentDeployer(config, datadog, prometheus, secrets, owner_references) env = deployer._make_env(app_spec) env_keys = [var.name for var in env] assert 'FIAAS_ARTIFACT_NAME' in env_keys assert 'FIAAS_IMAGE' in env_keys assert 'FIAAS_VERSION' in env_keys assert ('ARTIFACT_NAME' not in env_keys) == config.disable_deprecated_managed_env_vars assert ('IMAGE' not in env_keys) == config.disable_deprecated_managed_env_vars assert ('VERSION' not in env_keys) == config.disable_deprecated_managed_env_vars
def test_replicas_when_autoscaler_enabled(self, previous_replicas, max_replicas, min_replicas, cpu_request, expected_replicas, config, app_spec, get, put, post, datadog, prometheus, secrets): deployer = DeploymentDeployer(config, datadog, prometheus, secrets) image = "finntech/testimage:version2" version = "version2" app_spec = app_spec._replace(replicas=max_replicas, autoscaler=AutoscalerSpec( enabled=True, min_replicas=min_replicas, cpu_threshold_percentage=50), image=image) if cpu_request: app_spec = app_spec._replace(resources=ResourcesSpec( requests=ResourceRequirementSpec(cpu=cpu_request, memory=None), limits=ResourceRequirementSpec(cpu=None, memory=None))) expected_volumes = _get_expected_volumes(app_spec) expected_volume_mounts = _get_expected_volume_mounts(app_spec) mock_response = create_autospec(Response) mock_response.json.return_value = { 'metadata': pytest.helpers.create_metadata('testapp', labels=LABELS), 'spec': { 'selector': { 'matchLabels': SELECTOR }, 'template': { 'spec': { 'dnsPolicy': 'ClusterFirst', 'automountServiceAccountToken': False, 'serviceAccountName': 'default', 'terminationGracePeriodSeconds': 31, 'restartPolicy': 'Always', 'volumes': expected_volumes, 'imagePullSecrets': [], 'strategy': { 'type': 'rollingUpdate', 'rollingUpdate': { 'maxSurge': '25%', 'maxUnavailable': 0 }, }, 'containers': [{ 'livenessProbe': { 'initialDelaySeconds': 10, 'periodSeconds': 10, 'successThreshold': 1, 'failureThreshold': 3, 'timeoutSeconds': 1, 'tcpSocket': { 'port': 8080 } }, 'name': 'testapp', 'image': 'finntech/testimage:version', 'volumeMounts': expected_volume_mounts, 'command': [], 'env': create_environment_variables( config.infrastructure, global_env=config.global_env, environment=config.environment), 'envFrom': [{ 'configMapRef': { 'name': app_spec.name, 'optional': True, } }], 'imagePullPolicy': 'IfNotPresent', 'readinessProbe': { 'initialDelaySeconds': 10, 'periodSeconds': 10, 'successThreshold': 1, 'failureThreshold': 3, 'timeoutSeconds': 1, 'httpGet': { 'path': '/', 'scheme': 'HTTP', 'port': 8080, 'httpHeaders': [] } }, 'ports': [{ 'protocol': 'TCP', 'containerPort': 8080, 'name': 'http' }], 'resources': {} }] }, 'metadata': pytest.helpers.create_metadata('testapp', labels=LABELS) }, 'replicas': previous_replicas, 'revisionHistoryLimit': 5 } } get.side_effect = None get.return_value = mock_response expected_deployment = create_expected_deployment( config, app_spec, image=image, version=version, replicas=expected_replicas) put_mock_response = create_autospec(Response) put_mock_response.json.return_value = expected_deployment put.side_effect = None put.return_value = put_mock_response deployer.deploy(app_spec, SELECTOR, LABELS, False) pytest.helpers.assert_no_calls(post) pytest.helpers.assert_any_call(put, DEPLOYMENTS_URI + "testapp", expected_deployment) datadog.apply.assert_called_once_with(DeploymentMatcher(), app_spec, False) prometheus.apply.assert_called_once_with(DeploymentMatcher(), app_spec) secrets.apply.assert_called_once_with(DeploymentMatcher(), app_spec)