Repository: vmware-tanzu/tanzu-framework (language: go)

Issue:
Wrong Windows MD workers replicas on prod plan 
**Bug description**
Windows clusters using prod creates 3 MD for vSphere (one for each failure zone) and always set WORKER_MACHINE_COUNT in the first MD replicas instead of spreading them out.

**Affected product area (please put an X in all that apply)**

- ( ) APIs
- ( ) Addons
- ( ) CLI
- ( ) Docs
- ( ) IAM
- ( ) Installation
- (x) Plugin
- ( ) Security
- ( ) Test and Release
- ( ) User Experience
- ( ) Developer Experience

**Expected behavior**
To have the workers spread across MDs as Linux, the Cluster template is already fixed on 
https://github.com/vmware-tanzu/tanzu-framework/pull/3893

**Steps to reproduce the bug**

**Version** (include the SHA if the version is not obvious)

**Environment where the bug was observed (cloud, OS, etc)**

**Relevant Debug Output (Logs, manifests, etc)**



Discussion / hints:

Fix patch:
diff --git a/tkg/client/cluster.go b/tkg/client/cluster.go
index fd2bc3389e..aa4cb850e8 100644
--- a/tkg/client/cluster.go
+++ b/tkg/client/cluster.go
@@ -156,7 +156,7 @@ func (c *TkgClient) CreateCluster(options *CreateClusterOptions, waitForCluster
 			return false, err
 		}
 	} else {
-		bytes, err = c.getClusterConfigurationBytes(&options.ClusterConfigOptions, infraProviderName, isManagementCluster, options.IsWindowsWorkloadCluster)
+		bytes, err = c.getClusterConfigurationBytes(&options.ClusterConfigOptions, infraProviderName, isManagementCluster)
 		if err != nil {
 			return false, errors.Wrap(err, "unable to get cluster configuration")
 		}
@@ -199,7 +199,7 @@ func (c *TkgClient) CreateCluster(options *CreateClusterOptions, waitForCluster
 }
 
 // getClusterConfigurationBytes returns cluster configuration by taking into consideration of legacy vs clusterclass based cluster creation
-func (c *TkgClient) getClusterConfigurationBytes(options *ClusterConfigOptions, infraProviderName string, isManagementCluster, isWindowsWorkloadCluster bool) ([]byte, error) {
+func (c *TkgClient) getClusterConfigurationBytes(options *ClusterConfigOptions, infraProviderName string, isManagementCluster bool) ([]byte, error) {
 	deployClusterClassBasedCluster, err := c.ShouldDeployClusterClassBasedCluster(isManagementCluster)
 	if err != nil {
 		return nil, err
@@ -215,7 +215,7 @@ func (c *TkgClient) getClusterConfigurationBytes(options *ClusterConfigOptions,
 	}
 
 	// Get the cluster configuration yaml bytes
-	return c.getClusterConfiguration(options, isManagementCluster, infraProviderName, isWindowsWorkloadCluster)
+	return c.getClusterConfiguration(options, isManagementCluster, infraProviderName)
 }
 
 func getContentFromInputFile(fileName string) ([]byte, error) {
@@ -758,7 +758,7 @@ func (c *TkgClient) configureAndValidateProviderConfig(providerName string, opti
 		}
 	}
 
-	workerCounts, err := c.DistributeMachineDeploymentWorkers(*options.WorkerMachineCount, isProdPlan, false, providerName, false)
+	workerCounts, err := c.DistributeMachineDeploymentWorkers(*options.WorkerMachineCount, isProdPlan, false, providerName)
 	if err != nil {
 		return errors.Wrap(err, "failed to distribute machine deployments")
 	}
diff --git a/tkg/client/config.go b/tkg/client/config.go
index 6fac678b5f..ad998f9b48 100644
--- a/tkg/client/config.go
+++ b/tkg/client/config.go
@@ -43,7 +43,7 @@ func (c *TkgClient) GetClusterConfiguration(options *CreateClusterOptions) ([]by
 			if err := c.configureAndValidateConfiguration(options, nil, true); err != nil {
 				return nil, err
 			}
-			return c.getClusterConfiguration(&options.ClusterConfigOptions, false, provider, options.IsWindowsWorkloadCluster)
+			return c.getClusterConfiguration(&options.ClusterConfigOptions, false, provider)
 		}
 	}
 	currentRegion, err := c.GetCurrentRegionContext()
@@ -86,7 +86,7 @@ func (c *TkgClient) GetClusterConfiguration(options *CreateClusterOptions) ([]by
 		return nil, err
 	}
 
-	return c.getClusterConfigurationBytes(&options.ClusterConfigOptions, infraProviderName, false, options.IsWindowsWorkloadCluster)
+	return c.getClusterConfigurationBytes(&options.ClusterConfigOptions, infraProviderName, false)
 }
 
 func (c *TkgClient) configureAndValidateConfiguration(options *CreateClusterOptions, regionalClusterClient clusterclient.Client, skipValidation bool) error {
@@ -101,7 +101,7 @@ func (c *TkgClient) configureAndValidateConfiguration(options *CreateClusterOpti
 	return nil
 }
 
-func (c *TkgClient) getClusterConfiguration(options *ClusterConfigOptions, isManagementCluster bool, infraProvider string, isWindowsWorkloadCluster bool) ([]byte, error) {
+func (c *TkgClient) getClusterConfiguration(options *ClusterConfigOptions, isManagementCluster bool, infraProvider string) ([]byte, error) {
 	// Set CLUSTER_PLAN to viper configuration
 	c.SetPlan(options.ProviderRepositorySource.Flavor)
 
@@ -118,7 +118,7 @@ func (c *TkgClient) getClusterConfiguration(options *ClusterConfigOptions, isMan
 	SetClusterClass(c.TKGConfigReaderWriter())
 
 	// need to provide clusterctl the worker count for md0 and not the full worker-machine-count value.
-	workerCounts, err := c.DistributeMachineDeploymentWorkers(*options.WorkerMachineCount, options.ProviderRepositorySource.Flavor == constants.PlanProd, isManagementCluster, infraProviderName, isWindowsWorkloadCluster)
+	workerCounts, err := c.DistributeMachineDeploymentWorkers(*options.WorkerMachineCount, options.ProviderRepositorySource.Flavor == constants.PlanProd, isManagementCluster, infraProviderName)
 	if err != nil {
 		return nil, errors.Wrap(err, "failed to distribute machine deployments")
 	}
diff --git a/tkg/client/init.go b/tkg/client/init.go
index 48e4d02bd2..d5d8ad56f1 100644
--- a/tkg/client/init.go
+++ b/tkg/client/init.go
@@ -815,9 +815,9 @@ func (c *TkgClient) BuildRegionalClusterConfiguration(options *InitRegionOptions
 		dryRunMode, _ := c.readerwriterConfigClient.TKGConfigReaderWriter().Get(constants.ConfigVariableDryRunMode)
 		filter, _ := c.readerwriterConfigClient.TKGConfigReaderWriter().Get(constants.ConfigVariableFilterByAddonType)
 		if options.GenerateOnly && dryRunMode == "legacy" && filter != "" {
-			bytes, err = c.getClusterConfiguration(&clusterConfigOptions, true, clusterConfigOptions.ProviderRepositorySource.InfrastructureProvider, false)
+			bytes, err = c.getClusterConfiguration(&clusterConfigOptions, true, clusterConfigOptions.ProviderRepositorySource.InfrastructureProvider)
 		} else {
-			bytes, err = c.getClusterConfigurationBytes(&clusterConfigOptions, clusterConfigOptions.ProviderRepositorySource.InfrastructureProvider, true, false)
+			bytes, err = c.getClusterConfigurationBytes(&clusterConfigOptions, clusterConfigOptions.ProviderRepositorySource.InfrastructureProvider, true)
 		}
 		if err != nil {
 			return bytes, options.ClusterName, "", err
diff --git a/tkg/client/validate.go b/tkg/client/validate.go
index 955d3c5096..94bb330e3d 100644
--- a/tkg/client/validate.go
+++ b/tkg/client/validate.go
@@ -636,7 +636,7 @@ func (c *TkgClient) ConfigureAndValidateManagementClusterConfiguration(options *
 		return NewValidationError(ValidationErrorCode, err.Error())
 	}
 
-	workerCounts, err := c.DistributeMachineDeploymentWorkers(int64(workerMachineCount), isProdPlan, true, name, false)
+	workerCounts, err := c.DistributeMachineDeploymentWorkers(int64(workerMachineCount), isProdPlan, true, name)
 	if err != nil {
 		return NewValidationError(ValidationErrorCode, errors.Wrap(err, "failed to distribute machine deployments").Error())
 	}
@@ -1416,9 +1416,9 @@ func (c *TkgClient) ConfigureAndValidateCNIType(cniType string) error {
 }
 
 // DistributeMachineDeploymentWorkers distributes machine deployment for worker nodes
-func (c *TkgClient) DistributeMachineDeploymentWorkers(workerMachineCount int64, isProdConfig, isManagementCluster bool, infraProviderName string, isWindowsWorkloadCluster bool) ([]int, error) { // nolint:gocyclo
+func (c *TkgClient) DistributeMachineDeploymentWorkers(workerMachineCount int64, isProdConfig, isManagementCluster bool, infraProviderName string) ([]int, error) { // nolint:gocyclo
 	workerCounts := make([]int, 3)
-	if infraProviderName == DockerProviderName || isWindowsWorkloadCluster {
+	if infraProviderName == DockerProviderName {
 		workerCounts[0] = int(workerMachineCount)
 		return workerCounts, nil
 	}


Test patch:
diff --git a/tkg/client/client_suite_test.go b/tkg/client/client_suite_test.go
index 9b979c893d..2634b1db67 100644
--- a/tkg/client/client_suite_test.go
+++ b/tkg/client/client_suite_test.go
@@ -1487,7 +1487,7 @@ var _ = Describe("DistributeMachineDeploymentWorkers", func() {
 	JustBeforeEach(func() {
 		tkgClient, err = CreateTKGClient(tkgConfigPath, testingDir, defaultTKGBoMFileForTesting, 2*time.Second)
 		Expect(err).NotTo(HaveOccurred())
-		workerCounts, err = tkgClient.DistributeMachineDeploymentWorkers(workerMachineCount, isProdConfig, isManagementCluster, infraProviderName, false)
+		workerCounts, err = tkgClient.DistributeMachineDeploymentWorkers(workerMachineCount, isProdConfig, isManagementCluster, infraProviderName)
 	})
 
 	Context("when not aws and azure", func() {
@@ -1669,6 +1669,22 @@ var _ = Describe("DistributeMachineDeploymentWorkers", func() {
 		})
 	})
 
+	Context("when docker prod plan and is mgmt cluster", func() {
+		BeforeEach(func() {
+			workerMachineCount = 5
+			isProdConfig = true
+			isManagementCluster = true
+			infraProviderName = constants.InfrastructureProviderDocker
+			tkgConfigPath = configFile7
+		})
+		It("should have first worker count as total machine count ", func() {
+			Expect(err).To(Not(HaveOccurred()))
+			Expect(workerCounts[0]).To(Equal(5))
+			Expect(workerCounts[1]).To(Equal(0))
+			Expect(workerCounts[2]).To(Equal(0))
+		})
+	})
+
 	AfterEach(func() {
 		os.Remove(tmpTkgConfigPath)
 	})