Skip to content

Commit

Permalink
use k8s resource not go-units
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-wangxu committed Jul 28, 2024
1 parent 2cf2acc commit 7132ce0
Show file tree
Hide file tree
Showing 16 changed files with 17 additions and 657 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ all: test fmt vet build

.PHONY: test
test:
$(GO_TEST) -coverprofile=covprofile ./...
$(GO_TEST) -coverprofile=covprofile `go list ./... | grep -v /vendor/ | grep -v e2e`
$(GO_CMD) tool cover -html=covprofile -o coverage.html

.PHONY: build
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.19
require (
github.com/aws/aws-sdk-go v1.45.25
github.com/container-storage-interface/spec v1.7.0
github.com/docker/go-units v0.5.0
github.com/golang/protobuf v1.5.4
github.com/google/credstore v0.0.0-20181218150457-e184c60ef875
github.com/google/uuid v1.4.0
Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,6 @@ github.com/docker/go-metrics v0.0.1/go.mod h1:cG1hvH2utMXtqgqqYE9plW6lDxS3/5ayHz
github.com/docker/go-plugins-helpers v0.0.0-20211224144127-6eecb7beb651/go.mod h1:LFyLie6XcDbyKGeVK6bHe+9aJTYCxWLBg5IrJZOaXKA=
github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/docker/libnetwork v0.8.0-dev.2.0.20190625141545-5a177b73e316/go.mod h1:93m0aTqz6z+g32wla4l4WxTrdtvBRmVzYRkYvasA5Z8=
github.com/docker/libtrust v0.0.0-20150114040149-fa567046d9b1/go.mod h1:cyGadeNEkKy96OOhEzfZl+yxihPEzKnqJwvfuSUqbZE=
Expand Down
3 changes: 1 addition & 2 deletions pkg/agent/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"github.com/alibaba/open-local/pkg/utils"
"github.com/alibaba/open-local/pkg/utils/lvm"
"github.com/alibaba/open-local/pkg/utils/spdk"
units "github.com/docker/go-units"
snapshot "github.com/kubernetes-csi/external-snapshotter/client/v4/clientset/versioned"
corev1 "k8s.io/api/core/v1"
k8serr "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -327,7 +326,7 @@ func getReservedVGInfo(reservedAnno string) (infos map[string]ReservedVGInfo, er
}
} else {
// reservedSize
size, err = units.RAMInBytes(v)
size, err = utils.ParseUnits(v)
if err != nil {
return nil, fmt.Errorf("[getReservedVGInfo]get reserved size failed")
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/agent/discovery/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"strings"

localtype "github.com/alibaba/open-local/pkg"
"github.com/alibaba/open-local/pkg/utils"
"github.com/alibaba/open-local/pkg/utils/lvm"
units "github.com/docker/go-units"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
log "k8s.io/klog/v2"
)
Expand Down Expand Up @@ -85,7 +85,7 @@ func getSnapshotInitialInfo(param map[string]string) (initialSize uint64, thresh

// Step 1: get snapshot initial size
if str, exist := param[localtype.ParamSnapshotInitialSize]; exist {
size, err := units.RAMInBytes(str)
size, err := utils.ParseUnits(str)
if err != nil {
log.Error("[getSnapshotInitialInfo]get initialSize from snapshot annotation failed")
}
Expand All @@ -102,7 +102,7 @@ func getSnapshotInitialInfo(param map[string]string) (initialSize uint64, thresh
}
// Step 3: get snapshot increase size
if str, exist := param[localtype.ParamSnapshotExpansionSize]; exist {
size, err := units.RAMInBytes(str)
size, err := utils.ParseUnits(str)
if err != nil {
log.Error("[getSnapshotInitialInfo]get increase size from snapshot annotation failed")
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/csi/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"github.com/alibaba/open-local/pkg/signals"
"github.com/alibaba/open-local/pkg/utils"
"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/docker/go-units"
timestamppb "github.com/golang/protobuf/ptypes/timestamp"
"golang.org/x/net/context"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -937,7 +936,7 @@ func getSnapshotInitialInfo(param map[string]string) (initialSize uint64, thresh

// Step 1: get snapshot initial size
if str, exist := param[localtype.ParamSnapshotInitialSize]; exist {
size, err := units.RAMInBytes(str)
size, err := utils.ParseUnits(str)
if err != nil {
return 0, 0, 0, status.Errorf(codes.Internal, "getSnapshotInitialInfo: get initialSize from snapshot annotation failed: %s", err.Error())
}
Expand All @@ -954,7 +953,7 @@ func getSnapshotInitialInfo(param map[string]string) (initialSize uint64, thresh
}
// Step 3: get snapshot increase size
if str, exist := param[localtype.ParamSnapshotExpansionSize]; exist {
size, err := units.RAMInBytes(str)
size, err := utils.ParseUnits(str)
if err != nil {
return 0, 0, 0, status.Errorf(codes.Internal, "getSnapshotInitialInfo: get increase size from snapshot annotation failed: %s", err.Error())
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/utils/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -948,3 +948,13 @@ func GetFuncName(funcName interface{}, full bool) string {
}
return origin
}

func ParseUnits(value string) (int64, error) {
ret, err := resource.ParseQuantity(value)
if err != nil {
return 0, err
}
val := ret.Value()
return val, nil

}
67 changes: 0 additions & 67 deletions vendor/github.com/docker/go-units/CONTRIBUTING.md

This file was deleted.

191 changes: 0 additions & 191 deletions vendor/github.com/docker/go-units/LICENSE

This file was deleted.

Loading

0 comments on commit 7132ce0

Please sign in to comment.