Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build/nodemanPlugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ func Watch(cmd *cobra.Command, args []string) error {
}),
client.WithEnableMonitorResourceUsage(conf.EnableMonitorResourceUsage),
client.WithTextLineBreak(conf.TextLineBreak),
client.WithProjectKey(conf.ProjectKey),
client.WithEnvName(conf.EnvName),
)
if err != nil {
logger.Error("init client", logger.ErrAttr(err))
Expand Down
11 changes: 9 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type Client interface {
Close() error
}

// ErrNotFoundKvMD5 is err not found kv md5
// ErrNotFoundKvMD5 is returned when the kv md5 is not found
var ErrNotFoundKvMD5 = errors.New("not found kv md5")

// Client is the bscp client
Expand Down Expand Up @@ -99,8 +99,12 @@ func New(opts ...Option) (Client, error) {
// add finger printer
mh := sfs.SidecarMetaHeader{
BizID: clientOpt.bizID,
Token: clientOpt.token,
Fingerprint: clientOpt.fingerprint,
ProjectKey: clientOpt.projectKey,
EnvName: clientOpt.envName,
}

mhBytes, err := json.Marshal(mh)
if err != nil {
return nil, fmt.Errorf("encode sidecar meta header failed, err: %s", err.Error())
Expand Down Expand Up @@ -288,11 +292,13 @@ func (c *client) GetFile(app string, filePath string, opts ...AppOption) (*FileS
}

// PullFiles pull files from remote
func (c *client) PullFiles(app string, opts ...AppOption) (*Release, error) { // nolint
// nolint
func (c *client) PullFiles(app string, opts ...AppOption) (*Release, error) {
option := &AppOptions{}
for _, opt := range opts {
opt(option)
}

vas, _ := c.buildVas()
req := &pbfs.PullAppFileMetaReq{
ApiVersion: sfs.CurrentAPIVersion,
Expand All @@ -305,6 +311,7 @@ func (c *client) PullFiles(app string, opts ...AppOption) (*Release, error) { //
Token: c.opts.token,
Match: option.Match,
}

// compatible with the old version of bscp server which can only recognize param req.Key
if len(option.Match) > 0 {
req.Key = option.Match[0]
Expand Down
20 changes: 20 additions & 0 deletions client/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ type options struct {
enableMonitorResourceUsage bool
// textLineBreak is the text file line break character, default as LF
textLineBreak string
// projectKey is the project key of the bscp business
projectKey string
// envName is the environment name of the bscp business
envName string
}

// FileCache option for file cache
Expand Down Expand Up @@ -225,6 +229,22 @@ func WithTextLineBreak(lineBreak string) Option {
}
}

// WithProjectKey set project key
func WithProjectKey(projectKey string) Option {
return func(o *options) error {
o.projectKey = projectKey
return nil
}
}

// WithEnvName set env name
func WithEnvName(envName string) Option {
return func(o *options) error {
o.envName = envName
return nil
}
}

// AppOptions options for app pull and watch
type AppOptions struct {
// Match matches config items
Expand Down
3 changes: 3 additions & 0 deletions client/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ func newWatcher(u upstream.Upstream, opts *options) (*watcher, error) {

mh := sfs.SidecarMetaHeader{
BizID: w.opts.bizID,
Token: w.opts.token,
Fingerprint: w.opts.fingerprint,
ProjectKey: w.opts.projectKey,
EnvName: w.opts.envName,
}
mhBytes, err := json.Marshal(mh)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions cmd/bscp/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ var (
"cluster_id": env.ClusterID,
"pod_id": env.PodID,
"container_name": env.ContainerName,
"project_key": env.ProjectKey,
"env_name": env.EnvName,
}

watchEnvs = map[string]string{
Expand Down
10 changes: 10 additions & 0 deletions cmd/bscp/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,15 @@ func init() {
getCmd.PersistentFlags().StringP("token", "t", "", "sdk token")
getCmd.PersistentFlags().Int64P("dial-timeout-ms", "", constant.DefaultDialTimeoutMS,
"dial upstream timeout in millisecond")
getCmd.PersistentFlags().StringP("project-key", "", "", "project key")
getCmd.PersistentFlags().StringP("env-name", "", "", "env name")
for _, v := range getVipers {
mustBindPFlag(v, "feed_addrs", getCmd.PersistentFlags().Lookup("feed-addrs"))
mustBindPFlag(v, "biz", getCmd.PersistentFlags().Lookup("biz"))
mustBindPFlag(v, "token", getCmd.PersistentFlags().Lookup("token"))
mustBindPFlag(v, "dial_timeout_ms", getCmd.PersistentFlags().Lookup("dial-timeout-ms"))
mustBindPFlag(v, "project_key", getCmd.PersistentFlags().Lookup("project-key"))
mustBindPFlag(v, "env_name", getCmd.PersistentFlags().Lookup("env-name"))

for key, envName := range commonEnvs {
// bind env variable with viper
Expand Down Expand Up @@ -172,6 +176,8 @@ func runGetApp(args []string) error {
client.WithBizID(conf.Biz),
client.WithToken(conf.Token),
client.WithDialTimeoutMS(conf.DialTimeoutMS),
client.WithProjectKey(conf.ProjectKey),
client.WithEnvName(conf.EnvName),
)

if err != nil {
Expand Down Expand Up @@ -412,6 +418,8 @@ func runGetFile(args []string) error {
CacheDir: conf.FileCache.CacheDir,
ThresholdGB: conf.FileCache.ThresholdGB,
}),
client.WithProjectKey(conf.ProjectKey),
client.WithEnvName(conf.EnvName),
)

if err != nil {
Expand Down Expand Up @@ -556,6 +564,8 @@ func runGetKv(args []string) error {
client.WithBizID(conf.Biz),
client.WithToken(conf.Token),
client.WithDialTimeoutMS(conf.DialTimeoutMS),
client.WithProjectKey(conf.ProjectKey),
client.WithEnvName(conf.EnvName),
)

if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions cmd/bscp/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ func Pull(cmd *cobra.Command, args []string) {
ThresholdGB: conf.FileCache.ThresholdGB,
}),
client.WithTextLineBreak(conf.TextLineBreak),
client.WithProjectKey(conf.ProjectKey),
client.WithEnvName(conf.EnvName),
)

if err != nil {
logger.Error("init client", logger.ErrAttr(err))
os.Exit(1)
Expand Down Expand Up @@ -210,6 +213,11 @@ func init() {
mustBindPFlag(pullViper, "enable_resource", PullCmd.Flags().Lookup("enable-resource"))
PullCmd.Flags().StringP("text-line-break", "", "", "text file line break, default as LF")
mustBindPFlag(pullViper, "text_line_break", PullCmd.Flags().Lookup("text-line-break"))
// TODO: set project name and env name
PullCmd.Flags().StringP("project-key", "", "", "project key")
mustBindPFlag(pullViper, "project_key", PullCmd.Flags().Lookup("project-key"))
PullCmd.Flags().StringP("env-name", "", "", "env name")
mustBindPFlag(pullViper, "env_name", PullCmd.Flags().Lookup("env-name"))

for key, envName := range commonEnvs {
// bind env variable with viper
Expand Down
7 changes: 7 additions & 0 deletions cmd/bscp/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ func newWatchClient(labels map[string]string) (client.Client, error) {
}),
client.WithEnableMonitorResourceUsage(conf.EnableMonitorResourceUsage),
client.WithTextLineBreak(conf.TextLineBreak),
client.WithProjectKey(conf.ProjectKey),
client.WithEnvName(conf.EnvName),
)
}

Expand Down Expand Up @@ -309,6 +311,11 @@ func init() {
mustBindPFlag(watchViper, "enable_resource", WatchCmd.Flags().Lookup("enable-resource"))
WatchCmd.Flags().StringP("text-line-break", "", "", "text line break, default as LF")
mustBindPFlag(watchViper, "text_line_break", WatchCmd.Flags().Lookup("text-line-break"))
// TODO: set project name and env name
WatchCmd.Flags().StringP("project-key", "", "", "project key")
mustBindPFlag(watchViper, "project_key", WatchCmd.Flags().Lookup("project-key"))
WatchCmd.Flags().StringP("env-name", "", "", "env name")
mustBindPFlag(watchViper, "env_name", WatchCmd.Flags().Lookup("env-name"))

envs := map[string]string{}
for key, envName := range commonEnvs {
Expand Down
42 changes: 20 additions & 22 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,46 +1,44 @@
module github.com/TencentBlueKing/bscp-go

go 1.23.0

toolchain go1.23.7
go 1.25.0

require (
github.com/TencentBlueKing/bk-bscp/pkg v0.0.1
github.com/TencentBlueKing/bk-bscp/pkg v0.0.2-0.20260807085510-9f1bbe60f2ed
github.com/allegro/bigcache/v3 v3.1.0
github.com/dustin/go-humanize v1.0.1
github.com/fsnotify/fsnotify v1.7.0
github.com/fsnotify/fsnotify v1.9.0
github.com/olekukonko/tablewriter v0.0.5
github.com/prometheus/client_golang v1.19.0
github.com/prometheus/client_golang v1.19.1
github.com/prometheus/procfs v0.12.0
github.com/shirou/gopsutil/v3 v3.24.3
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.19.0
go.uber.org/atomic v1.11.0
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8
golang.org/x/sync v0.11.0
golang.org/x/sys v0.30.0
google.golang.org/grpc v1.64.0
golang.org/x/sync v0.19.0
golang.org/x/sys v0.39.0
google.golang.org/grpc v1.79.3
gopkg.in/natefinch/lumberjack.v2 v2.2.1
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/coreos/go-semver v0.3.1 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.17.1 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.1-vault-5 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/hashicorp/hcl v1.0.1-vault-7 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
Expand All @@ -57,10 +55,10 @@ require (
github.com/prometheus/common v0.48.0 // indirect
github.com/sagikazarmark/locafero v0.6.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/samber/lo v1.39.0 // indirect
github.com/samber/lo v1.52.0 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/afero v1.14.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/tidwall/gjson v1.16.0 // indirect
Expand All @@ -75,14 +73,14 @@ require (
go.etcd.io/etcd/client/v3 v3.5.14 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.35.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/text v0.22.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240617180043-68d350f18fd4 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240617180043-68d350f18fd4 // indirect
google.golang.org/protobuf v1.34.2 // indirect
golang.org/x/crypto v0.46.0 // indirect
golang.org/x/net v0.48.0 // indirect
golang.org/x/text v0.32.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20251202230838-ff82c1b0f217 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217 // indirect
google.golang.org/protobuf v1.36.10 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/gorm v1.25.4 // indirect
gorm.io/gorm v1.25.11 // indirect
k8s.io/klog/v2 v2.130.0 // indirect
)
Loading
Loading