#[path = "support.rs"]
mod support;
use noyalib::cst::parse_document;
use noyalib::Value;
const MANIFEST: &str = "\
# Production deployment for the api service.
apiVersion: apps/v1
kind: Deployment
metadata:
name: api
labels:
app: api
tier: backend
spec:
replicas: 3 # scale this for the prod tier
selector:
matchLabels:
app: api
template:
metadata:
labels:
app: api
spec:
containers:
- name: api
image: registry.example.com/api:1.4.2
ports:
- containerPort: 8080
# Resource limits set conservatively. Bump
# for the prod tier when traffic ramps.
resources:
limits:
cpu: \"500m\"
memory: \"512Mi\"
";
fn main() -> noyalib::Result<()> {
support::header("Entry API — surgical Kubernetes manifest patching");
let mut doc = parse_document(MANIFEST)?;
doc.entry("spec")
.insert_value("replicas", &Value::Number(noyalib::Number::Integer(10)))?;
doc.set(
"spec.template.spec.containers[0].image",
"registry.example.com/api:1.5.0",
)?;
let resources_path = "spec.template.spec.containers[0].resources.limits";
doc.entry(resources_path)
.insert_value("cpu", &Value::String("1500m".into()))?;
doc.entry(resources_path)
.insert_value("memory", &Value::String("1Gi".into()))?;
doc.entry("spec.template.metadata.labels")
.insert_value("tier", &Value::String("backend".into()))?;
println!("{}", doc);
println!();
println!(" Comments and indentation preserved byte-for-byte.");
println!(" Only the four targeted spans were rewritten.");
support::footer();
Ok(())
}