Package io.deephaven.util.kubernetes
Class KubernetesUtil
java.lang.Object
io.deephaven.util.kubernetes.KubernetesUtil
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final intstatic final intstatic final intstatic final intstatic final Stringstatic final StringK8SWorkerImpl will use this to maybe wait for a worker pod to exit before deleting the pod.static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final String[]static final Stringstatic final StringMetadata label with a boolean value that will determine if the secret for the worker cert's keystore password will be deleted when the pod is deleted programmatically.static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringThe toleration value is a : separated toleration key, operator, effect, and value service, for example "MyKey:Equal:NoSchedule:UserGroupWorkerTolerationValuesService".static final Stringstatic final Stringstatic Patternstatic Pattern -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcleanupObjects(io.deephaven.shadow.kube.io.fabric8.kubernetes.client.KubernetesClient k8sClient, io.deephaven.shadow.kube.io.fabric8.certmanager.client.CertManagerClient k8sCertMgrClient, String k8sNamespace, com.fishlib.io.logger.Logger log) Called at dispatcher startup to clean up any orphaned workers after a dispatcher restart, it cleans any orphaned objects related to workers.static voidcleanupObjects(String k8sNamespace, com.fishlib.io.logger.Logger log) static booleanstatic voiddeleteWorkerObjects(io.deephaven.shadow.kube.io.fabric8.kubernetes.client.KubernetesClient k8sClient, io.deephaven.shadow.kube.io.fabric8.certmanager.client.CertManagerClient k8sCertMgrClient, String k8sNamespace, String podName, com.fishlib.io.logger.Logger log) Does cleanup for a single worker pod that is being deleted, removing associated objects that may have been created such as a service, certificate, secret for a worker cert, and the secret for the cert keystore password.static StringgetK8sSafeLabel(String label) Make sure that names (for containers, pods, ports, etc) conform to RFC 1123 definition of a DNS label no longer than 63 chars.static StringgetK8sSafeLabel(String label, int maxLen) Make sure that names (for containers, pods, ports, etc) conform to RFC 1123 definition of a DNS label no longer than maxLen chars.static StringgetK8sSafeLabel(String label, int maxLen, Supplier<String> generator) Make sure that names (for containers, pods, ports, etc) conform to RFC 1123 definition of a DNS label.static io.deephaven.shadow.kube.io.fabric8.kubernetes.client.KubernetesClientstatic io.deephaven.shadow.kube.io.fabric8.certmanager.api.model.v1.CertificategetNewCertificate(String k8sNamespace, String k8sWorkerId, String... dnsNames) static io.deephaven.shadow.kube.io.fabric8.kubernetes.api.model.SecretgetNewWorkerKeystorePasswordSecret(String k8sNamespace) static io.deephaven.shadow.kube.io.fabric8.kubernetes.api.model.SecretgetNewWorkerKeystorePasswordSecret(String k8sNamespace, String password) static io.deephaven.shadow.kube.io.fabric8.kubernetes.api.model.PersistentVolumeClaimgetPersistentVolumeClaim(String k8sWorkerId, String pvcName, String accessMode, String storageClassName, String storageSize) Build the manifest spec for a persistent volume claim for a worker pod if someone has indicated they want one in the PQ's advanced settings.static StringgetWorkerCertificateIssuerName(String k8sNamespace) Return name of the certificate issuer object that will used to create certificates.static StringgetWorkerCertificateName(String k8sWorkerId) Return name of the certificate object that will be created for this worker.static StringgetWorkerCertificateSecretName(String k8sWorkerId) Return name of the secret object that will be created with the certificate for the worker.static StringReturn name of the key in k8s secret holding the password to the keystore mounted in the worker pod that has the password.static StringReturn name of the k8s secret holding the password to the keystore mounted in the worker pod.static StringgetWorkerServiceName(String k8sWorkerId) Return name of the k8s headless service object that will be created for this worker.static booleanstatic boolean
-
Field Details
-
VALID_RFC_1035_PATTERN
-
VALID_RFC_1123_PATTERN
-
DEFAULT_API_VERSION
- See Also:
-
PROP_CHART_NAME
- See Also:
-
PROP_RELEASE_NAME
- See Also:
-
PROP_RELEASE_NAMESPACE
- See Also:
-
PROP_WORKER_KEYSTORE_PASSWORD_SECRET_NAME
- See Also:
-
PROP_WORKER_KEYSTORE_PASSWORD_SECRET_KEY
- See Also:
-
PROP_CERTMGR_ENABLED
- See Also:
-
PROP_CERT_ISSUER
- See Also:
-
PROP_WORKER_VALIDATOR
- See Also:
-
PROP_DEFAULT_STORAGE_CLASS
- See Also:
-
PROP_WORKER_ROLE
- See Also:
-
PROP_DISPATCHER_APP_VALUE
- See Also:
-
PROP_SET_CPU_LIMIT
- See Also:
-
PROP_WORKER_TOLERATION
The toleration value is a : separated toleration key, operator, effect, and value service, for example "MyKey:Equal:NoSchedule:UserGroupWorkerTolerationValuesService". The value service must be an impl ofWorkerTolerationValuesService. See the workerTolerations section of the Deephaven helm chart's values.yaml for more information.- See Also:
-
PROP_WORKER_TOLERATION_COUNT
- See Also:
-
DFLT_ACCESS_MODE
- See Also:
-
DFLT_WORKER_VOL_MOUNT_PATH
- See Also:
-
PROP_DNS_LOOKUP_MAX_WAIT_SEC
- See Also:
-
DFLT_DNS_LOOKUP_MAX_WAIT_SEC
public static final int DFLT_DNS_LOOKUP_MAX_WAIT_SEC- See Also:
-
PROP_PRE_DNS_LOOKUP_DELAY_SEC
- See Also:
-
DFLT_PRE_DNS_LOOKUP_DELAY_SEC
public static final int DFLT_PRE_DNS_LOOKUP_DELAY_SEC- See Also:
-
PROP_DNS_LOOKUP_FREQUENCY_SEC
- See Also:
-
DFLT_DNS_LOOKUP_FREQUENCY_SEC
public static final int DFLT_DNS_LOOKUP_FREQUENCY_SEC- See Also:
-
PROP_POD_DELETE_MAX_WAIT_SEC
- See Also:
-
DFLT_POD_DELETE_MAX_WAIT_SEC
public static final int DFLT_POD_DELETE_MAX_WAIT_SEC- See Also:
-
PROP_WORKER_SUBDOMAIN_SVC_NAME
- See Also:
-
LABEL_NAME
- See Also:
-
LABEL_INSTANCE
- See Also:
-
LABEL_VERSION
- See Also:
-
LABEL_DISPATCHER_POD_NAME
- See Also:
-
LABEL_WORKER_CERT_NAME
- See Also:
-
LABEL_WORKER_CERT_SECRET_NAME
- See Also:
-
LABEL_WORKER_POD_NAME
- See Also:
-
LABEL_PQ_SERIAL
- See Also:
-
LABEL_PQ_NAME
- See Also:
-
LABEL_DISPATCHER_USER_NAME
- See Also:
-
LABEL_DISPATCHER_PROCESS_INFO_ID_NAME
- See Also:
-
LABEL_WORKER_PVC
- See Also:
-
LABEL_APP
- See Also:
-
LABEL_ROLE
- See Also:
-
LABEL_ROLE_VALUE_WORKER_SERVICE_TYPES
-
LABEL_WORKER_CERT_DELETE_KS_PWD_SECRET
Metadata label with a boolean value that will determine if the secret for the worker cert's keystore password will be deleted when the pod is deleted programmatically. If using one worker cert keystore password secret for all workers then it should be false. Deleting pods manually using kubectl elides cleanup, and may result in some extraneous secret objects.- See Also:
-
ENV_WORKER_POD_EXIT_WAIT_SEC
K8SWorkerImpl will use this to maybe wait for a worker pod to exit before deleting the pod.- See Also:
-
-
Constructor Details
-
KubernetesUtil
public KubernetesUtil()
-
-
Method Details
-
getKubernetesClient
public static io.deephaven.shadow.kube.io.fabric8.kubernetes.client.KubernetesClient getKubernetesClient() -
getPersistentVolumeClaim
public static io.deephaven.shadow.kube.io.fabric8.kubernetes.api.model.PersistentVolumeClaim getPersistentVolumeClaim(String k8sWorkerId, String pvcName, String accessMode, String storageClassName, String storageSize) Build the manifest spec for a persistent volume claim for a worker pod if someone has indicated they want one in the PQ's advanced settings.- Parameters:
k8sWorkerId- The worker id, typically the pod name e.g. query-server-79c6478c6d-mvvxk-worker-1pvcName- The name of the PVC to create or mountaccessMode- e.g. ReadWriteOncestorageClassName- What kind of storage class to use, k8s provider dependent. E.g. standard-rwo for GKE.storageSize- Size of the volume to request, e.g. 10Gi- Returns:
- PersistentVolumeClaim object
-
getWorkerKeystorePasswordSecretName
Return name of the k8s secret holding the password to the keystore mounted in the worker pod.- Returns:
- Worker keystore password secret name
-
getWorkerKeystorePasswordSecretKey
Return name of the key in k8s secret holding the password to the keystore mounted in the worker pod that has the password.- Returns:
- Worker keystore password secret key
-
deleteWorkerKeystorePasswordSecretWithPod
public static boolean deleteWorkerKeystorePasswordSecretWithPod() -
getWorkerCertificateName
Return name of the certificate object that will be created for this worker.- Parameters:
k8sWorkerId- The worker id, typically the pod name e.g. query-server-79c6478c6d-mvvxk-worker-1- Returns:
- name of the certificate object that will be created for this worker.
-
getWorkerCertificateSecretName
Return name of the secret object that will be created with the certificate for the worker.- Parameters:
k8sWorkerId- The worker id, typically the pod name e.g. query-server-79c6478c6d-mvvxk-worker-1- Returns:
- name of the secret object that will be created with the worker's certificate.
-
getWorkerServiceName
Return name of the k8s headless service object that will be created for this worker. The controller will use this name to lookup the worker's address, and this will be used in the worker certificate's SAN.- Parameters:
k8sWorkerId- The worker id, typically the pod name e.g. query-server-79c6478c6d-mvvxk-worker-1- Returns:
- name of the service object that will be created for this worker.
-
getWorkerCertificateIssuerName
Return name of the certificate issuer object that will used to create certificates. Defaults to <k8sNamespace>-issuer if not explicitly set as a config property.- Parameters:
k8sNamespace- The kubernetes namespace.- Returns:
- name of the certificate issuer.
-
isCertManagerEnabled
public static boolean isCertManagerEnabled() -
getNewCertificate
public static io.deephaven.shadow.kube.io.fabric8.certmanager.api.model.v1.Certificate getNewCertificate(String k8sNamespace, String k8sWorkerId, String... dnsNames) throws ParseException - Throws:
ParseException
-
getNewWorkerKeystorePasswordSecret
public static io.deephaven.shadow.kube.io.fabric8.kubernetes.api.model.Secret getNewWorkerKeystorePasswordSecret(String k8sNamespace) -
getNewWorkerKeystorePasswordSecret
-
getK8sSafeLabel
Make sure that names (for containers, pods, ports, etc) conform to RFC 1123 definition of a DNS label no longer than 63 chars. If label cannot be made compliant, a java UUID with a prefix of "dh-" will be returned.- Parameters:
label- The string to be sanitized.- See Also:
-
getK8sSafeLabel
Make sure that names (for containers, pods, ports, etc) conform to RFC 1123 definition of a DNS label no longer than maxLen chars. If label cannot be made compliant, a java UUID with a prefix of "dh-" will be returned.- Parameters:
label- The string to be sanitized.- See Also:
-
getK8sSafeLabel
Make sure that names (for containers, pods, ports, etc) conform to RFC 1123 definition of a DNS label.Specifically, must contain at least one letter [a-z] and it must contain only [a-z0-9-]; hyphens cannot be leading or trailing character of the string and cannot be adjacent to other hyphens; must be <= maxLen chars, with maxLen being no more than 63 characters. Input label is lower cased, and invalid characters are removed. In the event that the input label cannot be sanitized, the supplied generator will be invoked to supply a label.
- Parameters:
label- The string to be possibly sanitized.maxLen- The maximum length of the string to be returned; will be adjusted to a value between 2 and 63.generator- The label generationSupplierfunction to be used in the event that the input cannot be sanitized to satisfaction. The caller of this function is responsible for making sure that the generator will return a valid label.- See Also:
-
- "https://github.com/kubernetes/design-proposals-archive/blob/main/architecture/identifiers.md"
- "https://kubernetes.io/docs/reference/kubernetes-api/service-resources/service-v1/#ServiceSpec"
- "https://kubernetes.io/docs/concepts/overview/working-with-objects/names/"
-
cleanupObjects
-
cleanupObjects
public static void cleanupObjects(io.deephaven.shadow.kube.io.fabric8.kubernetes.client.KubernetesClient k8sClient, io.deephaven.shadow.kube.io.fabric8.certmanager.client.CertManagerClient k8sCertMgrClient, String k8sNamespace, com.fishlib.io.logger.Logger log) Called at dispatcher startup to clean up any orphaned workers after a dispatcher restart, it cleans any orphaned objects related to workers. 1st - Delete workers for like-kind (query or merge) dispatchers. 2nd - Delete worker service if worker is not running. 3rd - Delete worker certificate if worker is not running. 4th - Delete certificate secret if certificate is not present. Note: K8SWorkerImpl has been changed to remove worker pods and associated objects when it detects that a worker pod is no longer running (e.g. if the worker/pq exits or is stopped cleanly), and delete these objects throughdeleteWorkerObjects(KubernetesClient, CertManagerClient, String, String, Logger). This fn will kill any workers that are still around after a dispatcher is restarted though, and is run from the dispatcher's ctor when it starts up. -
deleteWorkerObjects
public static void deleteWorkerObjects(io.deephaven.shadow.kube.io.fabric8.kubernetes.client.KubernetesClient k8sClient, io.deephaven.shadow.kube.io.fabric8.certmanager.client.CertManagerClient k8sCertMgrClient, String k8sNamespace, String podName, com.fishlib.io.logger.Logger log) Does cleanup for a single worker pod that is being deleted, removing associated objects that may have been created such as a service, certificate, secret for a worker cert, and the secret for the cert keystore password.Any
PersistentVolumeClaimorPersistentVolumethat is created for a worker is not automatically deleted. If a user wishes to delete that, they must do that manually.- Parameters:
k8sClient- Kubernetes API clientk8sCertMgrClient- Kubernetes client for the cert-manager CRDk8sNamespace- Kubernetes namespace of worker objects being removedpodName- The .metadata.name of the worker pod being removedlog- Logger object
-
isSetCpuLimitToRequest
public static boolean isSetCpuLimitToRequest()
-