Switch to google/uuid from satori/go.uuid (#2852)

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
Sanket Sudake
2023-10-17 12:19:17 +05:30
committed by GitHub
parent 7b21fbc199
commit c6329ee3db
20 changed files with 58 additions and 124 deletions
+1 -2
View File
@@ -15,6 +15,7 @@ require (
github.com/go-git/go-git/v5 v5.9.0
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.3.0
github.com/gorilla/mux v1.8.0
github.com/graymeta/stow v0.2.8
github.com/hashicorp/go-multierror v1.1.1
@@ -28,7 +29,6 @@ require (
github.com/prometheus/common v0.44.0
github.com/robfig/cron/v3 v3.0.1
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
@@ -103,7 +103,6 @@ require (
github.com/golang/snappy v0.0.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
github.com/gotestyourself/gotestyourself v2.2.0+incompatible // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
-2
View File
@@ -431,8 +431,6 @@ github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 h1:OkMGxebDjyw0ULyrTYWeN0UNCCkmCWfjPnIA2W6oviI=
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06/go.mod h1:+ePHsJ1keEjQtpvf9HHw0f4ZeJ0TLRsxhunSI2hYJSs=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b h1:gQZ0qzfKHQIybLANtM3mBXNUtOfsCFXeTsnBqCsx1KM=
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/seccomp/libseccomp-golang v0.9.2-0.20220502022130-f33da4d89646/go.mod h1:JA8cRccbGaA1s33RQf7Y1+q9gHmZX1yB/z9WDN1C6fg=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
@@ -7,12 +7,10 @@ import (
"testing"
"time"
uuid "github.com/satori/go.uuid"
"github.com/stretchr/testify/assert"
apiv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes/fake"
k8sCache "k8s.io/client-go/tools/cache"
@@ -23,6 +21,7 @@ import (
genInformer "github.com/fission/fission/pkg/generated/informers/externalversions"
"github.com/fission/fission/pkg/utils"
"github.com/fission/fission/pkg/utils/loggerfactory"
"github.com/fission/fission/pkg/utils/uuid"
)
const (
@@ -120,15 +119,11 @@ func TestRefreshFuncPods(t *testing.T) {
}
assert.Equal(t, envRes.ObjectMeta.Name, envName)
funcUID, err := uuid.NewV4()
if err != nil {
t.Fatal(err)
}
funcSpec := fv1.Function{
ObjectMeta: metav1.ObjectMeta{
Name: functionName,
Namespace: defaultNamespace,
UID: types.UID(funcUID.String()),
UID: uuid.NewUUID(),
},
Spec: fv1.FunctionSpec{
Environment: fv1.EnvironmentReference{
+3 -11
View File
@@ -28,9 +28,9 @@ import (
"strconv"
"time"
"github.com/google/uuid"
"github.com/mholt/archiver/v3"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"go.uber.org/zap"
"golang.org/x/net/context/ctxhttp"
@@ -352,16 +352,8 @@ func (fetcher *Fetcher) Fetch(ctx context.Context, pkg *fv1.Package, req Functio
//checking if file is a zip
if match, _ := utils.IsZip(tmpPath); match && !req.KeepArchive {
// unarchive tmp file to a tmp unarchive path
id, err := uuid.NewV4()
if err != nil {
logger.Error("error generating uuid",
zap.Error(err),
zap.String("archive_location", tmpPath))
return http.StatusInternalServerError, err
}
tmpUnarchivePath := filepath.Join(fetcher.sharedVolumePath, id.String())
err = fetcher.unarchive(tmpPath, tmpUnarchivePath)
tmpUnarchivePath := filepath.Join(fetcher.sharedVolumePath, uuid.NewString())
err := fetcher.unarchive(tmpPath, tmpUnarchivePath)
if err != nil {
logger.Error("error unarchive",
zap.Error(err),
+3 -11
View File
@@ -20,7 +20,6 @@ import (
"fmt"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid"
asv2 "k8s.io/api/autoscaling/v2"
apiv1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
@@ -37,6 +36,7 @@ import (
"github.com/fission/fission/pkg/fission-cli/console"
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
"github.com/fission/fission/pkg/fission-cli/util"
"github.com/fission/fission/pkg/utils/uuid"
)
const (
@@ -217,11 +217,7 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
}
buildcmd := input.String(flagkey.PkgBuildCmd)
id, err := uuid.NewV4()
if err != nil {
return errors.Wrap(err, "error generating uuid")
}
pkgName := generatePackageName(fnName, id.String())
pkgName := generatePackageName(fnName, uuid.NewString())
// create new package in the same namespace as the function.
pkgMetadata, err = _package.CreatePackage(input, opts.Client(), pkgName, fnNamespace, envName,
@@ -401,11 +397,7 @@ func (opts *CreateSubCommand) run(input cli.Input) error {
}
}
id, err := uuid.NewV4()
if err != nil {
return errors.Wrap(err, "error generating UUID")
}
triggerName := id.String()
triggerName := uuid.NewString()
ht := &fv1.HTTPTrigger{
ObjectMeta: metav1.ObjectMeta{
Name: triggerName,
+2 -6
View File
@@ -3,7 +3,7 @@ package function
import (
"testing"
uuid "github.com/satori/go.uuid"
"github.com/fission/fission/pkg/utils/uuid"
)
func TestGeneratePackageName(t *testing.T) {
@@ -29,11 +29,7 @@ func TestGeneratePackageName(t *testing.T) {
},
} {
t.Run(test.name, func(t *testing.T) {
id, err := uuid.NewV4()
if err != nil {
t.Fatal(err)
}
pkgName := generatePackageName(test.fnName, id.String())
pkgName := generatePackageName(test.fnName, uuid.NewString())
if len(pkgName) > test.expected {
t.Errorf("expected len of package to be %v, got %v", test.expected, len(pkgName))
}
+2 -6
View File
@@ -23,7 +23,6 @@ import (
"strings"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid"
kerrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -34,6 +33,7 @@ import (
"github.com/fission/fission/pkg/fission-cli/console"
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
"github.com/fission/fission/pkg/fission-cli/util"
"github.com/fission/fission/pkg/utils/uuid"
)
type CreateSubCommand struct {
@@ -70,11 +70,7 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
// just name triggers by uuid.
if len(triggerName) == 0 {
console.Warn(fmt.Sprintf("--%v will be soon marked as required flag, see 'help' for details", flagkey.HtName))
id, err := uuid.NewV4()
if err != nil {
return err
}
triggerName = id.String()
triggerName = uuid.NewString()
}
userProvidedNS, fnNamespace, err := opts.GetResourceNamespace(input, flagkey.NamespaceFunction)
+2 -6
View File
@@ -20,7 +20,6 @@ import (
"fmt"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
fv1 "github.com/fission/fission/pkg/apis/core/v1"
@@ -30,6 +29,7 @@ import (
"github.com/fission/fission/pkg/fission-cli/console"
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
"github.com/fission/fission/pkg/fission-cli/util"
"github.com/fission/fission/pkg/utils/uuid"
)
type CreateSubCommand struct {
@@ -53,11 +53,7 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
watchName := input.String(flagkey.KwName)
if len(watchName) == 0 {
console.Warn(fmt.Sprintf("--%v will be soon marked as required flag, see 'help' for details", flagkey.MqtName))
id, err := uuid.NewV4()
if err != nil {
return errors.Wrap(err, "error generating uuid")
}
watchName = id.String()
watchName = uuid.NewString()
}
fnName := input.String(flagkey.KwFnName)
+2 -6
View File
@@ -20,7 +20,6 @@ import (
"fmt"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
fv1 "github.com/fission/fission/pkg/apis/core/v1"
@@ -31,6 +30,7 @@ import (
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
"github.com/fission/fission/pkg/fission-cli/util"
"github.com/fission/fission/pkg/mqtrigger/validator"
"github.com/fission/fission/pkg/utils/uuid"
)
type CreateSubCommand struct {
@@ -54,11 +54,7 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
mqtName := input.String(flagkey.MqtName)
if len(mqtName) == 0 {
console.Warn(fmt.Sprintf("--%v will be soon marked as required flag, see 'help' for details", flagkey.MqtName))
id, err := uuid.NewV4()
if err != nil {
return err
}
mqtName = id.String()
mqtName = uuid.NewString()
}
fnName := input.String(flagkey.MqtFnName)
+2 -6
View File
@@ -24,7 +24,6 @@ import (
"github.com/dchest/uniuri"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
fv1 "github.com/fission/fission/pkg/apis/core/v1"
@@ -34,6 +33,7 @@ import (
"github.com/fission/fission/pkg/fission-cli/console"
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
"github.com/fission/fission/pkg/fission-cli/util"
"github.com/fission/fission/pkg/utils/uuid"
)
type CreateSubCommand struct {
@@ -179,11 +179,7 @@ func CreatePackage(input cli.Input, client cmd.Client, pkgName string, pkgNamesp
}
if len(pkgName) == 0 {
id, err := uuid.NewV4()
if err != nil {
return nil, errors.Wrap(err, "error generating UUID")
}
pkgName = strings.ToLower(id.String())
pkgName = strings.ToLower(uuid.NewString())
}
pkg := &fv1.Package{
+2 -6
View File
@@ -27,7 +27,6 @@ import (
"github.com/dchest/uniuri"
"github.com/hashicorp/go-multierror"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
fv1 "github.com/fission/fission/pkg/apis/core/v1"
@@ -40,6 +39,7 @@ import (
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
"github.com/fission/fission/pkg/fission-cli/util"
"github.com/fission/fission/pkg/utils"
"github.com/fission/fission/pkg/utils/uuid"
)
// CreateArchive returns a fv1.Archive made from an archive . If specFile, then
@@ -124,11 +124,7 @@ func CreateArchive(client cmd.Client, input cli.Input, includeFiles []string, no
return nil, err
}
id, err := uuid.NewV4()
if err != nil {
return nil, err
}
file := filepath.Join(tmpDir, id.String())
file := filepath.Join(tmpDir, uuid.NewString())
err = utils.DownloadUrl(input.Context(), http.DefaultClient, fileURL, file)
if err != nil {
return nil, errors.Wrap(err, "error downloading file from the given URL")
+4 -11
View File
@@ -27,13 +27,13 @@ import (
"text/tabwriter"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid"
fv1 "github.com/fission/fission/pkg/apis/core/v1"
"github.com/fission/fission/pkg/fission-cli/cmd"
"github.com/fission/fission/pkg/fission-cli/util"
storageSvcClient "github.com/fission/fission/pkg/storagesvc/client"
"github.com/fission/fission/pkg/utils"
"github.com/fission/fission/pkg/utils/uuid"
)
func UploadArchiveFile(ctx context.Context, client cmd.Client, fileName string) (*fv1.Archive, error) {
@@ -141,11 +141,7 @@ func DownloadToTempFile(fileUrl string) (string, error) {
return "", errors.Wrapf(err, "error creating temp directory %v", tmpDir)
}
id, err := uuid.NewV4()
if err != nil {
return "", errors.Wrapf(err, "error generating UUID")
}
tmpFilename := id.String()
tmpFilename := uuid.NewString()
destination := filepath.Join(tmpDir, tmpFilename)
err = WriteArchiveToFile(destination, reader)
@@ -209,11 +205,8 @@ func WriteArchiveToFile(fileName string, reader io.Reader) error {
if err != nil {
return err
}
id, err := uuid.NewV4()
if err != nil {
return err
}
tmpFileName := id.String()
tmpFileName := uuid.NewString()
path := filepath.Join(tmpDir, tmpFileName+".tmp")
w, err := os.Create(path)
+2 -6
View File
@@ -22,7 +22,6 @@ import (
"path/filepath"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid"
"sigs.k8s.io/yaml"
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
@@ -30,6 +29,7 @@ import (
spectypes "github.com/fission/fission/pkg/fission-cli/cmd/spec/types"
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
"github.com/fission/fission/pkg/fission-cli/util"
"github.com/fission/fission/pkg/utils/uuid"
)
type InitSubCommand struct {
@@ -66,11 +66,7 @@ func (opts *InitSubCommand) complete(input cli.Input) error {
deployID := input.String(flagkey.SpecDeployID)
if len(deployID) == 0 {
id, err := uuid.NewV4()
if err != nil {
return errors.Wrap(err, "error generating UUID")
}
deployID = id.String()
deployID = uuid.NewString()
}
// Create spec dir
+2 -6
View File
@@ -21,10 +21,10 @@ import (
"time"
"github.com/fission/fission/pkg/fission-cli/cmd"
"github.com/fission/fission/pkg/utils/uuid"
"github.com/pkg/errors"
"github.com/robfig/cron/v3"
uuid "github.com/satori/go.uuid"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
fv1 "github.com/fission/fission/pkg/apis/core/v1"
@@ -55,11 +55,7 @@ func (opts *CreateSubCommand) do(input cli.Input) error {
func (opts *CreateSubCommand) complete(input cli.Input) (err error) {
name := input.String(flagkey.TtName)
if len(name) == 0 {
id, err := uuid.NewV4()
if err != nil {
return err
}
name = id.String()
name = uuid.NewString()
}
fnName := input.String(flagkey.TtFnName)
+2 -6
View File
@@ -3,9 +3,9 @@ package storagesvc
import (
"os"
"github.com/fission/fission/pkg/utils/uuid"
"github.com/graymeta/stow"
_ "github.com/graymeta/stow/local"
uuid "github.com/satori/go.uuid"
)
type localStorage struct {
@@ -35,11 +35,7 @@ func (ls localStorage) getStorageType() StorageType {
func (ls localStorage) getUploadFileName() (string, error) {
// This is not the item ID (that's returned by Put)
// should we just use handler.Filename? what are the constraints here?
id, err := uuid.NewV4()
if err != nil {
return "", err
}
return id.String(), err
return uuid.NewString(), nil
}
func (ls localStorage) getSubDir() string {
+4 -6
View File
@@ -6,7 +6,8 @@ import (
"github.com/graymeta/stow"
"github.com/graymeta/stow/s3"
uuid "github.com/satori/go.uuid"
"github.com/fission/fission/pkg/utils/uuid"
)
type (
@@ -54,11 +55,8 @@ func (ss s3Storage) getSubDir() string {
}
func (ss s3Storage) getUploadFileName() (string, error) {
id, err := uuid.NewV4()
if err != nil {
return "", err
}
return path.Join(ss.subDir, id.String()), nil
id := uuid.NewString()
return path.Join(ss.subDir, id), nil
}
func (ss s3Storage) dial() (stow.Location, error) {
+3 -7
View File
@@ -19,13 +19,12 @@ import (
"bytes"
"context"
"errors"
"fmt"
"net/http"
"net/url"
"os"
"time"
uuid "github.com/satori/go.uuid"
"github.com/fission/fission/pkg/utils/uuid"
)
const (
@@ -49,10 +48,7 @@ type (
)
func NewTracker() (*Tracker, error) {
id, err := uuid.NewV4()
if err != nil {
return nil, fmt.Errorf("tracker.NewTracker: error generating UUID: %w", err)
}
id := uuid.NewString()
gaTrackingID := os.Getenv(GA_TRACKING_ID)
if gaTrackingID == "" {
@@ -66,7 +62,7 @@ func NewTracker() (*Tracker, error) {
tracker := &Tracker{
gaPropertyID: gaTrackingID,
cid: id.String(),
cid: id,
gaAPIURL: gaAPIURL,
}
return tracker, nil
+4 -7
View File
@@ -7,8 +7,6 @@ import (
"strconv"
"time"
uuid "github.com/satori/go.uuid"
"go.uber.org/zap"
authorizationv1 "k8s.io/api/authorization/v1"
v1 "k8s.io/api/core/v1"
@@ -18,6 +16,8 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
"github.com/fission/fission/pkg/utils/uuid"
)
const (
@@ -292,11 +292,8 @@ func createGetSA(ctx context.Context, k8sClient kubernetes.Interface, SAName, ns
// generateSuffix generates a random string of 6 characters
func generateSuffix() (string, error) {
id, err := uuid.NewV4()
if err != nil {
return "", nil
}
return id.String()[:6], nil
id := uuid.NewString()
return id[:6], nil
}
func createServiceAccount() bool {
+2 -6
View File
@@ -31,12 +31,12 @@ import (
"github.com/mholt/archiver/v3"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid"
"golang.org/x/net/context/ctxhttp"
apiv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
fv1 "github.com/fission/fission/pkg/apis/core/v1"
"github.com/fission/fission/pkg/utils/uuid"
)
func UrlForFunction(name, namespace string) string {
@@ -60,11 +60,7 @@ func GetFunctionIstioServiceName(fnName, fnNamespace string) string {
// GetTempDir creates and return a temporary directory
func GetTempDir() (string, error) {
id, err := uuid.NewV4()
if err != nil {
return "", err
}
tmpDir := id.String()
tmpDir := uuid.NewString()
dir, err := os.MkdirTemp("", tmpDir)
return dir, err
}
+14
View File
@@ -0,0 +1,14 @@
package uuid
import (
"github.com/google/uuid"
"k8s.io/apimachinery/pkg/types"
)
func NewUUID() types.UID {
return types.UID(uuid.New().String())
}
func NewString() string {
return uuid.New().String()
}