def create(self, namespace):
"""Create the given namespace.
:param namespace: name of the namespace we want to create
:returns: True if the create succeeded, False otherwise
"""
response = self._post(
"/namespaces",
data={
"kind": "Namespace",
"apiVersion": "v1",
"metadata": {
"name": namespace,
}
}
)
if response['status'] == "Failure":
# I would rather raise.. but want to stay backward
# compatible for a little while.
# raise KubeError(response)
return False
self.config.set_namespace(namespace)
sa = ServiceAccount(self.config)
if not sa.exists("default"):
# this will (but not always) fail
try:
sa.create("default")
except sh.ErrorReturnCode_1 as err:
LOG.error(err)
LOG.error('(ignoring)')
return True
评论列表
文章目录