Skip to content

Commit

Permalink
Update Durations type to string to correct json schema
Browse files Browse the repository at this point in the history
  • Loading branch information
zerbitx committed Dec 2, 2024
1 parent e9d61cb commit baf9fa6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion chart/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3020,7 +3020,7 @@
"SleepModeAutoSleep": {
"properties": {
"afterInactivity": {
"type": "integer",
"type": "string",
"description": "AfterInactivity represents how long a vCluster can be idle before workloads are automaticaly put to sleep"
},
"schedule": {
Expand Down
30 changes: 16 additions & 14 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2367,11 +2367,15 @@ type SleepModeAutoSleep struct {
}

// Duration allows for automatic Marshalling from strings like "1m" to a time.Duration
type Duration time.Duration
type Duration string

// MarshalJSON implements Marshaler
func (d Duration) MarshalJSON() ([]byte, error) {
return json.Marshal(time.Duration(d).String())
dur, err := time.ParseDuration(string(d))
if err != nil {
return nil, err
}
return json.Marshal(dur.String())
}

// UnmarshalJSON implements Marshaler
Expand All @@ -2380,20 +2384,18 @@ func (d *Duration) UnmarshalJSON(b []byte) error {
if err := json.Unmarshal(b, &v); err != nil {
return err
}
switch value := v.(type) {
case float64:
*d = Duration(time.Duration(value))
return nil
case string:
tmp, err := time.ParseDuration(value)
if err != nil {
return err
}
*d = Duration(tmp)
return nil
default:

sval, ok := v.(string)
if !ok {
return errors.New("invalid duration")
}

_, err := time.ParseDuration(sval)
if err != nil {
return err
}
*d = Duration(sval)
return nil
}

// AutoWakeup holds the cron schedule to wake workloads automatically
Expand Down

0 comments on commit baf9fa6

Please sign in to comment.