Skip to content

Commit

Permalink
Merge pull request #279 from kubescape/retry-storage
Browse files Browse the repository at this point in the history
wait for storage when creating a client (other strategy)
  • Loading branch information
matthyx authored Apr 30, 2024
2 parents c76e872 + 03deffa commit 0ac93c3
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions pkg/storage/v1/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package storage

import (
"context"
"crypto/tls"
"encoding/json"
"fmt"
"net/http"
"node-agent/pkg/storage"
"os"
"strconv"
Expand Down Expand Up @@ -67,21 +65,9 @@ func CreateStorage(namespace string) (*Storage, error) {
}

// wait for storage to be ready
// create a client to skip TLS verification
customTransport := http.DefaultTransport.(*http.Transport).Clone()
// #nosec G402
customTransport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
client := &http.Client{Transport: customTransport}
if err := backoff.RetryNotify(func() error {
// call storage readiness endpoint
response, err := client.Get("https://storage:443/readyz")
if err != nil {
return err
}
if response.StatusCode != http.StatusOK {
return fmt.Errorf("storage not ready yet")
}
return nil
_, err := clientset.SpdxV1beta1().ApplicationProfiles("default").List(context.Background(), metav1.ListOptions{})
return err
}, backoff.WithMaxRetries(backoff.NewConstantBackOff(5*time.Second), 60), func(err error, d time.Duration) {
logger.L().Info("waiting for storage to be ready", helpers.Error(err), helpers.String("retry in", d.String()))
}); err != nil {
Expand Down

0 comments on commit 0ac93c3

Please sign in to comment.