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

creating a CronJob: 405 "the server does not allow this method on the requested resource" #191

Closed
Ploppz opened this issue Mar 18, 2020 · 5 comments
Labels
api Api abstraction related invalid rejected as a valid issue

Comments

@Ploppz
Copy link

Ploppz commented Mar 18, 2020

Running minikube v1.8.1, and with

kube = "0.30.0"
k8s-openapi = { version = "0.7.1", features = ["v1_15"] }

(same with v1_17)

    use k8s_openapi::{
        apimachinery::pkg::apis::meta::v1::ObjectMeta,
        api::batch::v1beta1::{CronJob, CronJobSpec, CronJobStatus, JobTemplateSpec},
        api::batch::v1::JobSpec,
        api::core::v1::{PodTemplateSpec, PodSpec, Container},
    };
    use kube::{Api, api::PostParams, client::APIClient, config::load_kube_config};

    let config = load_kube_config().await.context(err::KubeError)?;
    let client = APIClient::new(config);
    let api = Api::<CronJob>::all(client);

    api.create(
        &PostParams::default(),
        &CronJob {
            metadata: Some(ObjectMeta {
                labels: Some(BTreeMap::from_iter(
                        [("name".into(), name.clone())].iter().cloned()
                )),
                ..Default::default()
            }),
            spec: Some(CronJobSpec {
                schedule: schedule.frequency.clone(),
                job_template: JobTemplateSpec {
                    spec: Some(JobSpec {
                        template: PodTemplateSpec {
                            spec: Some(PodSpec {
                                containers: vec![
                                    Container {
                                        name: "hello".into(),
                                        image: Some("busybox".into()),
                                        args: Some(vec!["/bin/sh".into(),
                                        "-c".into(),
                                        "date; echo Hello".into()]),
                                        ..Default::default()
                                    }
                                ],
                                restart_policy: Some("OnFailure".into()),
                                ..Default::default()
                            }),
                            metadata: None,
                        },
                        ..Default::default()
                    }),
                    metadata: None,
                },
                ..Default::default()
            }),
            status: None,
        }).await.context(err::KubeError)?;

I get error:

KubeError { source: Api(ErrorResponse { status: "Failure", message: "the server does not allow this method on the requested resource", reason: "MethodNotAllowed", code: 405 }) }
@clux
Copy link
Member

clux commented Mar 18, 2020

MethodNotAllowed. Wtf. Ok, that is a strange. Thanks for the report. Will try to cross reference with the api later.

@clux clux added api Api abstraction related bug Something isn't working labels Mar 18, 2020
clux added a commit that referenced this issue Mar 19, 2020
@clux
Copy link
Member

clux commented Mar 19, 2020

Right, so I tried this on minikube running kubernetes 1.15 and with minor modifications, it worked. There's an attached commit (basically you only missed out the metadata.name - but that is required).

You might have gotten a newer version of cronjob than what your cluster supports.

@clux clux closed this as completed Mar 19, 2020
@clux clux added invalid rejected as a valid issue and removed bug Something isn't working labels Mar 19, 2020
@clux
Copy link
Member

clux commented Mar 19, 2020

To expand a bit. Make sure you pin the k8s-openapi api feature to your cluster version. That's the only feasible reason I can see you getting method invalid. I never got that. The example in that branch worked fine.

@Ploppz
Copy link
Author

Ploppz commented Mar 20, 2020

Thanks! From your example I saw that you use a namespace "default" while I had let api = Api::<CronJob>::all(client);. With namespace "default" it works for me too.

@clux
Copy link
Member

clux commented Mar 20, 2020

Oh right. Yeah, cronjob is not a cluster level resource! That's a thing we might be able to improve elsewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Api abstraction related invalid rejected as a valid issue
Projects
None yet
Development

No branches or pull requests

2 participants