Skip to content

Commit

Permalink
Updated for Asyncdr eks support
Browse files Browse the repository at this point in the history
  • Loading branch information
gejain committed Aug 20, 2024
1 parent d8c4222 commit 715d1ad
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 39 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ RUN apk add --no-cache openssh sshpass
# Install dependancy for OCP 4.14 CLI
RUN apk --update add gcompat

#Install aws-cli
RUN apk add aws-cli && aws --version

# Install yq
RUN wget https://github.com/mikefarah/yq/releases/download/v4.25.1/yq_linux_amd64 -O /usr/bin/yq && \
chmod +x /usr/bin/yq
Expand Down
2 changes: 1 addition & 1 deletion pkg/asyncdr/asyncdr.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ func ChangePxServiceToLoadBalancer(internalLB bool) error {
// Check if service is already of type loadbalancer
const (
pxStcServiceTypeKey = "portworx.io/service-type"
stcLoadBalancerValue = "LoadBalancer"
stcLoadBalancerValue = "portworx-service:LoadBalancer"
pxStcServiceKey = "service/portworx-service"
awsInternalLBKey = "service.beta.kubernetes.io/aws-load-balancer-internal"
awsInternalLBValue = "true"
Expand Down
62 changes: 25 additions & 37 deletions tests/basic/async_dr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ var _ = Describe("{MigrateDeploymentMetroAsync}", func() {
namespace := GetAppNamespace(ctx, taskName)
migrationNamespaces = append(migrationNamespaces, namespace)
log.Infof("Creating clusterpair between first and second cluster")
err = ScheduleBidirectionalClusterPair(defaultClusterPairName, namespace, "", "", "", "sync-dr", asyncdr.FirstCluster, asyncdr.SecondCluster)
err = ScheduleBidirectionalClusterPair(defaultClusterPairName, namespace, "", "", "", "sync-dr", asyncdr.FirstCluster, asyncdr.SecondCluster, nil)
log.FailOnError(err, "Failed creating bidirectional cluster pair")
}
}
Expand Down Expand Up @@ -268,7 +268,7 @@ var _ = Describe("{MigrateDeploymentMetroAsync}", func() {

for i, currMigNamespace := range migrationNamespaces {
log.Infof("Creating clusterpair between second and third cluster")
ScheduleBidirectionalClusterPair(defaultClusterPairNameNew, currMigNamespace, "", storkapi.BackupLocationType(defaultBackupLocation), defaultSecret, "async-dr", asyncdr.SecondCluster, asyncdr.ThirdCluster)
ScheduleBidirectionalClusterPair(defaultClusterPairNameNew, currMigNamespace, "", storkapi.BackupLocationType(defaultBackupLocation), defaultSecret, "async-dr", asyncdr.SecondCluster, asyncdr.ThirdCluster, nil)
migrationName := migrationKey + fmt.Sprintf("%d", i) + time.Now().Format("15h03m05s")
currMig, err := asyncdr.CreateMigration(migrationName, currMigNamespace, defaultClusterPairNameNew, currMigNamespace, &includeVolumesFlagAsync, &includeResourcesFlag, &startApplicationsFlag, nil)
Expect(err).NotTo(HaveOccurred(),
Expand Down Expand Up @@ -651,36 +651,6 @@ var _ = Describe("{StorkctlPerformFailoverFailbackeckEsClusterwide}", func() {
})
})

var _ = Describe("{ChangePXSvc}", func() {
// testrailID = 297921
// testrailID corresponds to: https://portworx.testrail.net/index.php?/cases/view/297921
BeforeEach(func() {
if !kubeConfigWritten {
// Write kubeconfig files after reading from the config maps created by torpedo deploy script
WriteKubeconfigToFiles()
kubeConfigWritten = true
}
wantAllAfterSuiteActions = false
})

// JustBeforeEach(func() {
// StartTorpedoTest("Change PX Svc", "Change PX Svc", nil, testrailID)
// runID = testrailuttils.AddRunsToMilestone(testrailID)
// })

It("Change PX service type", func() {
Step("Change PX service type", func() {
err := asyncdr.ChangePxServiceToLoadBalancer(false)
log.Infof("Error is: %v", err)
})
})

// JustAfterEach(func() {
// defer EndTorpedoTest()
// AfterEachTest(contexts, testrailID, runID)
// })
})

var _ = Describe("{UpgradeVolumeDriverDuringAppBkpRestore}", func() {
BeforeEach(func() {
if !kubeConfigWritten {
Expand Down Expand Up @@ -859,7 +829,7 @@ var _ = Describe("{UpgradeVolumeDriverDuringAsyncDrMigration}", func() {

Step("create clusterpair and start migration", func() {
log.InfoD("Creating clusterpair between first and second cluster")
err = ScheduleBidirectionalClusterPair(cpName, defaultNs, "", storkapi.BackupLocationType(defaultBackupLocation), defaultSecret, "async-dr", asyncdr.FirstCluster, asyncdr.SecondCluster)
err = ScheduleBidirectionalClusterPair(cpName, defaultNs, "", storkapi.BackupLocationType(defaultBackupLocation), defaultSecret, "async-dr", asyncdr.FirstCluster, asyncdr.SecondCluster, nil)
log.FailOnError(err, "Failed creating bidirectional cluster pair")

log.InfoD("Start migration schedule and perform failover")
Expand Down Expand Up @@ -1046,16 +1016,29 @@ func validateFailoverFailback(clusterType, taskNamePrefix string, single, skipSo
}

isCloud, cloudName := asyncdr.IsCloud()
var srcEp, destEp string
extraArgsCp := map[string]string{}
const defaultPort = "9001"

if isCloud {
if err = asyncdr.ChangePxServiceToLoadBalancer(false); err != nil {
log.FailOnError(err, "failed to change PX service to LoadBalancer on source cluster")
}
if cloudName == "eks" {
pxService, err := core.Instance().GetService("portworx-service", "kube-system")
log.FailOnError(err, "failed to get px service")
srcEp = pxService.Status.LoadBalancer.Ingress[0].Hostname
}
err = SetDestinationKubeConfig()
log.FailOnError(err, "Failed to set destination kubeconfig")
if err = asyncdr.ChangePxServiceToLoadBalancer(false); err != nil {
log.FailOnError(err, "failed to change PX service to LoadBalancer on destination cluster")
}
if cloudName == "eks" {
pxService, err := core.Instance().GetService("portworx-service", "kube-system")
log.FailOnError(err, "failed to get px service")
destEp = pxService.Status.LoadBalancer.Ingress[0].Hostname
}
err = SetSourceKubeConfig()
log.FailOnError(err, "Failed to set source kubeconfig")
}
Expand All @@ -1068,13 +1051,18 @@ func validateFailoverFailback(clusterType, taskNamePrefix string, single, skipSo
defaultBackupLocation = googleBackupLocation
}

if cloudName == "eks" {
extraArgsCp["src-ep"] = srcEp + ":" + defaultPort
extraArgsCp["dest-ep"] = destEp + ":" + defaultPort
}

log.Infof("Creating clusterpair between first and second cluster")
cpName := defaultClusterPairName + time.Now().Format("15h03m05s")

if clusterType == "asyncdr" {
err = ScheduleBidirectionalClusterPair(cpName, defaultNs, "", storkapi.BackupLocationType(defaultBackupLocation), defaultSecret, "async-dr", asyncdr.FirstCluster, asyncdr.SecondCluster)
err = ScheduleBidirectionalClusterPair(cpName, defaultNs, "", storkapi.BackupLocationType(defaultBackupLocation), defaultSecret, "async-dr", asyncdr.FirstCluster, asyncdr.SecondCluster, extraArgsCp)
} else {
err = ScheduleBidirectionalClusterPair(cpName, defaultNs, "", "", "", "sync-dr", asyncdr.FirstCluster, asyncdr.SecondCluster)
err = ScheduleBidirectionalClusterPair(cpName, defaultNs, "", "", "", "sync-dr", asyncdr.FirstCluster, asyncdr.SecondCluster, extraArgsCp)
}

log.FailOnError(err, "Failed creating bidirectional cluster pair")
Expand Down Expand Up @@ -1418,9 +1406,9 @@ func validateOperatorMigFailover(namespace, clusterType, opName, crName string,
kubeConfigPathDest, err := GetCustomClusterConfigPath(asyncdr.SecondCluster)
log.FailOnError(err, "Failed to get destination configPath: %v", err)
if clusterType == "asyncdr" {
err = ScheduleBidirectionalClusterPair(cpName, namespace, "", storkapi.BackupLocationType(defaultBackupLocation), defaultSecret, "async-dr", asyncdr.FirstCluster, asyncdr.SecondCluster)
err = ScheduleBidirectionalClusterPair(cpName, namespace, "", storkapi.BackupLocationType(defaultBackupLocation), defaultSecret, "async-dr", asyncdr.FirstCluster, asyncdr.SecondCluster, nil)
} else {
err = ScheduleBidirectionalClusterPair(cpName, namespace, "", "", "", "sync-dr", asyncdr.FirstCluster, asyncdr.SecondCluster)
err = ScheduleBidirectionalClusterPair(cpName, namespace, "", "", "", "sync-dr", asyncdr.FirstCluster, asyncdr.SecondCluster, nil)
}
log.FailOnError(err, "Failed creating bidirectional cluster pair")
log.Infof("Start migration schedule and perform failover")
Expand Down
9 changes: 8 additions & 1 deletion tests/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -4113,7 +4113,7 @@ func CreateClusterPairFile(pairInfo map[string]string, skipStorage, resetConfig
return addStorageOptions(pairInfo, clusterPairFileName)
}

func ScheduleBidirectionalClusterPair(cpName, cpNamespace, projectMappings string, objectStoreType storkv1.BackupLocationType, secretName string, mode string, sourceCluster int, destCluster int) (err error) {
func ScheduleBidirectionalClusterPair(cpName, cpNamespace, projectMappings string, objectStoreType storkv1.BackupLocationType, secretName string, mode string, sourceCluster int, destCluster int, extraArgs map[string]string) (err error) {
// var token string
// Setting kubeconfig to source because we will create bidirectional cluster pair based on source as reference
err = SetCustomKubeConfig(sourceCluster)
Expand Down Expand Up @@ -4196,6 +4196,13 @@ func ScheduleBidirectionalClusterPair(cpName, cpNamespace, projectMappings strin
}
}

if extraArgs != nil {
for key, value := range extraArgs {
cmdArgs = append(cmdArgs, "--"+key)
cmdArgs = append(cmdArgs, value)
}
}

if projectMappings != "" {
cmdArgs = append(cmdArgs, "--project-mappings")
cmdArgs = append(cmdArgs, projectMappings)
Expand Down

0 comments on commit 715d1ad

Please sign in to comment.