Documentation
¶
Index ¶
- type DefaultJobPodNameGetter
- type DynK8sInterface
- type JobPodNameGetter
- type JobsClient
- func (jc *JobsClient) ApplyKubernetesJob(jobFilePath, namespace string, readFile func(string) ([]byte, error)) error
- func (jc *JobsClient) DeleteKubernetesJob(ctx context.Context, jobName, namespace string) error
- func (jc *JobsClient) GetJobPodName(ctx context.Context, jobName, namespace string) (string, error)
- func (jc *JobsClient) JobExists(ctx context.Context, jobName, namespace string) (bool, error)
- func (jc *JobsClient) ListKubernetesJobs(ctx context.Context, namespace string) ([]batchv1.Job, error)
- func (jc *JobsClient) StreamJobLogs(workloadName, namespace string) error
- type K8sLoggerInterface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DefaultJobPodNameGetter ¶ added in v2.2.7
type DefaultJobPodNameGetter struct {
JC *JobsClient
}
DefaultJobPodNameGetter implements the default behavior for getting job pod names by using the JobsClient to fetch the pod name.
**Attributes:**
JC: A JobsClient for managing Kubernetes jobs.
func (*DefaultJobPodNameGetter) GetJobPodName ¶ added in v2.2.7
func (d *DefaultJobPodNameGetter) GetJobPodName(ctx context.Context, jobName, namespace string) (string, error)
GetJobPodName retrieves the name of the first pod associated with a specific Kubernetes job within a given namespace. It uses a label selector to find pods that are labeled with the job's name. This method is typically used in scenarios where jobs create a single pod or when only the first pod is of interest.
**Parameters:**
ctx: Context for managing control flow of the request. jobName: Name of the Kubernetes job to find pods for. namespace: Namespace where the job and its pods are located.
**Returns:**
string: The name of the first pod found that is associated with the job error: An error if no pods are found or if an error occurs during the pod retrieval
type DynK8sInterface ¶ added in v2.2.7
type DynK8sInterface interface { WaitForResourceState(ctx context.Context, resourceName, namespace, resourceType, desiredState string, checkStatusFunc func(name, namespace string) (bool, error)) error GetResourceStatus(ctx context.Context, kc *client.KubernetesClient, resourceName, namespace string, gvr schema.GroupVersionResource) (bool, error) }
DynK8sInterface defines the methods used from dynK8s to manage Kubernetes resources.
**Methods:**
WaitForResourceState: Waits for a Kubernetes resource to reach a desired state. GetResourceStatus: Retrieves the status of a Kubernetes resource.
type JobPodNameGetter ¶ added in v2.2.7
type JobPodNameGetter interface {
GetJobPodName(ctx context.Context, jobName, namespace string) (string, error)
}
JobPodNameGetter defines the method to get job pod name by job name and namespace.
**Methods:**
GetJobPodName: Retrieves the name of the first pod associated with a specific
type JobsClient ¶
type JobsClient struct { Client *client.KubernetesClient DynK8s DynK8sInterface K8sLogger K8sLoggerInterface StreamLogsFn func(clientset *kubernetes.Clientset, namespace, resourceType, resourceName string) error PodNameGetter JobPodNameGetter }
JobsClient represents a client for managing Kubernetes jobs through the Kubernetes API.
**Attributes:**
Client: A pointer to KubernetesClient for accessing Kubernetes API. DynK8s: A DynK8sInterface for managing Kubernetes resources. K8sLogger: A K8sLoggerInterface for streaming logs from Kubernetes pods. StreamLogsFn: A function for streaming logs from a Kubernetes pod. PodNameGetter: A JobPodNameGetter for getting job pod names.
func (*JobsClient) ApplyKubernetesJob ¶ added in v2.2.7
func (jc *JobsClient) ApplyKubernetesJob(jobFilePath, namespace string, readFile func(string) ([]byte, error)) error
ApplyKubernetesJob applies a Kubernetes job manifest to a Kubernetes cluster using the provided kubeconfig file. The job is applied to the specified namespace.
**Parameters:**
jobFilePath: Path to the job manifest file to apply. namespace: Namespace where the job should be applied.
**Returns:**
error: An error if the job could not be applied.
func (*JobsClient) DeleteKubernetesJob ¶
func (jc *JobsClient) DeleteKubernetesJob(ctx context.Context, jobName, namespace string) error
DeleteKubernetesJob deletes a specified Kubernetes job within a given namespace. It sets the deletion propagation policy to 'Foreground' to ensure that the delete operation waits until the cascading delete has completed.
**Parameters:**
ctx: Context for managing control flow of the request. jobName: Name of the Kubernetes job to delete. namespace: Namespace where the job is located.
**Returns:**
error: An error if the job could not be deleted.
func (*JobsClient) GetJobPodName ¶
GetJobPodName retrieves the name of the first pod associated with a specific Kubernetes job within a given namespace. It uses a label selector to find pods that are labeled with the job's name. This method is typically used in scenarios where jobs create a single pod or when only the first pod is of interest.
**Parameters:**
ctx: Context for managing control flow of the request. jobName: Name of the Kubernetes job to find pods for. namespace: Namespace where the job and its pods are located.
**Returns:**
string: The name of the first pod found that is associated with the job error: An error if no pods are found or if an error occurs during the pod retrieval
func (*JobsClient) JobExists ¶
JobExists checks if a Kubernetes job with the specified name exists within a given namespace.
**Parameters:**
ctx: Context for managing control flow of the request. jobName: Name of the Kubernetes job to check for existence. namespace: Namespace where the job is located.
**Returns:**
bool: true if the job exists, false otherwise. error: An error if the job existence check fails.
func (*JobsClient) ListKubernetesJobs ¶
func (jc *JobsClient) ListKubernetesJobs(ctx context.Context, namespace string) ([]batchv1.Job, error)
ListKubernetesJobs lists Kubernetes jobs from a specified namespace, or all namespaces if no namespace is specified. This method allows for either targeted or broad job retrieval.
**Parameters:**
ctx: Context for managing control flow of the request. namespace: Optional; specifies the namespace from which to list jobs. If empty, jobs will be listed from all namespaces.
**Returns:**
[]batchv1.Job: A slice of batchv1.Job objects containing the jobs found. error: An error if the API call to fetch the jobs fails.
func (*JobsClient) StreamJobLogs ¶ added in v2.2.7
func (jc *JobsClient) StreamJobLogs(workloadName, namespace string) error
StreamJobLogs monitors a Kubernetes job by waiting for it to reach the 'Ready' state and then streams logs from the associated pod.
**Parameters:**
jobsClient: A JobsClient for managing Kubernetes jobs. workloadName: Name of the Kubernetes job to monitor. namespace: Namespace where the job is located.
**Returns:**
error: An error if the job monitoring fails.
type K8sLoggerInterface ¶ added in v2.2.7
type K8sLoggerInterface interface {
StreamLogs(clientset kubernetes.Interface, namespace, resourceType, podName string) error
}
K8sLoggerInterface defines the methods used from k8sLogger to stream logs from Kubernetes pods.
**Methods:**
StreamLogs: Streams logs from a Kubernetes pod.