From f7ec6512512d9c4158cef4806219fef6681d8714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E7=8E=AE=E6=96=87?= Date: Wed, 27 Nov 2024 14:50:48 +0800 Subject: [PATCH] remove dep on old github.com/golang/protobuf --- go.mod | 2 +- pkg/disk/controllerserver.go | 5 ++--- pkg/disk/group_volume_snapshot_utils.go | 8 ++++---- pkg/disk/group_volume_snapshot_utils_test.go | 8 ++++---- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 81e5c70c0..6c34f69a0 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,6 @@ require ( github.com/go-logr/logr v1.4.1 github.com/go-ping/ping v0.0.0-20201022122018-3977ed72668a github.com/golang/mock v1.6.0 - github.com/golang/protobuf v1.5.4 github.com/google/go-cmp v0.6.0 github.com/jarcoal/httpmock v1.3.1 github.com/kubernetes-csi/csi-lib-utils v0.7.1 @@ -61,6 +60,7 @@ require ( github.com/go-openapi/swag v0.22.3 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect + github.com/golang/protobuf v1.5.4 // indirect github.com/google/gnostic-models v0.6.8 // indirect github.com/google/gofuzz v1.2.0 // indirect github.com/google/uuid v1.3.0 // indirect diff --git a/pkg/disk/controllerserver.go b/pkg/disk/controllerserver.go index f6a46ecb9..5637d61f7 100644 --- a/pkg/disk/controllerserver.go +++ b/pkg/disk/controllerserver.go @@ -30,7 +30,6 @@ import ( "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" "github.com/aliyun/alibaba-cloud-sdk-go/services/ecs" "github.com/container-storage-interface/spec/lib/go/csi" - "github.com/golang/protobuf/ptypes/timestamp" "github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/common" "github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/features" "github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/utils" @@ -803,13 +802,13 @@ func newListSnapshotsResponse(snapshots []ecs.Snapshot, nextToken string) (*csi. func formatCSISnapshot(ecsSnapshot *ecs.Snapshot) (*csi.Snapshot, error) { // creationTime == "" if created by snapshotGroup - var creationTime *timestamp.Timestamp + var creationTime *timestamppb.Timestamp if ecsSnapshot.CreationTime != "" { t, err := time.Parse(time.RFC3339, ecsSnapshot.CreationTime) if err != nil { return nil, status.Errorf(codes.Internal, "failed to parse snapshot creation time: %s", ecsSnapshot.CreationTime) } - creationTime = ×tamp.Timestamp{Seconds: t.Unix()} + creationTime = timestamppb.New(t) } var sizeGB int64 diff --git a/pkg/disk/group_volume_snapshot_utils.go b/pkg/disk/group_volume_snapshot_utils.go index f82510969..e40436858 100644 --- a/pkg/disk/group_volume_snapshot_utils.go +++ b/pkg/disk/group_volume_snapshot_utils.go @@ -9,10 +9,10 @@ import ( "github.com/aliyun/alibaba-cloud-sdk-go/services/ecs" "github.com/container-storage-interface/spec/lib/go/csi" - "github.com/golang/protobuf/ptypes/timestamp" "github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/common" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + "google.golang.org/protobuf/types/known/timestamppb" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/klog/v2" ) @@ -101,7 +101,7 @@ func formatGroupSnapshot(groupSnapshot *ecs.SnapshotGroup) (*csi.VolumeGroupSnap if err != nil { return nil, fmt.Errorf("failed to parse groupSnapshot creation time: %s", groupSnapshot.CreationTime) } - creationTime := timestamp.Timestamp{Seconds: t.Unix()} + creationTime := timestamppb.New(t) readyToUse := groupSnapshot.Status == SnapshotStatusAccomplished snapshots := []*csi.Snapshot{} @@ -110,7 +110,7 @@ func formatGroupSnapshot(groupSnapshot *ecs.SnapshotGroup) (*csi.VolumeGroupSnap if err != nil { return nil, err } - snapshot.CreationTime = &creationTime + snapshot.CreationTime = creationTime snapshot.GroupSnapshotId = groupSnapshot.SnapshotGroupId if !snapshot.ReadyToUse { // set readyToUse for groupsnapshots according to each snapshot status @@ -122,7 +122,7 @@ func formatGroupSnapshot(groupSnapshot *ecs.SnapshotGroup) (*csi.VolumeGroupSnap return &csi.VolumeGroupSnapshot{ GroupSnapshotId: groupSnapshot.SnapshotGroupId, Snapshots: snapshots, - CreationTime: &creationTime, + CreationTime: creationTime, ReadyToUse: readyToUse, }, nil } diff --git a/pkg/disk/group_volume_snapshot_utils_test.go b/pkg/disk/group_volume_snapshot_utils_test.go index 3eb3087de..0db8d0dbc 100644 --- a/pkg/disk/group_volume_snapshot_utils_test.go +++ b/pkg/disk/group_volume_snapshot_utils_test.go @@ -7,9 +7,9 @@ import ( "github.com/aliyun/alibaba-cloud-sdk-go/services/ecs" "github.com/container-storage-interface/spec/lib/go/csi" - "github.com/golang/protobuf/ptypes/timestamp" "github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/common" "github.com/stretchr/testify/assert" + "google.golang.org/protobuf/types/known/timestamppb" ) func Test_parseGroupSnapshotAnnotations(t *testing.T) { @@ -67,19 +67,19 @@ func Test_formatGroupSnapshot(t *testing.T) { { SnapshotId: "snapshot1", ReadyToUse: true, - CreationTime: ×tamp.Timestamp{Seconds: stamp.Unix()}, + CreationTime: timestamppb.New(stamp), GroupSnapshotId: "snapshotGroup1", SizeBytes: 10 * 1024 * 1024 * 1024, }, { SnapshotId: "snapshot2", ReadyToUse: false, - CreationTime: ×tamp.Timestamp{Seconds: stamp.Unix()}, + CreationTime: timestamppb.New(stamp), GroupSnapshotId: "snapshotGroup1", SizeBytes: 10 * 1024 * 1024 * 1024, }, }, - CreationTime: ×tamp.Timestamp{Seconds: stamp.Unix()}, + CreationTime: timestamppb.New(stamp), ReadyToUse: false, }