Let ks-apiserver optionally support authentication enabled and es without authentication enabled

Signed-off-by: Daniel Hu <farmer.hutao@outlook.com>
This commit is contained in:
Daniel Hu
2021-03-30 03:33:49 +00:00
parent 066dfe7066
commit 3798959eef
11 changed files with 112 additions and 24 deletions

View File

@@ -33,9 +33,19 @@ type Elastic struct {
index string
}
func New(address string, index string) (*Elastic, error) {
client, err := elasticsearch.NewClient(elasticsearch.Config{
func New(address string, basicAuth bool, username, password, index string) (*Elastic, error) {
var client *elasticsearch.Client
var err error
if !basicAuth {
username = ""
password = ""
}
client, err = elasticsearch.NewClient(elasticsearch.Config{
Addresses: []string{address},
Username: username,
Password: password,
})
return &Elastic{client: client, index: index}, err