diff --git a/cmd/plugin/rpaasv2/cmd/autoscale.go b/cmd/plugin/rpaasv2/cmd/autoscale.go index 4d2673c7b..b62d448fc 100644 --- a/cmd/plugin/rpaasv2/cmd/autoscale.go +++ b/cmd/plugin/rpaasv2/cmd/autoscale.go @@ -264,8 +264,13 @@ func writeAutoscale(w io.Writer, autoscale *autogenerated.Autoscale) { human, _ := exprDesc.ToDescription(s.Start, cron.Locale_en) fmt.Fprintf(&schedules, " Start: %s (%s)\n", human, s.Start) - human, _ = exprDesc.ToDescription(s.Start, cron.Locale_en) + human, _ = exprDesc.ToDescription(s.End, cron.Locale_en) fmt.Fprintf(&schedules, " End: %s (%s)", human, s.End) + + timezone := s.GetTimezone() + if timezone != "" { + fmt.Fprintf(&schedules, "\n Timezone: %s", timezone) + } } if text := schedules.String(); text != "" { diff --git a/cmd/plugin/rpaasv2/cmd/autoscale_test.go b/cmd/plugin/rpaasv2/cmd/autoscale_test.go index e1e5ed2e4..fc02487ef 100644 --- a/cmd/plugin/rpaasv2/cmd/autoscale_test.go +++ b/cmd/plugin/rpaasv2/cmd/autoscale_test.go @@ -13,6 +13,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "k8s.io/utils/pointer" "github.com/tsuru/rpaas-operator/pkg/rpaas/client/autogenerated" ) @@ -70,7 +71,7 @@ max replicas: 5 Schedules: []autogenerated.ScheduledWindow{ {MinReplicas: 1, Start: "00 08 * * 1-5", End: "00 20 * * 1-5"}, {MinReplicas: 5, Start: "00 20 * * 2", End: "00 01 * * 3"}, - {MinReplicas: 5, Start: "00 22 * * 0", End: "00 02 * * 1"}, + {MinReplicas: 5, Start: "00 22 * * 0", End: "00 02 * * 1", Timezone: pointer.String("America/Chile")}, }, }) }), @@ -82,17 +83,18 @@ max replicas: 100 | Schedule(s) | Window 1: | | | Min replicas: 1 | | | Start: At 08:00 AM, Monday through Friday (00 08 * * 1-5) | -| | End: At 08:00 AM, Monday through Friday (00 20 * * 1-5) | +| | End: At 08:00 PM, Monday through Friday (00 20 * * 1-5) | | | | | | Window 2: | | | Min replicas: 5 | | | Start: At 08:00 PM, only on Tuesday (00 20 * * 2) | -| | End: At 08:00 PM, only on Tuesday (00 01 * * 3) | +| | End: At 01:00 AM, only on Wednesday (00 01 * * 3) | | | | | | Window 3: | | | Min replicas: 5 | | | Start: At 10:00 PM, only on Sunday (00 22 * * 0) | -| | End: At 10:00 PM, only on Sunday (00 02 * * 1) | +| | End: At 02:00 AM, only on Monday (00 02 * * 1) | +| | Timezone: America/Chile | +-------------+-------------------------------------------------------------+ `, }, diff --git a/docs/openapi.yaml b/docs/openapi.yaml index 7c90ab65d..5778cc9e3 100644 --- a/docs/openapi.yaml +++ b/docs/openapi.yaml @@ -996,6 +996,10 @@ components: type: string description: An Cron expression defining the end of the scheduled window. example: "00 00 * * * 1-5" + timezone: + type: string + description: Timezone is a zone name registered on IANA time zone database, default is UTC. + example: "America/Sao_Paulo" required: - minReplicas - start diff --git a/go.mod b/go.mod index bf94387af..73096ffff 100644 --- a/go.mod +++ b/go.mod @@ -44,6 +44,7 @@ require ( k8s.io/client-go v0.26.2 k8s.io/kubectl v0.26.2 k8s.io/metrics v0.26.2 + k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5 sigs.k8s.io/controller-runtime v0.14.5 sigs.k8s.io/go-open-service-broker-client/v2 v2.0.0-20200925085050-ae25e62aaf10 ) @@ -158,7 +159,6 @@ require ( k8s.io/klog/v2 v2.90.1 // indirect k8s.io/kube-aggregator v0.24.2 // indirect k8s.io/kube-openapi v0.0.0-20230303024457-afdc3dddf62d // indirect - k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5 // indirect knative.dev/pkg v0.0.0-20230306194819-b77a78c6c0ad // indirect sigs.k8s.io/gateway-api v0.4.3 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect diff --git a/pkg/rpaas/client/autogenerated/model_scheduled_window.go b/pkg/rpaas/client/autogenerated/model_scheduled_window.go index 1ad9f0ec3..7394c4f9e 100644 --- a/pkg/rpaas/client/autogenerated/model_scheduled_window.go +++ b/pkg/rpaas/client/autogenerated/model_scheduled_window.go @@ -26,6 +26,8 @@ type ScheduledWindow struct { Start string `json:"start"` // An Cron expression defining the end of the scheduled window. End string `json:"end"` + // Timezone is a zone name registered on IANA time zone database, default is UTC. + Timezone *string `json:"timezone,omitempty"` } // NewScheduledWindow instantiates a new ScheduledWindow object @@ -120,6 +122,38 @@ func (o *ScheduledWindow) SetEnd(v string) { o.End = v } +// GetTimezone returns the Timezone field value if set, zero value otherwise. +func (o *ScheduledWindow) GetTimezone() string { + if o == nil || IsNil(o.Timezone) { + var ret string + return ret + } + return *o.Timezone +} + +// GetTimezoneOk returns a tuple with the Timezone field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ScheduledWindow) GetTimezoneOk() (*string, bool) { + if o == nil || IsNil(o.Timezone) { + return nil, false + } + return o.Timezone, true +} + +// HasTimezone returns a boolean if a field has been set. +func (o *ScheduledWindow) HasTimezone() bool { + if o != nil && !IsNil(o.Timezone) { + return true + } + + return false +} + +// SetTimezone gets a reference to the given string and assigns it to the Timezone field. +func (o *ScheduledWindow) SetTimezone(v string) { + o.Timezone = &v +} + func (o ScheduledWindow) MarshalJSON() ([]byte, error) { toSerialize, err := o.ToMap() if err != nil { @@ -133,6 +167,9 @@ func (o ScheduledWindow) ToMap() (map[string]interface{}, error) { toSerialize["minReplicas"] = o.MinReplicas toSerialize["start"] = o.Start toSerialize["end"] = o.End + if !IsNil(o.Timezone) { + toSerialize["timezone"] = o.Timezone + } return toSerialize, nil }