Ejemplo n.º 1
0
    def _build_item(self, item):
        try:
            obj = kinds_collection[item["kind"]]()
        except KeyError:
            logger.warning("Skipping unsupported kind %s" % item["kind"])
            return

        create = item["__created"]
        mode = item["__mode"]
        replicas = item["__scale_replicas"]
        obj.kubeguard_created = create  # special property to distinguish "created"
        for prop in objwalk(item):
            p, val = find_property(obj, prop)
            if p is None: continue
            val = k8s_to_domain_object(val)
            if isinstance(getattr(obj, p), Relation):
                getattr(obj, p).add(val)
            elif isinstance(getattr(obj, p), Property):
                setattr(obj, p, val)
            else:
                # means has setter
                setattr(obj, p, val)
        obj.yaml = copy.deepcopy(item)
        #cleanup service information
        for y in item:
            if y[0:2] == '__':
                del (obj.yaml[y])
        obj.yaml_orig = copy.deepcopy(obj.yaml)
        if mode == self.CREATE_MODE and hasattr(obj, "hook_after_create"):
            obj.hook_after_create(self.state_objects)
        if mode == self.LOAD_MODE and hasattr(obj, "hook_after_load"):
            obj.hook_after_load(self.state_objects)
        if mode == self.APPLY_MODE and hasattr(obj, "hook_after_apply"):
            obj.hook_after_apply(self.state_objects)
        # if mode == self.SCALE_MODE and hasattr(obj, "hook_scale"):
        #     obj.hook_scale(self.state_objects, replicas)
        self.state_objects.append(obj)
Ejemplo n.º 2
0
def test_convert_int_neg():
    assert k8s_to_domain_object("-123") == -123
Ejemplo n.º 3
0
def test_convert_int():
    assert k8s_to_domain_object("123") == 123
Ejemplo n.º 4
0
def test_convert_string():
    assert isinstance(k8s_to_domain_object("just_string"), str)
Ejemplo n.º 5
0
def test_convert_labeldict():
    assert isinstance(k8s_to_domain_object({"test":"test2"}), Label)
Ejemplo n.º 6
0
def test_convert_unit_minus():
    assert k8s_to_domain_object("-123Mi") == "-123Mi"
Ejemplo n.º 7
0
def test_convert_unit():
    assert k8s_to_domain_object("123Mi") == "123Mi"