How to Patch yaml from str into Deployment CR ? #1480
-
apiVersion: annomate.fun/v1
kind: AnnoTemplate
metadata:
name: log-sidecar
namespace: default
spec:
kind: SideCar
template: |
- name: log-tail
image: registry.cn-hangzhou.aliyuncs.com/log-service/logtail:latest
command:
- sh
- -c
- /usr/local/ilogtail/run_logtail.sh 10
volumeMounts:
- name: nginx-log
mountPath: /var/log/nginx async fn reconcile(obj: Arc<Deployment>, _ctx: Arc<()>) -> Result<Action> {
info!("reconcile : {}", obj.name_any());
let client = Client::try_default().await.unwrap();
let deployments: Api<Deployment> = Api::all(client.clone());
let anno_templates: Api<AnnoTemplate> = Api::all(client.clone());
for anno in obj.metadata.annotations.iter() {
for k in anno.keys() {
if k.starts_with("annomate.fun") {
let name = k.split("/").last().unwrap();
info!("name: {}", name);
let lp = ListParams::default().fields(&format!("metadata.name={}", name));
for anno_template in anno_templates.list(&lp).await.unwrap() {
let yaml_objs: Value =
serde_yaml::from_str(&anno_template.spec.template).unwrap();
info!("-----> : {:?}", yaml_objs[0]["name"]);
// TODO
}
}
}
}
Ok(Action::await_change())
} Business LogicUse Controller to watch Deployment Ask 4 HelpAs code above, I can get |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey @ppsite. Repeating a few things to see if I understand it correctly.
You will need to generate a patch, as you've noted in the title. The examples directory contains a few different examples that apply patches differently. There's also an example in the docs on how to create a patch via You'll need to find a way to construct a I do want to mention that for Deployment objects that need to have their template changed whenever they are created / update, I find |
Beta Was this translation helpful? Give feedback.
Hey @ppsite. Repeating a few things to see if I understand it correctly.
AnnoTemplate
) that you want to read. This is conditional on some annotation being present on the deployment.You will need to generate a patch, as you've noted in the title. The examples directory contains a few different examples that apply patches differently. There's also an example in the docs on how to create a patch via
serde_json
.You'll need to find a way to construct a
spec
that you want to patch (for example by pushing to the deployment's existing containers list every time you read and deserializ…