use super::{
exec_tail, kubernetes_version, log_lookup, namespace, pod, port_forward, restart_rollout,
test_pod, up_down, vector, wait_for_resource, wait_for_rollout, Interface, PortForwarder,
Reader, Result,
};
#[derive(Debug)]
pub struct Framework {
interface: Interface,
}
impl Framework {
pub fn new(interface: Interface) -> Self {
Self { interface }
}
pub async fn helm_chart(
&self,
namespace: &str,
helm_chart: &str,
release_name: &str,
helm_repo: &str,
config: vector::Config<'_>,
) -> Result<up_down::Manager<vector::CommandBuilder>> {
let env = vec![("CHART_REPO".to_owned(), helm_repo.to_owned())];
let mut manager = vector::manager(
self.interface.deploy_chart_command.as_str(),
namespace,
helm_chart,
release_name,
config,
Some(env),
)?;
manager.up().await?;
Ok(manager)
}
pub async fn namespace(
&self,
config: namespace::Config,
) -> Result<up_down::Manager<namespace::CommandBuilder>> {
let mut manager = namespace::manager(&self.interface.kubectl_command, config);
manager.up().await?;
Ok(manager)
}
pub async fn test_pod(
&self,
config: test_pod::Config,
) -> Result<up_down::Manager<test_pod::CommandBuilder>> {
let mut manager = test_pod::manager(&self.interface.kubectl_command, config);
manager.up().await?;
Ok(manager)
}
pub fn logs(&self, namespace: &str, resource: &str) -> Result<Reader> {
log_lookup(&self.interface.kubectl_command, namespace, resource)
}
pub fn exec_tail(&self, namespace: &str, resource: &str, file: &str) -> Result<Reader> {
exec_tail(&self.interface.kubectl_command, namespace, resource, file)
}
pub fn port_forward(
&self,
namespace: &str,
resource: &str,
local_port: u16,
resource_port: u16,
) -> Result<PortForwarder> {
port_forward(
&self.interface.kubectl_command,
namespace,
resource,
local_port,
resource_port,
)
}
pub async fn kubernetes_version(&self) -> Result<kubernetes_version::K8sVersion> {
kubernetes_version::get(&self.interface.kubectl_command).await
}
pub async fn wait<'a>(
&self,
namespace: &str,
resources: impl IntoIterator<Item = &'a str>,
wait_for: wait_for_resource::WaitFor<&'_ str>,
extra: impl IntoIterator<Item = &'a str>,
) -> Result<()> {
wait_for_resource::namespace(
&self.interface.kubectl_command,
namespace,
resources,
wait_for,
extra,
)
.await
}
pub async fn wait_all_namespaces<'a>(
&self,
resources: impl IntoIterator<Item = &'a str>,
wait_for: wait_for_resource::WaitFor<&'_ str>,
extra: impl IntoIterator<Item = &'a str>,
) -> Result<()> {
wait_for_resource::all_namespaces(
&self.interface.kubectl_command,
resources,
wait_for,
extra,
)
.await
}
pub async fn wait_for_rollout<'a>(
&self,
namespace: &str,
resource: &str,
extra: impl IntoIterator<Item = &'a str>,
) -> Result<()> {
wait_for_rollout::run(&self.interface.kubectl_command, namespace, resource, extra).await
}
pub async fn restart_rollout<'a>(
&self,
namespace: &str,
resources: &str,
extra: impl IntoIterator<Item = &'a str>,
) -> Result<()> {
restart_rollout::run(&self.interface.kubectl_command, namespace, resources, extra).await
}
async fn get_node_for_pod(&self, namespace: &str, pod: &str) -> Result<String> {
pod::get_node(&self.interface.kubectl_command, namespace, pod).await
}
async fn get_pod_on_node(&self, namespace: &str, node: &str, service: &str) -> Result<String> {
pod::get_pod_on_node(&self.interface.kubectl_command, namespace, node, service).await
}
pub async fn label_nodes(&self, label: &str) -> Result<String> {
pod::label_nodes(&self.interface.kubectl_command, label).await
}
pub async fn get_vector_pod_with_pod(
&self,
pod_namespace: &str,
pod_name: &str,
vector_pod_namespace: &str,
vector_pod_name: &str,
) -> Result<String> {
let node = self
.get_node_for_pod(pod_namespace, pod_name)
.await
.map_err(|_| "need the node name")?;
Ok(self
.get_pod_on_node(vector_pod_namespace, &node, vector_pod_name)
.await
.map_err(|_| "cant get the vector pod running on the test node")?)
}
}