From bfa5f4c64140cb9ea4fc236fd6ef878a7a4e346f Mon Sep 17 00:00:00 2001 From: Somefive Date: Tue, 11 Apr 2023 09:59:58 +0800 Subject: [PATCH] Feat: upgrade pkg & workflow (#5819) Signed-off-by: Somefive --- go.mod | 6 +++--- go.sum | 8 ++++---- pkg/resourcekeeper/cache.go | 6 +++--- pkg/workflow/providers/multicluster/deploy.go | 12 ++++++------ references/docgen/i18n_test.go | 15 ++++++--------- 5 files changed, 22 insertions(+), 25 deletions(-) diff --git a/go.mod b/go.mod index ebc6620aa..b5cb8b711 100644 --- a/go.mod +++ b/go.mod @@ -50,9 +50,9 @@ require ( github.com/hashicorp/hcl/v2 v2.16.2 github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174 github.com/imdario/mergo v0.3.13 - github.com/kubevela/pkg v1.8.1-0.20230403024929-46ddc1466157 + github.com/kubevela/pkg v1.8.1-0.20230410075324-9f0ba3b09495 github.com/kubevela/prism v1.7.0-alpha.1.0.20230403030519-b7e45f7f842e - github.com/kubevela/workflow v0.5.1-0.20230406080422-bd8faf72a9b0 + github.com/kubevela/workflow v0.5.1-0.20230410054920-9c36c21ea8fb github.com/kyokomi/emoji v2.2.4+incompatible github.com/mitchellh/hashstructure/v2 v2.0.2 github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect @@ -159,7 +159,7 @@ require ( github.com/cyphar/filepath-securejoin v0.2.3 // indirect github.com/docker/cli v20.10.20+incompatible // indirect github.com/docker/distribution v2.8.1+incompatible // indirect - github.com/docker/docker v20.10.20+incompatible // indirect + github.com/docker/docker v20.10.24+incompatible // indirect github.com/docker/docker-credential-helpers v0.7.0 // indirect github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-metrics v0.0.1 // indirect diff --git a/go.sum b/go.sum index 4e36c3391..3188122d7 100644 --- a/go.sum +++ b/go.sum @@ -949,12 +949,12 @@ github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/kubevela/pkg v1.8.1-0.20230403024929-46ddc1466157 h1:01SXHJZjS2CYlPY1HpcmIkFCNko59sttqC7u/PYFt7s= -github.com/kubevela/pkg v1.8.1-0.20230403024929-46ddc1466157/go.mod h1:A6f7lQwCOt0KRPnQz511QLB4JgzPpDXYUG7bY8LJkEE= +github.com/kubevela/pkg v1.8.1-0.20230410075324-9f0ba3b09495 h1:maT6E7JSrZgv4T1grgTBL69px7oUldc+tHIPxJ5SD9Y= +github.com/kubevela/pkg v1.8.1-0.20230410075324-9f0ba3b09495/go.mod h1:dGT23SGBw16frh5ReEYMFraxjppkX6jPCltBgTeLUhE= github.com/kubevela/prism v1.7.0-alpha.1.0.20230403030519-b7e45f7f842e h1:hc3ctkLfQVERra9IKDoAgMK4iMCY3XpXEJ0TfP9FhSQ= github.com/kubevela/prism v1.7.0-alpha.1.0.20230403030519-b7e45f7f842e/go.mod h1:bEPKTha7KhDhJAPXYBNAHTMRyqffDvf9UqWZV2BtQtI= -github.com/kubevela/workflow v0.5.1-0.20230406080422-bd8faf72a9b0 h1:P6MU4vFgmKIY6sTcfiaJBur0Fzr9n+g6KU853p0RRhg= -github.com/kubevela/workflow v0.5.1-0.20230406080422-bd8faf72a9b0/go.mod h1:Yb/EmokR1xV98+mVYc74InkABQqlkxdSpG0RyE5sxBs= +github.com/kubevela/workflow v0.5.1-0.20230410054920-9c36c21ea8fb h1:5/J8Aleqi+rdllhfvRRP40W2kdakpyYmPYnMcvbsK3Q= +github.com/kubevela/workflow v0.5.1-0.20230410054920-9c36c21ea8fb/go.mod h1:0GhIWFIPP+Zt31m4Aslx9mihoyNz3HrOvCV69ljMIBo= github.com/kylelemons/godebug v0.0.0-20160406211939-eadb3ce320cb/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= diff --git a/pkg/resourcekeeper/cache.go b/pkg/resourcekeeper/cache.go index 210c17ffa..3a2953482 100644 --- a/pkg/resourcekeeper/cache.go +++ b/pkg/resourcekeeper/cache.go @@ -19,7 +19,7 @@ package resourcekeeper import ( "context" - velasync "github.com/kubevela/pkg/util/sync" + pkgmaps "github.com/kubevela/pkg/util/maps" "github.com/pkg/errors" "k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -46,14 +46,14 @@ type resourceCacheEntry struct { type resourceCache struct { app *v1beta1.Application cli client.Client - m *velasync.Map[string, *resourceCacheEntry] + m *pkgmaps.SyncMap[string, *resourceCacheEntry] } func newResourceCache(cli client.Client, app *v1beta1.Application) *resourceCache { return &resourceCache{ app: app, cli: cli, - m: velasync.NewMap[string, *resourceCacheEntry](), + m: pkgmaps.NewSyncMap[string, *resourceCacheEntry](), } } diff --git a/pkg/workflow/providers/multicluster/deploy.go b/pkg/workflow/providers/multicluster/deploy.go index 73393dcb0..1c576e349 100644 --- a/pkg/workflow/providers/multicluster/deploy.go +++ b/pkg/workflow/providers/multicluster/deploy.go @@ -22,8 +22,8 @@ import ( "strings" "sync" + pkgmaps "github.com/kubevela/pkg/util/maps" "github.com/kubevela/pkg/util/slices" - pkgsync "github.com/kubevela/pkg/util/sync" "github.com/kubevela/workflow/pkg/cue/model/value" "github.com/pkg/errors" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -196,7 +196,7 @@ func (t *applyTask) varKeyWithoutReplica(v string) string { return fmt.Sprintf("%s/%s/%s/%s", t.placement.Cluster, t.placement.Namespace, "", v) } -func (t *applyTask) getVar(from string, cache *pkgsync.Map[string, *value.Value]) *value.Value { +func (t *applyTask) getVar(from string, cache *pkgmaps.SyncMap[string, *value.Value]) *value.Value { key := t.varKey(from) keyWithNoReplica := t.varKeyWithoutReplica(from) var val *value.Value @@ -209,7 +209,7 @@ func (t *applyTask) getVar(from string, cache *pkgsync.Map[string, *value.Value] return val } -func (t *applyTask) fillInputs(inputs *pkgsync.Map[string, *value.Value], build valueBuilder) error { +func (t *applyTask) fillInputs(inputs *pkgmaps.SyncMap[string, *value.Value], build valueBuilder) error { if len(t.component.Inputs) == 0 { return nil } @@ -238,7 +238,7 @@ func (t *applyTask) fillInputs(inputs *pkgsync.Map[string, *value.Value], build return nil } -func (t *applyTask) generateOutput(output *unstructured.Unstructured, outputs []*unstructured.Unstructured, cache *pkgsync.Map[string, *value.Value], build valueBuilder) error { +func (t *applyTask) generateOutput(output *unstructured.Unstructured, outputs []*unstructured.Unstructured, cache *pkgmaps.SyncMap[string, *value.Value], build valueBuilder) error { if len(t.component.Outputs) == 0 { return nil } @@ -287,7 +287,7 @@ func (t *applyTask) allDependsReady(healthyMap map[string]bool) bool { return true } -func (t *applyTask) allInputReady(cache *pkgsync.Map[string, *value.Value]) bool { +func (t *applyTask) allInputReady(cache *pkgmaps.SyncMap[string, *value.Value]) bool { for _, in := range t.component.Inputs { if val := t.getVar(in.From, cache); val == nil { return false @@ -306,7 +306,7 @@ type applyTaskResult struct { // applyComponents will apply components to placements. func applyComponents(ctx context.Context, apply oamProvider.ComponentApply, healthCheck oamProvider.ComponentHealthCheck, components []common.ApplicationComponent, placements []v1alpha1.PlacementDecision, parallelism int) (bool, string, error) { var tasks []*applyTask - var cache = pkgsync.NewMap[string, *value.Value]() + var cache = pkgmaps.NewSyncMap[string, *value.Value]() rootValue, err := value.NewValue("{}", nil, "") if err != nil { return false, "", err diff --git a/references/docgen/i18n_test.go b/references/docgen/i18n_test.go index 6032e7ea1..b728f4df5 100644 --- a/references/docgen/i18n_test.go +++ b/references/docgen/i18n_test.go @@ -19,6 +19,7 @@ package docgen import ( "fmt" "net/http" + "net/http/httptest" "testing" "time" @@ -26,14 +27,10 @@ import ( ) func TestLoad(t *testing.T) { - - go func() { - svr := http.NewServeMux() - svr.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, `{"Outputs":{"Chinese":"输出"}}`) - }) - http.ListenAndServe(":65502", svr) - }() + svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + _, _ = fmt.Fprintf(w, `{"Outputs":{"Chinese":"输出"}}`) + })) + defer svr.Close() time.Sleep(time.Millisecond) assert.Equal(t, En.Language(), Language("English")) assert.Equal(t, En.Get("nihaoha"), "nihaoha") @@ -52,6 +49,6 @@ func TestLoad(t *testing.T) { assert.Equal(t, Zh.Get("nihaoha"), "nihaoha") assert.Equal(t, Zh.Get("AlibabaCloud"), "阿里云") - LoadI18nData("http://127.0.0.1:65502") + LoadI18nData(svr.URL) assert.Equal(t, Zh.Get("Outputs"), "输出") }