fixed namespace restricted validation (#235)

This commit is contained in:
RoyUP9
2021-08-19 11:33:48 +03:00
committed by GitHub
parent a34c2fc0dc
commit 667f0dc87d
3 changed files with 8 additions and 16 deletions

View File

@@ -33,10 +33,6 @@ Supported protocols are HTTP and gRPC.`,
return errors.New("unexpected number of arguments")
}
if err := config.Config.Validate(); err != nil {
return errormessage.FormatError(err)
}
if err := config.Config.Tap.Validate(); err != nil {
return errormessage.FormatError(err)
}

View File

@@ -72,6 +72,14 @@ func RunMizuTap() {
targetNamespaces := getNamespaces(kubernetesProvider)
if config.Config.IsNsRestrictedMode() {
if len(targetNamespaces) != 1 || !mizu.Contains(targetNamespaces, config.Config.MizuResourcesNamespace) {
logger.Log.Errorf("Not supported mode. Mizu can't resolve IPs in other namespaces when running in namespace restricted mode.\n"+
"You can use the same namespace for --%s and --%s", configStructs.NamespacesTapName, config.MizuResourcesNamespaceConfigName)
return
}
}
var namespacesStr string
if !mizu.Contains(targetNamespaces, mizu.K8sAllNamespaces) {
namespacesStr = fmt.Sprintf("namespaces \"%s\"", strings.Join(targetNamespaces, "\", \""))

View File

@@ -3,7 +3,6 @@ package config
import (
"errors"
"fmt"
"github.com/up9inc/mizu/cli/config/configStructs"
"github.com/up9inc/mizu/cli/logger"
"github.com/up9inc/mizu/cli/mizu"
"io/ioutil"
@@ -32,17 +31,6 @@ var (
cmdName string
)
func (config *ConfigStruct) Validate() error {
if config.IsNsRestrictedMode() {
if config.Tap.AllNamespaces || len(config.Tap.Namespaces) != 1 || config.Tap.Namespaces[0] != config.MizuResourcesNamespace {
return fmt.Errorf("Not supported mode. Mizu can't resolve IPs in other namespaces when running in namespace restricted mode.\n"+
"You can use the same namespace for --%s and --%s", configStructs.NamespacesTapName, MizuResourcesNamespaceConfigName)
}
}
return nil
}
func InitConfig(cmd *cobra.Command) error {
cmdName = cmd.Name()