Skip to content

Commit

Permalink
cephfs: introduce parsetime() to parse createdAt field in snap return
Browse files Browse the repository at this point in the history
Signed-off-by: Humble Chirammal <hchiramm@redhat.com>
  • Loading branch information
humblec committed Aug 7, 2020
1 parent 9fac452 commit 0584beb
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions internal/cephfs/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ import (
"encoding/json"
"errors"
"fmt"
"time"

"github.com/ceph/ceph-csi/internal/util"

"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/timestamp"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
klog "k8s.io/klog/v2"
Expand Down Expand Up @@ -158,3 +161,21 @@ func getMonsAndClusterID(ctx context.Context, options map[string]string) (monito

return
}

func parseTime(ctx context.Context, createTime string) (*timestamp.Timestamp, error) {
tm := &timestamp.Timestamp{}
layout := "2006-01-02 15:04:05.000000"
// TODO currently parsing of timestamp to time.ANSIC generate from ceph fs is failng
var t time.Time
t, err := time.Parse(layout, createTime)
if err != nil {
klog.Errorf(util.Log(ctx, "failed to parse time %s %v"), createTime, err)
return tm, err
}
tm, err = ptypes.TimestampProto(t)
if err != nil {
klog.Errorf(util.Log(ctx, "failed to convert time %s %v"), createTime, err)
return tm, err
}
return tm, nil
}

0 comments on commit 0584beb

Please sign in to comment.