示例#1
0
def requires_bootstrap(deployment_config):
    try:
        Deployment.get(name=deployment_config.name,
                       namespace=deployment_config.namespace)
        return False
    except NotFound:
        return True
    except Exception as e:
        LOG.warning(e, exc_info=True)
 def _ready(self):
     try:
         dep = Deployment.get(self._app_spec.name, self._app_spec.namespace)
     except NotFound:
         return False
     return (dep.status.updatedReplicas >= dep.spec.replicas
             and dep.status.availableReplicas >= dep.spec.replicas)
示例#3
0
 def _ready(self):
     try:
         dep = Deployment.get(self._app_spec.name, self._app_spec.namespace)
     except NotFound:
         return False
     return (dep.status.updatedReplicas == dep.spec.replicas
             and dep.status.replicas == dep.spec.replicas
             and dep.status.availableReplicas == dep.spec.replicas
             and dep.status.observedGeneration >= dep.metadata.generation)
示例#4
0
    def action():
        for kind in kinds:
            assert kind.get(name)
        dep = Deployment.get(name)
        assert dep.spec.template.spec.containers[0].image == image
        svc = Service.get(name)
        assert svc.spec.type == service_type

        for kind, expected_dict in expected.items():
            actual = kind.get(name)
            assert_k8s_resource_matches(actual, expected_dict, image, service_type, deployment_id, strongbox_groups)
示例#5
0
    def deploy(self, app_spec, selector, labels, besteffort_qos_is_required):
        LOG.info("Creating new deployment for %s", app_spec.name)
        deployment_labels = merge_dicts(app_spec.labels.deployment, labels)
        metadata = ObjectMeta(name=app_spec.name,
                              namespace=app_spec.namespace,
                              labels=deployment_labels,
                              annotations=app_spec.annotations.deployment)
        container_ports = [
            ContainerPort(name=port_spec.name,
                          containerPort=port_spec.target_port)
            for port_spec in app_spec.ports
        ]
        env = self._make_env(app_spec)
        pull_policy = "IfNotPresent" if (":" in app_spec.image and ":latest"
                                         not in app_spec.image) else "Always"

        env_from = [
            EnvFromSource(configMapRef=ConfigMapEnvSource(name=app_spec.name,
                                                          optional=True))
        ]
        containers = [
            Container(
                name=app_spec.name,
                image=app_spec.image,
                ports=container_ports,
                env=env,
                envFrom=env_from,
                lifecycle=self._lifecycle,
                livenessProbe=_make_probe(app_spec.health_checks.liveness),
                readinessProbe=_make_probe(app_spec.health_checks.readiness),
                imagePullPolicy=pull_policy,
                volumeMounts=self._make_volume_mounts(app_spec),
                resources=_make_resource_requirements(app_spec.resources))
        ]

        automount_service_account_token = app_spec.admin_access
        init_containers = []
        service_account_name = "default"

        pod_spec = PodSpec(
            containers=containers,
            initContainers=init_containers,
            volumes=self._make_volumes(app_spec),
            serviceAccountName=service_account_name,
            automountServiceAccountToken=automount_service_account_token,
            terminationGracePeriodSeconds=self._grace_period)

        pod_labels = merge_dicts(app_spec.labels.pod,
                                 _add_status_label(labels))
        pod_metadata = ObjectMeta(name=app_spec.name,
                                  namespace=app_spec.namespace,
                                  labels=pod_labels,
                                  annotations=app_spec.annotations.pod)
        pod_template_spec = PodTemplateSpec(metadata=pod_metadata,
                                            spec=pod_spec)
        replicas = app_spec.replicas
        # we must avoid that the deployment scales up to app_spec.replicas if autoscaler has set another value
        if should_have_autoscaler(app_spec):
            try:
                deployment = Deployment.get(app_spec.name, app_spec.namespace)
                replicas = deployment.spec.replicas
            except NotFound:
                pass

        deployment_strategy = DeploymentStrategy(
            rollingUpdate=RollingUpdateDeployment(
                maxUnavailable=self._max_unavailable,
                maxSurge=self._max_surge))
        if app_spec.replicas == 1 and app_spec.singleton:
            deployment_strategy = DeploymentStrategy(
                rollingUpdate=RollingUpdateDeployment(maxUnavailable=1,
                                                      maxSurge=0))
        spec = DeploymentSpec(replicas=replicas,
                              selector=LabelSelector(matchLabels=selector),
                              template=pod_template_spec,
                              revisionHistoryLimit=5,
                              strategy=deployment_strategy)

        deployment = Deployment.get_or_create(metadata=metadata, spec=spec)
        _clear_pod_init_container_annotations(deployment)
        self._datadog.apply(deployment, app_spec, besteffort_qos_is_required)
        self._prometheus.apply(deployment, app_spec)
        self._secrets.apply(deployment, app_spec)
        deployment.save()