Kubernetes Helper Class Reference
- class smarter.common.helpers.k8s_helpers.KubernetesHelper(kubeconfig=None, configured=False, **kwargs)[source]
Bases:
SmarterHelperMixinHelper class for interacting with Kubernetes clusters.
This class provides a set of utility methods to manage and verify Kubernetes resources such as Ingresses, Certificates, and Secrets, as well as to apply manifests and update kubeconfig files for EKS clusters. It is designed to be used as a singleton and integrates with AWS EKS and cert-manager.
- Parameters:
- apply_manifest(manifest)[source]
Apply a Kubernetes manifest to the cluster.
- Parameters:
manifest (
str) – The Kubernetes manifest as a string.- Raises:
KubernetesHelperException – If applying the manifest fails.
- Returns:
None
- Return type:
None
- property configured: bool
Return whether the kubeconfig has been configured.
- Returns:
True if configured, False otherwise.
- Return type:
- delete_certificate(certificate_name, namespace)[source]
Delete a cert-manager certificate resource from the cluster. command: - kubectl delete certificate education.3141-5926-5359.api.example.com-tls -n smarter-platform-prod
- delete_ingress(ingress_name, namespace)[source]
Delete an Ingress resource from the cluster. command: - kubectl delete ingress education.3141-5926-5359.api.example.com -n smarter-platform-prod
- delete_ingress_resources(hostname, namespace)[source]
Delete an ingress and all child resources from the cluster. commands: - kubectl delete ingress education.3141-5926-5359.api.example.com -n smarter-platform-prod - kubectl delete certificate education.3141-5926-5359.api.example.com-tls -n smarter-platform-prod - kubectl delete secret education.3141-5926-5359.api.example.com-tls -n smarter-platform-prod
- delete_secret(secret_name, namespace)[source]
Delete a secret resource from the cluster. commands: - kubectl delete secret education.3141-5926-5359.api.example.com-tls -n smarter-platform-prod
- property kubeconfig: dict
Return the kubeconfig file as a dictionary.
- Returns:
The kubeconfig dictionary.
- Return type:
- property kubeconfig_path: str
Return the path to the kubeconfig file.
- Returns:
The kubeconfig file path.
- Return type:
- property namespace_verified: bool
Return whether the Kubernetes namespace has been verified.
- Returns:
True if the namespace has been verified, False otherwise.
- Return type:
- property ready: bool
Return whether the Kubernetes helper is ready for use. Returns True if Kubernetes is configured, AND, the Kubernetes namespace exists.
- Returns:
True if ready, False otherwise.
- Return type:
smarter_settings.environment_namespace
- update_kubeconfig()[source]
Generate a fresh kubeconfig file for the EKS cluster.
This method uses the AWS CLI to update the kubeconfig file for the specified EKS cluster.
- Raises:
KubernetesHelperException – If the kubeconfig update fails.
- Returns:
True if the kubeconfig was updated successfully, False otherwise.
- Return type:
- verify_certificate(name, namespace)[source]
Verify that a cert-manager certificate resource exists in the cluster and is in a ready state.
command: - kubectl get certificate smarter.3141-5926-5359.api.example.com-tls -n smarter-platform-prod -o json
parse json response and check for the following: - status.conditions.type == Ready
- verify_ingress(name, namespace)[source]
Verify that an Ingress resource exists in the cluster.
commands: - kubectl get ingress smarter.3141-5926-5359.api.example.com -n smarter-platform-prod -o json
- verify_ingress_resources(hostname, namespace)[source]
Verify that an ingress and all child resources exist in the cluster.
commands: - kubectl get ingress education.3141-5926-5359.api.example.com -n smarter-platform-prod -o json - kubectl get certificate education.3141-5926-5359.api.example.com-tls -n smarter-platform-prod -o json - kubectl get secret education.3141-5926-5359.api.example.com-tls -n smarter-platform-prod -o json