Skip to content

Commit

Permalink
test: add ut for revision manager
Browse files Browse the repository at this point in the history
  • Loading branch information
wu8685 committed Nov 16, 2023
1 parent f61b782 commit 2a3f45a
Show file tree
Hide file tree
Showing 3 changed files with 223 additions and 252 deletions.
10 changes: 0 additions & 10 deletions pkg/controllers/collaset/revision.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,6 @@ func (roa *revisionOwnerAdapter) GetPatch(obj metav1.Object) ([]byte, error) {
return getCollaSetPatch(cs)
}

func (roa *revisionOwnerAdapter) GetSelectorLabels(obj metav1.Object) map[string]string {
ips, _ := obj.(*appsalphav1.CollaSet)
labels := map[string]string{}
for k, v := range ips.Spec.Template.Labels {
labels[k] = v
}

return labels
}

func (roa *revisionOwnerAdapter) GetCurrentRevision(obj metav1.Object) string {
ips, _ := obj.(*appsalphav1.CollaSet)
return ips.Status.CurrentRevision
Expand Down
17 changes: 1 addition & 16 deletions pkg/controllers/utils/revision/revision_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ type OwnerAdapter interface {
GetCollisionCount(obj metav1.Object) *int32
GetHistoryLimit(obj metav1.Object) int32
GetPatch(obj metav1.Object) ([]byte, error)
GetSelectorLabels(obj metav1.Object) map[string]string
GetCurrentRevision(obj metav1.Object) string
IsInUsed(obj metav1.Object, controllerRevision string) bool
}
Expand Down Expand Up @@ -287,11 +286,7 @@ func (rm *RevisionManager) newRevision(set metav1.Object, revision int64, collis
return nil, err
}

revisionLabels := rm.ownerGetter.GetSelectorLabels(set)
if revisionLabels == nil {
revisionLabels = map[string]string{}
}

revisionLabels := map[string]string{}
if selector := rm.ownerGetter.GetSelector(set); selector != nil {
for k, v := range selector.MatchLabels {
revisionLabels[k] = v
Expand All @@ -309,16 +304,6 @@ func (rm *RevisionManager) newRevision(set metav1.Object, revision int64, collis
}

cr.Namespace = set.GetNamespace()
if cr.ObjectMeta.Annotations == nil {
cr.ObjectMeta.Annotations = make(map[string]string)
}
for key, value := range set.GetAnnotations() {
cr.ObjectMeta.Annotations[key] = value
}

if cr.ObjectMeta.Labels == nil {
cr.ObjectMeta.Labels = make(map[string]string)
}

return cr, nil
}
Expand Down
Loading

0 comments on commit 2a3f45a

Please sign in to comment.