Skip to content

Commit

Permalink
use metav1.Time
Browse files Browse the repository at this point in the history
  • Loading branch information
Song Gao committed Apr 15, 2020
1 parent cdac855 commit d5ba990
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 25 deletions.
4 changes: 3 additions & 1 deletion docs/api-references/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -2413,7 +2413,9 @@ int32
<td>
<code>lastAutoScalingTimestamp</code></br>
<em>
string
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#time-v1-meta">
Kubernetes meta/v1.Time
</a>
</em>
</td>
<td>
Expand Down
12 changes: 8 additions & 4 deletions manifests/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10781,8 +10781,10 @@ spec:
format: int32
type: integer
lastAutoScalingTimestamp:
description: LastAutoScalingTimestamp describes the last auto-scaling
timestamp for the component(tidb/tikv)
description: Time is a wrapper around time.Time which supports correct
marshaling to YAML and JSON. Wrappers are provided for many of
the factory methods that the time package offers.
format: date-time
type: string
metrics:
description: MetricsStatusList describes the metrics status in the
Expand Down Expand Up @@ -10826,8 +10828,10 @@ spec:
format: int32
type: integer
lastAutoScalingTimestamp:
description: LastAutoScalingTimestamp describes the last auto-scaling
timestamp for the component(tidb/tikv)
description: Time is a wrapper around time.Time which supports correct
marshaling to YAML and JSON. Wrappers are provided for many of
the factory methods that the time package offers.
format: date-time
type: string
metrics:
description: MetricsStatusList describes the metrics status in the
Expand Down
15 changes: 6 additions & 9 deletions pkg/apis/pingcap/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/apis/pingcap/v1alpha1/tidbclusterautoscaler_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ type BasicAutoScalerStatus struct {
RecommendedReplicas *int32 `json:"recommendedReplicas,omitempty"`
// LastAutoScalingTimestamp describes the last auto-scaling timestamp for the component(tidb/tikv)
// +optional
LastAutoScalingTimestamp *string `json:"lastAutoScalingTimestamp,omitempty"`
LastAutoScalingTimestamp *metav1.Time `json:"lastAutoScalingTimestamp,omitempty"`
}

// +k8s:openapi-gen=true
Expand Down
3 changes: 1 addition & 2 deletions pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions pkg/autoscaler/autoscaler/autoscaler_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,18 @@ func (am *autoScalerManager) updateAutoScaling(oldTc *v1alpha1.TidbCluster,
if tac.Annotations == nil {
tac.Annotations = map[string]string{}
}
f := func(key string) (string, error) {
f := func(key string) (*time.Time, error) {
v, ok := tac.Annotations[key]
if ok {
ts, err := strconv.ParseInt(v, 10, 64)
if err != nil {
klog.Errorf("failed to convert label[%s] key to int64, err:%v", key, err)
return "", err
return nil, err
}
return time.Unix(ts, 0).Format(time.RFC3339), nil
t := time.Unix(ts, 0)
return &t, nil
}
return "", nil
return nil, nil
}

if tac.Spec.TiKV != nil {
Expand All @@ -152,8 +153,8 @@ func (am *autoScalerManager) updateAutoScaling(oldTc *v1alpha1.TidbCluster,
if err != nil {
return err
}
if len(lastTimestamp) > 0 {
tac.Status.TiKV.LastAutoScalingTimestamp = &lastTimestamp
if lastTimestamp != nil {
tac.Status.TiKV.LastAutoScalingTimestamp = &metav1.Time{Time: *lastTimestamp}
}
} else {
tac.Status.TiKV = nil
Expand All @@ -164,8 +165,8 @@ func (am *autoScalerManager) updateAutoScaling(oldTc *v1alpha1.TidbCluster,
if err != nil {
return err
}
if len(lastTimestamp) > 0 {
tac.Status.TiDB.LastAutoScalingTimestamp = &lastTimestamp
if lastTimestamp != nil {
tac.Status.TiDB.LastAutoScalingTimestamp = &metav1.Time{Time: *lastTimestamp}
}
} else {
tac.Status.TiDB = nil
Expand Down

0 comments on commit d5ba990

Please sign in to comment.