From 10a59619c7b3e05ba1588369694547d203b12166 Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Tue, 30 Apr 2024 14:14:45 +0530 Subject: [PATCH] MM-57997: Fix bypass-upload in HA mode (#26850) Now we throw an error if the server is in HA. This is because there is no guarantee that the server where the request lands has access to the file locally. https://mattermost.atlassian.net/browse/MM-57997 ```release-note NONE ``` --- server/cmd/mmctl/commands/import.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/server/cmd/mmctl/commands/import.go b/server/cmd/mmctl/commands/import.go index 554bba01e4..23907a6d9b 100644 --- a/server/cmd/mmctl/commands/import.go +++ b/server/cmd/mmctl/commands/import.go @@ -257,6 +257,21 @@ func importProcessCmdF(c client.Client, command *cobra.Command, args []string) e bypassUpload, _ := command.Flags().GetBool("bypass-upload") if bypassUpload { if isLocal { + // First, we validate whether the server is in HA. + config, _, err := c.GetOldClientConfig(context.TODO(), "") + if err != nil { + return err + } + + enableCluster, err := strconv.ParseBool(config["EnableCluster"]) + if err != nil { + return fmt.Errorf("failed to parse EnableCluster: %w", err) + } + + if enableCluster { + return errors.New("--bypass-upload flag doesn't work if the server is in HA. Because the file has to be present locally on the server where the job request hits. Please disable HA and try again.") + } + // in local mode, we tell the server to directly read from this file. if _, err := os.Stat(importFile); errors.Is(err, os.ErrNotExist) { return fmt.Errorf("file %s doesn't exist. NOTE: If this file was uploaded to the server via mmctl import upload, please omit the --bypass-upload flag to revert to old behavior.", importFile)