Class BaseCmdKubeClient<K extends BaseCmdKubeClient<K>>
java.lang.Object
io.skodjob.testframe.clients.cmdClient.BaseCmdKubeClient<K>
- Type Parameters:
K- The subtype of KubeClient, for fluency.
- All Implemented Interfaces:
KubeCmdClient<K>
public abstract class BaseCmdKubeClient<K extends BaseCmdKubeClient<K>>
extends Object
implements KubeCmdClient<K>
Abstract class representing a base Kubernetes command-line client.
-
Method Summary
Modifier and TypeMethodDescriptionApplies resources from files.applyContent(String yamlContent) Applies YAML content.abstract Stringcmd()Abstract method to retrieve the command.Creates resources from files.createNamespace(String name) Creates a namespace.voidcreateResourceAndApply(String template, Map<String, String> params) Creates a resource from a template and applies it.Deletes resources from files.deleteByName(String resourceType, String resourceName) Deletes a resource by its name.deleteContent(String yamlContent) Deletes YAML content.deleteNamespace(String name) Deletes a namespace.Retrieves the description of a resource.Executes a command with the option to throw errors and log to output.Executes a command with the option to throw errors and log to output.Executes a command with the option to throw errors.Executes a command.Executes a command in a pod.execInPodContainer(boolean logToOutput, String pod, String container, String... command) Executes a command in a pod container with the option to log to output.execInPodContainer(String pod, String container, String... command) Executes a command in a pod container.Retrieves the YAML representation of a resource.Retrieves the events from the cluster.getResourceAsJson(String resourceType, String resourceName) Retrieves a resource as JSON.getResourceAsYaml(String resourceType, String resourceName) Retrieves a resource as YAML.getResourcesAsYaml(String resourceType) Retrieves resources as YAML.Lists resources of a certain type.listResourcesByLabel(String resourceType, String label) Lists resources by label.Retrieves logs of a pod/container.Processes a template file with parameters.Replaces resources from files.scaleByName(String kind, String name, int replicas) Scales resources by name.searchInLog(String resourceType, String resourceName, long sinceSeconds, String... grepPattern) Searches for patterns in logs.searchInLog(String resourceType, String resourceName, String resourceContainer, long sinceSeconds, String... grepPattern) Searches for patterns in logs of a specific container.toString()Converts the object to a string representation.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface io.skodjob.testframe.clients.cmdClient.KubeCmdClient
apply, create, defaultOlmNamespace, delete, getCurrentNamespace, getUsername, inNamespace, logs
-
Method Details
-
cmd
Abstract method to retrieve the command.- Specified by:
cmdin interfaceKubeCmdClient<K extends BaseCmdKubeClient<K>>- Returns:
- The command string.
-
deleteByName
Deletes a resource by its name.- Specified by:
deleteByNamein interfaceKubeCmdClient<K extends BaseCmdKubeClient<K>>- Parameters:
resourceType- The type of the resource.resourceName- The name of the resource.- Returns:
- The instance of the client.
-
get
Retrieves the YAML representation of a resource.- Specified by:
getin interfaceKubeCmdClient<K extends BaseCmdKubeClient<K>>- Parameters:
resource- The type of the resource.resourceName- The name of the resource.- Returns:
- The YAML representation of the resource.
-
getEvents
Retrieves the events from the cluster.- Specified by:
getEventsin interfaceKubeCmdClient<K extends BaseCmdKubeClient<K>>- Returns:
- The events as a string.
-
create
Creates resources from files.- Specified by:
createin interfaceKubeCmdClient<K extends BaseCmdKubeClient<K>>- Parameters:
files- The files representing the resources.- Returns:
- The instance of the client.
-
apply
Applies resources from files.- Specified by:
applyin interfaceKubeCmdClient<K extends BaseCmdKubeClient<K>>- Parameters:
files- The files representing the resources.- Returns:
- The instance of the client.
-
delete
Deletes resources from files.- Specified by:
deletein interfaceKubeCmdClient<K extends BaseCmdKubeClient<K>>- Parameters:
files- The files representing the resources.- Returns:
- The instance of the client.
-
replace
Replaces resources from files.- Specified by:
replacein interfaceKubeCmdClient<K extends BaseCmdKubeClient<K>>- Parameters:
files- The files representing the resources.- Returns:
- The instance of the client.
-
applyContent
Applies YAML content.- Specified by:
applyContentin interfaceKubeCmdClient<K extends BaseCmdKubeClient<K>>- Parameters:
yamlContent- The YAML content.- Returns:
- The instance of the client.
-
deleteContent
Deletes YAML content.- Specified by:
deleteContentin interfaceKubeCmdClient<K extends BaseCmdKubeClient<K>>- Parameters:
yamlContent- The YAML content.- Returns:
- The instance of the client.
-
createNamespace
Creates a namespace.- Specified by:
createNamespacein interfaceKubeCmdClient<K extends BaseCmdKubeClient<K>>- Parameters:
name- The name of the namespace.- Returns:
- The instance of the client.
-
deleteNamespace
Deletes a namespace.- Specified by:
deleteNamespacein interfaceKubeCmdClient<K extends BaseCmdKubeClient<K>>- Parameters:
name- The name of the namespace.- Returns:
- The instance of the client.
-
scaleByName
Scales resources by name.- Specified by:
scaleByNamein interfaceKubeCmdClient<K extends BaseCmdKubeClient<K>>- Parameters:
kind- The kind of the resource.name- The name of the resource.replicas- The number of replicas.- Returns:
- The instance of the client.
-
execInPod
Executes a command in a pod.- Specified by:
execInPodin interfaceKubeCmdClient<K extends BaseCmdKubeClient<K>>- Parameters:
pod- The name of the pod.command- The command to execute.- Returns:
- The execution result.
-
execInPodContainer
Executes a command in a pod container.- Specified by:
execInPodContainerin interfaceKubeCmdClient<K extends BaseCmdKubeClient<K>>- Parameters:
pod- The name of the pod.container- The name of the container.command- The command to execute.- Returns:
- The execution result.
-
execInPodContainer
public ExecResult execInPodContainer(boolean logToOutput, String pod, String container, String... command) Executes a command in a pod container with the option to log to output.- Specified by:
execInPodContainerin interfaceKubeCmdClient<K extends BaseCmdKubeClient<K>>- Parameters:
logToOutput- Whether to log the output.pod- The name of the pod.container- The name of the container.command- The command to execute.- Returns:
- The execution result.
-
exec
Executes a command.- Specified by:
execin interfaceKubeCmdClient<K extends BaseCmdKubeClient<K>>- Parameters:
command- The command to execute.- Returns:
- The execution result.
-
exec
Executes a command with the option to throw errors.- Specified by:
execin interfaceKubeCmdClient<K extends BaseCmdKubeClient<K>>- Parameters:
throwError- Whether to throw errors.command- The command to execute.- Returns:
- The execution result.
-
exec
Executes a command with the option to throw errors and log to output.- Specified by:
execin interfaceKubeCmdClient<K extends BaseCmdKubeClient<K>>- Parameters:
throwError- Whether to throw errors.logToOutput- Whether to log the output.command- The command to execute.- Returns:
- The execution result.
-
exec
Executes a command with the option to throw errors and log to output.- Specified by:
execin interfaceKubeCmdClient<K extends BaseCmdKubeClient<K>>- Parameters:
throwError- Whether to throw errors.logToOutput- Whether to log the output.timeout- timeout in miliscommand- The command to execute.- Returns:
- The execution result.
-
toString
Converts the object to a string representation. -
list
Lists resources of a certain type.- Specified by:
listin interfaceKubeCmdClient<K extends BaseCmdKubeClient<K>>- Parameters:
resourceType- The type of the resource.- Returns:
- A list of resource names.
-
getResourceAsJson
Retrieves a resource as JSON.- Specified by:
getResourceAsJsonin interfaceKubeCmdClient<K extends BaseCmdKubeClient<K>>- Parameters:
resourceType- The type of the resource.resourceName- The name of the resource.- Returns:
- The resource as JSON.
-
getResourceAsYaml
Retrieves a resource as YAML.- Specified by:
getResourceAsYamlin interfaceKubeCmdClient<K extends BaseCmdKubeClient<K>>- Parameters:
resourceType- The type of the resource.resourceName- The name of the resource.- Returns:
- The resource as YAML.
-
getResourcesAsYaml
Retrieves resources as YAML.- Specified by:
getResourcesAsYamlin interfaceKubeCmdClient<K extends BaseCmdKubeClient<K>>- Parameters:
resourceType- The type of the resource.- Returns:
- The resources as YAML.
-
createResourceAndApply
Creates a resource from a template and applies it.- Specified by:
createResourceAndApplyin interfaceKubeCmdClient<K extends BaseCmdKubeClient<K>>- Parameters:
template- The template file.params- The parameters for the template.
-
describe
Retrieves the description of a resource.- Specified by:
describein interfaceKubeCmdClient<K extends BaseCmdKubeClient<K>>- Parameters:
resourceType- The type of the resource.resourceName- The name of the resource.- Returns:
- The description of the resource.
-
logs
Retrieves logs of a pod/container.- Specified by:
logsin interfaceKubeCmdClient<K extends BaseCmdKubeClient<K>>- Parameters:
pod- The name of the pod.container- The name of the container.- Returns:
- The logs as a string.
-
searchInLog
public String searchInLog(String resourceType, String resourceName, long sinceSeconds, String... grepPattern) Searches for patterns in logs.- Specified by:
searchInLogin interfaceKubeCmdClient<K extends BaseCmdKubeClient<K>>- Parameters:
resourceType- The type of the resource.resourceName- The name of the resource.sinceSeconds- The duration since the logs should be searched.grepPattern- The patterns to search for.- Returns:
- The matching lines from logs.
-
searchInLog
public String searchInLog(String resourceType, String resourceName, String resourceContainer, long sinceSeconds, String... grepPattern) Searches for patterns in logs of a specific container.- Specified by:
searchInLogin interfaceKubeCmdClient<K extends BaseCmdKubeClient<K>>- Parameters:
resourceType- The type of the resource.resourceName- The name of the resource.resourceContainer- The name of the container.sinceSeconds- The duration since the logs should be searched.grepPattern- The patterns to search for.- Returns:
- The matching lines from logs.
-
listResourcesByLabel
Lists resources by label.- Specified by:
listResourcesByLabelin interfaceKubeCmdClient<K extends BaseCmdKubeClient<K>>- Parameters:
resourceType- The type of the resource.label- The label.- Returns:
- A list of resource names.
-
process
Processes a template file with parameters.- Specified by:
processin interfaceKubeCmdClient<K extends BaseCmdKubeClient<K>>- Parameters:
parameters- The parameters for the template.file- The template file.c- The consumer to process the output.- Returns:
- The instance of the client.
-