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

use human readable revision name instead of hash #191

Merged
merged 1 commit into from
Sep 2, 2020
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
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ require (
github.com/onsi/ginkgo v1.11.0
github.com/onsi/gomega v1.8.1
github.com/pkg/errors v0.9.1
github.com/rs/xid v1.2.1
github.com/stretchr/testify v1.4.0
go.uber.org/zap v1.10.0
golang.org/x/tools v0.0.0-20200630223951-c138986dd9b9 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,6 @@ github.com/prometheus/procfs v0.0.3 h1:CTwfnzjQ+8dS6MhHHu4YswVAD99sL2wjPqP+VkURm
github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ=
github.com/remyoudompheng/bigfft v0.0.0-20170806203942-52369c62f446/go.mod h1:uYEyJGbgTkfkS4+E/PavXkNJcbFIpEtjt2B0KDQ5+9M=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rs/xid v1.2.1 h1:mhH9Nq+C1fY2l1XIpgxIiUOfNpRBYH1kKcr+qfKgjRc=
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
Expand Down
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