예제 #1
0
def create_object(config=None, name=None, obj_type=None):
    if config is None:
        config = create_config()
    obj = K8sObject(
        config=config,
        name=name,
        obj_type=obj_type
    )
    return obj
예제 #2
0
    def __init__(self, config=None, name=None):

        temp = K8sObject(config=config, obj_type='Pod', name='temp')
        _type = 'CronJob'

        if config and is_reachable(config.api_host):
            v = temp.server_version()
            if int(v['major']) == 1 and int(v['minor']) == 4:
                _type = 'ScheduledJob'

        super(K8sCronJob, self).__init__(config=config,
                                         obj_type=_type,
                                         name=name)
예제 #3
0
    def __init__(self, config=None, name=None):

        if config and is_reachable(config.api_host):
            temp = K8sObject(config=config, obj_type='Pod', name='temp')
            v = temp.server_version()
            if int(v['major']) <= 1 and int(v['minor']) < 4:
                raise NotImplementedError(
                    'PetSets exist only on Kubernetes == 1.4.x.')
            if int(v['major']) >= 1 and int(v['minor']) >= 5:
                raise NotImplementedError(
                    'PetSets were refactored into StatefulSets on Kubernetes >= 1.5.x.'
                )

        super(K8sPetSet, self).__init__(config=config,
                                        name=name,
                                        obj_type='PetSet')
예제 #4
0
def assert_server_version(api_host=None, major=None, minor=None, type='exact'):
    try:
        if not api_host:
            return False
        if is_reachable(api_host):
            cfg = K8sConfig(api_host=api_host)
            obj = K8sObject(config=cfg, obj_type='Pod', name='temp')
            v = obj.server_version()
            if type == 'exact':
                if int(v['major']) != major or int(v['minor']) != minor:
                    msg = 'Desired: [ {}.{} ]. Observed: [ {}.{} ].'.format(major, minor, v['major'], v['minor'])
                    raise VersionMismatchException(msg)
            return True
        return False

    except VersionMismatchException:
        return False
예제 #5
0
    def __init__(self, config=None, name=None):

        temp = K8sObject(config=config, obj_type='Pod', name='temp')
        _type = 'CronJob'

        if config and is_reachable(config):
            v = temp.server_version()
            if int(v['major']) == 1 and int(v['minor']) == 4:
                _type = 'ScheduledJob'

        super(K8sCronJob, self).__init__(
            config=config,
            obj_type=_type,
            name=name
        )

        if config is not None and config.pull_secret is not None:
            self.add_image_pull_secrets(config.pull_secret)
예제 #6
0
def server_version():
    from kubernetes.K8sObject import K8sObject
    obj = K8sObject(obj_type='Pod', name='obj')
    v = obj.server_version()
    return v
예제 #7
0
 def __init__(self, config=None, name=None):
     K8sObject.__init__(self, config=config, obj_type='Service', name=name)
     self.model = Service(name=name, namespace=self.config.namespace)
예제 #8
0
 def __init__(self, name, obj_type, config=None):
     K8sObject.__init__(self, config=config, obj_type=obj_type, name=name)
예제 #9
0
 def __init__(self, config=None, name=None):
     K8sObject.__init__(self, config=config, obj_type='Secret', name=name)
     self.model = Secret(name=name, namespace=self.config.get_namespace())