mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-09-28 13:55:47 +00:00
✨ In case of tap
re-run, update the config and start a proxy
This commit is contained in:
@@ -4,23 +4,65 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/kubeshark/kubeshark/config"
|
||||
"github.com/rs/zerolog/log"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
const (
|
||||
SUFFIX_SECRET = "secret"
|
||||
SUFFIX_SECRET = "secret"
|
||||
SUFFIX_CONFIG_MAP = "config-map"
|
||||
SECRET_LICENSE = "LICENSE"
|
||||
CONFIG_POD_REGEX = "POD_REGEX"
|
||||
CONFIG_NAMESPACES = "NAMESPACES"
|
||||
CONFIG_SCRIPTING_ENV = "SCRIPTING_ENV"
|
||||
CONFIG_AUTH_ENABLED = "AUTH_ENABLED"
|
||||
CONFIG_AUTH_APPROVED_EMAILS = "AUTH_APPROVED_EMAILS"
|
||||
CONFIG_AUTH_APPROVED_DOMAINS = "AUTH_APPROVED_DOMAINS"
|
||||
)
|
||||
|
||||
func SetSecret(provider *Provider, key string, value string) (err error) {
|
||||
func SetSecret(provider *Provider, key string, value string) (updated bool, err error) {
|
||||
var secret *v1.Secret
|
||||
secret, err = provider.clientSet.CoreV1().Secrets(config.Config.Tap.Release.Namespace).Get(context.TODO(), SelfResourcesPrefix+SUFFIX_SECRET, metav1.GetOptions{})
|
||||
secret, err = provider.clientSet.CoreV1().Secrets(config.Config.Tap.Release.Namespace).Get(context.TODO(), SELF_RESOURCES_PREFIX+SUFFIX_SECRET, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
secret.StringData[key] = value
|
||||
if secret.StringData[key] != value {
|
||||
updated = true
|
||||
}
|
||||
secret.Data[key] = []byte(value)
|
||||
|
||||
_, err = provider.clientSet.CoreV1().Secrets(config.Config.Tap.Release.Namespace).Update(context.TODO(), secret, metav1.UpdateOptions{})
|
||||
if err == nil {
|
||||
if updated {
|
||||
log.Info().Str("secret", key).Str("value", value).Msg("Updated:")
|
||||
}
|
||||
} else {
|
||||
log.Error().Str("secret", key).Err(err).Send()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func SetConfig(provider *Provider, key string, value string) (updated bool, err error) {
|
||||
var configMap *v1.ConfigMap
|
||||
configMap, err = provider.clientSet.CoreV1().ConfigMaps(config.Config.Tap.Release.Namespace).Get(context.TODO(), SELF_RESOURCES_PREFIX+SUFFIX_CONFIG_MAP, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if configMap.Data[key] != value {
|
||||
updated = true
|
||||
}
|
||||
configMap.Data[key] = value
|
||||
|
||||
_, err = provider.clientSet.CoreV1().ConfigMaps(config.Config.Tap.Release.Namespace).Update(context.TODO(), configMap, metav1.UpdateOptions{})
|
||||
if err == nil {
|
||||
if updated {
|
||||
log.Info().Str("config", key).Str("value", value).Msg("Updated:")
|
||||
}
|
||||
} else {
|
||||
log.Error().Str("config", key).Err(err).Send()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user