diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index c41273f0..0054703e 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,8 +1,9 @@ name: lint on: - push: - branches: [ "main" ] + #FIXME: uncomment it once open source + #push: + #branches: [ "main" ] pull_request: branches: [ "main" ] diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8d37630c..b00b86f3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,11 +1,12 @@ name: test on: - push: - branches: [ "main" ] - paths-ignore: - - "site/**" - - "**/*.md" + #FIXME: uncomment it once open source + #push: + #branches: [ "main" ] + #paths-ignore: + #- "site/**" + #- "**/*.md" pull_request: branches: [ "main" ] paths-ignore: diff --git a/controller/tests/benchmark/httpfilterpolicy_controller_test.go b/controller/tests/benchmark/httpfilterpolicy_controller_test.go index 936bdf77..93b7b836 100644 --- a/controller/tests/benchmark/httpfilterpolicy_controller_test.go +++ b/controller/tests/benchmark/httpfilterpolicy_controller_test.go @@ -79,21 +79,21 @@ var _ = Describe("HTTPFilterPolicy controller", func() { var policies mosniov1.HTTPFilterPolicyList if err := k8sClient.List(ctx, &policies); err == nil { for _, e := range policies.Items { - Expect(k8sClient.Delete(ctx, &e)).Should(Succeed()) + pkg.DeleteK8sResource(ctx, k8sClient, &e) } } var virtualservices istiov1b1.VirtualServiceList if err := k8sClient.List(ctx, &virtualservices); err == nil { for _, e := range virtualservices.Items { - Expect(k8sClient.Delete(ctx, e)).Should(Succeed()) + pkg.DeleteK8sResource(ctx, k8sClient, e) } } var gateways istiov1b1.GatewayList if err := k8sClient.List(ctx, &gateways); err == nil { for _, e := range gateways.Items { - Expect(k8sClient.Delete(ctx, e)).Should(Succeed()) + pkg.DeleteK8sResource(ctx, k8sClient, e) } } }) diff --git a/controller/tests/integration/controller/consumer_controller_test.go b/controller/tests/integration/controller/consumer_controller_test.go index 0c336393..2163b685 100644 --- a/controller/tests/integration/controller/consumer_controller_test.go +++ b/controller/tests/integration/controller/consumer_controller_test.go @@ -50,14 +50,14 @@ var _ = Describe("Consumer controller", func() { var consumers mosniov1.ConsumerList if err := k8sClient.List(ctx, &consumers); err == nil { for _, e := range consumers.Items { - Expect(k8sClient.Delete(ctx, &e)).Should(Succeed()) + pkg.DeleteK8sResource(ctx, k8sClient, &e) } } var envoyfilters istiov1a3.EnvoyFilterList if err := k8sClient.List(ctx, &envoyfilters); err == nil { for _, e := range envoyfilters.Items { - Expect(k8sClient.Delete(ctx, e)).Should(Succeed()) + pkg.DeleteK8sResource(ctx, k8sClient, e) } } }) diff --git a/controller/tests/integration/controller/httpfilterpolicy_controller_test.go b/controller/tests/integration/controller/httpfilterpolicy_controller_test.go index f43f5433..b2942bc3 100644 --- a/controller/tests/integration/controller/httpfilterpolicy_controller_test.go +++ b/controller/tests/integration/controller/httpfilterpolicy_controller_test.go @@ -76,7 +76,7 @@ var _ = Describe("HTTPFilterPolicy controller", func() { var policies mosniov1.HTTPFilterPolicyList if err := k8sClient.List(ctx, &policies); err == nil { for _, e := range policies.Items { - Expect(k8sClient.Delete(ctx, &e)).Should(Succeed()) + pkg.DeleteK8sResource(ctx, k8sClient, &e) } } }) @@ -159,28 +159,28 @@ var _ = Describe("HTTPFilterPolicy controller", func() { var policies mosniov1.HTTPFilterPolicyList if err := k8sClient.List(ctx, &policies); err == nil { for _, e := range policies.Items { - Expect(k8sClient.Delete(ctx, &e)).Should(Succeed()) + pkg.DeleteK8sResource(ctx, k8sClient, &e) } } var virtualservices istiov1b1.VirtualServiceList if err := k8sClient.List(ctx, &virtualservices); err == nil { for _, e := range virtualservices.Items { - Expect(k8sClient.Delete(ctx, e)).Should(Succeed()) + pkg.DeleteK8sResource(ctx, k8sClient, e) } } var gateways istiov1b1.GatewayList if err := k8sClient.List(ctx, &gateways); err == nil { for _, e := range gateways.Items { - Expect(k8sClient.Delete(ctx, e)).Should(Succeed()) + pkg.DeleteK8sResource(ctx, k8sClient, e) } } var envoyfilters istiov1a3.EnvoyFilterList if err := k8sClient.List(ctx, &envoyfilters); err == nil { for _, e := range envoyfilters.Items { - Expect(k8sClient.Delete(ctx, e)).Should(Succeed()) + pkg.DeleteK8sResource(ctx, k8sClient, e) } } @@ -585,28 +585,28 @@ var _ = Describe("HTTPFilterPolicy controller", func() { var policies mosniov1.HTTPFilterPolicyList if err := k8sClient.List(ctx, &policies); err == nil { for _, e := range policies.Items { - Expect(k8sClient.Delete(ctx, &e)).Should(Succeed()) + pkg.DeleteK8sResource(ctx, k8sClient, &e) } } var httproutes gwapiv1.HTTPRouteList if err := k8sClient.List(ctx, &httproutes); err == nil { for _, e := range httproutes.Items { - Expect(k8sClient.Delete(ctx, &e)).Should(Succeed()) + pkg.DeleteK8sResource(ctx, k8sClient, &e) } } var gateways gwapiv1.GatewayList if err := k8sClient.List(ctx, &gateways); err == nil { for _, e := range gateways.Items { - Expect(k8sClient.Delete(ctx, &e)).Should(Succeed()) + pkg.DeleteK8sResource(ctx, k8sClient, &e) } } var envoyfilters istiov1a3.EnvoyFilterList if err := k8sClient.List(ctx, &envoyfilters); err == nil { for _, e := range envoyfilters.Items { - Expect(k8sClient.Delete(ctx, e)).Should(Succeed()) + pkg.DeleteK8sResource(ctx, k8sClient, e) } } diff --git a/controller/tests/integration/controller/serviceregistry_controller_test.go b/controller/tests/integration/controller/serviceregistry_controller_test.go index 3d6a14ea..e2d0cbea 100644 --- a/controller/tests/integration/controller/serviceregistry_controller_test.go +++ b/controller/tests/integration/controller/serviceregistry_controller_test.go @@ -46,7 +46,7 @@ var _ = Describe("ServiceRegistry controller", func() { var registries mosniov1.ServiceRegistryList if err := k8sClient.List(ctx, ®istries); err == nil { for _, e := range registries.Items { - Expect(k8sClient.Delete(ctx, &e)).Should(Succeed()) + pkg.DeleteK8sResource(ctx, k8sClient, &e) } } diff --git a/controller/tests/integration/registries/nacos_test.go b/controller/tests/integration/registries/nacos_test.go index 941ea5ce..fad3a902 100644 --- a/controller/tests/integration/registries/nacos_test.go +++ b/controller/tests/integration/registries/nacos_test.go @@ -138,7 +138,7 @@ var _ = Describe("Nacos", func() { var registries mosniov1.ServiceRegistryList if err := k8sClient.List(ctx, ®istries); err == nil { for _, e := range registries.Items { - Expect(k8sClient.Delete(ctx, &e)).Should(Succeed()) + pkg.DeleteK8sResource(ctx, k8sClient, &e) } } @@ -242,7 +242,7 @@ var _ = Describe("Nacos", func() { Expect(k8sClient.Patch(ctx, currNacos, base)).Should(Succeed()) Eventually(func() bool { entries = listServiceEntries() - return len(entries) == 2 + return len(entries) == 1 }, timeout, interval).Should(BeTrue()) // subscribe change diff --git a/controller/tests/pkg/utils.go b/controller/tests/pkg/utils.go index a9c32e76..70daac86 100644 --- a/controller/tests/pkg/utils.go +++ b/controller/tests/pkg/utils.go @@ -15,13 +15,16 @@ package pkg import ( + "context" "encoding/json" "strings" "testing" + . "github.com/onsi/gomega" "github.com/stretchr/testify/require" istiov1a3 "istio.io/client-go/pkg/apis/networking/v1alpha3" istiov1b1 "istio.io/client-go/pkg/apis/networking/v1beta1" + apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/client-go/rest" "sigs.k8s.io/controller-runtime/pkg/client" gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" @@ -74,3 +77,10 @@ func FakeK8sClient(t *testing.T) client.Client { require.NoError(t, err) return k8sClient } + +func DeleteK8sResource(ctx context.Context, k8sClient client.Client, obj client.Object, opts ...client.DeleteOption) { + err := k8sClient.Delete(ctx, obj, opts...) + if err != nil && !apierrors.IsNotFound(err) { + Expect(err).Should(Succeed()) + } +} diff --git a/e2e/pkg/k8s/k8s.go b/e2e/pkg/k8s/k8s.go index 9309ca65..1e333fd9 100644 --- a/e2e/pkg/k8s/k8s.go +++ b/e2e/pkg/k8s/k8s.go @@ -24,12 +24,15 @@ import ( "time" "github.com/stretchr/testify/require" + istiov1b1 "istio.io/client-go/pkg/apis/networking/v1beta1" apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/yaml" "sigs.k8s.io/controller-runtime/pkg/client" + gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" + mosniov1 "mosn.io/htnn/controller/api/v1" "mosn.io/htnn/pkg/log" ) @@ -100,3 +103,43 @@ func readResources(decoder *yaml.YAMLOrJSONDecoder) ([]unstructured.Unstructured return resources, nil } + +func deleteResource(t *testing.T, ctx context.Context, k8sClient client.Client, obj client.Object, opts ...client.DeleteOption) { + err := k8sClient.Delete(ctx, obj, opts...) + if err != nil && !apierrors.IsNotFound(err) { + require.NoError(t, err) + } + logger.Info("Deleted", "name", obj.GetName(), "kind", obj.GetObjectKind()) +} + +func CleanUp(t *testing.T, c client.Client) { + ctx := context.Background() + var policies mosniov1.HTTPFilterPolicyList + err := c.List(ctx, &policies) + require.NoError(t, err) + for _, e := range policies.Items { + deleteResource(t, ctx, c, &e) + } + + var consumers mosniov1.ConsumerList + err = c.List(ctx, &consumers) + require.NoError(t, err) + for _, e := range consumers.Items { + deleteResource(t, ctx, c, &e) + } + + var httproutes gwapiv1.HTTPRouteList + err = c.List(ctx, &httproutes) + require.NoError(t, err) + for _, e := range httproutes.Items { + deleteResource(t, ctx, c, &e) + } + + var virtualservices istiov1b1.VirtualServiceList + err = c.List(ctx, &virtualservices) + require.NoError(t, err) + for _, e := range virtualservices.Items { + deleteResource(t, ctx, c, e) + } + // let HTNN to clean up EnvoyFilter +} diff --git a/e2e/pkg/suite/suite.go b/e2e/pkg/suite/suite.go index b262447f..13734725 100644 --- a/e2e/pkg/suite/suite.go +++ b/e2e/pkg/suite/suite.go @@ -31,13 +31,10 @@ import ( "time" "github.com/stretchr/testify/require" - istiov1b1 "istio.io/client-go/pkg/apis/networking/v1beta1" "k8s.io/client-go/kubernetes" "sigs.k8s.io/controller-runtime/pkg/client" - gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" "sigs.k8s.io/gateway-api/conformance/utils/roundtripper" - mosniov1 "mosn.io/htnn/controller/api/v1" "mosn.io/htnn/e2e/pkg/k8s" "mosn.io/htnn/pkg/log" ) @@ -145,42 +142,7 @@ func (suite *Suite) stopPortForward(t *testing.T) { } func (suite *Suite) cleanup(t *testing.T) { - c := suite.Opt.Client - ctx := context.Background() - var policies mosniov1.HTTPFilterPolicyList - err := c.List(ctx, &policies) - require.NoError(t, err) - for _, e := range policies.Items { - // DeepCopy here is to satisfy the requirement of gosec - require.NoError(t, c.Delete(ctx, e.DeepCopy())) - logger.Info("Deleted", "name", e.GetName(), "kind", e.GetObjectKind()) - } - - var consumers mosniov1.ConsumerList - err = c.List(ctx, &consumers) - require.NoError(t, err) - for _, e := range consumers.Items { - // DeepCopy here is to satisfy the requirement of gosec - require.NoError(t, c.Delete(ctx, e.DeepCopy())) - logger.Info("Deleted", "name", e.GetName(), "kind", e.GetObjectKind()) - } - - var httproutes gwapiv1.HTTPRouteList - err = c.List(ctx, &httproutes) - require.NoError(t, err) - for _, e := range httproutes.Items { - require.NoError(t, c.Delete(ctx, e.DeepCopy())) - logger.Info("Deleted", "name", e.GetName(), "kind", e.GetObjectKind()) - } - - var virtualservices istiov1b1.VirtualServiceList - err = c.List(ctx, &virtualservices) - require.NoError(t, err) - for _, e := range virtualservices.Items { - require.NoError(t, c.Delete(ctx, e)) - logger.Info("Deleted", "name", e.GetName(), "kind", e.GetObjectKind()) - } - // let HTNN to clean up EnvoyFilter + k8s.CleanUp(t, suite.Opt.Client) } func (suite *Suite) K8sClient() client.Client { diff --git a/go.mod b/go.mod index a50d077e..3d308747 100644 --- a/go.mod +++ b/go.mod @@ -9,6 +9,7 @@ toolchain go1.21.5 require ( github.com/agiledragon/gomonkey/v2 v2.11.0 + github.com/avast/retry-go v3.0.0+incompatible github.com/casbin/casbin/v2 v2.82.0 github.com/cncf/xds/go v0.0.0-20231109132714-523115ebc101 github.com/coreos/go-oidc/v3 v3.9.0 @@ -30,9 +31,9 @@ require ( github.com/redis/go-redis/v9 v9.5.1 github.com/spf13/viper v1.18.2 github.com/stretchr/testify v1.8.4 - go.uber.org/zap v1.26.0 - golang.org/x/net v0.19.0 - golang.org/x/oauth2 v0.15.0 + go.uber.org/zap v1.27.0 + golang.org/x/net v0.21.0 + golang.org/x/oauth2 v0.17.0 golang.org/x/text v0.14.0 golang.org/x/time v0.5.0 google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 @@ -119,11 +120,11 @@ require ( go.opentelemetry.io/otel/sdk v1.21.0 // indirect go.opentelemetry.io/otel/trace v1.21.0 // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/crypto v0.17.0 // indirect + golang.org/x/crypto v0.19.0 // indirect golang.org/x/exp v0.0.0-20231219180239-dc181d75b848 // indirect golang.org/x/sync v0.5.0 // indirect - golang.org/x/sys v0.16.0 // indirect - golang.org/x/term v0.15.0 // indirect + golang.org/x/sys v0.17.0 // indirect + golang.org/x/term v0.17.0 // indirect golang.org/x/tools v0.16.1 // indirect gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect google.golang.org/appengine v1.6.8 // indirect diff --git a/go.sum b/go.sum index 25a44ace..133dd224 100644 --- a/go.sum +++ b/go.sum @@ -12,6 +12,8 @@ github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8 github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g= github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig+0+Ap1h4unLjW6YQJpKZVmUzxsD4E/Q= github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE= +github.com/avast/retry-go v3.0.0+incompatible h1:4SOWQ7Qs+oroOTQOYnAHqelpCO0biHSxpiH9JdtuBj0= +github.com/avast/retry-go v3.0.0+incompatible/go.mod h1:XtSnn+n/sHqQIpZ10K1qAevBhOOCWBLXXy3hyiqqBrY= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= @@ -309,16 +311,16 @@ go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= go.uber.org/zap v1.15.0/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc= -go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo= -go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so= +go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= +go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= -golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= +golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo= +golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20231219180239-dc181d75b848 h1:+iq7lrkxmFNBM7xx+Rae2W6uyPfhPeDWD+n+JgppptE= golang.org/x/exp v0.0.0-20231219180239-dc181d75b848/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI= @@ -342,11 +344,11 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c= -golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= +golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= +golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.15.0 h1:s8pnnxNVzjWyrvYdFUQq5llS1PX2zhPXmccZv99h7uQ= -golang.org/x/oauth2 v0.15.0/go.mod h1:q48ptWNTY5XWf+JNten23lcvHpLJ0ZSxF5ttTHKVCAM= +golang.org/x/oauth2 v0.17.0 h1:6m3ZPmLEFdVxKKWnKq4VqZ60gutO35zm+zrAHVmHyDQ= +golang.org/x/oauth2 v0.17.0/go.mod h1:OzPDGQiuQMguemayvdylqddI7qcD9lnSDb+1FiwQ5HA= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -368,12 +370,12 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= +golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= -golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= +golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U= +golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= diff --git a/pkg/filtermanager/filtermanager.go b/pkg/filtermanager/filtermanager.go index 58af4adb..fcf42ca3 100644 --- a/pkg/filtermanager/filtermanager.go +++ b/pkg/filtermanager/filtermanager.go @@ -350,6 +350,11 @@ func FilterManagerFactory(c interface{}, cb capi.FilterCallbackHandler) capi.Str fm := conf.pool.Get().(*filterManager) fm.callbacks.FilterCallbackHandler = cb + canSkipMethod := fm.canSkipMethod + if canSkipMethod == nil { + canSkipMethod = newSkipMethodsMap() + } + filters := make([]*filterWrapper, len(newConfig)) for i, fc := range newConfig { factory := fc.Factory @@ -357,7 +362,6 @@ func FilterManagerFactory(c interface{}, cb capi.FilterCallbackHandler) capi.Str f := factory(config, fm.callbacks) // Technically, the factory might create different f for different calls. We don't support this edge case for now. if fm.canSkipMethod == nil { - canSkipMethod := newSkipMethodsMap() for meth := range canSkipMethod { ok, err := isMethodFromPassThroughFilter(f, meth) if err != nil { @@ -366,11 +370,13 @@ func FilterManagerFactory(c interface{}, cb capi.FilterCallbackHandler) capi.Str } canSkipMethod[meth] = canSkipMethod[meth] && ok } - fm.canSkipMethod = canSkipMethod } filters[i] = newFilterWrapper(fc.Name, f) } + if fm.canSkipMethod == nil { + fm.canSkipMethod = canSkipMethod + } fm.filters = filters if conf.consumerFiltersEndAt != 0 { diff --git a/pkg/filtermanager/filtermanager_test.go b/pkg/filtermanager/filtermanager_test.go index 1f0298bd..0bfc350c 100644 --- a/pkg/filtermanager/filtermanager_test.go +++ b/pkg/filtermanager/filtermanager_test.go @@ -343,6 +343,31 @@ func (f *addReqFilter) DecodeHeaders(headers api.RequestHeaderMap, endStream boo return api.Continue } +func TestSkipMethodWhenThereAreMultiFilters(t *testing.T) { + cb := envoy.NewCAPIFilterCallbackHandler() + config := initFilterManagerConfig("ns") + config.current = []*model.ParsedFilterConfig{ + { + Name: "add_req", + Factory: addReqFactory, + ParsedConfig: addReqConf{ + hdrName: "x-htnn-route", + }, + }, + { + Name: "on_log", + Factory: onLogFactory, + }, + } + + for i := 0; i < 2; i++ { + m := FilterManagerFactory(config, cb).(*filterManager) + assert.Equal(t, false, m.canSkipOnLog) + assert.Equal(t, false, m.canSkipDecodeHeaders) + assert.Equal(t, true, m.canSkipDecodeData) + } +} + func TestFiltersFromConsumer(t *testing.T) { cb := envoy.NewCAPIFilterCallbackHandler() config := initFilterManagerConfig("ns") diff --git a/plugins/oidc/config.go b/plugins/oidc/config.go index c23df2c9..cc6d1028 100644 --- a/plugins/oidc/config.go +++ b/plugins/oidc/config.go @@ -19,6 +19,7 @@ import ( "net/http" "time" + "github.com/avast/retry-go" "github.com/coreos/go-oidc/v3/oidc" "github.com/gorilla/securecookie" "golang.org/x/oauth2" @@ -72,7 +73,21 @@ func ctxWithClient(ctx context.Context) context.Context { func (conf *config) Init(cb api.ConfigCallbackHandler) error { ctx := ctxWithClient(context.Background()) - provider, err := oidc.NewProvider(ctx, conf.Issuer) + var provider *oidc.Provider + var err error + err = retry.Do( + func() error { + provider, err = oidc.NewProvider(ctx, conf.Issuer) + return err + }, + retry.RetryIf(func(err error) bool { + api.LogWarnf("failed to get oidc provider, err: %v", err) + return true + }), + retry.Attempts(3), + // backoff delay + retry.Delay(500*time.Millisecond), + ) if err != nil { return err } diff --git a/plugins/tests/integration/consumer_restriction_test.go b/plugins/tests/integration/consumer_restriction_test.go index ee1441d1..03f7f60d 100644 --- a/plugins/tests/integration/consumer_restriction_test.go +++ b/plugins/tests/integration/consumer_restriction_test.go @@ -27,7 +27,22 @@ import ( ) func TestConsumerRestriction(t *testing.T) { - dp, err := data_plane.StartDataPlane(t, nil) + dp, err := data_plane.StartDataPlane(t, &data_plane.Option{ + Bootstrap: data_plane.Bootstrap().AddConsumer("tom", map[string]interface{}{ + "auth": map[string]interface{}{ + "keyAuth": `{"key":"tom"}`, + }, + }).AddConsumer("with_filter", map[string]interface{}{ + "auth": map[string]interface{}{ + "keyAuth": `{"key":"marvin"}`, + }, + "filters": map[string]interface{}{ + "demo": map[string]interface{}{ + "config": `{"hostName": "Mike"}`, + }, + }, + }), + }) if err != nil { t.Fatalf("failed to start data plane: %v", err) return diff --git a/plugins/tests/integration/consumer_test.go b/plugins/tests/integration/consumer_test.go index f982bbe0..0b751173 100644 --- a/plugins/tests/integration/consumer_test.go +++ b/plugins/tests/integration/consumer_test.go @@ -26,7 +26,18 @@ import ( ) func TestConsumerWithFilter(t *testing.T) { - dp, err := data_plane.StartDataPlane(t, nil) + dp, err := data_plane.StartDataPlane(t, &data_plane.Option{ + Bootstrap: data_plane.Bootstrap().AddConsumer("with_filter", map[string]interface{}{ + "auth": map[string]interface{}{ + "keyAuth": `{"key":"marvin"}`, + }, + "filters": map[string]interface{}{ + "demo": map[string]interface{}{ + "config": `{"hostName": "Mike"}`, + }, + }, + }), + }) if err != nil { t.Fatalf("failed to start data plane: %v", err) return diff --git a/plugins/tests/integration/data_plane/bootstrap.go b/plugins/tests/integration/data_plane/bootstrap.go index d5f78c31..c21f1e8d 100644 --- a/plugins/tests/integration/data_plane/bootstrap.go +++ b/plugins/tests/integration/data_plane/bootstrap.go @@ -16,6 +16,8 @@ package data_plane import ( _ "embed" + "encoding/json" + "math/rand" "os" "gopkg.in/yaml.v3" @@ -28,11 +30,13 @@ var ( type bootstrap struct { backendRoutes []map[string]interface{} + consumers map[string]map[string]interface{} } func Bootstrap() *bootstrap { return &bootstrap{ backendRoutes: []map[string]interface{}{}, + consumers: map[string]map[string]interface{}{}, } } @@ -46,6 +50,25 @@ func (b *bootstrap) AddBackendRoute(s string) *bootstrap { return b } +func (b *bootstrap) AddConsumer(name string, c map[string]interface{}) *bootstrap { + if c["filters"] != nil { + filters := c["filters"].(map[string]interface{}) + for _, f := range filters { + d := map[string]interface{}{} + fc := f.(map[string]interface{})["config"].(string) + json.Unmarshal([]byte(fc), &d) + f.(map[string]interface{})["config"] = d + } + } + + by, _ := json.Marshal(c) + b.consumers[name] = map[string]interface{}{ + "v": rand.Intn(99999), + "d": string(by), + } + return b +} + func (b *bootstrap) WriteTo(cfgFile *os.File) error { var root map[string]interface{} // check if the input is valid yaml @@ -62,6 +85,12 @@ func (b *bootstrap) WriteTo(cfgFile *os.File) error { } vh["routes"] = routes + cf := root["static_resources"].(map[string]interface{})["listeners"].([]interface{})[0].(map[string]interface{})["filter_chains"].([]interface{})[0].(map[string]interface{})["filters"].([]interface{})[0].(map[string]interface{})["typed_config"].(map[string]interface{})["http_filters"].([]interface{})[0].(map[string]interface{})["typed_config"].(map[string]interface{}) + consumers := cf["plugin_config"].(map[string]interface{})["value"].(map[string]interface{})["ns"].(map[string]interface{}) + for name, c := range b.consumers { + consumers[name] = c + } + res, err := yaml.Marshal(&root) if err != nil { return err diff --git a/plugins/tests/integration/data_plane/bootstrap.yml b/plugins/tests/integration/data_plane/bootstrap.yml index cbaaa8df..43a2e8c4 100644 --- a/plugins/tests/integration/data_plane/bootstrap.yml +++ b/plugins/tests/integration/data_plane/bootstrap.yml @@ -31,33 +31,11 @@ static_resources: "@type": type.googleapis.com/xds.type.v3.TypedStruct value: ns: - rick: + placeholder: d: | { "auth":{ - "keyAuth":"{\"key\":\"rick\"}", - "hmacAuth": "{\"accessKey\":\"ak\",\"secretKey\":\"sk\",\"signedHeaders\":[\"x-custom-a\"],\"algorithm\":\"HMAC_SHA256\"}" - } - } - v: 4355415 - tom: - d: | - { - "auth":{ - "keyAuth":"{\"key\":\"tom\"}" - } - } - v: 4355415 - with_filter: - d: | - { - "auth":{ - "keyAuth":"{\"key\":\"marvin\"}" - }, - "filters":{ - "demo":{ - "config":{"hostName":"Mike"} - } + "keyAuth":"{\"key\":\"placeholder\"}" } } v: 4355415 diff --git a/plugins/tests/integration/hmac_auth_test.go b/plugins/tests/integration/hmac_auth_test.go index 38d20544..e8079446 100644 --- a/plugins/tests/integration/hmac_auth_test.go +++ b/plugins/tests/integration/hmac_auth_test.go @@ -27,7 +27,23 @@ import ( ) func TestHmacAuth(t *testing.T) { - dp, err := data_plane.StartDataPlane(t, nil) + dp, err := data_plane.StartDataPlane(t, &data_plane.Option{ + Bootstrap: data_plane.Bootstrap().AddConsumer("rick", map[string]interface{}{ + "auth": map[string]interface{}{ + "keyAuth": `{"key":"rick"}`, + "hmacAuth": `{"accessKey":"ak","secretKey":"sk","signedHeaders":["x-custom-a"],"algorithm":"HMAC_SHA256"}`, + }, + }).AddConsumer("with_filter", map[string]interface{}{ + "auth": map[string]interface{}{ + "keyAuth": `{"key":"marvin"}`, + }, + "filters": map[string]interface{}{ + "demo": map[string]interface{}{ + "config": `{"hostName": "Mike"}`, + }, + }, + }), + }) if err != nil { t.Fatalf("failed to start data plane: %v", err) return diff --git a/plugins/tests/integration/key_auth_test.go b/plugins/tests/integration/key_auth_test.go index d9651a2e..842576bb 100644 --- a/plugins/tests/integration/key_auth_test.go +++ b/plugins/tests/integration/key_auth_test.go @@ -26,7 +26,18 @@ import ( ) func TestKeyAuth(t *testing.T) { - dp, err := data_plane.StartDataPlane(t, nil) + dp, err := data_plane.StartDataPlane(t, &data_plane.Option{ + Bootstrap: data_plane.Bootstrap().AddConsumer("rick", map[string]interface{}{ + "auth": map[string]interface{}{ + "keyAuth": `{"key":"rick"}`, + "hmacAuth": `{"accessKey":"ak","secretKey":"sk","signedHeaders":["x-custom-a"],"algorithm":"HMAC_SHA256"}`, + }, + }).AddConsumer("tom", map[string]interface{}{ + "auth": map[string]interface{}{ + "keyAuth": `{"key":"tom"}`, + }, + }), + }) if err != nil { t.Fatalf("failed to start data plane: %v", err) return diff --git a/plugins/tests/integration/oidc_test.go b/plugins/tests/integration/oidc_test.go index b0dbc119..42399135 100644 --- a/plugins/tests/integration/oidc_test.go +++ b/plugins/tests/integration/oidc_test.go @@ -79,7 +79,7 @@ func TestOIDC(t *testing.T) { require.Nil(t, err) uri = resp.Header.Get("Location") return uri != "" - }, 5*time.Second, 1*time.Second) + }, 10*time.Second, 1*time.Second) u, err := url.ParseRequestURI(uri) require.NoError(t, err) diff --git a/site/Dockerfile b/site/Dockerfile index 195927fe..e022a2bd 100644 --- a/site/Dockerfile +++ b/site/Dockerfile @@ -13,7 +13,7 @@ # limitations under the License. # Use debian image for ARM64 support -FROM floryn90/hugo:ext-debian@sha256:4f404fec004c20c8c562ce37f2a0bd94058e5cad6d0b1caf746f9cdb546c432f +FROM floryn90/hugo:ext-debian@sha256:327b204be365f1b149e998c46c87177a2d8baf98e9f541e44e63d05e6616bcb6 RUN apt install -y --no-install-recommends git && \ git config --global --add safe.directory /src diff --git a/site/package.json b/site/package.json index eba11d46..bd24ffbd 100644 --- a/site/package.json +++ b/site/package.json @@ -36,7 +36,7 @@ "devDependencies": { "autoprefixer": "^10.4.14", "cross-env": "^7.0.3", - "hugo-extended": "0.123.0", + "hugo-extended": "0.123.2", "postcss-cli": "^11.0.0" } }