Пример #1
0
    def get_value(self, options: OptionGetter) -> ConfigFileOutput:
        if not isinstance(options, Builder):
            raise InvalidParamError('Options must be a "Builder" instance')

        ret = {}
        if self.option_get('enable.log_level'):
            ret.update({
                'log.console.level':
                options.option_get('config.loglevel'),
            })
        if self.option_get('enable.cluster_formation'):
            ret.update({
                'cluster_formation.peer_discovery_backend':
                'k8s',
                'cluster_formation.k8s.host':
                'kubernetes.default.svc.cluster.local',
                'cluster_formation.k8s.address_type':
                'hostname',
                'cluster_formation.k8s.service_name':
                options.object_name('service-headless'),
                'queue_master_locator':
                'min-masters',
            })

        load_definitions = options.option_get('config.load_definitions')
        if load_definitions is not None:
            ret.update({
                'load_definitions':
                '/etc/rabbitmq-load-definition/load_definition.json',
            })

        if self.option_get('config.merge_config') is not None:
            Merger.merge(ret, self.option_get('config.merge_config'))

        return ConfigFileOutput_DictSingleLevel(ret)
Пример #2
0
    def build(self, provider: Provider, resources: KResourceDatabase,
              name: str, config: Optional[Any],
              merge_config: Optional[Any]) -> ObjectItem:
        ret = super().build(provider, resources, name, config, merge_config)
        ret['spec']['csi']['driver'] = 'dobs.csi.digitalocean.com'
        if config is not None:
            if 'nodriver' in config and config['nodriver'] is True:
                del ret['spec']['csi']['driver']

        if self.noformat is not None:
            if 'volumeAttributes' not in ret['spec']['csi']:
                ret['spec']['csi']['volumeAttributes'] = {}
            if 'com.digitalocean.csi/noformat' not in ret['spec']['csi'][
                    'volumeAttributes']:
                ret['spec']['csi']['volumeAttributes'][
                    'com.digitalocean.csi/noformat'] = QuotedStr(
                        'false' if self.noformat is False else 'true')

        if 'volumeHandle' in ret['spec']['csi'] and ret['spec']['csi'][
                'volumeHandle'] is not None:
            # https://github.com/digitalocean/csi-digitalocean/blob/master/examples/kubernetes/pod-single-existing-volume/README.md
            Merger.merge(
                ret, {
                    'metadata': {
                        'annotations': {
                            'pv.kubernetes.io/provisioned-by':
                            'dobs.csi.digitalocean.com',
                        }
                    }
                })

        if 'storageClassName' not in ret['spec']:
            ret['spec']['storageClassName'] = 'do-block-storage'

        return ret
Пример #3
0
    def build(self, provider: Provider, resources: 'KResourceDatabase',
              name: str, config: Optional[Any],
              merge_config: Optional[Any]) -> ObjectItem:
        pvdata: Dict[Any, Any] = {
            'apiVersion': 'v1',
            'kind': 'PersistentVolume',
            'metadata': {
                'name': name,
            },
            'spec': {
                'csi': None,
            },
        }
        if self.storageclass is not None:
            pvdata['spec']['storageClassName'] = self.storageclass
        if config is not None:
            if 'name' in config:
                pvdata['metadata']['name'] = config['name']
            if 'csi' in config:
                pvdata['spec']['csi'] = config['csi']

        ret = Merger.merge(pvdata,
                           merge_config if merge_config is not None else {})

        if ret['spec']['csi'] is None:
            raise InvalidParamError('"csi" config is required')

        return ret
Пример #4
0
    def build(self, provider: Provider, resources: KResourceDatabase, name: str,
              config: Optional[Any], merge_config: Optional[Any]) -> ObjectItem:
        pvdata = {
            'apiVersion': 'v1',
            'kind': 'PersistentVolume',
            'metadata': {
                'name': name,
            },
            'spec': {
                'awsElasticBlockStore': {},
            },
        }
        if self.storageclass is not None:
            pvdata['spec']['storageClassName'] = self.storageclass
        is_static = False
        if config is not None:
            if 'name' in config:
                pvdata['metadata']['name'] = config['name']
            if 'csi' in config:
                if 'volumeHandle' in config['csi']:
                    is_static = True
                    pvdata['spec']['awsElasticBlockStore']['volumeID'] = config['csi']['volumeHandle']
                if 'fsType' in config['csi']:
                    pvdata['spec']['awsElasticBlockStore']['fsType'] = config['csi']['fsType']
                if 'readOnly' in config['csi']:
                    pvdata['spec']['awsElasticBlockStore']['readOnly'] = config['csi']['readOnly']

        ret = Merger.merge(pvdata, merge_config if merge_config is not None else {})

        if is_static:
            # Static storage must set class name as ''
            ret['spec']['storageClassName'] = ''

        return ret
Пример #5
0
    def init_value(self, options: OptionGetter) -> ConfigFileExtensionData:
        ret = ConfigFileExtensionData({})

        if self.option_get('scrape.prometheus.enabled'):
            Merger.merge(
                ret.data, {
                    'scrape_configs': [
                        Merger.merge(
                            {
                                'job_name':
                                QuotedStr(
                                    self.option_get(
                                        'scrape.prometheus.job_name')),
                                'static_configs': [{
                                    'targets': [
                                        'localhost:9090',
                                    ]
                                }],
                            },
                            self.option_get('scrape.prometheus.merge_config'))
                    ]
                })

        return ret
Пример #6
0
    def build(self, provider: Provider, resources: 'KResourceDatabase',
              name: str, config: Optional[Any],
              merge_config: Optional[Any]) -> ObjectItem:
        if config is not None:
            if 'name' in config:
                name = config['name']

        ret = Merger.merge(
            {
                'apiVersion': 'storage.k8s.io/v1',
                'kind': 'StorageClass',
                'metadata': {
                    'name': name,
                },
            }, merge_config if merge_config is not None else {})

        return ret
Пример #7
0
    def build(self, provider: Provider, resources: 'KResourceDatabase',
              name: str, config: Optional[Any],
              merge_config: Optional[Any]) -> ObjectItem:
        pvdata: Dict[Any, Any] = {
            'apiVersion': 'v1',
            'kind': 'PersistentVolume',
            'metadata': {
                'name': name,
            },
            'spec': {},
        }
        if self.storageclass is not None:
            pvdata['spec']['storageClassName'] = self.storageclass
        if config is not None:
            if 'name' in config:
                pvdata['metadata']['name'] = config['name']

        return Merger.merge(pvdata,
                            merge_config if merge_config is not None else {})
Пример #8
0
 def finish_value(self, options: OptionGetter,
                  data: ConfigFileExtensionData) -> ConfigFileOutput:
     if self.option_get('config.merge_config') is not None:
         Merger.merge(data.data, self.option_get('config.merge_config'))
     return ConfigFileOutput_Dict(data.data)
Пример #9
0
    def build(self, provider: Provider, resources: 'KResourceDatabase',
              name: str, config: Optional[Any],
              merge_config: Optional[Any]) -> ObjectItem:
        pvcdata: Dict[Any, Any] = {
            'apiVersion': 'v1',
            'kind': 'PersistentVolumeClaim',
            'metadata': {
                'name': name,
            },
            'spec': {},
        }
        if self.storageclass is not None:
            pvcdata['spec']['storageClassName'] = self.storageclass

        persistentVolume: Optional[ObjectItem] = None
        if config is not None:
            if 'name' in config:
                pvcdata['metadata']['name'] = config['name']
            if 'namespace' in config:
                pvcdata['metadata']['namespace'] = config['namespace']
            if 'persistentVolume' in config:
                persistentVolume = resources.persistentvolume_build(
                    provider, config['persistentVolume'])[0]

        if persistentVolume is not None:
            if dict_has_name(persistentVolume, 'spec.storageClassName'):
                pv_storageclassname = dict_get_value(persistentVolume,
                                                     'spec.storageClassName')
                if pv_storageclassname is not None:
                    pvcdata['spec']['storageClassName'] = pv_storageclassname

            if not dict_has_name(pvcdata,
                                 'spec.accessModes') and dict_has_name(
                                     persistentVolume, 'spec.accessModes'):
                pvcdata['spec']['accessModes'] = persistentVolume['spec'][
                    'accessModes']

            if not dict_has_name(
                    pvcdata,
                    'spec.resources.requests.storage') and dict_has_name(
                        persistentVolume, 'spec.capacity.storage'):
                Merger.merge(
                    pvcdata, {
                        'spec': {
                            'resources': {
                                'requests': {
                                    'storage':
                                    dict_get_value(persistentVolume,
                                                   'spec.capacity.storage'),
                                }
                            }
                        }
                    })

        ret = Merger.merge(pvcdata,
                           merge_config if merge_config is not None else {})

        if not self.allow_selector:
            if 'selector' in ret['spec']:
                if persistentVolume is None:
                    raise InvalidParamError(
                        'PersistentVolumeClaim does not support selector but a PersistentVolume was not supplied'
                    )
                del ret['spec']['selector']
                ret['spec']['storageClassName'] = ''
                ret['spec']['volumeName'] = persistentVolume['metadata'][
                    'name']

        return ret