-
Notifications
You must be signed in to change notification settings - Fork 21
test: update stop update run integration test #387
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
Open
britaniar
wants to merge
2
commits into
kubefleet-dev:main
Choose a base branch
from
britaniar:stopUpdrateRunTest
base: main
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.
+227
−427
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 |
|---|---|---|
|
|
@@ -26,7 +26,6 @@ import ( | |
| "github.com/google/go-cmp/cmp" | ||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
| "github.com/prometheus/client_golang/prometheus" | ||
| prometheusclientmodel "github.com/prometheus/client_model/go" | ||
|
|
||
| corev1 "k8s.io/api/core/v1" | ||
|
|
@@ -363,24 +362,6 @@ func generateSucceededMetric(updateRun *placementv1beta1.ClusterStagedUpdateRun) | |
| } | ||
| } | ||
|
|
||
| func labelPairsToMap(pairs []*prometheusclientmodel.LabelPair) prometheus.Labels { | ||
| m := prometheus.Labels{} | ||
| for _, p := range pairs { | ||
| m[p.GetName()] = p.GetValue() | ||
| } | ||
| return m | ||
| } | ||
|
|
||
| func removeMetricFromMetricList(metricList []*prometheusclientmodel.Metric, metricToRemove *prometheusclientmodel.Metric) []*prometheusclientmodel.Metric { | ||
| var result []*prometheusclientmodel.Metric | ||
| for _, metric := range metricList { | ||
| if !cmp.Equal(labelPairsToMap(metric.Label), labelPairsToMap(metricToRemove.Label)) { | ||
| result = append(result, metric) | ||
| } | ||
| } | ||
| return result | ||
| } | ||
|
|
||
| func generateTestClusterStagedUpdateRun() *placementv1beta1.ClusterStagedUpdateRun { | ||
| return &placementv1beta1.ClusterStagedUpdateRun{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
|
|
@@ -480,25 +461,44 @@ func generateTestClusterResourceBindingsAndClusters(policySnapshotIndex int) ([] | |
| return resourceBindings, targetClusters, unscheduledClusters | ||
| } | ||
|
|
||
| func generateSmallTestClusterResourceBindingsAndClusters(policySnapshotIndex int) ([]*placementv1beta1.ClusterResourceBinding, []*clusterv1beta1.MemberCluster, []*clusterv1beta1.MemberCluster) { | ||
| func generateSmallTestClusterResourceBindingsAndClusters(policySnapshotIndex int, numUnscheduledClusters int) ([]*placementv1beta1.ClusterResourceBinding, []*clusterv1beta1.MemberCluster, []*clusterv1beta1.MemberCluster) { | ||
| numTargetClusters := 3 | ||
| policySnapshotName := fmt.Sprintf(placementv1beta1.PolicySnapshotNameFmt, testCRPName, policySnapshotIndex) | ||
| resourceBindings := make([]*placementv1beta1.ClusterResourceBinding, numTargetClusters) | ||
| resourceBindings := make([]*placementv1beta1.ClusterResourceBinding, numTargetClusters+numUnscheduledClusters) | ||
| targetClusters := make([]*clusterv1beta1.MemberCluster, numTargetClusters) | ||
| for i := range targetClusters { | ||
| // split the clusters into 2 regions | ||
| region := regionEastus | ||
| if i%2 == 0 { | ||
| region = regionWestus | ||
| } | ||
| // reserse the order of the clusters by index | ||
| // reverse the order of the clusters by index | ||
| targetClusters[i] = generateTestMemberCluster(numTargetClusters-1-i, "cluster-"+strconv.Itoa(i), map[string]string{"group": "prod", "region": region}) | ||
| resourceBindings[i] = generateTestClusterResourceBinding(policySnapshotName, targetClusters[i].Name, placementv1beta1.BindingStateScheduled) | ||
| } | ||
| unscheduledClusters := make([]*clusterv1beta1.MemberCluster, 0) | ||
|
|
||
| resourceBindings, unscheduledClusters := generateTestUnscheduledClusterResourceBindingsAndClusters(policySnapshotIndex, numUnscheduledClusters, resourceBindings) | ||
| return resourceBindings, targetClusters, unscheduledClusters | ||
| } | ||
|
|
||
| func generateTestUnscheduledClusterResourceBindingsAndClusters(policySnapshotIndex int, numUnscheduledClusters int, bindings []*placementv1beta1.ClusterResourceBinding) ([]*placementv1beta1.ClusterResourceBinding, []*clusterv1beta1.MemberCluster) { | ||
| policySnapshotName := fmt.Sprintf(placementv1beta1.PolicySnapshotNameFmt, testCRPName, policySnapshotIndex) | ||
| targetClusters := len(bindings) - numUnscheduledClusters | ||
| unscheduledClusters := make([]*clusterv1beta1.MemberCluster, numUnscheduledClusters) | ||
| // Half of the unscheduled clusters have old policy snapshot. | ||
| for i := range numUnscheduledClusters / 2 { | ||
| unscheduledClusters[i] = generateTestMemberCluster(i, "unscheduled-cluster-"+strconv.Itoa(i), map[string]string{"group": "staging"}) | ||
| // Update the policySnapshot name so that these clusters are considered to-be-deleted. | ||
| bindings[targetClusters+i] = generateTestClusterResourceBinding(policySnapshotName+"a", unscheduledClusters[i].Name, placementv1beta1.BindingStateUnscheduled) | ||
|
Collaborator
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. Can we come up with a better format specifier for policySnapshotName |
||
| } | ||
| // The other half of the unscheduled clusters have latest policy snapshot but still unscheduled. | ||
| for i := numUnscheduledClusters / 2; i < numUnscheduledClusters; i++ { | ||
| unscheduledClusters[i] = generateTestMemberCluster(i, "unscheduled-cluster-"+strconv.Itoa(i), map[string]string{"group": "staging"}) | ||
| bindings[targetClusters+i] = generateTestClusterResourceBinding(policySnapshotName, unscheduledClusters[i].Name, placementv1beta1.BindingStateUnscheduled) | ||
| } | ||
| return bindings, unscheduledClusters | ||
| } | ||
|
|
||
| func generateTestClusterResourceBinding(policySnapshotName, targetCluster string, state placementv1beta1.BindingState) *placementv1beta1.ClusterResourceBinding { | ||
| binding := &placementv1beta1.ClusterResourceBinding{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
|
|
||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
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.
We can pass policySnapshotName as the parameter instead of policySnapshotIndex