コード例 #1
0
def initialize(log_kwargs=None, interactive=False, default_cluster_provider=None, skip_to=None):
    if interactive and not skip_to:
        logs.info('Starting interactive initialization of the operator on the following cluster:')
        print_info(minimal=True)
        input('Verify your are connected to the right cluster and press <RETURN> to continue')
        logs.info(f'Creating operator namespace: {OPERATOR_NAMESPACE}', **(log_kwargs or {}))
        subprocess.call(f'kubectl create ns {OPERATOR_NAMESPACE}', shell=True)
        assert default_cluster_provider in ['gcloud', 'aws'], f'invalid cluster provider: {default_cluster_provider}'

    from ckan_cloud_operator.labels import manager as labels_manager
    from ckan_cloud_operator.crds import manager as crds_manager
    from ckan_cloud_operator.providers.db import manager as db_manager
    from ckan_cloud_operator.providers.ckan import manager as ckan_manager
    from ckan_cloud_operator.providers.routers import manager as routers_manager
    from ckan_cloud_operator.providers.solr import manager as solr_manager
    from ckan_cloud_operator.providers.storage import manager as storage_manager

    for component, func in (
            ('labels', lambda lk: labels_manager.initialize(log_kwargs=lk)),
            ('cluster', lambda lk: providers_manager.get_provider('cluster', default=default_cluster_provider).initialize(interactive=interactive)),
            ('crds', lambda lk: crds_manager.initialize(log_kwargs=lk)),
            ('db', lambda lk: db_manager.initialize(log_kwargs=lk, interactive=interactive, default_cluster_provider=default_cluster_provider)),
            ('routers', lambda lk: routers_manager.initialize(interactive=interactive)),
            ('solr', lambda lk: solr_manager.initialize(interactive=interactive)),
            ('storage', lambda lk: storage_manager.initialize(interactive=interactive)),
            ('ckan', lambda lk: ckan_manager.initialize(interactive=interactive)),
    ):
        if not skip_to or skip_to == component:
            skip_to = None
            log_kwargs = {'cluster-init': component}
            logs.info(f'Initializing', **log_kwargs)
            func(log_kwargs)
コード例 #2
0
def initialize(log_kwargs=None, interactive=False, default_cluster_provider=None, skip_to=None):
    if interactive:
        logs.info('Starting interactive initialization of the operator on the following cluster:')
        print_info(minimal=True)
        if sys.stdout.isatty():
            input('Verify you are connected to the right cluster and press <RETURN> to continue')

    if not skip_to:
        logs.info(f'Creating operator namespace: {OPERATOR_NAMESPACE}', **(log_kwargs or {}))
        subprocess.call(f'kubectl create ns {OPERATOR_NAMESPACE}', shell=True)
        assert default_cluster_provider in ['gcloud', 'aws', 'azure', 'minikube'], f'invalid cluster provider: {default_cluster_provider}'
        subprocess.call(f'kubectl -n {OPERATOR_NAMESPACE} create secret generic ckan-cloud-provider-cluster-{default_cluster_provider}', shell=True)
        subprocess.call(f'kubectl -n {OPERATOR_NAMESPACE} create configmap operator-conf --from-literal=ckan-cloud-operator-image=viderum/ckan-cloud-operator:latest --from-literal=label-prefix={OPERATOR_NAMESPACE}', shell=True)

    from ckan_cloud_operator.providers import manager as providers_manager
    from ckan_cloud_operator.labels import manager as labels_manager
    from ckan_cloud_operator.crds import manager as crds_manager
    from ckan_cloud_operator.providers.db import manager as db_manager
    from ckan_cloud_operator.providers.ckan import manager as ckan_manager
    from ckan_cloud_operator.providers.routers import manager as routers_manager
    from ckan_cloud_operator.providers.solr import manager as solr_manager
    from ckan_cloud_operator.providers.storage import manager as storage_manager
    from ckan_cloud_operator.providers.apps import manager as apps_manager

    for component, func in (
            ('labels', lambda lk: labels_manager.initialize(log_kwargs=lk)),
            ('cluster', lambda lk: providers_manager.get_provider('cluster', default=default_cluster_provider).initialize(interactive=interactive)),
            ('crds', lambda lk: crds_manager.initialize(log_kwargs=lk)),
            ('db', lambda lk: db_manager.initialize(log_kwargs=lk, interactive=interactive, default_cluster_provider=default_cluster_provider)),
            ('routers', lambda lk: routers_manager.initialize(interactive=interactive)),
            ('solr', lambda lk: solr_manager.initialize(interactive=interactive)),
            ('storage', lambda lk: storage_manager.initialize(interactive=interactive)),
            ('ckan', lambda lk: ckan_manager.initialize(interactive=interactive)),
            ('apps', lambda lk: apps_manager.initialize(interactive=interactive)),
    ):
        if not skip_to or skip_to == component:
            skip_to = None
            log_kwargs = {'cluster-init': component}
            logs.info(f'Initializing', **log_kwargs)
            func(log_kwargs)
コード例 #3
0
 def initialize_labels(lk):
     from ckan_cloud_operator.labels import manager as labels_manager
     labels_manager.initialize(log_kwargs=lk, interactive=interactive)