mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-06-25 07:45:01 +00:00
Update mizu install command (#811)
This commit is contained in:
parent
1c11523d9d
commit
bf2362d836
@ -1,10 +1,9 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/up9inc/mizu/cli/config"
|
|
||||||
"github.com/up9inc/mizu/cli/telemetry"
|
"github.com/up9inc/mizu/cli/telemetry"
|
||||||
|
"github.com/up9inc/mizu/shared/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
var installCmd = &cobra.Command{
|
var installCmd = &cobra.Command{
|
||||||
@ -12,13 +11,13 @@ var installCmd = &cobra.Command{
|
|||||||
Short: "Installs mizu components",
|
Short: "Installs mizu components",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
go telemetry.ReportRun("install", nil)
|
go telemetry.ReportRun("install", nil)
|
||||||
runMizuInstall()
|
logger.Log.Infof("This command has been deprecated, please use helm as described below.\n\n")
|
||||||
return nil
|
|
||||||
},
|
logger.Log.Infof("To install stable build of Mizu on your cluster using helm, run the following command:")
|
||||||
PreRunE: func(cmd *cobra.Command, args []string) error {
|
logger.Log.Infof(" helm install mizu https://static.up9.com/mizu/helm --namespace=mizu-ent --create-namespace\n\n")
|
||||||
if config.Config.IsNsRestrictedMode() {
|
|
||||||
return fmt.Errorf("install is not supported in restricted namespace mode")
|
logger.Log.Infof("To install development build of Mizu on your cluster using helm, run the following command:")
|
||||||
}
|
logger.Log.Infof(" helm install mizu https://static.up9.com/mizu/helm-develop --namespace=mizu-ent --create-namespace")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
@ -27,4 +26,3 @@ var installCmd = &cobra.Command{
|
|||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(installCmd)
|
rootCmd.AddCommand(installCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,82 +0,0 @@
|
|||||||
package cmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/creasty/defaults"
|
|
||||||
"github.com/up9inc/mizu/cli/config"
|
|
||||||
"github.com/up9inc/mizu/cli/errormessage"
|
|
||||||
"github.com/up9inc/mizu/cli/resources"
|
|
||||||
"github.com/up9inc/mizu/cli/uiUtils"
|
|
||||||
"github.com/up9inc/mizu/shared"
|
|
||||||
"github.com/up9inc/mizu/shared/logger"
|
|
||||||
k8serrors "k8s.io/apimachinery/pkg/api/errors"
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
)
|
|
||||||
|
|
||||||
func runMizuInstall() {
|
|
||||||
kubernetesProvider, err := getKubernetesProviderForCli()
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
|
||||||
defer cancel() // cancel will be called when this function exits
|
|
||||||
|
|
||||||
var serializedValidationRules string
|
|
||||||
var serializedContract string
|
|
||||||
|
|
||||||
var defaultMaxEntriesDBSizeBytes int64 = 200 * 1000 * 1000
|
|
||||||
|
|
||||||
defaultResources := shared.Resources{}
|
|
||||||
if err := defaults.Set(&defaultResources); err != nil {
|
|
||||||
logger.Log.Debug(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
mizuAgentConfig := getInstallMizuAgentConfig(defaultMaxEntriesDBSizeBytes, defaultResources)
|
|
||||||
serializedMizuConfig, err := getSerializedMizuAgentConfig(mizuAgentConfig)
|
|
||||||
if err != nil {
|
|
||||||
logger.Log.Errorf(uiUtils.Error, fmt.Sprintf("Error serializing mizu config: %v", errormessage.FormatError(err)))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = resources.CreateInstallMizuResources(ctx, kubernetesProvider, serializedValidationRules,
|
|
||||||
serializedContract, serializedMizuConfig, config.Config.IsNsRestrictedMode(),
|
|
||||||
config.Config.MizuResourcesNamespace, config.Config.AgentImage,
|
|
||||||
config.Config.KratosImage, config.Config.KetoImage,
|
|
||||||
nil, defaultMaxEntriesDBSizeBytes, defaultResources, config.Config.ImagePullPolicy(),
|
|
||||||
config.Config.LogLevel(), false); err != nil {
|
|
||||||
var statusError *k8serrors.StatusError
|
|
||||||
if errors.As(err, &statusError) && (statusError.ErrStatus.Reason == metav1.StatusReasonAlreadyExists) {
|
|
||||||
logger.Log.Info("Mizu is already running in this namespace, run `mizu clean` to remove the currently running Mizu instance")
|
|
||||||
} else {
|
|
||||||
defer resources.CleanUpMizuResources(ctx, cancel, kubernetesProvider, config.Config.IsNsRestrictedMode(), config.Config.MizuResourcesNamespace)
|
|
||||||
logger.Log.Errorf(uiUtils.Error, fmt.Sprintf("Error creating resources: %v", errormessage.FormatError(err)))
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.Log.Infof(uiUtils.Magenta, "Installation completed, run `mizu view` to connect to the mizu daemon instance")
|
|
||||||
}
|
|
||||||
|
|
||||||
func getInstallMizuAgentConfig(maxDBSizeBytes int64, tapperResources shared.Resources) *shared.MizuAgentConfig {
|
|
||||||
mizuAgentConfig := shared.MizuAgentConfig{
|
|
||||||
MaxDBSizeBytes: maxDBSizeBytes,
|
|
||||||
AgentImage: config.Config.AgentImage,
|
|
||||||
PullPolicy: config.Config.ImagePullPolicyStr,
|
|
||||||
LogLevel: config.Config.LogLevel(),
|
|
||||||
TapperResources: tapperResources,
|
|
||||||
MizuResourcesNamespace: config.Config.MizuResourcesNamespace,
|
|
||||||
AgentDatabasePath: shared.DataDirPath,
|
|
||||||
StandaloneMode: true,
|
|
||||||
ServiceMap: config.Config.ServiceMap,
|
|
||||||
OAS: config.Config.OAS,
|
|
||||||
Telemetry: config.Config.Telemetry,
|
|
||||||
Elastic: config.Config.Elastic,
|
|
||||||
}
|
|
||||||
|
|
||||||
return &mizuAgentConfig
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user