-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AKS cloud support for asyncdr #2737
Open
gejain
wants to merge
9
commits into
master
Choose a base branch
from
akstest
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
46fb50e
AKS support for asyncdr
gejain 6a03049
Merge branch 'master' into akstest
gejain 1d37edd
Merge branch 'master' into akstest
gejain d8c4222
Merge branch 'master' into akstest
gejain 715d1ad
Updated for Asyncdr eks support
gejain 9d9bbc3
Merge branch 'master' into akstest
gejain 293dd09
Merge branch 'master' into akstest
gejain 54dba2b
Merge branch 'master' into akstest
gejain 2201fd8
Merge branch 'master' into akstest
gejain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,11 +10,15 @@ import ( | |
"time" | ||
|
||
crdv1 "github.com/kubernetes-incubator/external-storage/snapshot/pkg/apis/crd/v1" | ||
oputils "github.com/libopenstorage/operator/drivers/storage/portworx/util" | ||
opcorev1 "github.com/libopenstorage/operator/pkg/apis/core/v1" | ||
storkdriver "github.com/libopenstorage/stork/drivers/volume" | ||
storkapi "github.com/libopenstorage/stork/pkg/apis/stork/v1alpha1" | ||
"github.com/libopenstorage/stork/pkg/k8sutils" | ||
"github.com/portworx/sched-ops/k8s/apiextensions" | ||
"github.com/portworx/sched-ops/k8s/apps" | ||
"github.com/portworx/sched-ops/k8s/core" | ||
"github.com/portworx/sched-ops/k8s/operator" | ||
"github.com/portworx/sched-ops/k8s/storage" | ||
storkops "github.com/portworx/sched-ops/k8s/stork" | ||
"github.com/portworx/sched-ops/task" | ||
|
@@ -58,9 +62,9 @@ const ( | |
tempDir = "/tmp" | ||
portworxProvisioner = "kubernetes.io/portworx-volume" | ||
DefaultScName = "async-sc" | ||
FirstCluster = 0 | ||
SecondCluster = 1 | ||
ThirdCluster = 2 | ||
FirstCluster = 0 | ||
SecondCluster = 1 | ||
ThirdCluster = 2 | ||
) | ||
|
||
var ( | ||
|
@@ -287,7 +291,7 @@ func CreateSnapshotSchedule( | |
pvcName string, | ||
scheduleName string, | ||
policyName string, | ||
snapshotType string,) (*storkapi.VolumeSnapshotSchedule, error) { | ||
snapshotType string) (*storkapi.VolumeSnapshotSchedule, error) { | ||
|
||
snapSched := &storkapi.VolumeSnapshotSchedule{ | ||
ObjectMeta: meta_v1.ObjectMeta{ | ||
|
@@ -320,7 +324,7 @@ func CreateSchedulePolicyWithRetain(policyName string, interval int, retain stor | |
Policy: storkapi.SchedulePolicyItem{ | ||
Interval: &storkapi.IntervalPolicy{ | ||
IntervalMinutes: interval, | ||
Retain: retain, | ||
Retain: retain, | ||
}, | ||
}} | ||
schedPolicy, err = storkops.Instance().CreateSchedulePolicy(schedPolicy) | ||
|
@@ -338,12 +342,12 @@ func ValidateSnapshotScheduleCount(pvcs []string, schedNs, schedPol, snapshotTyp | |
return fmt.Errorf("Error creating snapshot schedule: %v", err) | ||
} | ||
log.InfoD("SnapSchedule is %v", snapSchedule) | ||
time.Sleep(30*time.Second) | ||
time.Sleep(30 * time.Second) | ||
err = WaitForRetainSnapshotsSuccessful(scheduleName, schedNs, int(retain), snapInterval) | ||
if err != nil { | ||
return fmt.Errorf("Error waiting for retain snapshots: %v", err) | ||
} | ||
time.Sleep(30*time.Second) | ||
time.Sleep(30 * time.Second) | ||
schedule, err := storkops.Instance().GetSnapshotSchedule(scheduleName, schedNs) | ||
if err != nil { | ||
return fmt.Errorf("Failed to get snapshot schedule") | ||
|
@@ -358,39 +362,39 @@ func ValidateSnapshotScheduleCount(pvcs []string, schedNs, schedPol, snapshotTyp | |
|
||
// WaitForRetainSnapshotsSuccessful waits for a certain number of snapshots to complete. | ||
func WaitForRetainSnapshotsSuccessful(snapSchedName string, schedNs string, retain int, snapInterval int) error { | ||
for i := 0; i < retain + 1; i++ { | ||
checkSuccessfulSnapshots := func() (interface{}, bool, error) { | ||
snapSchedule, err := storkops.Instance().GetSnapshotSchedule(snapSchedName, schedNs) | ||
if err != nil { | ||
return nil, true, fmt.Errorf("failed to get snapshot schedule: %v", snapSchedName) | ||
} | ||
for i := 0; i < retain+1; i++ { | ||
checkSuccessfulSnapshots := func() (interface{}, bool, error) { | ||
snapSchedule, err := storkops.Instance().GetSnapshotSchedule(snapSchedName, schedNs) | ||
if err != nil { | ||
return nil, true, fmt.Errorf("failed to get snapshot schedule: %v", snapSchedName) | ||
} | ||
currentIndex := i | ||
if currentIndex >= len(snapSchedule.Status.Items["Interval"]) { | ||
currentIndex = len(snapSchedule.Status.Items["Interval"]) - 1 | ||
} | ||
if snapSchedule.Status.Items["Interval"][currentIndex].Status != crdv1.VolumeSnapshotConditionReady { | ||
return nil, true, fmt.Errorf("snapshot %v failed with status: %v", snapSchedule.Status.Items["Interval"][currentIndex].Name, snapSchedule.Status.Items["Interval"][currentIndex].Status) | ||
} | ||
return nil, false, nil | ||
} | ||
|
||
snapStartTime := time.Now() | ||
_, err := task.DoRetryWithTimeout(checkSuccessfulSnapshots, time.Minute*time.Duration(snapInterval*2), time.Second*10) | ||
if err != nil { | ||
return err | ||
} | ||
snapEndTime := time.Now() | ||
snapTimeTaken := snapEndTime.Sub(snapStartTime) | ||
snapIntervalMins := time.Minute * time.Duration(snapInterval) | ||
if currentIndex >= len(snapSchedule.Status.Items["Interval"]) { | ||
currentIndex = len(snapSchedule.Status.Items["Interval"]) - 1 | ||
} | ||
if snapSchedule.Status.Items["Interval"][currentIndex].Status != crdv1.VolumeSnapshotConditionReady { | ||
return nil, true, fmt.Errorf("snapshot %v failed with status: %v", snapSchedule.Status.Items["Interval"][currentIndex].Name, snapSchedule.Status.Items["Interval"][currentIndex].Status) | ||
} | ||
return nil, false, nil | ||
} | ||
|
||
snapStartTime := time.Now() | ||
_, err := task.DoRetryWithTimeout(checkSuccessfulSnapshots, time.Minute*time.Duration(snapInterval*2), time.Second*10) | ||
if err != nil { | ||
return err | ||
} | ||
snapEndTime := time.Now() | ||
snapTimeTaken := snapEndTime.Sub(snapStartTime) | ||
snapIntervalMins := time.Minute * time.Duration(snapInterval) | ||
|
||
if i == retain { | ||
break | ||
} | ||
|
||
log.Infof("Waiting for next snapshot interval to start. Time pending to start next snap trigger: %v", snapIntervalMins-snapTimeTaken) | ||
time.Sleep(snapIntervalMins - snapTimeTaken + 10*time.Second) | ||
} | ||
return nil | ||
log.Infof("Waiting for next snapshot interval to start. Time pending to start next snap trigger: %v", snapIntervalMins-snapTimeTaken) | ||
time.Sleep(snapIntervalMins - snapTimeTaken + 10*time.Second) | ||
} | ||
return nil | ||
} | ||
|
||
func CreateSchedulePolicy(policyName string, interval int) (pol *storkapi.SchedulePolicy, err error) { | ||
|
@@ -756,3 +760,96 @@ func CheckDefaultPxStorageClass(name string) error { | |
} | ||
return nil | ||
} | ||
|
||
func ChangePxServiceToLoadBalancer(internalLB bool, storageDriverName string, pxStc *opcorev1.StorageCluster) error { | ||
// Check if service is already of type loadbalancer | ||
const ( | ||
pxStcServiceTypeKey = "portworx.io/service-type" | ||
stcLoadBalancerValue = "portworx-service:LoadBalancer" | ||
pxStcServiceKey = "service/portworx-service" | ||
awsInternalLBKey = "service.beta.kubernetes.io/aws-load-balancer-internal" | ||
awsInternalLBValue = "true" | ||
awsLBTypeKey = "service.beta.kubernetes.io/aws-load-balancer-type" | ||
awsLBTypeVal = "nlb" | ||
awsNLBTargetTypeKey = "service.beta.kubernetes.io/aws-load-balancer-nlb-target-type" | ||
awsNLBTargetTypeVal = "ip" | ||
awsLBSubnetKey = "service.beta.kubernetes.io/aws-load-balancer-subnets" | ||
pxServiceName = "portworx-service" | ||
pxNamespace = "kube-system" | ||
) | ||
|
||
pxService, err := core.Instance().GetService(pxServiceName, pxNamespace) | ||
if err != nil { | ||
return fmt.Errorf("failed to get portworx service before changing it to load balancer: %v", err) | ||
} | ||
log.Infof("Current Service Type is %s, pxService.Spec.Type") | ||
if pxService.Spec.Type == v1.ServiceTypeLoadBalancer { | ||
log.InfoD("portworx service is already of type LoadBalancer") | ||
return nil | ||
} | ||
|
||
if storageDriverName == storkdriver.PortworxDriverName { | ||
if pxStc != nil { | ||
// Change portworx service to LoadBalancer, since this is an EKS/AKS/GKE with PX operator install for Portworx | ||
if pxStc.ObjectMeta.Annotations == nil { | ||
pxStc.ObjectMeta.Annotations = make(map[string]string) | ||
} | ||
pxStc.ObjectMeta.Annotations[pxStcServiceTypeKey] = stcLoadBalancerValue | ||
|
||
if internalLB { | ||
if os.Getenv("LB_SUBNET_KEY") == "" { | ||
return fmt.Errorf("We need subnet for setting up Internal LB, Please set LB_SUBNET_KEY") | ||
} | ||
// Add LoadBalancer annotations specific to EKS ELB | ||
if pxStc.Spec.Metadata == nil { | ||
pxStc.Spec.Metadata = &opcorev1.Metadata{} | ||
pxStc.Spec.Metadata.Annotations = make(map[string]map[string]string) | ||
pxStc.Spec.Metadata.Annotations[pxStcServiceKey] = make(map[string]string) | ||
} | ||
if pxStc.Spec.Metadata.Annotations == nil { | ||
pxStc.Spec.Metadata.Annotations = make(map[string]map[string]string) | ||
} | ||
pxStc.Spec.Metadata.Annotations[pxStcServiceKey] = make(map[string]string) | ||
pxStc.Spec.Metadata.Annotations[pxStcServiceKey][awsInternalLBKey] = awsInternalLBValue | ||
pxStc.Spec.Metadata.Annotations[pxStcServiceKey][awsLBTypeKey] = awsLBTypeVal | ||
pxStc.Spec.Metadata.Annotations[pxStcServiceKey][awsNLBTargetTypeKey] = awsNLBTargetTypeVal | ||
pxStc.Spec.Metadata.Annotations[pxStcServiceKey][awsLBSubnetKey] = os.Getenv("LB_SUBNET_KEY") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about we add a check to see if |
||
} | ||
_, err = operator.Instance().UpdateStorageCluster(pxStc) | ||
|
||
if err != nil { | ||
return fmt.Errorf("failed to update PX service type to LoadBalancer on EKS: %v", err) | ||
} | ||
|
||
} else { | ||
return fmt.Errorf("No storage clusters found") | ||
} | ||
|
||
time.Sleep(1 * time.Minute) | ||
|
||
// Check if service has been changed to type loadbalancer | ||
pxService, err := core.Instance().GetService(pxServiceName, pxNamespace) | ||
if err != nil { | ||
return fmt.Errorf("failed to get portworx service after changing it to load balancer: %v", err) | ||
} | ||
if pxService.Spec.Type != v1.ServiceTypeLoadBalancer { | ||
return fmt.Errorf("failed to set portworx service to type %s", v1.ServiceTypeLoadBalancer) | ||
} | ||
|
||
} | ||
return nil | ||
} | ||
|
||
func IsCloud(stc *opcorev1.StorageCluster) (bool, string) { | ||
if oputils.IsEKS(stc) { | ||
log.InfoD("EKS installation detected.") | ||
return true, "eks" | ||
} else if oputils.IsAKS(stc) { | ||
log.InfoD("AKS installation detected.") | ||
return true, "aks" | ||
} else if oputils.IsGKE(stc) { | ||
log.InfoD("GKE installation detected.") | ||
return true, "gke" | ||
} | ||
return false, "" | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this cli used for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its needed for EKS cluster switch from torepedo. We need to access source and destination.
Without this we get below error -
failed to switch to context. RefreshNodeRegistry Error