kube-rs / kube

Rust Kubernetes client and controller runtime
https://kube.rs
Apache License 2.0
2.8k stars 292 forks source link

Using customized Kubeconfig struct not working as per documentation #1401

Closed MushiTheMoshi closed 5 months ago

MushiTheMoshi commented 5 months ago

Current and expected behavior

Hi there,

First of all great work done here. Thanks for all the hard work, library is awesome.

I am trying to initialize a Client using kubeconfig struct, although is not clear how to do it, can't find any example.

So not able to identify whether is a bug or a bad setting on my side.

Expected:

Client initialized via Config::from_custom_kubeconfig authenticate to remote k8s

Values:

Kubeconfig {
    preferences: None,
    clusters: [
        NamedCluster {
            name: "cluster1",
            cluster: Some(
                Cluster {
                    server: Some(
                        "REDACTED valid endpoint",
                    ),
                    insecure_skip_tls_verify: None,
                    certificate_authority: None,
                    certificate_authority_data: Some(
                        "REDACTED valid cert",
                    ),
                    proxy_url: None,
                    tls_server_name: None,
                    extensions: None,
                },
            ),
        },
    ],
    auth_infos: [
        NamedAuthInfo {
            name: "dev-platform",
            auth_info: Some(
                AuthInfo {
                    username: Some(
                        "user1",
                    ),
                    password: None,
                    token: Some(
                        Secret([REDACTED alloc::string::String]),
                    ),
                    token_file: None,
                    client_certificate: None,
                    client_certificate_data: None,
                    client_key: None,
                    client_key_data: None,
                    impersonate: None,
                    impersonate_groups: None,
                    auth_provider: None,
                    exec: None,
                },
            ),
        },
    ],
    contexts: [
        NamedContext {
            name: "cluster1",
            context: Some(
                Context {
                    cluster: "cluster1",
                    user: "user1",
                    namespace: Some(
                        "default",
                    ),
                    extensions: None,
                },
            ),
        },
    ],
    current_context: Some(
        "cluster1",
    ),
    extensions: None,
    kind: Some(
        "Config",
    ),
    api_version: Some(
        "client.authentication.k8s.io/v1beta1",
    ),
}
let config = Config::from_custom_kubeconfig(
    config__,
    &KubeConfigOptions{
        context: Some("cluster1".to_string()),
        cluster: Some("cluster1".to_string()),
        user: Some("user1".to_string())},
).await;

Thanks in advance, Julio

Possible solution

No response

Additional context

No response

Environment

ubuntu 22.08

Configuration and features

anyhow = "1.0.75"
assert_cmd = "2.0.12"
aws-config = "1.1.4"
aws-credential-types = "1.1.4"
aws-sdk-eks = "1.13.0"
aws-sdk-eksauth = "1.10.0"
aws-sdk-sts = "0.30.0"
aws-sigv4 = "1.1.4"
aws-smithy-runtime-api = "1.1.4"
aws-types = "1.1.4"
base64 = "0.21.7"
clap = { version = "4.4.2", features = ["derive", "env"] }
futures = "0.3.28"
futures-util = "0.3.28"
http = "0.2.11"
k8s-openapi = { version = "0.21.0", default-features = false, features=["v1_29"] }
kube = "0.88.1"
lambda_runtime = "0.6.1"
predicates = "3.0.3"
serde = { version = "1.0.126", features = ["derive"] }
serde_json = "1.0.64"
tokio = { version = "1", features = ["full"] }
tokio-stream = "0.1.14"
tokio-test = "0.4.2"
tower = { version = "0.4.13", features = ["limit"] }
tracing = { version = "0.1", features = ["log"] }
tracing-subscriber = "0.3.17"
urlencoding = "2.1.3"
secrecy = "0.8.0"
hyper = { version = "0.14.13", features = ["client", "http1", "stream", "tcp"] }

Affected crates

No response

Would you like to work on fixing this bug?

None

clux commented 5 months ago

Hard to tell from this report. Are you using the right user name (you specify user1 but the auth name is dev-platform)? Are you giving it the right values? You could debug print the resulting Config struct to verify it gets correctly converted from_custom_kubeconfig.

MushiTheMoshi commented 5 months ago

I use this example as reference, anyways I am sure the user exist, I am looking for an example as I am not sure whether that's the correct way of doing it, if you could point me in the right direction, I'd appreciate...

let config__ = Kubeconfig{...

error:

thread 'tests::k8s_get_auth' panicked at 'Error in this: FindUser("user1")', src/main.rs:270:37