mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
Add a flag to specify the index name
This commit is contained in:
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -69,6 +70,10 @@ func Usage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
indexNamePtr := flag.String(
|
||||||
|
"index", "kustomize", "The name of the ElasticSearch index.")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
githubToken := os.Getenv(githubAccessTokenVar)
|
githubToken := os.Getenv(githubAccessTokenVar)
|
||||||
if githubToken == "" {
|
if githubToken == "" {
|
||||||
fmt.Printf("Must set the variable '%s' to make github requests.\n",
|
fmt.Printf("Must set the variable '%s' to make github requests.\n",
|
||||||
@@ -77,7 +82,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
idx, err := index.NewKustomizeIndex(ctx)
|
idx, err := index.NewKustomizeIndex(ctx, *indexNamePtr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Could not create an index: %v\n", err)
|
fmt.Printf("Could not create an index: %v\n", err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -97,14 +98,14 @@ type KustomizeIndex struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create index reference to the index containing the kustomize documents.
|
// Create index reference to the index containing the kustomize documents.
|
||||||
func NewKustomizeIndex(ctx context.Context) (*KustomizeIndex, error) {
|
func NewKustomizeIndex(ctx context.Context, indexName string) (*KustomizeIndex, error) {
|
||||||
idx, err := newIndex(ctx, "kustomize")
|
idx, err := newIndex(ctx, indexName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
indicesExistsOp := idx.client.Indices.Exists
|
indicesExistsOp := idx.client.Indices.Exists
|
||||||
resp, err := indicesExistsOp([]string{"kustomize"},
|
resp, err := indicesExistsOp([]string{indexName},
|
||||||
indicesExistsOp.WithContext(idx.ctx),
|
indicesExistsOp.WithContext(idx.ctx),
|
||||||
indicesExistsOp.WithPretty())
|
indicesExistsOp.WithPretty())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -112,9 +113,9 @@ func NewKustomizeIndex(ctx context.Context) (*KustomizeIndex, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if resp.StatusCode == 200 {
|
if resp.StatusCode == 200 {
|
||||||
fmt.Printf("The kustomize index already exists\n")
|
log.Printf("The %s index already exists", indexName)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Creating the kustomize index\n")
|
log.Printf("Creating the %s index\n", indexName)
|
||||||
if err := idx.CreateIndex([]byte(IndexConfig)); err != nil {
|
if err := idx.CreateIndex([]byte(IndexConfig)); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user