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

Can't Create Namespace #966

Closed
that-soda-pop opened this issue Jul 28, 2022 · 1 comment
Closed

Can't Create Namespace #966

that-soda-pop opened this issue Jul 28, 2022 · 1 comment
Labels
bug Something isn't working invalid rejected as a valid issue

Comments

@that-soda-pop
Copy link

that-soda-pop commented Jul 28, 2022

Current and expected behavior

It seems I can create all objects except a namespace,
I get the following error:

ApiError: the server could not find the requested resource: NotFound (ErrorResponse { status: "Failure", message: "the server could not find the requested resource", reason: "NotFound", code: 404 }

running the serialized struct as json with kubectl apply works as expected.

Possible solution

No response

Additional context

    async fn create_namespace_if_missing(&self, namespace_name: &str) -> anyhow::Result<()> {
        let client = self.client.clone();

        let s: Api<Namespace> = Api::default_namespaced(client);
        if s.get(namespace_name).await.is_err() {
            debug!("missing namespace");
            let prj = Namespace {
                metadata: ObjectMeta {
                    name: Some(namespace_name.to_string()),
                    labels: bt_helper("name", namespace_name),
                    ..Default::default()
                },
                ..Default::default()
            };

            s.create(&Default::default(), &prj).await?;
        } else {
            debug!("namespace exists");
        }
        Ok(())
    }

fn bt_helper(k: &str, v: &str) -> Option<BTreeMap<String, String>> {
    let mut data = BTreeMap::new();
    data.insert(k.to_string(), v.to_string());
    Some(data)
}

Environment

Client Version: v1.24.2
Kustomize Version: v4.5.4
Server Version: v1.24.2

Configuration and features

kube = { version = "0.74.0", features = ["runtime", "derive"] }
k8s-openapi = { version = "0.15.0", features = ["v1_24"] }

Affected crates

No response

Would you like to work on fixing this bug?

No response

@that-soda-pop that-soda-pop added the bug Something isn't working label Jul 28, 2022
@clux
Copy link
Member

clux commented Jul 28, 2022

This code is actually illegal in master because it's the same confusion source as was fixed in #956

The problem is that Namespace is not a Namespaced resource (as funny as that may sound); use Api::all instead.

@clux clux added the invalid rejected as a valid issue label Jul 28, 2022
@clux clux closed this as completed Jul 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working invalid rejected as a valid issue
Projects
None yet
Development

No branches or pull requests

2 participants