Skip to content
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: use non-namespaced API in remote cluster, not local #80

Merged
merged 1 commit into from
Sep 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,16 @@ async fn api_for(
Some(namespace.to_owned()),
),
None => (
Api::default_namespaced_with(client.clone(), &ar),
Some(client.default_namespace().to_owned()),
// assume cluster-scoped resource.
// TODO: should someday handle "default namespace for the kubeconfig being used"
Api::all_with(client.clone(), &ar),
None,
),
},
None => (Api::all_with(client.clone(), &ar), None),
None => (
Api::namespaced_with(client.clone(), local_ns, &ar),
Some(local_ns.to_owned()),
),
};

Ok(NamespacedApi { api, ar, namespace })
Expand Down Expand Up @@ -211,13 +216,11 @@ fn apply_mappings(
let source_metadata = convert_metadata(&subtree["metadata"]);
let mut subtree = subtree.clone();
cleanup_subtree(&mut subtree);
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.clone());
source.metadata.namespace = subtree["metadata"]["namespace"]
.as_str()
.map(str::to_string);
source.metadata.annotations = source_metadata.annotations;
source.metadata.labels = source_metadata.labels;
template = clone_resource(&source, target_ref, target_namespace, &ar)?;
Expand Down