Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

Commit

Permalink
use human readable revision name instead of hash
Browse files Browse the repository at this point in the history
Signed-off-by: 天元 <jianbo.sjb@alibaba-inc.com>
  • Loading branch information
wonderflow committed Sep 1, 2020
1 parent f5a727e commit 43c45b5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
10 changes: 4 additions & 6 deletions pkg/controller/v1alpha2/applicationconfiguration/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import (
"reflect"
"sort"
"strings"
"time"

"github.com/crossplane/crossplane-runtime/pkg/logging"
"github.com/rs/xid"
appsv1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -141,7 +139,7 @@ func (c *ComponentHandler) createControllerRevision(mt metav1.Object, obj runtim
return false
}
nextRevision := curRevision + 1
revisionName := ConstructRevisionName(mt.GetName())
revisionName := ConstructRevisionName(mt.GetName(), nextRevision)

curComp.Status.LatestRevision = &v1alpha2.Revision{
Name: revisionName,
Expand Down Expand Up @@ -260,9 +258,9 @@ func (c *ComponentHandler) cleanupControllerRevision(curComp *v1alpha2.Component
}

// ConstructRevisionName will generate revisionName from componentName
// hash suffix char set added to componentName is (0-9, a-v)
func ConstructRevisionName(componentName string) string {
return strings.Join([]string{componentName, xid.NewWithTime(time.Now()).String()}, "-")
// will be <componentName>-v<RevisionNumber>, for example: comp-v1
func ConstructRevisionName(componentName string, revision int64) string {
return strings.Join([]string{componentName, fmt.Sprintf("v%d", revision)}, "-")
}

// ExtractComponentName will extract componentName from revisionName
Expand Down
19 changes: 9 additions & 10 deletions pkg/controller/v1alpha2/applicationconfiguration/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,15 @@ func TestComponentHandler(t *testing.T) {

func TestConstructExtract(t *testing.T) {
tests := []string{"tam1", "test-comp", "xx", "tt-x-x-c"}
for _, componentName := range tests {
for i := 0; i < 30; i++ {
t.Run(fmt.Sprintf("tests %d for component[%s]", i, componentName), func(t *testing.T) {
revisionName := ConstructRevisionName(componentName)
got := ExtractComponentName(revisionName)
if got != componentName {
t.Errorf("want to get %s from %s but got %s", componentName, revisionName, got)
}
})
}
revisionNum := []int64{1, 5, 10, 100000}
for idx, componentName := range tests {
t.Run(fmt.Sprintf("tests %d for component[%s]", idx, componentName), func(t *testing.T) {
revisionName := ConstructRevisionName(componentName, revisionNum[idx])
got := ExtractComponentName(revisionName)
if got != componentName {
t.Errorf("want to get %s from %s but got %s", componentName, revisionName, got)
}
})
}
}

Expand Down

0 comments on commit 43c45b5

Please sign in to comment.