Skip to content

Instantly share code, notes, and snippets.

@ihcsim
Last active February 4, 2022 20:00
Show Gist options
  • Save ihcsim/0f99d30a8c26d9e35dc09fbef6a2492c to your computer and use it in GitHub Desktop.
Save ihcsim/0f99d30a8c26d9e35dc09fbef6a2492c to your computer and use it in GitHub Desktop.
use std::collections::HashMap;
#[derive(Debug)]
struct Service {
name: String,
namespace: String,
endpoints: Vec<String>,
mappings: HashMap<String, String>,
}
fn main() {
let svc = Service {
name: "nginx".to_string(),
namespace: "default".to_string(),
endpoints: vec!["192.168.0.1".to_string(), "192.168.0.2".to_string()],
mappings: HashMap::from([
("pod-0".to_string(), "192.168.0.1".to_string()),
("pod-1".to_string(), "192.168.0.2".to_string()),
]),
};
let mut nginx = svc;
nginx.namespace = "ingress".to_string();
nginx.endpoints.push("192.168.0.3".to_string());
nginx
.mappings
.insert("pod-2".to_string(), "192.168.0.3".to_string());
println!("{:?}\n{:?}", svc, nginx);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment