-
I made my own struct to representing the 3rd party CRD: #[derive(Clone, Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct TerraformSpec {
pub terraform_version: String,
pub terraform_module: TerraformModule,
pub backend: String,
pub ignore_delete: bool,
pub task_options: Vec<TaskOption>,
}
pub type Terraform = Object<TerraformSpec, NotUsed>; Initialising the API client: let gvk = GroupVersionKind::gvk(&"tf.galleybytes.com", &"v1beta1", &"Terraform");
let (ar, caps) = kube::discovery::pinned_kind(&ctx.client.clone(), &gvk)
.await
.expect(format!("could not get gvk {:?}", gvk).as_str());
let terraform_api = Api::<Terraform>::all_with(ctx.client.clone(), &ar); Some information about the API:
List works and returns items: let list = terraform_api.list(&Default::default()).await.unwrap(); But when I try to Crete a new resource I get a 404: let resource = Terraform::new(
name.as_str(),
&ar,
TerraformSpec {
backend: format!(
r#"
terraform {{
backend "kubernetes" {{
secret_suffix = "{name}"
in_cluster_config = true
namespace = "{namespace}"
}}
}}
"#
),
ignore_delete: false,
terraform_module: TerraformModule {
source: "terraform-aws-modules/sqs/aws?ref=4.0.2".into(),
},
terraform_version: "1.5.4".into(),
task_options: vec![TaskOption {
r#for: vec!["*".into()],
env: vec![Env::tf_var("name".into(), "foobar".into())],
}],
},
);
let created = terraform_api
.create(&PostParams::default(), &resource)
.await;
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
404 makes me think that maybe you are using Btw, I see you are using #[derive(CustomResource)]
#[kube(group = "tf.galleybytes.com" version = "v1beta1")]
#[kube(namespaced)] // if you are namespaced
struct TerraformSpec { ..as_before() } so that you can use the fully typed api: let tfs_all: Api<Terraform> = Api::all(client.clone()); // for --all style listing
let tfs_ns: Api<Terraform> = Api::default_namespaced(client.clone()); // for namespaced .get or .create without needing to do api discovery |
Beta Was this translation helpful? Give feedback.
-
I didn't used the
What is the equivalent of |
Beta Was this translation helpful? Give feedback.
404 makes me think that maybe you are using
Api::all_with
on a namespaced resource, but that's just a hunch. Is that what you are doing? If so tryApi::namespaced_with
. See #1276 for some context of why you need both anApi::namespaced
and anApi::all
atm if you want to do both global lists + namespaced create/get.Btw, I see you are using
Object
and a dynamic api on top even though you have typed structs. You don't need to use the dynamic api for this. You could importkube::CustomResource
with thederive
feature and adds…