diff --git a/go.mod b/go.mod index a01d2b70..0d126a4f 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index f93640f2..9547e2bc 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/pkg/controller/v1alpha2/applicationconfiguration/component.go b/pkg/controller/v1alpha2/applicationconfiguration/component.go index 5f080156..922e4b6e 100644 --- a/pkg/controller/v1alpha2/applicationconfiguration/component.go +++ b/pkg/controller/v1alpha2/applicationconfiguration/component.go @@ -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" @@ -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, @@ -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 -v, 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 diff --git a/pkg/controller/v1alpha2/applicationconfiguration/component_test.go b/pkg/controller/v1alpha2/applicationconfiguration/component_test.go index 20338f4f..e393c963 100644 --- a/pkg/controller/v1alpha2/applicationconfiguration/component_test.go +++ b/pkg/controller/v1alpha2/applicationconfiguration/component_test.go @@ -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) + } + }) } }