fix: unjank the demo #85
@ -2,7 +2,10 @@ use derive_new::new;
|
|||||||
use futures_util::StreamExt;
|
use futures_util::StreamExt;
|
||||||
use k8s_openapi::{
|
use k8s_openapi::{
|
||||||
ClusterResourceScope, NamespaceResourceScope,
|
ClusterResourceScope, NamespaceResourceScope,
|
||||||
api::{apps::v1::Deployment, core::v1::Pod},
|
api::{
|
||||||
|
apps::v1::Deployment,
|
||||||
|
core::v1::{ObjectReference, Pod},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use kube::{
|
use kube::{
|
||||||
Client, Config, Error, Resource,
|
Client, Config, Error, Resource,
|
||||||
@ -244,37 +247,39 @@ impl K8sClient {
|
|||||||
|
|
||||||
pub async fn apply_yaml_many(
|
pub async fn apply_yaml_many(
|
||||||
&self,
|
&self,
|
||||||
|
api_resource: &ApiResource,
|
||||||
yaml: &Vec<serde_yaml::Value>,
|
yaml: &Vec<serde_yaml::Value>,
|
||||||
ns: Option<&str>,
|
ns: Option<&str>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
for y in yaml.iter() {
|
for y in yaml.iter() {
|
||||||
self.apply_yaml(y, ns).await?;
|
self.apply_yaml(api_resource, y, ns).await?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn apply_yaml(
|
pub async fn apply_yaml(
|
||||||
&self,
|
&self,
|
||||||
|
api_resource: &ApiResource,
|
||||||
yaml: &serde_yaml::Value,
|
yaml: &serde_yaml::Value,
|
||||||
ns: Option<&str>,
|
ns: Option<&str>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let obj: DynamicObject = serde_yaml::from_value(yaml.clone()).expect("TODO do not unwrap");
|
let obj: DynamicObject = serde_yaml::from_value(yaml.clone()).expect("TODO do not unwrap");
|
||||||
let name = obj.metadata.name.as_ref().expect("YAML must have a name");
|
let name = obj.metadata.name.as_ref().expect("YAML must have a name");
|
||||||
let namespace = obj
|
|
||||||
.metadata
|
|
||||||
.namespace
|
|
||||||
.as_ref()
|
|
||||||
.expect("YAML must have a namespace");
|
|
||||||
|
|
||||||
// 4. Define the API resource type using the GVK from the object.
|
let namespace = match ns {
|
||||||
// The plural name 'applications' is taken from your CRD definition.
|
Some(n) => n,
|
||||||
error!("This only supports argocd application harcoded, very rrrong");
|
None => {
|
||||||
let gvk = GroupVersionKind::gvk("argoproj.io", "v1alpha1", "Application");
|
obj
|
||||||
let api_resource = ApiResource::from_gvk_with_plural(&gvk, "applications");
|
.metadata
|
||||||
|
.namespace
|
||||||
|
.as_ref()
|
||||||
|
.expect("YAML must have a namespace")
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
// 5. Create a dynamic API client for this resource type.
|
// 5. Create a dynamic API client for this resource type.
|
||||||
let api: Api<DynamicObject> =
|
let api: Api<DynamicObject> =
|
||||||
Api::namespaced_with(self.client.clone(), namespace, &api_resource);
|
Api::namespaced_with(self.client.clone(), namespace, api_resource);
|
||||||
|
|
||||||
// 6. Apply the object to the cluster using Server-Side Apply.
|
// 6. Apply the object to the cluster using Server-Side Apply.
|
||||||
// This will create the resource if it doesn't exist, or update it if it does.
|
// This will create the resource if it doesn't exist, or update it if it does.
|
||||||
|
Loading…
Reference in New Issue
Block a user