POST storage limit to Hub and better error handling

This commit is contained in:
M. Mert Yildiran
2023-02-06 07:58:43 +03:00
parent 43e9e90f7d
commit 5d15667a03
2 changed files with 15 additions and 8 deletions

View File

@@ -426,6 +426,9 @@ func postHubStarted(ctx context.Context, kubernetesProvider *kubernetes.Provider
log.Error().Err(err).Send() log.Error().Err(err).Send()
} }
// Storage Limit
connector.PostStorageLimitToHub(config.Config.Tap.StorageLimitBytes())
// Pod regex // Pod regex
connector.PostRegexToHub(config.Config.Tap.PodRegexStr, state.targetNamespaces) connector.PostRegexToHub(config.Config.Tap.PodRegexStr, state.targetNamespaces)

View File

@@ -8,7 +8,6 @@ import (
"net/url" "net/url"
"time" "time"
"github.com/kubeshark/kubeshark/config"
"github.com/kubeshark/kubeshark/config/configStructs" "github.com/kubeshark/kubeshark/config/configStructs"
"github.com/kubeshark/kubeshark/utils" "github.com/kubeshark/kubeshark/utils"
@@ -71,7 +70,8 @@ func (connector *Connector) PostWorkerPodToHub(pod *v1.Pod) {
} else { } else {
ok := false ok := false
for !ok { for !ok {
if _, err = utils.Post(postWorkerUrl, "application/json", bytes.NewBuffer(podMarshalled), connector.client); err != nil { var resp *http.Response
if resp, err = utils.Post(postWorkerUrl, "application/json", bytes.NewBuffer(podMarshalled), connector.client); err != nil || resp.StatusCode != http.StatusOK {
if _, ok := err.(*url.Error); ok { if _, ok := err.(*url.Error); ok {
break break
} }
@@ -79,7 +79,6 @@ func (connector *Connector) PostWorkerPodToHub(pod *v1.Pod) {
} else { } else {
ok = true ok = true
log.Debug().Interface("worker-pod", pod).Msg("Reported worker pod to Hub:") log.Debug().Interface("worker-pod", pod).Msg("Reported worker pod to Hub:")
connector.PostStorageLimitToHub(config.Config.Tap.StorageLimitBytes())
} }
time.Sleep(time.Second) time.Sleep(time.Second)
} }
@@ -101,7 +100,8 @@ func (connector *Connector) PostStorageLimitToHub(limit int64) {
} else { } else {
ok := false ok := false
for !ok { for !ok {
if _, err = utils.Post(postStorageLimitUrl, "application/json", bytes.NewBuffer(payloadMarshalled), connector.client); err != nil { var resp *http.Response
if resp, err = utils.Post(postStorageLimitUrl, "application/json", bytes.NewBuffer(payloadMarshalled), connector.client); err != nil || resp.StatusCode != http.StatusOK {
if _, ok := err.(*url.Error); ok { if _, ok := err.(*url.Error); ok {
break break
} }
@@ -133,7 +133,8 @@ func (connector *Connector) PostRegexToHub(regex string, namespaces []string) {
} else { } else {
ok := false ok := false
for !ok { for !ok {
if _, err = utils.Post(postRegexUrl, "application/json", bytes.NewBuffer(payloadMarshalled), connector.client); err != nil { var resp *http.Response
if resp, err = utils.Post(postRegexUrl, "application/json", bytes.NewBuffer(payloadMarshalled), connector.client); err != nil || resp.StatusCode != http.StatusOK {
if _, ok := err.(*url.Error); ok { if _, ok := err.(*url.Error); ok {
break break
} }
@@ -163,7 +164,8 @@ func (connector *Connector) PostLicense(license string) {
} else { } else {
ok := false ok := false
for !ok { for !ok {
if _, err = utils.Post(postLicenseUrl, "application/json", bytes.NewBuffer(payloadMarshalled), connector.client); err != nil { var resp *http.Response
if resp, err = utils.Post(postLicenseUrl, "application/json", bytes.NewBuffer(payloadMarshalled), connector.client); err != nil || resp.StatusCode != http.StatusOK {
if _, ok := err.(*url.Error); ok { if _, ok := err.(*url.Error); ok {
break break
} }
@@ -189,7 +191,8 @@ func (connector *Connector) PostConsts(consts map[string]interface{}) {
} else { } else {
ok := false ok := false
for !ok { for !ok {
if _, err = utils.Post(postConstsUrl, "application/json", bytes.NewBuffer(payloadMarshalled), connector.client); err != nil { var resp *http.Response
if resp, err = utils.Post(postConstsUrl, "application/json", bytes.NewBuffer(payloadMarshalled), connector.client); err != nil || resp.StatusCode != http.StatusOK {
if _, ok := err.(*url.Error); ok { if _, ok := err.(*url.Error); ok {
break break
} }
@@ -211,7 +214,8 @@ func (connector *Connector) PostScript(script *configStructs.Script) {
} else { } else {
ok := false ok := false
for !ok { for !ok {
if _, err = utils.Post(postScriptUrl, "application/json", bytes.NewBuffer(payloadMarshalled), connector.client); err != nil { var resp *http.Response
if resp, err = utils.Post(postScriptUrl, "application/json", bytes.NewBuffer(payloadMarshalled), connector.client); err != nil || resp.StatusCode != http.StatusOK {
if _, ok := err.(*url.Error); ok { if _, ok := err.(*url.Error); ok {
break break
} }