Skip to content

Commit

Permalink
fix UT
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Zhang committed Oct 12, 2023
1 parent dc20beb commit fa8e1b5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 14 additions & 3 deletions pkg/controllers/workgenerator/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import (
"context"
"errors"
"fmt"
"sort"
"strconv"
"strings"
"time"

"go.uber.org/atomic"
Expand Down Expand Up @@ -396,6 +398,7 @@ func (r *Reconciler) getConfigMapEnvelopWorkObj(ctx context.Context, workNamePre
klog.V(2).InfoS("Successfully extract the enveloped resources from the configMap", "numOfResources", len(manifest),
"snapshot", klog.KObj(resourceSnapshot), "resourceBinding", klog.KObj(resourceBinding), "configMapWrapper", klog.KObj(envelopeObj))
// Try to see if we already have a work represent the same enveloped object for this CRP in the same cluster
// The ParentResourceSnapshotIndexLabel can change between snapshots so we have to exclude that label in the match
envelopWorkLabelMatcher := client.MatchingLabels{
fleetv1beta1.ParentBindingLabel: resourceBinding.Name,
fleetv1beta1.CRPTrackingLabel: resourceBinding.Labels[fleetv1beta1.CRPTrackingLabel],
Expand Down Expand Up @@ -574,15 +577,23 @@ func extractResFromConfigMap(uConfigMap *unstructured.Unstructured) ([]fleetv1be
if err != nil {
return nil, err
}
// the list order is not stable as the map traverse is random
for _, value := range configMap.Data {
content, err := yaml.ToJSON([]byte(value))
if err != nil {
return nil, err
content, jsonErr := yaml.ToJSON([]byte(value))
if jsonErr != nil {
return nil, jsonErr
}
manifests = append(manifests, fleetv1beta1.Manifest{
RawExtension: runtime.RawExtension{Raw: content},
})
}
// stable sort the manifests so that we can have a deterministic order
sort.Slice(manifests, func(i, j int) bool {
obj1 := manifests[i].Raw
obj2 := manifests[j].Raw
// order by its json formatted string
return strings.Compare(string(obj1), string(obj2)) > 0
})
return manifests, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ var _ = Describe("Test Work Generator Controller", func() {
})
})

FContext("Test Bound ClusterResourceBinding with a single resource snapshot with envelop objects", func() {
Context("Test Bound ClusterResourceBinding with a single resource snapshot with envelop objects", func() {
var masterSnapshot *fleetv1beta1.ClusterResourceSnapshot

BeforeEach(func() {
Expand Down

0 comments on commit fa8e1b5

Please sign in to comment.