Skip to content

Options not optional? #2

@arichtman

Description

@arichtman

Hi all,

Thanks for the wonderful work on this project so far!

I'm attempting to deserialize YAML into a wrapper struct with some Prost-generated field structs but Option<Duration> is catching even when the struct field is not provided in the input YAML, yielding AnyErr("Field 'NodeGroupAutoscalingOptions::scaleDownUnneededTime' was not initialized").

Do I need to implement something for Duration to be able to deserialize it? There's no YAML primitive that suits as far as I know but it's Option<Option<i64>> kindof? Setting an integer value yields AnyErr("Expected a YAML hash, got: Integer(655555)")

I've included the relevant code snippets inline but there's also a reproduction with Nix DevShell on this branch. Either use git submodules or run ./protos.sh to clone the dependencies and then just cargo run

Wrapper struct:

#[derive(Debug, Facet, Default)]
#[facet(rename_all = "camelCase")]
pub struct Config {
    pub node_group_autoscaling_options: HashMap<String, NodeGroupAutoscalingOptions>,
}

Prost-generated sub-structs

#[derive(facet::Facet)]
#[facet(rename_all = "camelCase")]
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
pub struct NodeGroupAutoscalingOptions {
    /// ScaleDownUtilizationThreshold sets threshold for nodes to be considered for scale down
    /// if cpu or memory utilization is over threshold.
    #[prost(double, tag = "1")]
    pub scale_down_utilization_threshold: f64,
    /// ScaleDownGpuUtilizationThreshold sets threshold for gpu nodes to be
    /// considered for scale down if gpu utilization is over threshold.
    #[prost(double, tag = "2")]
    pub scale_down_gpu_utilization_threshold: f64,
    /// ScaleDownUnneededTime sets the duration CA expects a node to be
    /// unneeded/eligible for removal before scaling down the node.
    #[prost(message, optional, tag = "3")]
    pub scale_down_unneeded_time: ::core::option::Option<
        super::super::super::super::k8s::io::apimachinery::pkg::apis::meta::v1::Duration,
    >,
    /// ScaleDownUnreadyTime represents how long an unready node should be
    /// unneeded before it is eligible for scale down.
    #[prost(message, optional, tag = "4")]
    pub scale_down_unready_time: ::core::option::Option<
        super::super::super::super::k8s::io::apimachinery::pkg::apis::meta::v1::Duration,
    >,
    /// MaxNodeProvisionTime time CA waits for node to be provisioned
    #[prost(message, optional, tag = "5")]
    pub max_node_provision_time: ::core::option::Option<
        super::super::super::super::k8s::io::apimachinery::pkg::apis::meta::v1::Duration,
    >,
    /// ZeroOrMaxNodeScaling means that a node group should be scaled up to maximum size or down to zero nodes all at once instead of one-by-one.
    #[prost(bool, tag = "6")]
    pub zero_or_max_node_scaling: bool,
    /// IgnoreDaemonSetsUtilization sets if daemonsets utilization should be considered during node scale-down
    #[prost(bool, tag = "7")]
    pub ignore_daemon_sets_utilization: bool,
}

/// Duration is a wrapper around time.Duration which supports correct
/// marshaling to YAML and JSON. In particular, it marshals into strings, which
/// can be used as map keys in json.
#[derive(facet::Facet)]
#[facet(rename_all = "camelCase")]
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
pub struct Duration {
    #[prost(int64, optional, tag = "1")]
    pub duration: ::core::option::Option<i64>,
}

Input YAML:

nodeGroupAutoscalingOptions:
  default:
    scaleDownUtilizationThreshold: 0.2
    scaleDownGpuUtilizationThreshold: 0.1
    zeroOrMaxNodeScaling: true
    ignoreDaemonSetsUtilization: true

PS: If you set just the YAML key scaleDownUnneededTime: you get a fun AnyErr("Value '\u{1b}[34mOption<Duration>\u{1b}[39m' was not initialized")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions