diff --git a/kr8s/_api.py b/kr8s/_api.py index 5575c58c..1a41e1c9 100644 --- a/kr8s/_api.py +++ b/kr8s/_api.py @@ -111,6 +111,7 @@ async def _create_session(self) -> None: headers=headers, verify=await self.auth.ssl_context(), timeout=self._timeout, + follow_redirects=True, ) def _construct_url( @@ -130,7 +131,7 @@ def _construct_url( parts = [base] if version: parts.append(version) - if namespace is not None: + if namespace: parts.extend(["namespaces", namespace]) parts.append(url) return "/".join(parts) diff --git a/kr8s/_auth.py b/kr8s/_auth.py index 9920b5bc..6747f974 100644 --- a/kr8s/_auth.py +++ b/kr8s/_auth.py @@ -31,7 +31,7 @@ def __init__( self.client_key_file: Optional[PathType] = None self.server_ca_file: Optional[PathType] = None self.token: Optional[str] = None - self.namespace: Optional[str] = namespace + self._namespace: Optional[str] = namespace self.active_context: str = "" self.kubeconfig: KubeConfigSet self.tls_server_name: Optional[str] = None @@ -100,6 +100,14 @@ async def ssl_context(self): sslcontext.load_verify_locations(cafile=self.server_ca_file) return sslcontext + @property + def namespace(self) -> str: + return self._namespace if self._namespace else "default" + + @namespace.setter + def namespace(self, value: str): + self._namespace = value + async def _load_kubeconfig(self) -> None: """Load kubernetes auth from kubeconfig.""" if isinstance(self._kubeconfig_path_or_dict, str) or isinstance( @@ -131,8 +139,8 @@ async def _load_kubeconfig(self) -> None: self.active_context = self.kubeconfig.contexts[0]["name"] # Load configuration options from the context - if self.namespace is None: - self.namespace = self.kubeconfig.current_namespace + if self._namespace is None: + self._namespace = self.kubeconfig.current_namespace # If no cluster is found in the context, assume it's a service account if not self._context["cluster"]: