Skip to content
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

test: add v1beta1 E2E test cases (2/) #558

Merged
merged 7 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 81 additions & 40 deletions test/e2e/actuals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func validateConfigMapOnCluster(cluster *framework.Cluster, name types.Namespace
ignoreObjectMetaAutoGeneratedFields,
ignoreObjectMetaAnnotationField,
); diff != "" {
return fmt.Errorf("app deployment diff (-got, +want): %s", diff)
return fmt.Errorf("app config map diff (-got, +want): %s", diff)
}

return nil
Expand All @@ -82,6 +82,26 @@ func workNamespaceAndConfigMapPlacedOnClusterActual(cluster *framework.Cluster)
}
}

func crpRolloutFailedConditions(generation int64) []metav1.Condition {
return []metav1.Condition{
{
Type: string(placementv1beta1.ClusterResourcePlacementScheduledConditionType),
Status: metav1.ConditionFalse,
ObservedGeneration: generation,
},
{
Type: string(placementv1beta1.ClusterResourcePlacementSynchronizedConditionType),
Status: metav1.ConditionTrue,
ObservedGeneration: generation,
},
{
Type: string(placementv1beta1.ClusterResourcePlacementAppliedConditionType),
Status: metav1.ConditionTrue,
ObservedGeneration: generation,
},
}
}

func crpRolloutCompletedConditions(generation int64) []metav1.Condition {
return []metav1.Condition{
{
Expand Down Expand Up @@ -128,58 +148,79 @@ func resourcePlacementRolloutCompletedConditions(generation int64) []metav1.Cond
}
}

func validateCRPStatus(name types.NamespacedName, wantSelectedResources []placementv1beta1.ResourceIdentifier) error {
crp := &placementv1beta1.ClusterResourcePlacement{}
if err := hubClient.Get(ctx, name, crp); err != nil {
return err
}

wantCRPConditions := crpRolloutCompletedConditions(crp.Generation)
wantPlacementStatus := []placementv1beta1.ResourcePlacementStatus{
func resourcePlacementRolloutFailedConditions(generation int64) []metav1.Condition {
return []metav1.Condition{
{
ClusterName: memberCluster1Name,
Conditions: resourcePlacementRolloutCompletedConditions(crp.Generation),
Type: string(placementv1beta1.ResourceScheduledConditionType),
Status: metav1.ConditionFalse,
ObservedGeneration: generation,
},
}
}

func workResourceIdentifiers() []placementv1beta1.ResourceIdentifier {
workNamespaceName := fmt.Sprintf(workNamespaceNameTemplate, GinkgoParallelProcess())
appConfigMapName := fmt.Sprintf(appConfigMapNameTemplate, GinkgoParallelProcess())

return []placementv1beta1.ResourceIdentifier{
{
ClusterName: memberCluster2Name,
Conditions: resourcePlacementRolloutCompletedConditions(crp.Generation),
Kind: "Namespace",
Name: workNamespaceName,
Version: "v1",
},
{
ClusterName: memberCluster3Name,
Conditions: resourcePlacementRolloutCompletedConditions(crp.Generation),
Kind: "ConfigMap",
Name: appConfigMapName,
Version: "v1",
Namespace: workNamespaceName,
},
}
wantStatus := placementv1beta1.ClusterResourcePlacementStatus{
Conditions: wantCRPConditions,
PlacementStatuses: wantPlacementStatus,
SelectedResources: wantSelectedResources,
}
if diff := cmp.Diff(crp.Status, wantStatus, crpStatusCmpOptions...); diff != "" {
return fmt.Errorf("CRP status diff (-got, +want): %s", diff)
}
return nil
}

func crpStatusUpdatedActual() func() error {
func crpStatusUpdatedActual(
wantSelectedResourceIdentifiers []placementv1beta1.ResourceIdentifier,
wantSelectedClusters, wantUnselectedClusters []string,
) func() error {
crpName := fmt.Sprintf(crpNameTemplate, GinkgoParallelProcess())
workNamespaceName := fmt.Sprintf(workNamespaceNameTemplate, GinkgoParallelProcess())
appConfigMapName := fmt.Sprintf(appConfigMapNameTemplate, GinkgoParallelProcess())

return func() error {
wantSelectedResources := []placementv1beta1.ResourceIdentifier{
{
Kind: "Namespace",
Name: workNamespaceName,
Version: "v1",
},
{
Kind: "ConfigMap",
Name: appConfigMapName,
Version: "v1",
Namespace: workNamespaceName,
},
crp := &placementv1beta1.ClusterResourcePlacement{}
if err := hubClient.Get(ctx, types.NamespacedName{Name: crpName}, crp); err != nil {
return err
}

wantPlacementStatus := []placementv1beta1.ResourcePlacementStatus{}
for _, name := range wantSelectedClusters {
wantPlacementStatus = append(wantPlacementStatus, placementv1beta1.ResourcePlacementStatus{
ClusterName: name,
Conditions: resourcePlacementRolloutCompletedConditions(crp.Generation),
})
}
for _, name := range wantUnselectedClusters {
wantPlacementStatus = append(wantPlacementStatus, placementv1beta1.ResourcePlacementStatus{
ClusterName: name,
Conditions: resourcePlacementRolloutFailedConditions(crp.Generation),
})
}
return validateCRPStatus(types.NamespacedName{Name: crpName}, wantSelectedResources)

wantCRPConditions := crpRolloutCompletedConditions(crp.Generation)
if len(wantUnselectedClusters) > 0 {
wantCRPConditions = crpRolloutFailedConditions(crp.Generation)
}

// Note that the CRP controller will only keep decisions regarding unselected clusters for a CRP if:
//
// * The CRP is of the PickN placement type and the required N count cannot be fulfilled; or
// * The CRP is of the PickFixed placement type and the list of target clusters speciified cannot be fulfilled.
wantStatus := placementv1beta1.ClusterResourcePlacementStatus{
Conditions: wantCRPConditions,
PlacementStatuses: wantPlacementStatus,
SelectedResources: wantSelectedResourceIdentifiers,
}
if diff := cmp.Diff(crp.Status, wantStatus, crpStatusCmpOptions...); diff != "" {
return fmt.Errorf("CRP status diff (-got, +want): %s", diff)
}
return nil
}
}

Expand Down
Loading
Loading