Skip to content

Commit

Permalink
Merge remote-tracking branch 'github-bk-bcs/master'
Browse files Browse the repository at this point in the history
* github-bk-bcs/master:
  feat: vault mysql storage add etcd ha backend (#2917)
  refactor: 增加中英文icon (#2919)
  fix: 切换服务后版本对比下拉列表没有刷新--bug=119754095 (#2918)
  fix(bk-bscp): access blueking notification center (#2916)
  feat(bk-bscp): access blueking notification center (#2915)
  feat:Helm Release 详情扩展 (#2891)
  feat:新增模板集相关metrics (#2890)
  fix: 调整info-box样式问题 (#2914)
  • Loading branch information
wenxinlee2015 committed Jan 23, 2024
2 parents 34863a5 + dedd859 commit eb7206d
Show file tree
Hide file tree
Showing 38 changed files with 1,637 additions and 584 deletions.
5 changes: 2 additions & 3 deletions bcs-services/bcs-bscp/cmd/api-server/service/bknotice.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"net/http"

"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/cc"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/config"
)

// bkNoticeService is http handler for bknotice service.
Expand All @@ -30,7 +29,7 @@ func (s *bkNoticeService) GetCurrentAnnouncements(w http.ResponseWriter, r *http
// Prepare the new request

proxyURL := fmt.Sprintf("%s/v1/announcement/get_current_announcements/?platform=%s",
config.G.Base.AppCode, cc.ApiServer().BKNotice.Host)
cc.ApiServer().BKNotice.Host, cc.ApiServer().Esb.AppCode)

proxyReq, err := http.NewRequest("GET", proxyURL, nil)
if err != nil {
Expand All @@ -39,7 +38,7 @@ func (s *bkNoticeService) GetCurrentAnnouncements(w http.ResponseWriter, r *http
}

authHeader := fmt.Sprintf("{\"bk_app_code\": \"%s\", \"bk_app_secret\": \"%s\"}",
config.G.Base.AppCode, config.G.Base.AppSecret)
cc.ApiServer().Esb.AppCode, cc.ApiServer().Esb.AppSecret)

proxyReq.Header.Set("X-Bkapi-Authorization", authHeader)

Expand Down
130 changes: 130 additions & 0 deletions bcs-services/bcs-bscp/cmd/api-server/service/bknotice_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
* Tencent is pleased to support the open source community by making Blueking Container Service available.
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/

package service

import (
"encoding/json"
"net/http"
"net/http/httptest"
"os"
"path"
"testing"
"text/template"

"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/cmd/api-server/options"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/cc"
)

// SysOpt is the system option
var SysOpt *options.Option

var configFileTmpl = `
esb:
appCode: {{ .AppCode }}
appSecret: {{ .AppSecret }}
bkNotice:
enable: true
host: {{ .BKNoticeHost }}
repository:
# storageType: S3
storageType: BKREPO
bkRepo:
endpoints:
- http://example.bktencent.com
project: bscp
username: example
password: example
s3:
endpoint: ""
accessKeyID: ""
secretAccessKey: ""
useSSL: true
bucketName: bscp-example
`

type MockHttpClient struct {
DoFunc func(req *http.Request) (*http.Response, error)
}

func (m *MockHttpClient) Do(req *http.Request) (*http.Response, error) {
return m.DoFunc(req)
}

func TestGetCurrentAnnouncements(t *testing.T) {

tempDir := os.TempDir()
SysOpt.Sys.ConfigFiles = []string{path.Join(tempDir, "cc.yaml")}
file, err := os.OpenFile(path.Join(tempDir, "cc.yaml"), os.O_RDWR|os.O_CREATE, 0755)
if err != nil {
t.Errorf("open file failed, err: %s", err.Error())
}
defer file.Close()
tpl, err := template.New("cc.yaml").Parse(configFileTmpl)
if err != nil {
t.Errorf("parse template failed, err: %s", err.Error())
}
if e := tpl.Execute(file, map[string]string{
"AppCode": os.Getenv("APP_CODE"),
"AppSecret": os.Getenv("APP_SECRET"),
"BKNoticeHost": os.Getenv("BK_NOTICE_HOST"),
}); e != nil {
t.Errorf("execute template failed, err: %s", e.Error())
}

if e := cc.LoadSettings(SysOpt.Sys); e != nil {
t.Errorf("load settings from config files failed, err: %s", e.Error())
}

service, err := newBKNoticeService()
if err != nil {
t.Errorf("newBKNoticeService failed: %v", err)
}

recorder := httptest.NewRecorder()
// Mock 一个http请求
request, _ := http.NewRequest("GET", "/", nil)

// 调用API
service.GetCurrentAnnouncements(recorder, request)

// 检查状态码
if status := recorder.Code; status != http.StatusOK {
t.Errorf("handler returned wrong status code: got %v want %v", status, http.StatusOK)
}

// 检查响应体
type expectedResp struct {
Result bool `json:"result"`
Code int `json:"code"`
Data interface{} `json:"data"`
}
expected := &expectedResp{}
if err := json.Unmarshal(recorder.Body.Bytes(), expected); err != nil {
t.Errorf("handler returned response failed: %v", err)
}

if expected.Code != 0 {
t.Errorf("handler returned response failed, code: %v", expected.Code)
}

if !expected.Result {
t.Errorf("handler returned response failed, result: %v", expected.Result)
}
}

func init() {

SysOpt = options.InitOptions()

cc.InitService(cc.APIServerName)
}
1 change: 1 addition & 0 deletions bcs-services/bcs-bscp/cmd/vault-server/vault/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.20

// alias github.com/hashicorp/vault release commit
replace (
github.com/hashicorp/vault => github.com/ifooth/vault v0.0.0-20240122073913-369f84ba6ea4
github.com/hashicorp/vault/api => github.com/hashicorp/vault/api v1.9.3-0.20230721171514-bf23fe8636b0
github.com/hashicorp/vault/api/auth/approle => github.com/hashicorp/vault/api/auth/approle v0.4.2-0.20230721171514-bf23fe8636b0
github.com/hashicorp/vault/api/auth/kubernetes => github.com/hashicorp/vault/api/auth/kubernetes v0.4.2-0.20230721171514-bf23fe8636b0
Expand Down
4 changes: 2 additions & 2 deletions bcs-services/bcs-bscp/cmd/vault-server/vault/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1846,8 +1846,6 @@ github.com/hashicorp/raft-snapshot v1.0.4/go.mod h1:5sL9eUn72lH5DzsFIJ9jaysITbHk
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
github.com/hashicorp/serf v0.10.1 h1:Z1H2J60yRKvfDYAOZLd2MU0ND4AH/WDz7xYHDWQsIPY=
github.com/hashicorp/serf v0.10.1/go.mod h1:yL2t6BqATOLGc5HF7qbFkTfXoPIY0WZdWHfEvMqbG+4=
github.com/hashicorp/vault v1.14.1 h1:JBRe4N6g6iu3yWenhlMn9PwSNAQYIQQ6PTYnbccvyxM=
github.com/hashicorp/vault v1.14.1/go.mod h1:VH1j4CD8lYPQ+XjmgpAF7gt0M2swsARFHndbDyDRgkU=
github.com/hashicorp/vault-plugin-auth-alicloud v0.15.0 h1:R2SVwOeVLG5DXzUx42UWhjfFqS0Z9+ncfebPu+gO9VA=
github.com/hashicorp/vault-plugin-auth-alicloud v0.15.0/go.mod h1:YQXpa2s4rGYKm3Oa/Nkgh5SuGVfHFNEIUwDDYWyhloE=
github.com/hashicorp/vault-plugin-auth-azure v0.15.1 h1:CknW0l2O70326KfepWeDuPszuNherhAtVNaSLRBsS4U=
Expand Down Expand Up @@ -1925,6 +1923,8 @@ github.com/huandu/xstrings v1.4.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ifooth/vault v0.0.0-20240122073913-369f84ba6ea4 h1:pYiY9fDylGGhyqDQ4KdAXvXXrWfP6kbGkJDnpg6CsSE=
github.com/ifooth/vault v0.0.0-20240122073913-369f84ba6ea4/go.mod h1:VH1j4CD8lYPQ+XjmgpAF7gt0M2swsARFHndbDyDRgkU=
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
Expand Down
1 change: 1 addition & 0 deletions bcs-services/bcs-bscp/pkg/cc/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type ApiServerSetting struct {
Log LogOption `yaml:"log"`
Repo Repository `yaml:"repository"`
BKNotice BKNotice `yaml:"bkNotice"`
Esb Esb `yaml:"esb"`
FeatureFlags map[FeatureFlag]FeatureFlagOption `yaml:"featureFlags"`
}

Expand Down
3 changes: 1 addition & 2 deletions bcs-services/bcs-bscp/pkg/components/bknotice/bknotice.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (

"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/cc"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/components"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/config"
)

type registerSystemResp struct {
Expand All @@ -34,7 +33,7 @@ func RegisterSystem(ctx context.Context) error {
url := fmt.Sprintf("%s/v1/register/", cc.ApiServer().BKNotice.Host)

authHeader := fmt.Sprintf("{\"bk_app_code\": \"%s\", \"bk_app_secret\": \"%s\"}",
config.G.Base.AppCode, config.G.Base.AppSecret)
cc.ApiServer().Esb.AppCode, cc.ApiServer().Esb.AppSecret)

resp, err := components.GetClient().R().
SetContext(ctx).
Expand Down
94 changes: 94 additions & 0 deletions bcs-services/bcs-bscp/pkg/dal/vault/vault_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Tencent is pleased to support the open source community by making Blueking Container Service available.
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/

package vault

import (
"os"
"testing"

"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/cc"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/kit"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/types"
)

func initClient(t testing.TB) Set {
vaultToken := os.Getenv("VAULT_TOKEN")
vaultAddr := os.Getenv("VAULT_ADDR")
if vaultAddr == "" || vaultToken == "" {
t.Skipf("VAULT_ADDR or VAULT_TOKEN env is missing")
}

s, err := NewSet(cc.Vault{
Address: vaultAddr,
Token: vaultToken,
})
if err != nil {
t.Fatalf("new set err: %s", err)
}

return s
}

func TestGetKv(t *testing.T) {
s := initClient(t)
kt := kit.New()

opt := &types.GetLastKvOpt{
BizID: 2,
AppID: 1,
Key: "conf",
}

_, _, err := s.GetLastKv(kt, opt)
if err != nil {
t.Fatalf("GetLastKv err: %s", err)
}
}

func BenchmarkGetKv(b *testing.B) {
s := initClient(b)
kt := kit.New()

opt := &types.GetLastKvOpt{
BizID: 2,
AppID: 1,
Key: "conf",
}

for i := 0; i < b.N; i++ {
_, _, err := s.GetLastKv(kt, opt)
if err != nil {
b.Fatalf("GetLastKv err: %s", err)
}
}
}

func BenchmarkParallelGetKv(b *testing.B) {
s := initClient(b)
kt := kit.New()

opt := &types.GetLastKvOpt{
BizID: 2,
AppID: 1,
Key: "conf",
}

b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
_, _, err := s.GetLastKv(kt, opt)
if err != nil {
b.Fatalf("GetLastKv err: %s", err)
}
}
})
}
Binary file modified bcs-services/bcs-bscp/ui/src/assets/fonts/iconcool.eot
Binary file not shown.
6 changes: 6 additions & 0 deletions bcs-services/bcs-bscp/ui/src/assets/fonts/iconcool.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bcs-services/bcs-bscp/ui/src/assets/fonts/iconcool.ttf
Binary file not shown.
Binary file modified bcs-services/bcs-bscp/ui/src/assets/fonts/iconcool.woff
Binary file not shown.
4 changes: 4 additions & 0 deletions bcs-services/bcs-bscp/ui/src/css/common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@
.bk-textarea.is-focused:not(.is-readonly),
.bk-select.is-focus .bk-select-trigger .bk-input--default {
border-color: #3a84ff;
}

.info-box-style .bk-modal-content {
min-height: auto !important;
}
Loading

0 comments on commit eb7206d

Please sign in to comment.