kube-rs / kopium

Kubernetes OPenapI UnMangler
Apache License 2.0
113 stars 21 forks source link

Allow opt-out to `PodMonitor` duplicate case-clashes #205

Closed clux closed 8 months ago

clux commented 8 months ago

Running kopium on the PodMonitor prometheus crd we encounter the strange enum that has two variants (with different cases) that by default produces this:

#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub enum PodMonitorPodMetricsEndpointsMetricRelabelingsAction {
    #[serde(rename = "replace")]
    Replace,
    Replace,
    #[serde(rename = "keep")]
    Keep,
    Keep,
    /// .....
}

we can now pass a substring of struct names to opt-out the rename behaviour so that if we run kopium here on podmonitors with:

  kubectl apply --server-side -f podmonitor.crd.yaml
  kopium --no-rename RelabelingsAction podmonitors.monitoring.coreos.com

we end up with a dumber enum that looks like:

#[derive(Serialize, Deserialize, Clone, Debug)]
pub enum PodMonitorPodMetricsEndpointsRelabelingsAction {
    replace,
    Replace,
    keep,
    Keep,
    drop,
    Drop,
    /// ...
}

of course, this will cause rust warnings for non_camel_case_types that will have to be ignored.

clux commented 8 months ago

some counterpoints to this;

clux commented 8 months ago

..maybe it is better to look for duplicate keys on the Container side (as per comment) and if we find any duplicates, THEN remove duplicates instead.. EDIT: trying this in https://github.com/kube-rs/kopium/pull/206

clux commented 8 months ago

After examining approaches, this PR here would force a hard-to-discover user opt-in to an inferior solution (with warnings generated) that would likely need further massaging on the user side to be nice.

Closing this in favour of https://github.com/kube-rs/kopium/pull/206 which is actually usable by default despite sometimes producing anachronistic member names.