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
pull/1533/head
倒霉狐狸 3 years ago committed by GitHub
parent 23a96a3d63
commit 0597883e70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      contrib/config/kubernetes/config_test.go
  2. 40
      contrib/config/kubernetes/example.go
  3. 14
      contrib/config/kubernetes/watcher_test.go
  4. 2
      hack/.lintcheck_failures

@ -1,9 +1,11 @@
package kubernetes package kubernetes
import ( import (
"log"
"path/filepath" "path/filepath"
"testing" "testing"
"github.com/go-kratos/kratos/v2/config"
"k8s.io/client-go/util/homedir" "k8s.io/client-go/util/homedir"
) )
@ -22,3 +24,19 @@ func TestSource(t *testing.T) {
t.Log(v) 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 ( import (
"context" "context"
"path/filepath"
"testing"
"time"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/homedir" "k8s.io/client-go/util/homedir"
"path/filepath"
"testing"
"time"
) )
func TestKube(t *testing.T) { 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{ cmWatcher, err := client.CoreV1().ConfigMaps("mesh").Watch(context.Background(), metav1.ListOptions{
LabelSelector: "app=test", LabelSelector: "app=test",
//FieldSelector: "", // FieldSelector: "",
}) })
if err != nil { if err != nil {
t.Error(err) t.Error(err)
@ -32,13 +33,10 @@ func TestKube(t *testing.T) {
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
cmWatcher.Stop() cmWatcher.Stop()
}() }()
for { for c := range cmWatcher.ResultChan() {
select {
case c := <-cmWatcher.ResultChan():
if c.Object == nil { if c.Object == nil {
return return
} }
t.Log(c.Type, c.Object) t.Log(c.Type, c.Object)
} }
}
} }

@ -1,5 +1,3 @@
./contrib/config/apollo
./contrib/config/kubernetes
./contrib/registry/nacos ./contrib/registry/nacos
./contrib/registry/consul ./contrib/registry/consul
./contrib/registry/kubernetes ./contrib/registry/kubernetes

Loading…
Cancel
Save