@@ -1494,10 +1494,16 @@ def validate(self) -> None:
14941494 raise SpecValidationError (
14951495 'Invalid SPDK log level. Valid values are: DEBUG, INFO, WARNING, ERROR, NOTICE' )
14961496
1497- if self .spdk_ping_interval_in_seconds < 1.0 :
1497+ if (
1498+ self .spdk_ping_interval_in_seconds
1499+ and self .spdk_ping_interval_in_seconds < 1.0
1500+ ):
14981501 raise SpecValidationError ("SPDK ping interval should be at least 1 second" )
14991502
1500- if self .allowed_consecutive_spdk_ping_failures < 1 :
1503+ if (
1504+ self .allowed_consecutive_spdk_ping_failures
1505+ and self .allowed_consecutive_spdk_ping_failures < 1
1506+ ):
15011507 raise SpecValidationError ("Allowed consecutive SPDK ping failures should be at least 1" )
15021508
15031509 if self .state_update_interval_sec < 0 :
@@ -2032,7 +2038,7 @@ def __init__(self,
20322038 port : Optional [int ] = None ,
20332039 protocol : Optional [str ] = 'https' ,
20342040 initial_admin_password : Optional [str ] = None ,
2035- anonymous_access : Optional [ bool ] = True ,
2041+ anonymous_access : bool = True ,
20362042 extra_container_args : Optional [GeneralArgList ] = None ,
20372043 extra_entrypoint_args : Optional [GeneralArgList ] = None ,
20382044 custom_configs : Optional [List [CustomConfig ]] = None ,
@@ -2067,6 +2073,24 @@ def validate(self) -> None:
20672073 'be inaccessible.' )
20682074 raise SpecValidationError (err_msg )
20692075
2076+ def to_json (self ) -> "OrderedDict[str, Any]" :
2077+ json_dict = super (GrafanaSpec , self ).to_json ()
2078+ if not self .anonymous_access :
2079+ # This field was added as a boolean that defaults
2080+ # to True, which makes it get dropped when the user
2081+ # sets it to False and it is converted to json. This means
2082+ # the in memory version of the spec will have the option set
2083+ # correctly, but the persistent version we store in the config-key
2084+ # store will always drop this option. It's already been backported to
2085+ # some release versions, or we'd probably just rename it to
2086+ # no_anonymous_access and default it to False. This block is to
2087+ # handle this option specially and in the future, we should avoid
2088+ # boolean fields that default to True.
2089+ if 'spec' not in json_dict :
2090+ json_dict ['spec' ] = {}
2091+ json_dict ['spec' ]['anonymous_access' ] = False
2092+ return json_dict
2093+
20702094
20712095yaml .add_representer (GrafanaSpec , ServiceSpec .yaml_representer )
20722096
0 commit comments