mirror of
https://github.com/go-kratos/kratos.git
synced 2025-03-17 21:07:54 +02:00
fix: contrib config kubernetes lint err (#1523)
* fix: contrib metrics datadog lint err * fix: contrib config nacos lint err * fix: contrib config kubernetes lint err * remove unwanted docs
This commit is contained in:
parent
23a96a3d63
commit
0597883e70
@ -1,9 +1,11 @@
|
||||
package kubernetes
|
||||
|
||||
import (
|
||||
"log"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/go-kratos/kratos/v2/config"
|
||||
"k8s.io/client-go/util/homedir"
|
||||
)
|
||||
|
||||
@ -22,3 +24,19 @@ func TestSource(t *testing.T) {
|
||||
t.Log(v)
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleNewSource() {
|
||||
conf := config.New(
|
||||
config.WithSource(
|
||||
NewSource(
|
||||
Namespace("mesh"),
|
||||
LabelSelector("app=test"),
|
||||
KubeConfig(filepath.Join(homedir.HomeDir(), ".kube", "config")),
|
||||
),
|
||||
),
|
||||
)
|
||||
err := conf.Load()
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
}
|
||||
|
@ -1,40 +0,0 @@
|
||||
package kubernetes
|
||||
|
||||
import (
|
||||
"log"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/go-kratos/kratos/v2/config"
|
||||
"k8s.io/client-go/util/homedir"
|
||||
)
|
||||
|
||||
// 部署在mesh namespace 下configmap
|
||||
const yamlData = `database:
|
||||
mysql:
|
||||
dsn: "root:Test@tcp(mysql.database.svc.cluster.local:3306)/test?timeout=1s&readTimeout=1s&writeTimeout=1s&parseTime=true&loc=Local&charset=utf8mb4,utf8"
|
||||
active: 20
|
||||
idle: 10
|
||||
idle_timeout: 3600
|
||||
redis:
|
||||
addr: "redis-master.redis.svc.cluster.local:6379"
|
||||
password: ""
|
||||
db: 4`
|
||||
|
||||
const yamlApp = `application:
|
||||
expire: 3600`
|
||||
|
||||
func main() {
|
||||
conf := config.New(
|
||||
config.WithSource(
|
||||
NewSource(
|
||||
Namespace("mesh"),
|
||||
LabelSelector("app=test"),
|
||||
KubeConfig(filepath.Join(homedir.HomeDir(), ".kube", "config")),
|
||||
),
|
||||
),
|
||||
)
|
||||
err := conf.Load()
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
}
|
@ -2,13 +2,14 @@ package kubernetes
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
"k8s.io/client-go/util/homedir"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestKube(t *testing.T) {
|
||||
@ -23,7 +24,7 @@ func TestKube(t *testing.T) {
|
||||
}
|
||||
cmWatcher, err := client.CoreV1().ConfigMaps("mesh").Watch(context.Background(), metav1.ListOptions{
|
||||
LabelSelector: "app=test",
|
||||
//FieldSelector: "",
|
||||
// FieldSelector: "",
|
||||
})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
@ -32,13 +33,10 @@ func TestKube(t *testing.T) {
|
||||
time.Sleep(5 * time.Second)
|
||||
cmWatcher.Stop()
|
||||
}()
|
||||
for {
|
||||
select {
|
||||
case c := <-cmWatcher.ResultChan():
|
||||
if c.Object == nil {
|
||||
return
|
||||
}
|
||||
t.Log(c.Type, c.Object)
|
||||
for c := range cmWatcher.ResultChan() {
|
||||
if c.Object == nil {
|
||||
return
|
||||
}
|
||||
t.Log(c.Type, c.Object)
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
./contrib/config/apollo
|
||||
./contrib/config/kubernetes
|
||||
./contrib/registry/nacos
|
||||
./contrib/registry/consul
|
||||
./contrib/registry/kubernetes
|
||||
|
Loading…
x
Reference in New Issue
Block a user