Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f831c242a5 |
No files matched your search
+452
-62
@@ -16,6 +16,8 @@ pub enum ContainerCmd {
|
||||
DockerLogs,
|
||||
KubectlPods,
|
||||
KubectlServices,
|
||||
KubectlDeployments,
|
||||
KubectlIngress,
|
||||
KubectlLogs,
|
||||
}
|
||||
|
||||
@@ -26,6 +28,8 @@ pub fn run(cmd: ContainerCmd, args: &[String], verbose: u8) -> Result<i32> {
|
||||
ContainerCmd::DockerLogs => docker_logs(args, verbose),
|
||||
ContainerCmd::KubectlPods => kubectl_pods(args, verbose),
|
||||
ContainerCmd::KubectlServices => kubectl_services(args, verbose),
|
||||
ContainerCmd::KubectlDeployments => kubectl_deployments(args, verbose),
|
||||
ContainerCmd::KubectlIngress => kubectl_ingress(args, verbose),
|
||||
ContainerCmd::KubectlLogs => kubectl_logs(args, verbose),
|
||||
}
|
||||
}
|
||||
@@ -230,72 +234,137 @@ fn kubectl_pods(args: &[String], _verbose: u8) -> Result<i32> {
|
||||
run_kubectl_json(cmd, "get pods", format_kubectl_pods)
|
||||
}
|
||||
|
||||
fn format_kubectl_pods(json: &Value) -> String {
|
||||
let Some(pods) = json["items"].as_array().filter(|a| !a.is_empty()) else {
|
||||
return "No pods found\n".to_string();
|
||||
};
|
||||
let (mut running, mut pending, mut failed, mut restarts_total) = (0, 0, 0, 0i64);
|
||||
let mut issues: Vec<String> = Vec::new();
|
||||
|
||||
for pod in pods {
|
||||
let ns = pod["metadata"]["namespace"].as_str().unwrap_or("-");
|
||||
let name = pod["metadata"]["name"].as_str().unwrap_or("-");
|
||||
let phase = pod["status"]["phase"].as_str().unwrap_or("Unknown");
|
||||
|
||||
if let Some(containers) = pod["status"]["containerStatuses"].as_array() {
|
||||
for c in containers {
|
||||
restarts_total += c["restartCount"].as_i64().unwrap_or(0);
|
||||
/// Compute a pod's effective status, mirroring kubectl's STATUS column: a
|
||||
/// container waiting/terminated reason (CrashLoopBackOff, ImagePullBackOff, …)
|
||||
/// takes precedence over the coarse `phase`.
|
||||
fn pod_status(pod: &Value) -> String {
|
||||
if let Some(containers) = pod["status"]["containerStatuses"].as_array() {
|
||||
for c in containers {
|
||||
if let Some(reason) = c["state"]["waiting"]["reason"].as_str() {
|
||||
return reason.to_string();
|
||||
}
|
||||
}
|
||||
|
||||
match phase {
|
||||
"Running" => running += 1,
|
||||
"Pending" => {
|
||||
pending += 1;
|
||||
issues.push(format!("{}/{} Pending", ns, name));
|
||||
}
|
||||
"Failed" | "Error" => {
|
||||
failed += 1;
|
||||
issues.push(format!("{}/{} {}", ns, name, phase));
|
||||
}
|
||||
_ => {
|
||||
if let Some(containers) = pod["status"]["containerStatuses"].as_array() {
|
||||
for c in containers {
|
||||
if let Some(w) = c["state"]["waiting"]["reason"].as_str() {
|
||||
if w.contains("CrashLoop") || w.contains("Error") {
|
||||
failed += 1;
|
||||
issues.push(format!("{}/{} {}", ns, name, w));
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(reason) = c["state"]["terminated"]["reason"].as_str() {
|
||||
if reason != "Completed" {
|
||||
return reason.to_string();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
match pod["status"]["phase"].as_str().unwrap_or("Unknown") {
|
||||
"Succeeded" => "Completed".to_string(),
|
||||
other => other.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
let mut parts = Vec::new();
|
||||
if running > 0 {
|
||||
parts.push(format!("{}", running));
|
||||
/// Human-readable age from an RFC3339 creation timestamp ("45s", "3h", "14d").
|
||||
fn resource_age(ts: &str) -> String {
|
||||
use chrono::{DateTime, Utc};
|
||||
let Ok(created) = DateTime::parse_from_rfc3339(ts) else {
|
||||
return "?".to_string();
|
||||
};
|
||||
let secs = (Utc::now() - created.with_timezone(&Utc))
|
||||
.num_seconds()
|
||||
.max(0);
|
||||
if secs < 60 {
|
||||
format!("{}s", secs)
|
||||
} else if secs < 3600 {
|
||||
format!("{}m", secs / 60)
|
||||
} else if secs < 86400 {
|
||||
format!("{}h", secs / 3600)
|
||||
} else {
|
||||
format!("{}d", secs / 86400)
|
||||
}
|
||||
if pending > 0 {
|
||||
parts.push(format!("{} pending", pending));
|
||||
}
|
||||
|
||||
fn format_kubectl_pods(json: &Value) -> String {
|
||||
let Some(pods) = json["items"].as_array().filter(|a| !a.is_empty()) else {
|
||||
return "No pods found\n".to_string();
|
||||
};
|
||||
|
||||
struct PodRow {
|
||||
ns: String,
|
||||
name: String,
|
||||
status: String,
|
||||
ready: String,
|
||||
restarts: i64,
|
||||
age: String,
|
||||
issue: bool,
|
||||
}
|
||||
if failed > 0 {
|
||||
parts.push(format!("{} [x]", failed));
|
||||
|
||||
let mut rows: Vec<PodRow> = Vec::new();
|
||||
let mut status_counts: std::collections::BTreeMap<String, usize> = Default::default();
|
||||
let mut restarts_total = 0i64;
|
||||
|
||||
for pod in pods {
|
||||
let ns = pod["metadata"]["namespace"].as_str().unwrap_or("-").to_string();
|
||||
let name = pod["metadata"]["name"].as_str().unwrap_or("-").to_string();
|
||||
let status = pod_status(pod);
|
||||
let age = resource_age(pod["metadata"]["creationTimestamp"].as_str().unwrap_or(""));
|
||||
|
||||
let (mut ready_n, mut ready_total, mut restarts) = (0i64, 0i64, 0i64);
|
||||
if let Some(containers) = pod["status"]["containerStatuses"].as_array() {
|
||||
ready_total = containers.len() as i64;
|
||||
for c in containers {
|
||||
if c["ready"].as_bool().unwrap_or(false) {
|
||||
ready_n += 1;
|
||||
}
|
||||
restarts += c["restartCount"].as_i64().unwrap_or(0);
|
||||
}
|
||||
}
|
||||
restarts_total += restarts;
|
||||
*status_counts.entry(status.clone()).or_insert(0) += 1;
|
||||
|
||||
// An issue is anything not cleanly Running/Completed, a Running pod
|
||||
// that is not fully ready, or one that has restarted — exactly what
|
||||
// an operator needs to see first. A finished Job sits at 0/N ready
|
||||
// by design, so the ready check only applies to Running pods.
|
||||
let issue = !matches!(status.as_str(), "Running" | "Completed")
|
||||
|| (status == "Running" && ready_total > 0 && ready_n < ready_total)
|
||||
|| restarts > 0;
|
||||
|
||||
rows.push(PodRow {
|
||||
ns,
|
||||
name,
|
||||
status,
|
||||
ready: format!("{}/{}", ready_n, ready_total),
|
||||
restarts,
|
||||
age,
|
||||
issue,
|
||||
});
|
||||
}
|
||||
|
||||
// Issues first, then namespace/name — problems surface at the top.
|
||||
rows.sort_by(|a, b| {
|
||||
b.issue
|
||||
.cmp(&a.issue)
|
||||
.then(a.ns.cmp(&b.ns))
|
||||
.then(a.name.cmp(&b.name))
|
||||
});
|
||||
|
||||
let breakdown: Vec<String> = status_counts
|
||||
.iter()
|
||||
.map(|(s, n)| format!("{} {}", n, s))
|
||||
.collect();
|
||||
let mut out = format!("{} pods · {}", pods.len(), breakdown.join(" · "));
|
||||
if restarts_total > 0 {
|
||||
parts.push(format!("{} restarts", restarts_total));
|
||||
out.push_str(&format!(" · {} restarts", restarts_total));
|
||||
}
|
||||
out.push('\n');
|
||||
|
||||
let mut out = format!("{} pods: {}\n", pods.len(), parts.join(", "));
|
||||
if !issues.is_empty() {
|
||||
out.push_str("[warn] Issues:\n");
|
||||
for issue in issues.iter().take(10) {
|
||||
out.push_str(&format!(" {}\n", issue));
|
||||
}
|
||||
if issues.len() > 10 {
|
||||
out.push_str(&format!(" ... +{} more", issues.len() - 10));
|
||||
}
|
||||
// TOON table: column names declared once, then dense comma-separated rows.
|
||||
const MAX_ROWS: usize = 80;
|
||||
out.push_str(&format!(
|
||||
"pods[{}]{{ns,name,status,ready,restarts,age}}:\n",
|
||||
rows.len()
|
||||
));
|
||||
for r in rows.iter().take(MAX_ROWS) {
|
||||
out.push_str(&format!(
|
||||
" {},{},{},{},{},{}\n",
|
||||
r.ns, r.name, r.status, r.ready, r.restarts, r.age
|
||||
));
|
||||
}
|
||||
if rows.len() > MAX_ROWS {
|
||||
out.push_str(&format!(" ... +{} more\n", rows.len() - MAX_ROWS));
|
||||
}
|
||||
out
|
||||
}
|
||||
@@ -313,12 +382,18 @@ fn format_kubectl_services(json: &Value) -> String {
|
||||
let Some(services) = json["items"].as_array().filter(|a| !a.is_empty()) else {
|
||||
return "No services found\n".to_string();
|
||||
};
|
||||
let mut out = format!("{} services:\n", services.len());
|
||||
|
||||
for svc in services.iter().take(15) {
|
||||
let mut type_counts: std::collections::BTreeMap<String, usize> = Default::default();
|
||||
let mut rows: Vec<String> = Vec::new();
|
||||
|
||||
for svc in services {
|
||||
let ns = svc["metadata"]["namespace"].as_str().unwrap_or("-");
|
||||
let name = svc["metadata"]["name"].as_str().unwrap_or("-");
|
||||
let svc_type = svc["spec"]["type"].as_str().unwrap_or("-");
|
||||
let cluster_ip = svc["spec"]["clusterIP"].as_str().unwrap_or("-");
|
||||
*type_counts.entry(svc_type.to_string()).or_insert(0) += 1;
|
||||
|
||||
// Ports joined with ';' — ',' is the TOON field separator.
|
||||
let ports: Vec<String> = svc["spec"]["ports"]
|
||||
.as_array()
|
||||
.map(|arr| {
|
||||
@@ -338,16 +413,157 @@ fn format_kubectl_services(json: &Value) -> String {
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default();
|
||||
out.push_str(&format!(
|
||||
" {}/{} {} [{}]\n",
|
||||
rows.push(format!(
|
||||
" {},{},{},{},{}\n",
|
||||
ns,
|
||||
name,
|
||||
svc_type,
|
||||
ports.join(",")
|
||||
cluster_ip,
|
||||
ports.join(";")
|
||||
));
|
||||
}
|
||||
if services.len() > 15 {
|
||||
out.push_str(&format!(" ... +{} more", services.len() - 15));
|
||||
|
||||
let breakdown: Vec<String> = type_counts
|
||||
.iter()
|
||||
.map(|(t, n)| format!("{} {}", n, t))
|
||||
.collect();
|
||||
let mut out = format!("{} services · {}\n", services.len(), breakdown.join(" · "));
|
||||
|
||||
// TOON table: columns declared once, then dense comma-separated rows.
|
||||
const MAX_ROWS: usize = 80;
|
||||
out.push_str("services[");
|
||||
out.push_str(&services.len().to_string());
|
||||
out.push_str("]{ns,name,type,clusterIP,ports}:\n");
|
||||
for row in rows.iter().take(MAX_ROWS) {
|
||||
out.push_str(row);
|
||||
}
|
||||
if rows.len() > MAX_ROWS {
|
||||
out.push_str(&format!(" ... +{} more\n", rows.len() - MAX_ROWS));
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
fn kubectl_deployments(args: &[String], _verbose: u8) -> Result<i32> {
|
||||
let mut cmd = resolved_command("kubectl");
|
||||
cmd.args(["get", "deployments", "-o", "json"]);
|
||||
for arg in args {
|
||||
cmd.arg(arg);
|
||||
}
|
||||
run_kubectl_json(cmd, "get deployments", format_kubectl_deployments)
|
||||
}
|
||||
|
||||
fn format_kubectl_deployments(json: &Value) -> String {
|
||||
let Some(deps) = json["items"].as_array().filter(|a| !a.is_empty()) else {
|
||||
return "No deployments found\n".to_string();
|
||||
};
|
||||
|
||||
struct DeployRow {
|
||||
ns: String,
|
||||
name: String,
|
||||
ready: String,
|
||||
uptodate: i64,
|
||||
available: i64,
|
||||
age: String,
|
||||
issue: bool,
|
||||
}
|
||||
|
||||
let mut rows: Vec<DeployRow> = Vec::new();
|
||||
let mut healthy = 0usize;
|
||||
|
||||
for dep in deps {
|
||||
let ns = dep["metadata"]["namespace"].as_str().unwrap_or("-").to_string();
|
||||
let name = dep["metadata"]["name"].as_str().unwrap_or("-").to_string();
|
||||
let age = resource_age(dep["metadata"]["creationTimestamp"].as_str().unwrap_or(""));
|
||||
let desired = dep["spec"]["replicas"].as_i64().unwrap_or(0);
|
||||
let ready = dep["status"]["readyReplicas"].as_i64().unwrap_or(0);
|
||||
let uptodate = dep["status"]["updatedReplicas"].as_i64().unwrap_or(0);
|
||||
let available = dep["status"]["availableReplicas"].as_i64().unwrap_or(0);
|
||||
// A deployment is an issue when fewer replicas are ready than desired.
|
||||
let issue = ready < desired;
|
||||
if !issue {
|
||||
healthy += 1;
|
||||
}
|
||||
rows.push(DeployRow {
|
||||
ns,
|
||||
name,
|
||||
ready: format!("{}/{}", ready, desired),
|
||||
uptodate,
|
||||
available,
|
||||
age,
|
||||
issue,
|
||||
});
|
||||
}
|
||||
|
||||
// Degraded deployments first, then namespace/name.
|
||||
rows.sort_by(|a, b| {
|
||||
b.issue
|
||||
.cmp(&a.issue)
|
||||
.then(a.ns.cmp(&b.ns))
|
||||
.then(a.name.cmp(&b.name))
|
||||
});
|
||||
|
||||
let mut out = format!(
|
||||
"{} deployments · {} ready · {} degraded\n",
|
||||
deps.len(),
|
||||
healthy,
|
||||
deps.len() - healthy
|
||||
);
|
||||
const MAX_ROWS: usize = 80;
|
||||
out.push_str(&format!(
|
||||
"deployments[{}]{{ns,name,ready,uptodate,available,age}}:\n",
|
||||
rows.len()
|
||||
));
|
||||
for r in rows.iter().take(MAX_ROWS) {
|
||||
out.push_str(&format!(
|
||||
" {},{},{},{},{},{}\n",
|
||||
r.ns, r.name, r.ready, r.uptodate, r.available, r.age
|
||||
));
|
||||
}
|
||||
if rows.len() > MAX_ROWS {
|
||||
out.push_str(&format!(" ... +{} more\n", rows.len() - MAX_ROWS));
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
fn kubectl_ingress(args: &[String], _verbose: u8) -> Result<i32> {
|
||||
let mut cmd = resolved_command("kubectl");
|
||||
cmd.args(["get", "ingress", "-o", "json"]);
|
||||
for arg in args {
|
||||
cmd.arg(arg);
|
||||
}
|
||||
run_kubectl_json(cmd, "get ingress", format_kubectl_ingress)
|
||||
}
|
||||
|
||||
fn format_kubectl_ingress(json: &Value) -> String {
|
||||
let Some(ingresses) = json["items"].as_array().filter(|a| !a.is_empty()) else {
|
||||
return "No ingress found\n".to_string();
|
||||
};
|
||||
|
||||
let mut out = format!("{} ingress\n", ingresses.len());
|
||||
const MAX_ROWS: usize = 80;
|
||||
out.push_str(&format!(
|
||||
"ingress[{}]{{ns,name,class,hosts,age}}:\n",
|
||||
ingresses.len()
|
||||
));
|
||||
for ing in ingresses.iter().take(MAX_ROWS) {
|
||||
let ns = ing["metadata"]["namespace"].as_str().unwrap_or("-");
|
||||
let name = ing["metadata"]["name"].as_str().unwrap_or("-");
|
||||
let class = ing["spec"]["ingressClassName"].as_str().unwrap_or("-");
|
||||
let age = resource_age(ing["metadata"]["creationTimestamp"].as_str().unwrap_or(""));
|
||||
// Hosts joined with ';' — ',' is the TOON field separator.
|
||||
let hosts: Vec<&str> = ing["spec"]["rules"]
|
||||
.as_array()
|
||||
.map(|arr| arr.iter().filter_map(|r| r["host"].as_str()).collect())
|
||||
.unwrap_or_default();
|
||||
let hosts_str = if hosts.is_empty() {
|
||||
"*".to_string()
|
||||
} else {
|
||||
hosts.join(";")
|
||||
};
|
||||
out.push_str(&format!(" {},{},{},{},{}\n", ns, name, class, hosts_str, age));
|
||||
}
|
||||
if ingresses.len() > MAX_ROWS {
|
||||
out.push_str(&format!(" ... +{} more\n", ingresses.len() - MAX_ROWS));
|
||||
}
|
||||
out
|
||||
}
|
||||
@@ -616,6 +832,8 @@ pub fn run_kubectl_get(args: &[String], verbose: u8) -> Result<i32> {
|
||||
match kubectl_get_target(args) {
|
||||
Some(("pods", rest)) => run(ContainerCmd::KubectlPods, rest, verbose),
|
||||
Some(("services", rest)) => run(ContainerCmd::KubectlServices, rest, verbose),
|
||||
Some(("deployments", rest)) => run(ContainerCmd::KubectlDeployments, rest, verbose),
|
||||
Some(("ingress", rest)) => run(ContainerCmd::KubectlIngress, rest, verbose),
|
||||
_ => run_kubectl_get_passthrough(args, verbose),
|
||||
}
|
||||
}
|
||||
@@ -630,6 +848,8 @@ fn kubectl_get_target(args: &[String]) -> Option<(&'static str, &[String])> {
|
||||
match resource {
|
||||
"po" | "pod" | "pods" => Some(("pods", rest)),
|
||||
"svc" | "service" | "services" => Some(("services", rest)),
|
||||
"deploy" | "deployment" | "deployments" => Some(("deployments", rest)),
|
||||
"ing" | "ingress" | "ingresses" => Some(("ingress", rest)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -820,7 +1040,8 @@ api-1 | Connected to database";
|
||||
|
||||
#[test]
|
||||
fn test_kubectl_get_target_unsupported_resource() {
|
||||
let args = vec!["deployments".to_string()];
|
||||
// configmaps has no dedicated filter — must fall through to passthrough.
|
||||
let args = vec!["configmaps".to_string()];
|
||||
|
||||
assert_eq!(kubectl_get_target(&args), None);
|
||||
}
|
||||
@@ -841,4 +1062,173 @@ api-1 | Connected to database";
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ── kubectl TOON filters ───────────────────────────────
|
||||
|
||||
fn count_tokens(s: &str) -> usize {
|
||||
s.split_whitespace().count()
|
||||
}
|
||||
|
||||
const PODS_FIXTURE: &str =
|
||||
include_str!("../../../tests/fixtures/kubectl/get_pods.json");
|
||||
const SERVICES_FIXTURE: &str =
|
||||
include_str!("../../../tests/fixtures/kubectl/get_services.json");
|
||||
const DEPLOYMENTS_FIXTURE: &str =
|
||||
include_str!("../../../tests/fixtures/kubectl/get_deployments.json");
|
||||
const INGRESS_FIXTURE: &str =
|
||||
include_str!("../../../tests/fixtures/kubectl/get_ingress.json");
|
||||
|
||||
#[test]
|
||||
fn test_format_kubectl_pods_toon_structure() {
|
||||
let json: Value = serde_json::from_str(PODS_FIXTURE).unwrap();
|
||||
let out = format_kubectl_pods(&json);
|
||||
// TOON header declares the columns once.
|
||||
assert!(
|
||||
out.contains("]{ns,name,status,ready,restarts,age}:"),
|
||||
"missing TOON header, got:\n{out}"
|
||||
);
|
||||
// Summary line: "<n> pods · <per-status breakdown>".
|
||||
assert!(
|
||||
out.lines().next().unwrap_or("").contains(" pods · "),
|
||||
"missing summary line, got:\n{out}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_kubectl_pods_keeps_pod_names_and_issues() {
|
||||
let json: Value = serde_json::from_str(PODS_FIXTURE).unwrap();
|
||||
let out = format_kubectl_pods(&json);
|
||||
// Pod names and their problem state survive (the old filter dropped them).
|
||||
assert!(out.contains("badimage,ErrImagePull"), "got:\n{out}");
|
||||
assert!(out.contains("pending-huge,Pending"), "got:\n{out}");
|
||||
// Problem pods sort before healthy Running pods: `badimage` must
|
||||
// appear ahead of any `web-*` pod.
|
||||
let badimage_pos = out.find("badimage,").expect("badimage missing");
|
||||
let web_pos = out.find("web-").expect("web pod missing");
|
||||
assert!(
|
||||
badimage_pos < web_pos,
|
||||
"issues should sort before healthy pods, got:\n{out}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_kubectl_pods_savings() {
|
||||
let json: Value = serde_json::from_str(PODS_FIXTURE).unwrap();
|
||||
let out = format_kubectl_pods(&json);
|
||||
let savings = 100.0 - (count_tokens(&out) as f64 / count_tokens(PODS_FIXTURE) as f64 * 100.0);
|
||||
assert!(savings >= 60.0, "expected ≥60% savings, got {savings:.1}%");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_kubectl_pods_empty() {
|
||||
let json: Value = serde_json::json!({"items": []});
|
||||
assert_eq!(format_kubectl_pods(&json), "No pods found\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_kubectl_services_toon_structure() {
|
||||
let json: Value = serde_json::from_str(SERVICES_FIXTURE).unwrap();
|
||||
let out = format_kubectl_services(&json);
|
||||
assert!(
|
||||
out.contains("services[") && out.contains("]{ns,name,type,clusterIP,ports}:"),
|
||||
"missing TOON header, got:\n{out}"
|
||||
);
|
||||
assert!(out.contains(",web,"), "service name 'web' missing, got:\n{out}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_kubectl_services_savings() {
|
||||
let json: Value = serde_json::from_str(SERVICES_FIXTURE).unwrap();
|
||||
let out = format_kubectl_services(&json);
|
||||
let savings =
|
||||
100.0 - (count_tokens(&out) as f64 / count_tokens(SERVICES_FIXTURE) as f64 * 100.0);
|
||||
assert!(savings >= 60.0, "expected ≥60% savings, got {savings:.1}%");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_resource_age_formats() {
|
||||
use chrono::{Duration, Utc};
|
||||
let ts = |d: Duration| (Utc::now() - d).to_rfc3339();
|
||||
assert!(resource_age(&ts(Duration::seconds(30))).ends_with('s'));
|
||||
assert!(resource_age(&ts(Duration::minutes(5))).ends_with('m'));
|
||||
assert!(resource_age(&ts(Duration::hours(3))).ends_with('h'));
|
||||
assert!(resource_age(&ts(Duration::days(14))).ends_with('d'));
|
||||
assert_eq!(resource_age("not-a-date"), "?");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_kubectl_deployments_toon() {
|
||||
let json: Value = serde_json::from_str(DEPLOYMENTS_FIXTURE).unwrap();
|
||||
let out = format_kubectl_deployments(&json);
|
||||
assert!(
|
||||
out.contains("]{ns,name,ready,uptodate,available,age}:"),
|
||||
"missing TOON header, got:\n{out}"
|
||||
);
|
||||
assert!(
|
||||
out.lines().next().unwrap_or("").contains(" deployments · "),
|
||||
"missing summary, got:\n{out}"
|
||||
);
|
||||
// Deployment names survive.
|
||||
assert!(out.contains(",web,"), "deployment 'web' missing, got:\n{out}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_kubectl_deployments_savings() {
|
||||
let json: Value = serde_json::from_str(DEPLOYMENTS_FIXTURE).unwrap();
|
||||
let out = format_kubectl_deployments(&json);
|
||||
let savings = 100.0
|
||||
- (count_tokens(&out) as f64 / count_tokens(DEPLOYMENTS_FIXTURE) as f64 * 100.0);
|
||||
assert!(savings >= 60.0, "expected ≥60% savings, got {savings:.1}%");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_kubectl_deployments_empty() {
|
||||
let json: Value = serde_json::json!({"items": []});
|
||||
assert_eq!(format_kubectl_deployments(&json), "No deployments found\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_kubectl_ingress_toon() {
|
||||
let json: Value = serde_json::from_str(INGRESS_FIXTURE).unwrap();
|
||||
let out = format_kubectl_ingress(&json);
|
||||
assert!(
|
||||
out.contains("]{ns,name,class,hosts,age}:"),
|
||||
"missing TOON header, got:\n{out}"
|
||||
);
|
||||
// Multiple hosts joined with ';' (',' is the field separator).
|
||||
assert!(
|
||||
out.contains("web.example.com;api.example.com"),
|
||||
"multi-host ingress not joined with ';', got:\n{out}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_kubectl_ingress_empty() {
|
||||
let json: Value = serde_json::json!({"items": []});
|
||||
assert_eq!(format_kubectl_ingress(&json), "No ingress found\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_kubectl_get_target_deployment_aliases() {
|
||||
for resource in ["deploy", "deployment", "deployments"] {
|
||||
let args = vec![resource.to_string(), "-A".to_string()];
|
||||
assert_eq!(
|
||||
kubectl_get_target(&args),
|
||||
Some(("deployments", &args[1..])),
|
||||
"failed for {resource}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_kubectl_get_target_ingress_aliases() {
|
||||
for resource in ["ing", "ingress", "ingresses"] {
|
||||
let args = vec![resource.to_string()];
|
||||
assert_eq!(
|
||||
kubectl_get_target(&args),
|
||||
Some(("ingress", &args[1..])),
|
||||
"failed for {resource}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
+530
@@ -0,0 +1,530 @@
|
||||
{
|
||||
"apiVersion": "v1",
|
||||
"items": [
|
||||
{
|
||||
"apiVersion": "apps/v1",
|
||||
"kind": "Deployment",
|
||||
"metadata": {
|
||||
"annotations": {
|
||||
"deployment.kubernetes.io/revision": "1",
|
||||
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"apps/v1\",\"kind\":\"Deployment\",\"metadata\":{\"annotations\":{},\"name\":\"api\",\"namespace\":\"backend\"},\"spec\":{\"replicas\":6,\"selector\":{\"matchLabels\":{\"app\":\"api\"}},\"template\":{\"metadata\":{\"labels\":{\"app\":\"api\"}},\"spec\":{\"containers\":[{\"image\":\"nginx:alpine\",\"name\":\"api\"}]}}}}\n"
|
||||
},
|
||||
"creationTimestamp": "2026-05-17T10:34:17Z",
|
||||
"generation": 1,
|
||||
"name": "api",
|
||||
"namespace": "backend",
|
||||
"resourceVersion": "1079",
|
||||
"uid": "c71818ad-10f5-4ad2-9a97-4dab9a4ea2c4"
|
||||
},
|
||||
"spec": {
|
||||
"progressDeadlineSeconds": 600,
|
||||
"replicas": 6,
|
||||
"revisionHistoryLimit": 10,
|
||||
"selector": {
|
||||
"matchLabels": {
|
||||
"app": "api"
|
||||
}
|
||||
},
|
||||
"strategy": {
|
||||
"rollingUpdate": {
|
||||
"maxSurge": "25%",
|
||||
"maxUnavailable": "25%"
|
||||
},
|
||||
"type": "RollingUpdate"
|
||||
},
|
||||
"template": {
|
||||
"metadata": {
|
||||
"creationTimestamp": null,
|
||||
"labels": {
|
||||
"app": "api"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"containers": [
|
||||
{
|
||||
"image": "nginx:alpine",
|
||||
"imagePullPolicy": "IfNotPresent",
|
||||
"name": "api",
|
||||
"resources": {},
|
||||
"terminationMessagePath": "/dev/termination-log",
|
||||
"terminationMessagePolicy": "File"
|
||||
}
|
||||
],
|
||||
"dnsPolicy": "ClusterFirst",
|
||||
"restartPolicy": "Always",
|
||||
"schedulerName": "default-scheduler",
|
||||
"securityContext": {},
|
||||
"terminationGracePeriodSeconds": 30
|
||||
}
|
||||
}
|
||||
},
|
||||
"status": {
|
||||
"availableReplicas": 6,
|
||||
"conditions": [
|
||||
{
|
||||
"lastTransitionTime": "2026-05-17T10:34:19Z",
|
||||
"lastUpdateTime": "2026-05-17T10:34:19Z",
|
||||
"message": "Deployment has minimum availability.",
|
||||
"reason": "MinimumReplicasAvailable",
|
||||
"status": "True",
|
||||
"type": "Available"
|
||||
},
|
||||
{
|
||||
"lastTransitionTime": "2026-05-17T10:34:17Z",
|
||||
"lastUpdateTime": "2026-05-17T10:34:19Z",
|
||||
"message": "ReplicaSet \"api-7b89467fdb\" has successfully progressed.",
|
||||
"reason": "NewReplicaSetAvailable",
|
||||
"status": "True",
|
||||
"type": "Progressing"
|
||||
}
|
||||
],
|
||||
"observedGeneration": 1,
|
||||
"readyReplicas": 6,
|
||||
"replicas": 6,
|
||||
"updatedReplicas": 6
|
||||
}
|
||||
},
|
||||
{
|
||||
"apiVersion": "apps/v1",
|
||||
"kind": "Deployment",
|
||||
"metadata": {
|
||||
"annotations": {
|
||||
"deployment.kubernetes.io/revision": "1",
|
||||
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"apps/v1\",\"kind\":\"Deployment\",\"metadata\":{\"annotations\":{},\"name\":\"web\",\"namespace\":\"default\"},\"spec\":{\"replicas\":18,\"selector\":{\"matchLabels\":{\"app\":\"web\"}},\"template\":{\"metadata\":{\"labels\":{\"app\":\"web\"}},\"spec\":{\"containers\":[{\"image\":\"nginx:alpine\",\"name\":\"nginx\",\"ports\":[{\"containerPort\":80}]}]}}}}\n"
|
||||
},
|
||||
"creationTimestamp": "2026-05-17T10:34:00Z",
|
||||
"generation": 1,
|
||||
"name": "web",
|
||||
"namespace": "default",
|
||||
"resourceVersion": "967",
|
||||
"uid": "112854e3-f99a-463c-925a-e6e5469f8683"
|
||||
},
|
||||
"spec": {
|
||||
"progressDeadlineSeconds": 600,
|
||||
"replicas": 18,
|
||||
"revisionHistoryLimit": 10,
|
||||
"selector": {
|
||||
"matchLabels": {
|
||||
"app": "web"
|
||||
}
|
||||
},
|
||||
"strategy": {
|
||||
"rollingUpdate": {
|
||||
"maxSurge": "25%",
|
||||
"maxUnavailable": "25%"
|
||||
},
|
||||
"type": "RollingUpdate"
|
||||
},
|
||||
"template": {
|
||||
"metadata": {
|
||||
"creationTimestamp": null,
|
||||
"labels": {
|
||||
"app": "web"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"containers": [
|
||||
{
|
||||
"image": "nginx:alpine",
|
||||
"imagePullPolicy": "IfNotPresent",
|
||||
"name": "nginx",
|
||||
"ports": [
|
||||
{
|
||||
"containerPort": 80,
|
||||
"protocol": "TCP"
|
||||
}
|
||||
],
|
||||
"resources": {},
|
||||
"terminationMessagePath": "/dev/termination-log",
|
||||
"terminationMessagePolicy": "File"
|
||||
}
|
||||
],
|
||||
"dnsPolicy": "ClusterFirst",
|
||||
"restartPolicy": "Always",
|
||||
"schedulerName": "default-scheduler",
|
||||
"securityContext": {},
|
||||
"terminationGracePeriodSeconds": 30
|
||||
}
|
||||
}
|
||||
},
|
||||
"status": {
|
||||
"availableReplicas": 18,
|
||||
"conditions": [
|
||||
{
|
||||
"lastTransitionTime": "2026-05-17T10:34:13Z",
|
||||
"lastUpdateTime": "2026-05-17T10:34:13Z",
|
||||
"message": "Deployment has minimum availability.",
|
||||
"reason": "MinimumReplicasAvailable",
|
||||
"status": "True",
|
||||
"type": "Available"
|
||||
},
|
||||
{
|
||||
"lastTransitionTime": "2026-05-17T10:34:00Z",
|
||||
"lastUpdateTime": "2026-05-17T10:34:14Z",
|
||||
"message": "ReplicaSet \"web-599d64b499\" has successfully progressed.",
|
||||
"reason": "NewReplicaSetAvailable",
|
||||
"status": "True",
|
||||
"type": "Progressing"
|
||||
}
|
||||
],
|
||||
"observedGeneration": 1,
|
||||
"readyReplicas": 18,
|
||||
"replicas": 18,
|
||||
"updatedReplicas": 18
|
||||
}
|
||||
},
|
||||
{
|
||||
"apiVersion": "apps/v1",
|
||||
"kind": "Deployment",
|
||||
"metadata": {
|
||||
"annotations": {
|
||||
"deployment.kubernetes.io/revision": "1"
|
||||
},
|
||||
"creationTimestamp": "2026-05-17T10:33:29Z",
|
||||
"generation": 1,
|
||||
"labels": {
|
||||
"k8s-app": "kube-dns"
|
||||
},
|
||||
"name": "coredns",
|
||||
"namespace": "kube-system",
|
||||
"resourceVersion": "529",
|
||||
"uid": "7a3ef920-ef34-4d62-98e7-18b252e78a73"
|
||||
},
|
||||
"spec": {
|
||||
"progressDeadlineSeconds": 600,
|
||||
"replicas": 2,
|
||||
"revisionHistoryLimit": 10,
|
||||
"selector": {
|
||||
"matchLabels": {
|
||||
"k8s-app": "kube-dns"
|
||||
}
|
||||
},
|
||||
"strategy": {
|
||||
"rollingUpdate": {
|
||||
"maxSurge": "25%",
|
||||
"maxUnavailable": 1
|
||||
},
|
||||
"type": "RollingUpdate"
|
||||
},
|
||||
"template": {
|
||||
"metadata": {
|
||||
"creationTimestamp": null,
|
||||
"labels": {
|
||||
"k8s-app": "kube-dns"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"affinity": {
|
||||
"podAntiAffinity": {
|
||||
"preferredDuringSchedulingIgnoredDuringExecution": [
|
||||
{
|
||||
"podAffinityTerm": {
|
||||
"labelSelector": {
|
||||
"matchExpressions": [
|
||||
{
|
||||
"key": "k8s-app",
|
||||
"operator": "In",
|
||||
"values": [
|
||||
"kube-dns"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"topologyKey": "kubernetes.io/hostname"
|
||||
},
|
||||
"weight": 100
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"containers": [
|
||||
{
|
||||
"args": [
|
||||
"-conf",
|
||||
"/etc/coredns/Corefile"
|
||||
],
|
||||
"image": "registry.k8s.io/coredns/coredns:v1.11.3",
|
||||
"imagePullPolicy": "IfNotPresent",
|
||||
"livenessProbe": {
|
||||
"failureThreshold": 5,
|
||||
"httpGet": {
|
||||
"path": "/health",
|
||||
"port": 8080,
|
||||
"scheme": "HTTP"
|
||||
},
|
||||
"initialDelaySeconds": 60,
|
||||
"periodSeconds": 10,
|
||||
"successThreshold": 1,
|
||||
"timeoutSeconds": 5
|
||||
},
|
||||
"name": "coredns",
|
||||
"ports": [
|
||||
{
|
||||
"containerPort": 53,
|
||||
"name": "dns",
|
||||
"protocol": "UDP"
|
||||
},
|
||||
{
|
||||
"containerPort": 53,
|
||||
"name": "dns-tcp",
|
||||
"protocol": "TCP"
|
||||
},
|
||||
{
|
||||
"containerPort": 9153,
|
||||
"name": "metrics",
|
||||
"protocol": "TCP"
|
||||
}
|
||||
],
|
||||
"readinessProbe": {
|
||||
"failureThreshold": 3,
|
||||
"httpGet": {
|
||||
"path": "/ready",
|
||||
"port": 8181,
|
||||
"scheme": "HTTP"
|
||||
},
|
||||
"periodSeconds": 10,
|
||||
"successThreshold": 1,
|
||||
"timeoutSeconds": 1
|
||||
},
|
||||
"resources": {
|
||||
"limits": {
|
||||
"memory": "170Mi"
|
||||
},
|
||||
"requests": {
|
||||
"cpu": "100m",
|
||||
"memory": "70Mi"
|
||||
}
|
||||
},
|
||||
"securityContext": {
|
||||
"allowPrivilegeEscalation": false,
|
||||
"capabilities": {
|
||||
"add": [
|
||||
"NET_BIND_SERVICE"
|
||||
],
|
||||
"drop": [
|
||||
"ALL"
|
||||
]
|
||||
},
|
||||
"readOnlyRootFilesystem": true
|
||||
},
|
||||
"terminationMessagePath": "/dev/termination-log",
|
||||
"terminationMessagePolicy": "File",
|
||||
"volumeMounts": [
|
||||
{
|
||||
"mountPath": "/etc/coredns",
|
||||
"name": "config-volume",
|
||||
"readOnly": true
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"dnsPolicy": "Default",
|
||||
"nodeSelector": {
|
||||
"kubernetes.io/os": "linux"
|
||||
},
|
||||
"priorityClassName": "system-cluster-critical",
|
||||
"restartPolicy": "Always",
|
||||
"schedulerName": "default-scheduler",
|
||||
"securityContext": {},
|
||||
"serviceAccount": "coredns",
|
||||
"serviceAccountName": "coredns",
|
||||
"terminationGracePeriodSeconds": 30,
|
||||
"tolerations": [
|
||||
{
|
||||
"key": "CriticalAddonsOnly",
|
||||
"operator": "Exists"
|
||||
},
|
||||
{
|
||||
"effect": "NoSchedule",
|
||||
"key": "node-role.kubernetes.io/control-plane"
|
||||
}
|
||||
],
|
||||
"volumes": [
|
||||
{
|
||||
"configMap": {
|
||||
"defaultMode": 420,
|
||||
"items": [
|
||||
{
|
||||
"key": "Corefile",
|
||||
"path": "Corefile"
|
||||
}
|
||||
],
|
||||
"name": "coredns"
|
||||
},
|
||||
"name": "config-volume"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"status": {
|
||||
"availableReplicas": 2,
|
||||
"conditions": [
|
||||
{
|
||||
"lastTransitionTime": "2026-05-17T10:33:53Z",
|
||||
"lastUpdateTime": "2026-05-17T10:33:53Z",
|
||||
"message": "Deployment has minimum availability.",
|
||||
"reason": "MinimumReplicasAvailable",
|
||||
"status": "True",
|
||||
"type": "Available"
|
||||
},
|
||||
{
|
||||
"lastTransitionTime": "2026-05-17T10:33:34Z",
|
||||
"lastUpdateTime": "2026-05-17T10:33:53Z",
|
||||
"message": "ReplicaSet \"coredns-668d6bf9bc\" has successfully progressed.",
|
||||
"reason": "NewReplicaSetAvailable",
|
||||
"status": "True",
|
||||
"type": "Progressing"
|
||||
}
|
||||
],
|
||||
"observedGeneration": 1,
|
||||
"readyReplicas": 2,
|
||||
"replicas": 2,
|
||||
"updatedReplicas": 2
|
||||
}
|
||||
},
|
||||
{
|
||||
"apiVersion": "apps/v1",
|
||||
"kind": "Deployment",
|
||||
"metadata": {
|
||||
"annotations": {
|
||||
"deployment.kubernetes.io/revision": "1",
|
||||
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"apps/v1\",\"kind\":\"Deployment\",\"metadata\":{\"annotations\":{},\"name\":\"local-path-provisioner\",\"namespace\":\"local-path-storage\"},\"spec\":{\"replicas\":1,\"selector\":{\"matchLabels\":{\"app\":\"local-path-provisioner\"}},\"template\":{\"metadata\":{\"labels\":{\"app\":\"local-path-provisioner\"}},\"spec\":{\"containers\":[{\"command\":[\"local-path-provisioner\",\"--debug\",\"start\",\"--helper-image\",\"docker.io/kindest/local-path-helper:v20241212-8ac705d0\",\"--config\",\"/etc/config/config.json\"],\"env\":[{\"name\":\"POD_NAMESPACE\",\"valueFrom\":{\"fieldRef\":{\"fieldPath\":\"metadata.namespace\"}}},{\"name\":\"CONFIG_MOUNT_PATH\",\"value\":\"/etc/config/\"}],\"image\":\"docker.io/kindest/local-path-provisioner:v20250214-acbabc1a\",\"imagePullPolicy\":\"IfNotPresent\",\"name\":\"local-path-provisioner\",\"volumeMounts\":[{\"mountPath\":\"/etc/config/\",\"name\":\"config-volume\"}]}],\"nodeSelector\":{\"kubernetes.io/os\":\"linux\"},\"serviceAccountName\":\"local-path-provisioner-service-account\",\"tolerations\":[{\"effect\":\"NoSchedule\",\"key\":\"node-role.kubernetes.io/control-plane\",\"operator\":\"Equal\"},{\"effect\":\"NoSchedule\",\"key\":\"node-role.kubernetes.io/master\",\"operator\":\"Equal\"}],\"volumes\":[{\"configMap\":{\"name\":\"local-path-config\"},\"name\":\"config-volume\"}]}}}}\n"
|
||||
},
|
||||
"creationTimestamp": "2026-05-17T10:33:31Z",
|
||||
"generation": 1,
|
||||
"name": "local-path-provisioner",
|
||||
"namespace": "local-path-storage",
|
||||
"resourceVersion": "520",
|
||||
"uid": "7c396f8a-84d6-425e-948b-fe894d59bf50"
|
||||
},
|
||||
"spec": {
|
||||
"progressDeadlineSeconds": 600,
|
||||
"replicas": 1,
|
||||
"revisionHistoryLimit": 10,
|
||||
"selector": {
|
||||
"matchLabels": {
|
||||
"app": "local-path-provisioner"
|
||||
}
|
||||
},
|
||||
"strategy": {
|
||||
"rollingUpdate": {
|
||||
"maxSurge": "25%",
|
||||
"maxUnavailable": "25%"
|
||||
},
|
||||
"type": "RollingUpdate"
|
||||
},
|
||||
"template": {
|
||||
"metadata": {
|
||||
"creationTimestamp": null,
|
||||
"labels": {
|
||||
"app": "local-path-provisioner"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"containers": [
|
||||
{
|
||||
"command": [
|
||||
"local-path-provisioner",
|
||||
"--debug",
|
||||
"start",
|
||||
"--helper-image",
|
||||
"docker.io/kindest/local-path-helper:v20241212-8ac705d0",
|
||||
"--config",
|
||||
"/etc/config/config.json"
|
||||
],
|
||||
"env": [
|
||||
{
|
||||
"name": "POD_NAMESPACE",
|
||||
"valueFrom": {
|
||||
"fieldRef": {
|
||||
"apiVersion": "v1",
|
||||
"fieldPath": "metadata.namespace"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "CONFIG_MOUNT_PATH",
|
||||
"value": "/etc/config/"
|
||||
}
|
||||
],
|
||||
"image": "docker.io/kindest/local-path-provisioner:v20250214-acbabc1a",
|
||||
"imagePullPolicy": "IfNotPresent",
|
||||
"name": "local-path-provisioner",
|
||||
"resources": {},
|
||||
"terminationMessagePath": "/dev/termination-log",
|
||||
"terminationMessagePolicy": "File",
|
||||
"volumeMounts": [
|
||||
{
|
||||
"mountPath": "/etc/config/",
|
||||
"name": "config-volume"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"dnsPolicy": "ClusterFirst",
|
||||
"nodeSelector": {
|
||||
"kubernetes.io/os": "linux"
|
||||
},
|
||||
"restartPolicy": "Always",
|
||||
"schedulerName": "default-scheduler",
|
||||
"securityContext": {},
|
||||
"serviceAccount": "local-path-provisioner-service-account",
|
||||
"serviceAccountName": "local-path-provisioner-service-account",
|
||||
"terminationGracePeriodSeconds": 30,
|
||||
"tolerations": [
|
||||
{
|
||||
"effect": "NoSchedule",
|
||||
"key": "node-role.kubernetes.io/control-plane",
|
||||
"operator": "Equal"
|
||||
},
|
||||
{
|
||||
"effect": "NoSchedule",
|
||||
"key": "node-role.kubernetes.io/master",
|
||||
"operator": "Equal"
|
||||
}
|
||||
],
|
||||
"volumes": [
|
||||
{
|
||||
"configMap": {
|
||||
"defaultMode": 420,
|
||||
"name": "local-path-config"
|
||||
},
|
||||
"name": "config-volume"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"status": {
|
||||
"availableReplicas": 1,
|
||||
"conditions": [
|
||||
{
|
||||
"lastTransitionTime": "2026-05-17T10:33:53Z",
|
||||
"lastUpdateTime": "2026-05-17T10:33:53Z",
|
||||
"message": "Deployment has minimum availability.",
|
||||
"reason": "MinimumReplicasAvailable",
|
||||
"status": "True",
|
||||
"type": "Available"
|
||||
},
|
||||
{
|
||||
"lastTransitionTime": "2026-05-17T10:33:34Z",
|
||||
"lastUpdateTime": "2026-05-17T10:33:53Z",
|
||||
"message": "ReplicaSet \"local-path-provisioner-7dc846544d\" has successfully progressed.",
|
||||
"reason": "NewReplicaSetAvailable",
|
||||
"status": "True",
|
||||
"type": "Progressing"
|
||||
}
|
||||
],
|
||||
"observedGeneration": 1,
|
||||
"readyReplicas": 1,
|
||||
"replicas": 1,
|
||||
"updatedReplicas": 1
|
||||
}
|
||||
}
|
||||
],
|
||||
"kind": "List",
|
||||
"metadata": {
|
||||
"resourceVersion": ""
|
||||
}
|
||||
}
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
{
|
||||
"apiVersion": "v1",
|
||||
"items": [
|
||||
{
|
||||
"apiVersion": "networking.k8s.io/v1",
|
||||
"kind": "Ingress",
|
||||
"metadata": {
|
||||
"annotations": {
|
||||
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"networking.k8s.io/v1\",\"kind\":\"Ingress\",\"metadata\":{\"annotations\":{},\"name\":\"api-ingress\",\"namespace\":\"backend\"},\"spec\":{\"ingressClassName\":\"nginx\",\"rules\":[{\"host\":\"api.internal\",\"http\":{\"paths\":[{\"backend\":{\"service\":{\"name\":\"api\",\"port\":{\"number\":8080}}},\"path\":\"/\",\"pathType\":\"Prefix\"}]}}]}}\n"
|
||||
},
|
||||
"creationTimestamp": "2026-05-17T12:27:41Z",
|
||||
"generation": 1,
|
||||
"name": "api-ingress",
|
||||
"namespace": "backend",
|
||||
"resourceVersion": "8702",
|
||||
"uid": "db7a81c9-e100-4617-a04a-b099ee526bd8"
|
||||
},
|
||||
"spec": {
|
||||
"ingressClassName": "nginx",
|
||||
"rules": [
|
||||
{
|
||||
"host": "api.internal",
|
||||
"http": {
|
||||
"paths": [
|
||||
{
|
||||
"backend": {
|
||||
"service": {
|
||||
"name": "api",
|
||||
"port": {
|
||||
"number": 8080
|
||||
}
|
||||
}
|
||||
},
|
||||
"path": "/",
|
||||
"pathType": "Prefix"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"status": {
|
||||
"loadBalancer": {}
|
||||
}
|
||||
},
|
||||
{
|
||||
"apiVersion": "networking.k8s.io/v1",
|
||||
"kind": "Ingress",
|
||||
"metadata": {
|
||||
"annotations": {
|
||||
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"networking.k8s.io/v1\",\"kind\":\"Ingress\",\"metadata\":{\"annotations\":{},\"name\":\"web-ingress\",\"namespace\":\"default\"},\"spec\":{\"rules\":[{\"host\":\"web.example.com\",\"http\":{\"paths\":[{\"backend\":{\"service\":{\"name\":\"web\",\"port\":{\"number\":80}}},\"path\":\"/\",\"pathType\":\"Prefix\"}]}},{\"host\":\"api.example.com\",\"http\":{\"paths\":[{\"backend\":{\"service\":{\"name\":\"web\",\"port\":{\"number\":80}}},\"path\":\"/v1\",\"pathType\":\"Prefix\"}]}}]}}\n"
|
||||
},
|
||||
"creationTimestamp": "2026-05-17T12:27:41Z",
|
||||
"generation": 1,
|
||||
"name": "web-ingress",
|
||||
"namespace": "default",
|
||||
"resourceVersion": "8701",
|
||||
"uid": "9b53ff68-9ba6-496d-a56e-bcc5af037492"
|
||||
},
|
||||
"spec": {
|
||||
"rules": [
|
||||
{
|
||||
"host": "web.example.com",
|
||||
"http": {
|
||||
"paths": [
|
||||
{
|
||||
"backend": {
|
||||
"service": {
|
||||
"name": "web",
|
||||
"port": {
|
||||
"number": 80
|
||||
}
|
||||
}
|
||||
},
|
||||
"path": "/",
|
||||
"pathType": "Prefix"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"host": "api.example.com",
|
||||
"http": {
|
||||
"paths": [
|
||||
{
|
||||
"backend": {
|
||||
"service": {
|
||||
"name": "web",
|
||||
"port": {
|
||||
"number": 80
|
||||
}
|
||||
}
|
||||
},
|
||||
"path": "/v1",
|
||||
"pathType": "Prefix"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"status": {
|
||||
"loadBalancer": {}
|
||||
}
|
||||
}
|
||||
],
|
||||
"kind": "List",
|
||||
"metadata": {
|
||||
"resourceVersion": ""
|
||||
}
|
||||
}
|
||||
Vendored
+8909
File diff suppressed because it is too large.
Load diff
+312
@@ -0,0 +1,312 @@
|
||||
{
|
||||
"apiVersion": "v1",
|
||||
"items": [
|
||||
{
|
||||
"apiVersion": "v1",
|
||||
"kind": "Service",
|
||||
"metadata": {
|
||||
"annotations": {
|
||||
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Service\",\"metadata\":{\"annotations\":{},\"name\":\"api\",\"namespace\":\"backend\"},\"spec\":{\"ports\":[{\"port\":8080,\"targetPort\":80}],\"selector\":{\"app\":\"api\"}}}\n"
|
||||
},
|
||||
"creationTimestamp": "2026-05-17T10:34:01Z",
|
||||
"name": "api",
|
||||
"namespace": "backend",
|
||||
"resourceVersion": "684",
|
||||
"uid": "447a6d10-5314-47ae-94c9-5907272be563"
|
||||
},
|
||||
"spec": {
|
||||
"clusterIP": "10.96.115.66",
|
||||
"clusterIPs": [
|
||||
"10.96.115.66"
|
||||
],
|
||||
"internalTrafficPolicy": "Cluster",
|
||||
"ipFamilies": [
|
||||
"IPv4"
|
||||
],
|
||||
"ipFamilyPolicy": "SingleStack",
|
||||
"ports": [
|
||||
{
|
||||
"port": 8080,
|
||||
"protocol": "TCP",
|
||||
"targetPort": 80
|
||||
}
|
||||
],
|
||||
"selector": {
|
||||
"app": "api"
|
||||
},
|
||||
"sessionAffinity": "None",
|
||||
"type": "ClusterIP"
|
||||
},
|
||||
"status": {
|
||||
"loadBalancer": {}
|
||||
}
|
||||
},
|
||||
{
|
||||
"apiVersion": "v1",
|
||||
"kind": "Service",
|
||||
"metadata": {
|
||||
"annotations": {
|
||||
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Service\",\"metadata\":{\"annotations\":{},\"name\":\"api-headless\",\"namespace\":\"backend\"},\"spec\":{\"clusterIP\":\"None\",\"ports\":[{\"port\":8080}],\"selector\":{\"app\":\"api\"}}}\n"
|
||||
},
|
||||
"creationTimestamp": "2026-05-17T10:34:01Z",
|
||||
"name": "api-headless",
|
||||
"namespace": "backend",
|
||||
"resourceVersion": "679",
|
||||
"uid": "4771b6ae-e0c8-4491-ac20-89117b237f5d"
|
||||
},
|
||||
"spec": {
|
||||
"clusterIP": "None",
|
||||
"clusterIPs": [
|
||||
"None"
|
||||
],
|
||||
"internalTrafficPolicy": "Cluster",
|
||||
"ipFamilies": [
|
||||
"IPv4"
|
||||
],
|
||||
"ipFamilyPolicy": "SingleStack",
|
||||
"ports": [
|
||||
{
|
||||
"port": 8080,
|
||||
"protocol": "TCP",
|
||||
"targetPort": 8080
|
||||
}
|
||||
],
|
||||
"selector": {
|
||||
"app": "api"
|
||||
},
|
||||
"sessionAffinity": "None",
|
||||
"type": "ClusterIP"
|
||||
},
|
||||
"status": {
|
||||
"loadBalancer": {}
|
||||
}
|
||||
},
|
||||
{
|
||||
"apiVersion": "v1",
|
||||
"kind": "Service",
|
||||
"metadata": {
|
||||
"creationTimestamp": "2026-05-17T10:33:28Z",
|
||||
"labels": {
|
||||
"component": "apiserver",
|
||||
"provider": "kubernetes"
|
||||
},
|
||||
"name": "kubernetes",
|
||||
"namespace": "default",
|
||||
"resourceVersion": "196",
|
||||
"uid": "3b559f07-6f6f-4b1e-9e55-96f32719a0bc"
|
||||
},
|
||||
"spec": {
|
||||
"clusterIP": "10.96.0.1",
|
||||
"clusterIPs": [
|
||||
"10.96.0.1"
|
||||
],
|
||||
"internalTrafficPolicy": "Cluster",
|
||||
"ipFamilies": [
|
||||
"IPv4"
|
||||
],
|
||||
"ipFamilyPolicy": "SingleStack",
|
||||
"ports": [
|
||||
{
|
||||
"name": "https",
|
||||
"port": 443,
|
||||
"protocol": "TCP",
|
||||
"targetPort": 6443
|
||||
}
|
||||
],
|
||||
"sessionAffinity": "None",
|
||||
"type": "ClusterIP"
|
||||
},
|
||||
"status": {
|
||||
"loadBalancer": {}
|
||||
}
|
||||
},
|
||||
{
|
||||
"apiVersion": "v1",
|
||||
"kind": "Service",
|
||||
"metadata": {
|
||||
"annotations": {
|
||||
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Service\",\"metadata\":{\"annotations\":{},\"name\":\"web\",\"namespace\":\"default\"},\"spec\":{\"ports\":[{\"port\":80}],\"selector\":{\"app\":\"web\"}}}\n"
|
||||
},
|
||||
"creationTimestamp": "2026-05-17T10:34:00Z",
|
||||
"name": "web",
|
||||
"namespace": "default",
|
||||
"resourceVersion": "646",
|
||||
"uid": "a0312b24-bd92-49e7-bc22-52ed1e1dadea"
|
||||
},
|
||||
"spec": {
|
||||
"clusterIP": "10.96.188.104",
|
||||
"clusterIPs": [
|
||||
"10.96.188.104"
|
||||
],
|
||||
"internalTrafficPolicy": "Cluster",
|
||||
"ipFamilies": [
|
||||
"IPv4"
|
||||
],
|
||||
"ipFamilyPolicy": "SingleStack",
|
||||
"ports": [
|
||||
{
|
||||
"port": 80,
|
||||
"protocol": "TCP",
|
||||
"targetPort": 80
|
||||
}
|
||||
],
|
||||
"selector": {
|
||||
"app": "web"
|
||||
},
|
||||
"sessionAffinity": "None",
|
||||
"type": "ClusterIP"
|
||||
},
|
||||
"status": {
|
||||
"loadBalancer": {}
|
||||
}
|
||||
},
|
||||
{
|
||||
"apiVersion": "v1",
|
||||
"kind": "Service",
|
||||
"metadata": {
|
||||
"annotations": {
|
||||
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Service\",\"metadata\":{\"annotations\":{},\"name\":\"web-lb\",\"namespace\":\"default\"},\"spec\":{\"ports\":[{\"port\":443,\"targetPort\":80}],\"selector\":{\"app\":\"web\"},\"type\":\"LoadBalancer\"}}\n"
|
||||
},
|
||||
"creationTimestamp": "2026-05-17T10:34:01Z",
|
||||
"name": "web-lb",
|
||||
"namespace": "default",
|
||||
"resourceVersion": "674",
|
||||
"uid": "597a3951-2a93-45cb-b819-548cabf69cf9"
|
||||
},
|
||||
"spec": {
|
||||
"allocateLoadBalancerNodePorts": true,
|
||||
"clusterIP": "10.96.139.146",
|
||||
"clusterIPs": [
|
||||
"10.96.139.146"
|
||||
],
|
||||
"externalTrafficPolicy": "Cluster",
|
||||
"internalTrafficPolicy": "Cluster",
|
||||
"ipFamilies": [
|
||||
"IPv4"
|
||||
],
|
||||
"ipFamilyPolicy": "SingleStack",
|
||||
"ports": [
|
||||
{
|
||||
"nodePort": 31272,
|
||||
"port": 443,
|
||||
"protocol": "TCP",
|
||||
"targetPort": 80
|
||||
}
|
||||
],
|
||||
"selector": {
|
||||
"app": "web"
|
||||
},
|
||||
"sessionAffinity": "None",
|
||||
"type": "LoadBalancer"
|
||||
},
|
||||
"status": {
|
||||
"loadBalancer": {}
|
||||
}
|
||||
},
|
||||
{
|
||||
"apiVersion": "v1",
|
||||
"kind": "Service",
|
||||
"metadata": {
|
||||
"annotations": {
|
||||
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Service\",\"metadata\":{\"annotations\":{},\"name\":\"web-np\",\"namespace\":\"default\"},\"spec\":{\"ports\":[{\"nodePort\":30080,\"port\":80}],\"selector\":{\"app\":\"web\"},\"type\":\"NodePort\"}}\n"
|
||||
},
|
||||
"creationTimestamp": "2026-05-17T10:34:01Z",
|
||||
"name": "web-np",
|
||||
"namespace": "default",
|
||||
"resourceVersion": "665",
|
||||
"uid": "c55104d5-bdc9-4a77-920b-0723fc57dee4"
|
||||
},
|
||||
"spec": {
|
||||
"clusterIP": "10.96.236.0",
|
||||
"clusterIPs": [
|
||||
"10.96.236.0"
|
||||
],
|
||||
"externalTrafficPolicy": "Cluster",
|
||||
"internalTrafficPolicy": "Cluster",
|
||||
"ipFamilies": [
|
||||
"IPv4"
|
||||
],
|
||||
"ipFamilyPolicy": "SingleStack",
|
||||
"ports": [
|
||||
{
|
||||
"nodePort": 30080,
|
||||
"port": 80,
|
||||
"protocol": "TCP",
|
||||
"targetPort": 80
|
||||
}
|
||||
],
|
||||
"selector": {
|
||||
"app": "web"
|
||||
},
|
||||
"sessionAffinity": "None",
|
||||
"type": "NodePort"
|
||||
},
|
||||
"status": {
|
||||
"loadBalancer": {}
|
||||
}
|
||||
},
|
||||
{
|
||||
"apiVersion": "v1",
|
||||
"kind": "Service",
|
||||
"metadata": {
|
||||
"annotations": {
|
||||
"prometheus.io/port": "9153",
|
||||
"prometheus.io/scrape": "true"
|
||||
},
|
||||
"creationTimestamp": "2026-05-17T10:33:29Z",
|
||||
"labels": {
|
||||
"k8s-app": "kube-dns",
|
||||
"kubernetes.io/cluster-service": "true",
|
||||
"kubernetes.io/name": "CoreDNS"
|
||||
},
|
||||
"name": "kube-dns",
|
||||
"namespace": "kube-system",
|
||||
"resourceVersion": "225",
|
||||
"uid": "55d701a4-da48-47a7-ac41-ed6690bd0419"
|
||||
},
|
||||
"spec": {
|
||||
"clusterIP": "10.96.0.10",
|
||||
"clusterIPs": [
|
||||
"10.96.0.10"
|
||||
],
|
||||
"internalTrafficPolicy": "Cluster",
|
||||
"ipFamilies": [
|
||||
"IPv4"
|
||||
],
|
||||
"ipFamilyPolicy": "SingleStack",
|
||||
"ports": [
|
||||
{
|
||||
"name": "dns",
|
||||
"port": 53,
|
||||
"protocol": "UDP",
|
||||
"targetPort": 53
|
||||
},
|
||||
{
|
||||
"name": "dns-tcp",
|
||||
"port": 53,
|
||||
"protocol": "TCP",
|
||||
"targetPort": 53
|
||||
},
|
||||
{
|
||||
"name": "metrics",
|
||||
"port": 9153,
|
||||
"protocol": "TCP",
|
||||
"targetPort": 9153
|
||||
}
|
||||
],
|
||||
"selector": {
|
||||
"k8s-app": "kube-dns"
|
||||
},
|
||||
"sessionAffinity": "None",
|
||||
"type": "ClusterIP"
|
||||
},
|
||||
"status": {
|
||||
"loadBalancer": {}
|
||||
}
|
||||
}
|
||||
],
|
||||
"kind": "List",
|
||||
"metadata": {
|
||||
"resourceVersion": ""
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user