Пример #1
0
    def test_replicaset_creation_timestamp(self):
        c_redis = _utils.create_container(name="redis", image="redis")
        c_nginx_1 = _utils.create_container(name="nginx", image="nginx")
        c_nginx_2 = _utils.create_container(name="postgres",
                                            image="postgres:alpine")

        name = "yodep-{0}".format(str(uuid.uuid4()))
        dep = _utils.create_deployment(name=name)
        dep.add_container(c_redis)
        dep.desired_replicas = 2

        if _utils.is_reachable(dep.config):
            dep.create()
            self.assertEqual(1, dep.revision)
            dep.add_container(c_nginx_1)
            dep.update()
            dep.get()
            self.assertEqual(2, dep.revision)
            dep.add_container(c_nginx_2)
            dep.update()
            dep.get()
            self.assertEqual(3, dep.revision)

            rsets = K8sReplicaSet(config=dep.config, name="yo").list()
            for i in range(0, len(rsets) - 1):
                self.assertGreaterEqual(rsets[i].creation_timestamp,
                                        rsets[i + 1].creation_timestamp)
Пример #2
0
def create_rs(config=None, name=None):
    if config is None:
        config = create_config()
    obj = K8sReplicaSet(
        config=config,
        name=name,
    )
    return obj
Пример #3
0
 def delete(self, cascade=False):
     super(K8sDeployment, self).delete(cascade)
     if cascade:
         rsets = K8sReplicaSet(
             config=self.config,
             name="yo"
         ).list(pattern=self.name)
         [rset.delete(cascade=cascade) for rset in rsets]
     return self
Пример #4
0
def cleanup_rs():
    ref = create_rs(name="throwaway")
    if is_reachable(ref.config.api_host):
        _list = ref.list()
        while len(_list) > 0:
            for rs in _list:
                try:
                    obj = K8sReplicaSet(config=ref.config, name=rs['metadata']['name']).get()
                    obj.delete()
                except NotFoundException:
                    continue
            _list = ref.list()
    def test_purge_replica_set(self):
        c_redis = _utils.create_container(name="redis", image="redis")
        c_nginx = _utils.create_container(name="nginx", image="nginx")
        c_postgres = _utils.create_container(name="postgres", image="postgres:alpine")
        # c_memcached = utils.create_container(name="memcached", image="memcached:alpine")

        name = "yodep-{0}".format(str(uuid.uuid4()))
        dep = _utils.create_deployment(name=name)
        dep.add_container(c_redis)
        dep.desired_replicas = 2

        if _utils.is_reachable(dep.config):
            dep.create()
            dep.add_container(c_nginx)
            dep.update()
            dep.add_container(c_postgres)
            dep.update()
            rsets = K8sReplicaSet(config=dep.config, name="yo").list()
            self.assertEqual(3, len(rsets))
            dep.purge_replica_sets(keep=2)
            rsets = K8sReplicaSet(config=dep.config, name="yo").list()
            self.assertEqual(2, len(rsets))
Пример #6
0
    def test_delete_cascade(self):
        c_redis = _utils.create_container(name="redis", image="redis")
        c_nginx = _utils.create_container(name="nginx", image="nginx")
        name = "yodep-{0}".format(str(uuid.uuid4()))
        dep = _utils.create_deployment(name=name)
        dep.add_container(c_redis)
        dep.desired_replicas = 3

        if _utils.is_reachable(dep.config):
            dep.create()
            dep.add_container(c_nginx)
            dep.update()
            repsets = K8sReplicaSet(config=dep.config, name="yo").list()
            self.assertEqual(2, len(repsets))
            pods = K8sPod(config=dep.config, name="yo").list()
            self.assertLessEqual(3, len(pods))  # rollout burst
            dep.delete(cascade=True)
            result = dep.list()
            self.assertIsInstance(result, list)
            self.assertEqual(0, len(result))
            repsets = K8sReplicaSet(config=dep.config, name="yo").list()
            self.assertEqual(0, len(repsets))
            pods = K8sPod(config=dep.config, name="yo").list()
            self.assertEqual(0, len(pods))
Пример #7
0
    def purge_replica_sets(self, keep=3):
        """
        Builds a list of ReplicaSets, sorted from newest to oldest.
        Slices the array, keeping the most X most recent ReplicaSets.
        
        :param keep: The number of ReplicaSets to keep.
        :return: None
        """

        rsets = K8sReplicaSet(config=self.config,
                              name="yo").list(pattern=self.name, reverse=True)

        to_purge = rsets[keep:]
        for rset in to_purge:
            rset.delete(cascade=True)
Пример #8
0
    def test_delete_no_cascade(self):
        name = "yocontainer"
        container = _utils.create_container(name=name)
        name = "yodep-{0}".format(str(uuid.uuid4()))
        dep = _utils.create_deployment(name=name)
        dep.add_container(container)
        dep.desired_replicas = 3

        if _utils.is_reachable(dep.config):
            dep.create()
            dep.delete(cascade=False)
            result = dep.list()
            self.assertIsInstance(result, list)
            self.assertEqual(0, len(result))
            repsets = K8sReplicaSet(config=dep.config, name="yo").list()
            self.assertEqual(1, len(repsets))
            pods = K8sPod(config=dep.config, name="yo").list()
            self.assertEqual(3, len(pods))
Пример #9
0
 def delete(self, cascade=False):
     # delete cascade on top level
     super(K8sDeployment, self).delete(cascade)
     if cascade:
         rsets = K8sReplicaSet(config=self.config,
                               name="yo").list(pattern=self.name)
         # delete cascade on replicasets
         for rset in rsets:
             try:
                 rset.delete(cascade=cascade)
             except NotFoundException:
                 pass
         pods = K8sPod(config=self.config,
                       name="yo").list(pattern=self.name)
         # delete cascade on pods
         for pod in pods:
             try:
                 pod.delete(cascade=cascade)
             except NotFoundException:
                 pass
     return self