mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-06-27 00:29:31 +00:00
✨ Do POST /license
after Hub is started
This commit is contained in:
parent
4cb4ba568b
commit
17e038e703
@ -398,6 +398,10 @@ func postHubStarted(ctx context.Context, kubernetesProvider *kubernetes.Provider
|
|||||||
|
|
||||||
connector.PostRegexToHub(config.Config.Tap.PodRegexStr, state.targetNamespaces)
|
connector.PostRegexToHub(config.Config.Tap.PodRegexStr, state.targetNamespaces)
|
||||||
|
|
||||||
|
if config.Config.License != "" {
|
||||||
|
connector.PostLicense(config.Config.License)
|
||||||
|
}
|
||||||
|
|
||||||
url := kubernetes.GetLocalhostOnPort(config.Config.Tap.Proxy.Hub.SrcPort)
|
url := kubernetes.GetLocalhostOnPort(config.Config.Tap.Proxy.Hub.SrcPort)
|
||||||
log.Info().Str("url", url).Msg(fmt.Sprintf(utils.Green, "Hub is available at:"))
|
log.Info().Str("url", url).Msg(fmt.Sprintf(utils.Green, "Hub is available at:"))
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,7 @@ type ConfigStruct struct {
|
|||||||
DumpLogs bool `yaml:"dumplogs" default:"false"`
|
DumpLogs bool `yaml:"dumplogs" default:"false"`
|
||||||
ConfigFilePath string `yaml:"configpath,omitempty" readonly:""`
|
ConfigFilePath string `yaml:"configpath,omitempty" readonly:""`
|
||||||
HeadlessMode bool `yaml:"headless" default:"false"`
|
HeadlessMode bool `yaml:"headless" default:"false"`
|
||||||
|
License string `yaml:"license" default:""`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *ConfigStruct) SetDefaults() {
|
func (config *ConfigStruct) SetDefaults() {
|
||||||
|
@ -145,3 +145,33 @@ func (connector *Connector) PostRegexToHub(regex string, namespaces []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type postLicenseRequest struct {
|
||||||
|
License string `json:"license"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (connector *Connector) PostLicense(license string) {
|
||||||
|
postLicenseUrl := fmt.Sprintf("%s/license", connector.url)
|
||||||
|
|
||||||
|
payload := postLicenseRequest{
|
||||||
|
License: license,
|
||||||
|
}
|
||||||
|
|
||||||
|
if payloadMarshalled, err := json.Marshal(payload); err != nil {
|
||||||
|
log.Error().Err(err).Msg("Failed to marshal the payload:")
|
||||||
|
} else {
|
||||||
|
ok := false
|
||||||
|
for !ok {
|
||||||
|
if _, err = utils.Post(postLicenseUrl, "application/json", bytes.NewBuffer(payloadMarshalled), connector.client); err != nil {
|
||||||
|
if _, ok := err.(*url.Error); ok {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
log.Debug().Err(err).Msg("Failed sending the license to Hub:")
|
||||||
|
} else {
|
||||||
|
ok = true
|
||||||
|
log.Debug().Str("license", license).Msg("Reported license to Hub:")
|
||||||
|
}
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user