Arnavion / k8s-openapi

Rust definitions of the resource types in the Kubernetes client API
Apache License 2.0
373 stars 42 forks source link

ServiceSpec not creating headless service when cluster_ip set to None #147

Closed gregcusack closed 11 months ago

gregcusack commented 11 months ago

Hi! I am trying to create a headless service for a deployment. The documentation for ServiceSpec says for cluster_ip field:

Valid values are "None", empty string (""), or a valid IP address. Setting this to "None" makes a "headless service" 

However, when I set this to None the service that is created still creates a cluster ip. Here is a brief snippet of the code I am running:

let service = Service {
    metadata: ObjectMeta {
        name: Some(format!("{}-service", app_name).to_string()),
        namespace: Some(namespace.to_string()),
        ..Default::default()
    },
    spec: Some(ServiceSpec {
        selector: Some(label_selector),
        cluster_ip: None,
        ports: Some(vec![ServicePort {
            port: 8899, // RPC Port
            name: Some("rpc-port".to_string()),
            ..Default::default()
        },
        ServicePort {
            port: 9900, //Faucet Port
            name: Some("faucet-port".to_string()),
            ..Default::default()
        }]),
        ..Default::default()
    }),
    ..Default::default()
};

The service with its ports, names, etc gets created no problem, but the cluster ip keeps getting set no matter what I put in the cluster_ip: field. Any idea what's going on here?

Is it possible this never got implemented? Or I am dumb and am screwing this up.

clux commented 11 months ago

you probably wanna set cluster_ip to Some("None".into()) rather than None to make this work

gregcusack commented 11 months ago

ya that worked 100p. I am dumb. Thank you so much for your help and time!

Arnavion commented 11 months ago

(All the docs for the generated types are the descriptions from the OpenAPI spec, which in turn uses comments from the Golang source code to generate those descriptions. So in general the comments will refer to Golang concepts, not Rust concepts.)

gregcusack commented 11 months ago

oh that is good to know! thank you!!