-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: handle cluster scoped resources #79
Conversation
src/controller.rs
Outdated
let mut template = if let Some(ns) = target_namespace { | ||
DynamicObject::new(&target_ref.name, ar) | ||
.within(ns) | ||
.data(json!({})) | ||
} else { | ||
DynamicObject::new(&target_ref.name, ar).data(json!({})) | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let mut template = if let Some(ns) = target_namespace { | |
DynamicObject::new(&target_ref.name, ar) | |
.within(ns) | |
.data(json!({})) | |
} else { | |
DynamicObject::new(&target_ref.name, ar).data(json!({})) | |
}; | |
let mut template = DynamicObject::new(&target_ref.name, ar).data(json!({})); | |
template.metadata.namespace = target_namespace; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i did it in a few places so change it in those places too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, one minor suggestion to simplify the code
let mut source = if let Value::Null = subtree["metadata"]["namespace"] { | ||
DynamicObject::new(&subtree["metadata"]["name"].to_string(), &ar).data(subtree) | ||
} else { | ||
DynamicObject::new(&subtree["metadata"]["name"].to_string(), &ar) | ||
.within(&subtree["metadata"]["namespace"].to_string()) | ||
.data(subtree) | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar situation here
let mut source = if let Value::Null = subtree["metadata"]["namespace"] { | |
DynamicObject::new(&subtree["metadata"]["name"].to_string(), &ar).data(subtree) | |
} else { | |
DynamicObject::new(&subtree["metadata"]["name"].to_string(), &ar) | |
.within(&subtree["metadata"]["namespace"].to_string()) | |
.data(subtree) | |
}; | |
let mut source = DynamicObject::new(&subtree["metadata"]["name"].to_string(), &ar).data(subtree); | |
source.metadata.namespace = subtree["metadata"]["namespace"].as_str().map(str::to_string); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another suggestion
hit a bug in our cluster where we are trying to sync cluster scoped resources, which we've never tried before. it was getting a 404 on the creation of the resource.
at first i went and fixed the
apply_mappings
function, which was causing namespaces to becomeSome("null")
. turns out that wasn't making its way into the final resource but i left it as it's a nice tidy-up anyway.the real issue is that with namespace missing sinker assumed default namespace and creates a specifically namespaced client, that points to "default". in kube-rs this isn't the same as if you specified "default" in the yaml for a cluster-scoped resource, which would just get ignored. in kube-rs you have to use the cluster-scoped client.
i started trying to write a test for this but this code called
cluster_client
which requires an API, so i'd need to set up a tower mock of one and it would be a big faff.