From 3f9c82462f1b75f7cbf99d1f260b6fdf95d093c7 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Fri, 26 Aug 2016 13:50:22 -0400 Subject: [PATCH] Make sure the Quay Enterprise Kubernetes namespace exists Prevents config from failing to save. Also clarifies any other errors that do occur. Fixes #1449 --- util/config/provider/k8sprovider.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/util/config/provider/k8sprovider.py b/util/config/provider/k8sprovider.py index 78702b9c1..5775e94dd 100644 --- a/util/config/provider/k8sprovider.py +++ b/util/config/provider/k8sprovider.py @@ -58,11 +58,20 @@ class KubernetesConfigProvider(FileConfigProvider): def _assert_success(self, response): if response.status_code != 200: - logger.error('K8s API call failed with response: %s => %s', response.status_code, + logger.error('Kubernetes API call failed with response: %s => %s', response.status_code, response.text) - raise CannotWriteConfigException('K8s API call failed. Please report this to support') + raise CannotWriteConfigException('Kubernetes API call failed: %s' % response.text) def _update_secret_file(self, filename, value): + # Check first that the namespace for Quay Enterprise exists. If it does not, report that + # as an error, as it seems to be a common issue. + namespace_url = 'namespaces/%s' % (QE_NAMESPACE) + response = self._execute_k8s_api('GET', namespace_url) + if response.status_code != 200: + msg = 'A Kubernetes namespace with name `%s` must be created to save config' % QE_NAMESPACE + raise CannotWriteConfigException(msg) + + # Save the secret to the namespace. secret_data = {} secret_data[filename] = base64.b64encode(value)