Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use k8s 1.29 client libs #75

Merged
merged 2 commits into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
runs-on: ubuntu-20.04
steps:

- name: Set up Go 1.20
- name: Set up Go 1.21
uses: actions/setup-go@v1
with:
go-version: '1.20'
go-version: '1.21'
id: go

- uses: actions/checkout@v2
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ REPO := $(notdir $(shell pwd))
BIN := db-client-go

# https://github.com/appscodelabs/gengo-builder
CODE_GENERATOR_IMAGE ?= ghcr.io/appscode/gengo:release-1.25
CODE_GENERATOR_IMAGE ?= ghcr.io/appscode/gengo:release-1.29

# This version-strategy uses git tags to set the version string
git_branch := $(shell git rev-parse --abbrev-ref HEAD)
Expand Down Expand Up @@ -55,10 +55,10 @@ BIN_PLATFORMS := $(DOCKER_PLATFORMS)
OS := $(if $(GOOS),$(GOOS),$(shell go env GOOS))
ARCH := $(if $(GOARCH),$(GOARCH),$(shell go env GOARCH))

BASEIMAGE_PROD ?= gcr.io/distroless/static-debian11
BASEIMAGE_DBG ?= debian:bullseye
BASEIMAGE_PROD ?= gcr.io/distroless/static-debian12
BASEIMAGE_DBG ?= debian:bookworm

GO_VERSION ?= 1.20
GO_VERSION ?= 1.21
BUILD_IMAGE ?= ghcr.io/appscode/golang-dev:$(GO_VERSION)

OUTBIN = bin/$(OS)_$(ARCH)/$(BIN)
Expand Down Expand Up @@ -177,7 +177,7 @@ test: $(BUILD_DIRS)
./hack/test.sh $(SRC_PKGS) \
"

ADDTL_LINTERS := goconst,gofmt,goimports,unparam
ADDTL_LINTERS := gofmt,goimports,unparam

.PHONY: lint
lint: $(BUILD_DIRS)
Expand Down
8 changes: 4 additions & 4 deletions elasticsearch/es_client_v6.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ func (es *ESClientV6) GetClusterWriteStatus(ctx context.Context, db *api.Elastic
return errors.Wrap(err3, "Failed to perform write request")
}
if res.IsError() {
return errors.New(fmt.Sprintf("Failed to get response from write request with error statuscode %d", res.StatusCode))
return fmt.Errorf("failed to get response from write request with error statuscode %d", res.StatusCode)
}

defer func(res *esapi.Response) {
if res != nil {
err3 = res.Body.Close()
if err3 != nil {
klog.Errorf("Failed to close write request response body", err3)
klog.Errorf("Failed to close write request response body, reason: %s", err3)
}
}
}(res)
Expand Down Expand Up @@ -194,7 +194,7 @@ func (es *ESClientV6) GetClusterReadStatus(ctx context.Context, db *api.Elastics
if res != nil {
err = res.Body.Close()
if err != nil {
klog.Errorf("failed to close read request response body", err)
klog.Errorf("failed to close read request response body, reason: %s", err)
}
}
}(res)
Expand All @@ -203,7 +203,7 @@ func (es *ESClientV6) GetClusterReadStatus(ctx context.Context, db *api.Elastics
return kutil.ErrNotFound
}
if res.IsError() {
return errors.New(fmt.Sprintf("Failed to get response from write request with error statuscode %d", res.StatusCode))
return fmt.Errorf("failed to get response from write request with error statuscode %d", res.StatusCode)
}

return nil
Expand Down
60 changes: 30 additions & 30 deletions elasticsearch/es_client_v7.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,14 @@ func (es *ESClientV7) SyncCredentialFromSecret(secret *core.Secret) error {

res, err := req.Do(context.Background(), es.client.Transport)
if err != nil {
klog.Errorf("failed to send change password request for", username)
klog.Errorf("failed to send change password request, reason: %s", username)
return err
}

defer func(Body io.ReadCloser) {
err = Body.Close()
if err != nil {
klog.Errorf("failed to close auth response body", err)
klog.Errorf("failed to close auth response body, reason: %s", err)
}
}(res.Body)

Expand Down Expand Up @@ -210,14 +210,14 @@ func (es *ESClientV7) GetClusterWriteStatus(ctx context.Context, db *api.Elastic
return errors.Wrap(err3, "Failed to perform write request")
}
if res.IsError() {
return errors.New(fmt.Sprintf("Failed to get response from write request with error statuscode %d", res.StatusCode))
return fmt.Errorf("failed to get response from write request with error statuscode %d", res.StatusCode)
}

defer func(res *esapi.Response) {
if res != nil {
err3 = res.Body.Close()
if err3 != nil {
klog.Errorf("Failed to close write request response body", err3)
klog.Errorf("Failed to close write request response body, reason: %s", err3)
}
}
}(res)
Expand Down Expand Up @@ -256,7 +256,7 @@ func (es *ESClientV7) GetClusterReadStatus(ctx context.Context, db *api.Elastics
if res != nil {
err = res.Body.Close()
if err != nil {
klog.Errorf("failed to close read request response body", err)
klog.Errorf("failed to close read request response body, reason: %s", err)
}
}
}(res)
Expand All @@ -265,7 +265,7 @@ func (es *ESClientV7) GetClusterReadStatus(ctx context.Context, db *api.Elastics
return kutil.ErrNotFound
}
if res.IsError() {
return errors.New(fmt.Sprintf("Failed to get response from write request with error statuscode %d", res.StatusCode))
return fmt.Errorf("failed to get response from write request with error statuscode %d", res.StatusCode)
}

return nil
Expand All @@ -290,7 +290,7 @@ func (es *ESClientV7) GetTotalDiskUsage(ctx context.Context) (string, error) {
defer func(Body io.ReadCloser) {
err = Body.Close()
if err != nil {
klog.Errorf("failed to close response body from Disk Usage Request", err)
klog.Errorf("failed to close response body from Disk Usage Request, reason: %s", err)
}
}(res.Body)

Expand All @@ -311,17 +311,17 @@ func (es *ESClientV7) GetDBUserRole(ctx context.Context) (error, bool) {
defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {
klog.Errorf("failed to close response body from GetDBUserRole", err)
klog.Errorf("failed to close response body from GetDBUserRole, reason: %s", err)
}
}(res.Body)

if err != nil {
klog.Errorf("failed to get existing DB user role", err)
klog.Errorf("failed to get existing DB user role, reason: %s", err)
return err, false
}
if res.IsError() {
err = errors.New(fmt.Sprintf("fetching DB user role failed with error status code %d", res.StatusCode))
klog.Errorf("Failed to fetch DB user role", err)
err = fmt.Errorf("fetching DB user role failed with error status code %d", res.StatusCode)
klog.Errorf("Failed to fetch DB user role, reason: %s", err)
return nil, false
}

Expand Down Expand Up @@ -353,7 +353,7 @@ func (es *ESClientV7) CreateDBUserRole(ctx context.Context) error {

userRoleReqJSON, err := json.Marshal(userRoleReqStruct)
if err != nil {
klog.Errorf("Failed to parse rollRequest body to JSOn", err)
klog.Errorf("Failed to parse rollRequest body to json, reason: %s", err)
return err
}
body := bytes.NewReader(userRoleReqJSON)
Expand All @@ -366,17 +366,17 @@ func (es *ESClientV7) CreateDBUserRole(ctx context.Context) error {
defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {
klog.Errorf("failed to close response body from EnsureDBUserRole function", err)
klog.Errorf("failed to close response body from EnsureDBUserRole function, reason: %s", err)
}
}(res.Body)
if err != nil {
klog.Errorf("Failed to perform request to create DB user role", err)
klog.Errorf("Failed to perform request to create DB user role, reason: %s", err)
return err
}

if res.IsError() {
err = errors.New(fmt.Sprintf("DB user role creation failed with error status code %d", res.StatusCode))
klog.Errorf("Failed to create DB user role", err)
err = fmt.Errorf("DB user role creation failed with error status code %d", res.StatusCode)
klog.Errorf("Failed to create DB user role, reason: %s", err)
return err
}
return nil
Expand All @@ -388,18 +388,18 @@ func (es *ESClientV7) IndexExistsOrNot(index string) error {
}
res, err := req.Do(context.Background(), es.client)
if err != nil {
klog.Errorf(fmt.Sprintf("failed to get response while checking either index exists or not %v", err))
klog.Errorf("failed to get response while checking either index exists or not %v", err)
return err
}
defer func(Body io.ReadCloser) {
err = Body.Close()
if err != nil {
klog.Errorf("failed to close response body for checking the existence of index", err)
klog.Errorf("failed to close response body for checking the existence of index, reason: %s", err)
}
}(res.Body)

if res.IsError() {
klog.Errorf(fmt.Sprintf("failed to get index with statuscode %d", res.StatusCode))
klog.Errorf("failed to get index with statuscode %d", res.StatusCode)
return errors.New("index does not exist")
}
return nil
Expand All @@ -414,18 +414,18 @@ func (es *ESClientV7) CreateIndex(index string) error {

res, err := req.Do(context.Background(), es.client)
if err != nil {
klog.Errorf("failed to apply create index request ", err)
klog.Errorf("failed to apply create index request, reason: %s", err)
return err
}
defer func(Body io.ReadCloser) {
err = Body.Close()
if err != nil {
klog.Errorf("failed to close response body for creating index", err)
klog.Errorf("failed to close response body for creating index, reason: %s", err)
}
}(res.Body)

if res.IsError() {
klog.Errorf(fmt.Sprintf("creating index failed with statuscode %d", res.StatusCode))
klog.Errorf("creating index failed with statuscode %d", res.StatusCode)
return errors.New("failed to create index")
}

Expand All @@ -439,18 +439,18 @@ func (es *ESClientV7) DeleteIndex(index string) error {

res, err := req.Do(context.Background(), es.client)
if err != nil {
klog.Errorf("failed to apply delete index request", err)
klog.Errorf("failed to apply delete index request, reason: %s", err)
return err
}
defer func(Body io.ReadCloser) {
err = Body.Close()
if err != nil {
klog.Errorf("failed to close response body for deleting index", err)
klog.Errorf("failed to close response body for deleting index, reason: %s", err)
}
}(res.Body)

if res.IsError() {
klog.Errorf(fmt.Sprintf("failed to delete index with status code %d", res.StatusCode))
klog.Errorf("failed to delete index with status code %d", res.StatusCode)
return errors.New("failed to delete index")
}

Expand All @@ -469,12 +469,12 @@ func (es *ESClientV7) CountData(index string) (int, error) {
defer func(Body io.ReadCloser) {
err = Body.Close()
if err != nil {
klog.Errorf("failed to close response body for counting data", err)
klog.Errorf("failed to close response body for counting data, reason: %s", err)
}
}(res.Body)

if res.IsError() {
klog.Errorf(fmt.Sprintf("failed to count number of documents in index with statuscode %d", res.StatusCode))
klog.Errorf("failed to count number of documents in index with statuscode %d", res.StatusCode)
return 0, errors.New("failed to count number of documents")
}

Expand Down Expand Up @@ -509,18 +509,18 @@ func (es *ESClientV7) PutData(index, id string, data map[string]interface{}) err

res, err := req.Do(context.Background(), es.client)
if err != nil {
klog.Errorf("failed to put data in the index", err)
klog.Errorf("failed to put data in the index, reason: %s", err)
return err
}
defer func(Body io.ReadCloser) {
err = Body.Close()
if err != nil {
klog.Errorf("failed to close response body for putting data in the index", err)
klog.Errorf("failed to close response body for putting data in the index, reason: %s", err)
}
}(res.Body)

if res.IsError() {
klog.Errorf(fmt.Sprintf("failed to put data in an index with statuscode %d", res.StatusCode))
klog.Errorf("failed to put data in an index with statuscode %d", res.StatusCode)
return errors.New("failed to put data in an index")
}
return nil
Expand Down
Loading
Loading