Skip to content

Commit

Permalink
Merge pull request #34 from beclab/uploader4
Browse files Browse the repository at this point in the history
uploader for external, fix pvc error when resubaccount before uploading
  • Loading branch information
eball authored Jan 22, 2025
2 parents b5feee8 + 21e9ec5 commit c40bbf7
Show file tree
Hide file tree
Showing 8 changed files with 492 additions and 125 deletions.
278 changes: 255 additions & 23 deletions cmd/upload/app/handler4.go

Large diffs are not rendered by default.

32 changes: 23 additions & 9 deletions cmd/upload/app/os_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"k8s.io/klog/v2"
"strings"
"sync"
"time"
)

var PVCs *PVCCache = nil
Expand Down Expand Up @@ -77,21 +78,26 @@ func GetAnnotation(ctx context.Context, client *kubernetes.Clientset, key string
}

klog.Infof("bfl.Annotations: %+v", bfl.Annotations)
klog.Infof("bfl.Annotations[%s]: %s at time %s", key, bfl.Annotations[key], time.Now().Format(time.RFC3339))
return bfl.Annotations[key], nil
}

type PVCCache struct {
server *Server
userPvcMap map[string]string
cachePvcMap map[string]string
mu sync.Mutex
server *Server
userPvcMap map[string]string
userPvcTime map[string]time.Time
cachePvcMap map[string]string
cachePvcTime map[string]time.Time
mu sync.Mutex
}

func NewPVCCache(server *Server) *PVCCache {
return &PVCCache{
server: server,
userPvcMap: make(map[string]string),
cachePvcMap: make(map[string]string),
server: server,
userPvcMap: make(map[string]string),
userPvcTime: make(map[string]time.Time),
cachePvcMap: make(map[string]string),
cachePvcTime: make(map[string]time.Time),
}
}

Expand All @@ -100,14 +106,18 @@ func (p *PVCCache) getUserPVCOrCache(bflName string) (string, error) {
defer p.mu.Unlock()

if val, ok := p.userPvcMap[bflName]; ok {
return val, nil
if t, ok := p.userPvcTime[bflName]; ok && time.Since(t) <= 2*time.Minute {
p.userPvcTime[bflName] = time.Now()
return val, nil
}
}

userPvc, err := GetAnnotation(p.server.context, p.server.k8sClient, "userspace_pvc", bflName)
if err != nil {
return "", err
}
p.userPvcMap[bflName] = userPvc
p.userPvcTime[bflName] = time.Now()
return userPvc, nil
}

Expand All @@ -116,13 +126,17 @@ func (p *PVCCache) getCachePVCOrCache(bflName string) (string, error) {
defer p.mu.Unlock()

if val, ok := p.cachePvcMap[bflName]; ok {
return val, nil
if t, ok := p.cachePvcTime[bflName]; ok && time.Since(t) <= 2*time.Minute {
p.cachePvcTime[bflName] = time.Now()
return val, nil
}
}

cachePvc, err := GetAnnotation(p.server.context, p.server.k8sClient, "appcache_pvc", bflName)
if err != nil {
return "", err
}
p.cachePvcMap[bflName] = cachePvc
p.cachePvcTime[bflName] = time.Now()
return cachePvc, nil
}
30 changes: 18 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module bytetrade.io/web3os/tapr

go 1.18
go 1.22

toolchain go1.23.3

require (
github.com/dgrijalva/jwt-go v3.2.0+incompatible
Expand All @@ -15,18 +17,20 @@ require (
github.com/json-iterator/go v1.1.12
github.com/lib/pq v1.2.0
github.com/mitchellh/mapstructure v1.4.3
github.com/nats-io/nats.go v1.29.0
github.com/nats-io/nats-server v1.4.1
github.com/nats-io/nats.go v1.36.0
github.com/percona/percona-backup-mongodb v0.0.0-20221024072933-3ec38a5fc670
github.com/percona/percona-server-mongodb-operator v1.14.0
github.com/prometheus/client_golang v1.14.0
github.com/prometheus/common v0.37.0
github.com/robfig/cron/v3 v3.0.1
github.com/shirou/gopsutil v3.21.11+incompatible
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/thoas/go-funk v0.9.3
github.com/vmware-tanzu/velero v1.11.0
go.mongodb.org/mongo-driver v1.11.7
golang.org/x/crypto v0.23.0
golang.org/x/crypto v0.31.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.26.3
k8s.io/apimachinery v0.26.3
Expand Down Expand Up @@ -54,6 +58,7 @@ require (
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-ini/ini v1.67.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
Expand All @@ -70,7 +75,7 @@ require (
github.com/jessevdk/go-flags v1.5.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/klauspost/pgzip v1.2.5 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand All @@ -86,9 +91,7 @@ require (
github.com/mongodb/mongo-tools v0.0.0-20220803145531-1d46e6e7021f // indirect
github.com/montanaflynn/stats v0.6.6 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/nats-io/gnatsd v1.4.1 // indirect
github.com/nats-io/nats-server v1.4.1 // indirect
github.com/nats-io/nkeys v0.4.7 // indirect
github.com/nats-io/nkeys v0.4.9 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
Expand All @@ -97,21 +100,24 @@ require (
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee // indirect
github.com/tklauser/go-sysconf v0.3.14 // indirect
github.com/tklauser/numcpus v0.8.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.50.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.1 // indirect
github.com/xdg-go/stringprep v1.0.3 // indirect
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/oauth2 v0.4.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/term v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/term v0.27.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/time v0.8.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand Down
Loading

0 comments on commit c40bbf7

Please sign in to comment.