From f381f4dd3cd751d42519b4e69e31391356744abc Mon Sep 17 00:00:00 2001
From: Claudio Pisa
+ {% if kubeconfig_enabled %} + {% blocktrans trimmed %} + You can optionally provide a Kubernetes Namespace. It will be included in the + kubeconfig file which can be downloaded from the next screen. + {% endblocktrans %} + {% endif %} +
{% endblock %} diff --git a/openstack_dashboard/dashboards/identity/application_credentials/templates/application_credentials/_success.html b/openstack_dashboard/dashboards/identity/application_credentials/templates/application_credentials/_success.html index 1f56049c79..54c36ab55d 100644 --- a/openstack_dashboard/dashboards/identity/application_credentials/templates/application_credentials/_success.html +++ b/openstack_dashboard/dashboards/identity/application_credentials/templates/application_credentials/_success.html @@ -31,5 +31,11 @@ {{ download_clouds_yaml_label }} + {% if download_kubeconfig_url %} + + + {{ download_kubeconfig_label }} + + {% endif %} {{ cancel_label }} {% endblock %} diff --git a/openstack_dashboard/dashboards/identity/application_credentials/templates/application_credentials/kubeconfig.template b/openstack_dashboard/dashboards/identity/application_credentials/templates/application_credentials/kubeconfig.template new file mode 100644 index 0000000000..49693a37c6 --- /dev/null +++ b/openstack_dashboard/dashboards/identity/application_credentials/templates/application_credentials/kubeconfig.template @@ -0,0 +1,26 @@ +apiVersion: v1 +kind: Config +clusters: +- name: kubernetes + cluster: + server: {{ kubernetes_url }} + certificate-authority-data: {{ kubernetes_certificate_authority_data }} +contexts: +- name: kubernetes + context: + cluster: kubernetes + user: {{ user }} + namespace: {{ kubernetes_namespace }} +current-context: kubernetes +users: + - name: {{ user }} + user: + exec: + apiVersion: client.authentication.k8s.io/v1beta1 + command: bin/kubectl-keystone-auth + args: + - "--keystone-url={{ auth_url }} + - "--domain-name=none" + - "--user-name={{ user }}" + - "--application-credential-id={{ application_credential_id }}" + - "--application-credential-secret={{ application_credential_secret }}" diff --git a/openstack_dashboard/dashboards/identity/application_credentials/urls.py b/openstack_dashboard/dashboards/identity/application_credentials/urls.py index 3de9d13114..24e3061db7 100644 --- a/openstack_dashboard/dashboards/identity/application_credentials/urls.py +++ b/openstack_dashboard/dashboards/identity/application_credentials/urls.py @@ -28,6 +28,8 @@ urlpatterns = [ views.CreateSuccessfulView.as_view(), name='success'), url(r'^download_openrc/$', views.download_rc_file, name='download_openrc'), + url(r'^download_kubeconfig/$', + views.download_kubeconfig_file, name='download_kubeconfig'), url(r'^download_clouds_yaml/$', views.download_clouds_yaml_file, name='download_clouds_yaml'), ] diff --git a/openstack_dashboard/dashboards/identity/application_credentials/views.py b/openstack_dashboard/dashboards/identity/application_credentials/views.py index b5e61f7fc8..7a3866968b 100644 --- a/openstack_dashboard/dashboards/identity/application_credentials/views.py +++ b/openstack_dashboard/dashboards/identity/application_credentials/views.py @@ -86,6 +86,11 @@ class CreateView(forms.ModalFormView): kwargs['next_view'] = CreateSuccessfulView return kwargs + def get_context_data(self, **kwargs): + context = super(CreateView, self).get_context_data(**kwargs) + context['kubeconfig_enabled'] = settings.KUBECONFIG_ENABLED + return context + class CreateSuccessfulView(forms.ModalFormView): template_name = 'identity/application_credentials/success.html' @@ -97,15 +102,20 @@ class CreateSuccessfulView(forms.ModalFormView): cancel_label = _("Close") download_openrc_label = _("Download openrc file") download_clouds_yaml_label = _("Download clouds.yaml") + download_kubeconfig_label = _("Download kubeconfig file") def get_context_data(self, **kwargs): context = super(CreateSuccessfulView, self).get_context_data(**kwargs) context['download_openrc_label'] = self.download_openrc_label context['download_clouds_yaml_label'] = self.download_clouds_yaml_label + context['download_kubeconfig_label'] = self.download_kubeconfig_label context['download_openrc_url'] = reverse( 'horizon:identity:application_credentials:download_openrc') context['download_clouds_yaml_url'] = reverse( 'horizon:identity:application_credentials:download_clouds_yaml') + if settings.KUBECONFIG_ENABLED: + context['download_kubeconfig_url'] = reverse( + 'horizon:identity:application_credentials:download_kubeconfig') return context def get_initial(self): @@ -125,12 +135,18 @@ def _get_context(request): interface = 'public' region = getattr(request.user, 'services_region', '') app_cred = request.session['application_credential'] - context = dict(auth_url=auth_url, - interface=interface, - region=region, - application_credential_id=app_cred['id'], - application_credential_name=app_cred['name'], - application_credential_secret=app_cred['secret']) + context = { + 'auth_url': auth_url, + 'interface': interface, + 'region': region, + 'user': request.user, + 'application_credential_id': app_cred['id'], + 'application_credential_name': app_cred['name'], + 'application_credential_secret': app_cred['secret'], + 'kubernetes_namespace': app_cred['kubernetes_namespace'], + 'kubernetes_url': settings.KUBECONFIG_KUBERNETES_URL, + 'kubernetes_certificate_authority_data': + settings.KUBECONFIG_CERTIFICATE_AUTHORITY_DATA} return context @@ -166,6 +182,14 @@ def download_clouds_yaml_file(request): return _render_attachment(filename, template, context, request) +def download_kubeconfig_file(request): + context = _get_context(request) + template = 'identity/application_credentials/kubeconfig.template' + filename = 'app-cred-%s-kubeconfig' % context['application_credential_name'] + response = _render_attachment(filename, template, context, request) + return response + + class DetailView(views.HorizonTemplateView): template_name = 'identity/application_credentials/detail.html' page_title = "{{ application_credential.name }}" diff --git a/openstack_dashboard/defaults.py b/openstack_dashboard/defaults.py index f93c0f8130..fa081afc17 100644 --- a/openstack_dashboard/defaults.py +++ b/openstack_dashboard/defaults.py @@ -374,3 +374,11 @@ REST_API_REQUIRED_SETTINGS = [ # and are not encrypted on the browser. This is an experimental API and # may be deprecated in the future without notice. REST_API_ADDITIONAL_SETTINGS = [] + +# Kubernetes clusters can use Keystone as an external identity provider. +# Horizon can generate a 'kubeconfig' file from the application credentials +# control panel which can be used for authenticating with a Kubernetes cluster. +# These settings control the kubeconfig parameters. +KUBECONFIG_ENABLED = False +KUBECONFIG_KUBERNETES_URL = "" +KUBECONFIG_CERTIFICATE_AUTHORITY_DATA = "" diff --git a/releasenotes/notes/bp-kubernetes-config-gen-bcebcbd8f9fb9991.yaml b/releasenotes/notes/bp-kubernetes-config-gen-bcebcbd8f9fb9991.yaml new file mode 100644 index 0000000000..d2758d64b2 --- /dev/null +++ b/releasenotes/notes/bp-kubernetes-config-gen-bcebcbd8f9fb9991.yaml @@ -0,0 +1,8 @@ +--- +features: + - | + [`blueprint kubernetes-config-gen