From ed7f745598992328c310aada113d38eb0ff7cafa Mon Sep 17 00:00:00 2001 From: Zixuan Liu Date: Mon, 24 Jan 2022 20:06:52 +0800 Subject: [PATCH 01/24] feat: add allow auto update schema cmd (#567) Signed-off-by: Zixuan Liu --- go.mod | 8 +- go.sum | 75 ++++++----------- .../get_is_allow_auto_update_schema.go | 62 ++++++++++++++ .../is_allow_auto_update_schema_test.go | 66 +++++++++++++++ pkg/ctl/namespace/namespace.go | 2 + .../set_is_allow_auto_update_schema.go | 83 +++++++++++++++++++ pkg/pulsar/namespace.go | 18 ++++ pkg/pulsar/utils/policies.go | 1 + 8 files changed, 264 insertions(+), 51 deletions(-) create mode 100644 pkg/ctl/namespace/get_is_allow_auto_update_schema.go create mode 100644 pkg/ctl/namespace/is_allow_auto_update_schema_test.go create mode 100644 pkg/ctl/namespace/set_is_allow_auto_update_schema.go diff --git a/go.mod b/go.mod index 249da43d..f7672654 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/ghodss/yaml v1.0.0 github.com/go-sql-driver/mysql v1.5.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/golang/protobuf v1.4.3 + github.com/golang/protobuf v1.5.2 github.com/gorilla/mux v1.7.4 // indirect github.com/imdario/mergo v0.3.8 github.com/kr/pretty v0.2.0 // indirect @@ -21,17 +21,19 @@ require ( github.com/mattn/go-colorable v0.1.2 // indirect github.com/mattn/go-runewidth v0.0.4 // indirect github.com/olekukonko/tablewriter v0.0.1 + github.com/onsi/gomega v1.18.0 github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.4.2 // indirect github.com/spf13/cobra v0.0.5 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.5.1 github.com/testcontainers/testcontainers-go v0.0.10 - golang.org/x/net v0.0.0-20210220033124-5f55cee0dc0d // indirect golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93 google.golang.org/appengine v1.6.7 // indirect gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect - gopkg.in/yaml.v2 v2.3.0 + gopkg.in/yaml.v2 v2.4.0 ) replace github.com/apache/pulsar-client-go/oauth2 => github.com/apache/pulsar-client-go/oauth2 v0.0.0-20211006154457-742f1b107403 + +replace golang.org/x/sys => golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 diff --git a/go.sum b/go.sum index 00fdce58..aa7d578b 100644 --- a/go.sum +++ b/go.sum @@ -95,6 +95,7 @@ github.com/go-redis/redis v6.15.6+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8w github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs= github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 h1:ZpnhV/YsD2/4cESfV5+Hoeu/iUR3ruzNvZ+yQfO03a0= github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4= github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= @@ -124,8 +125,9 @@ github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:W github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM= -github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= @@ -134,8 +136,9 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.1 h1:JFrFEBb2xKufg6XkJsJr+WbKb4FQlURi5RUcBveYu9k= github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= @@ -145,6 +148,7 @@ github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hf github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= @@ -159,6 +163,7 @@ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/imdario/mergo v0.3.8 h1:CGgOkSJeqMRmt0D9XLWExdT4m4F1vd3FV3VPt+0VxkQ= github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= @@ -196,19 +201,25 @@ github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c h1:nXxl5PrvVm2L/wCy8d github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/mtibben/percent v0.2.1 h1:5gssi8Nqo8QU/r2pynCm+hBQHpkB/uNK7BJCFogWdzs= github.com/mtibben/percent v0.2.1/go.mod h1:KG9uO+SZkUp+VkRHsCdYQV3XSZrrSpR3O9ibNBTZrns= -github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= +github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= +github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/olekukonko/tablewriter v0.0.1 h1:b3iUnf1v+ppJiOfNX4yxxqfWKMQPZR5yoh8urCTFX88= github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= -github.com/onsi/ginkgo v1.14.0 h1:2mOpI4JVVPBN+WQRa0WKH2eXR+Ey+uK4n7Zj0aYpIQA= github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= +github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc= +github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= +github.com/onsi/ginkgo/v2 v2.0.0 h1:CcuG/HvWNkkaqCUpJifQY8z7qEMBJya6aLPx6ftGyjQ= +github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= -github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= +github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= +github.com/onsi/gomega v1.18.0 h1:ngbYoRctxjl8SiF7XgP0NxBFbfHcg3wfHMMaFHWwMTM= +github.com/onsi/gomega v1.18.0/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs= github.com/opencontainers/go-digest v1.0.0-rc1 h1:WzifXhOVOEOuFYOJAW6aQqW0TooG2iki3E3Ii+WN7gQ= github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= github.com/opencontainers/image-spec v1.0.1 h1:JMemWkRwHx4Zj+fVxWoMCFm/8sYGGrUVojFA6h/TRcI= @@ -329,8 +340,8 @@ golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81R golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20210220033124-5f55cee0dc0d h1:1aflnvSoWWLI2k/dMUAl5lvU1YO4Mb4hz0gh+1rjcxU= -golang.org/x/net v0.0.0-20210220033124-5f55cee0dc0d/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 h1:DzZ89McO9/gWPsQXS/FVKAlG02ZjaQ6AlZRBimEYOd0= +golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -348,43 +359,6 @@ golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 h1:SQFwaSi55rU7vdNs9Yr0Z324VNlrF+0wMqRXT4St8ck= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181228144115-9a3f9b0469bb/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -392,8 +366,9 @@ golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fq golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs= @@ -441,6 +416,7 @@ golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roY golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -524,8 +500,10 @@ google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2 google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= -google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= @@ -537,8 +515,9 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWD gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gotest.tools v0.0.0-20181223230014-1083505acf35 h1:zpdCK+REwbk+rqjJmHhiCN6iBIigrZ39glqSF0P3KF0= gotest.tools v0.0.0-20181223230014-1083505acf35/go.mod h1:R//lfYlUuTOTfblYI3lGoAAAebUdzjvbmQsuB7Ykd90= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/pkg/ctl/namespace/get_is_allow_auto_update_schema.go b/pkg/ctl/namespace/get_is_allow_auto_update_schema.go new file mode 100644 index 00000000..7155961b --- /dev/null +++ b/pkg/ctl/namespace/get_is_allow_auto_update_schema.go @@ -0,0 +1,62 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package namespace + +import ( + "strconv" + + "github.com/streamnative/pulsarctl/pkg/cmdutils" + "github.com/streamnative/pulsarctl/pkg/pulsar/utils" +) + +func GetIsAllowAutoUpdateSchemaCmd(vc *cmdutils.VerbCmd) { + var desc cmdutils.LongDescription + desc.CommandUsedFor = "Get the whether to allow auto update schema on a namespace" + desc.CommandPermission = "This command requires tenant admin permissions" + + var examples []cmdutils.Example + examples = append(examples, cmdutils.Example{ + Desc: desc.CommandUsedFor, + Command: "pulsarctl namespaces get-is-allow-auto-update-schema (namespace-name)", + }) + desc.CommandExamples = examples + + vc.SetDescription( + "get-is-allow-auto-update-schema", + desc.CommandUsedFor, + desc.ToString(), + desc.ExampleToString()) + + vc.SetRunFuncWithNameArg(func() error { + return doGetIsAllowAutoUpdateSchema(vc) + }, "the namespace name is not specified or the namespace name is specified more than one") +} + +func doGetIsAllowAutoUpdateSchema(vc *cmdutils.VerbCmd) error { + ns, err := utils.GetNamespaceName(vc.NameArg) + if err != nil { + return err + } + + admin := cmdutils.NewPulsarClient() + result, err := admin.Namespaces().GetIsAllowAutoUpdateSchema(*ns) + if err == nil { + vc.Command.Println(strconv.FormatBool(result)) + } + return err +} diff --git a/pkg/ctl/namespace/is_allow_auto_update_schema_test.go b/pkg/ctl/namespace/is_allow_auto_update_schema_test.go new file mode 100644 index 00000000..52423781 --- /dev/null +++ b/pkg/ctl/namespace/is_allow_auto_update_schema_test.go @@ -0,0 +1,66 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package namespace + +import ( + "fmt" + "testing" + + "github.com/onsi/gomega" + "github.com/streamnative/pulsarctl/pkg/test" +) + +func TestIsAllowAutoUpdateSchemaCmd(t *testing.T) { + g := gomega.NewWithT(t) + + ns := "public/test-is-allow-auto-update-schema-" + test.RandomSuffix() + createArgs := []string{"create", ns} + g.Eventually(func(g gomega.Gomega) { + _, execErr, _, _ := TestNamespaceCommands(createNs, createArgs) + g.Expect(execErr).Should(gomega.BeNil()) + }).Should(gomega.Succeed()) + + setArgs := []string{"set-is-allow-auto-update-schema", "--disable", ns} + g.Eventually(func(g gomega.Gomega) { + out, execErr, _, _ := TestNamespaceCommands(SetIsAllowAutoUpdateSchemaCmd, setArgs) + g.Expect(execErr).Should(gomega.BeNil()) + g.Expect(out.String()).Should(gomega.Equal( + fmt.Sprintf("Successfully disable auto update schema on a namespace %s\n", ns))) + }).Should(gomega.Succeed()) + + getArgs := []string{"get-is-allow-auto-update-schema", ns} + g.Eventually(func(g gomega.Gomega) { + out, execErr, _, _ := TestNamespaceCommands(GetIsAllowAutoUpdateSchemaCmd, getArgs) + g.Expect(execErr).Should(gomega.BeNil()) + g.Expect(out.String()).Should(gomega.Equal("false\n")) + }).Should(gomega.Succeed()) + + setArgs = []string{"set-is-allow-auto-update-schema", "--enable", ns} + g.Eventually(func(g gomega.Gomega) { + out, execErr, _, _ := TestNamespaceCommands(SetIsAllowAutoUpdateSchemaCmd, setArgs) + g.Expect(execErr).Should(gomega.BeNil()) + g.Expect(out.String()).Should(gomega.Equal( + fmt.Sprintf("Successfully enable auto update schema on a namespace %s\n", ns))) + }).Should(gomega.Succeed()) + + g.Eventually(func(g gomega.Gomega) { + out, execErr, _, _ := TestNamespaceCommands(GetIsAllowAutoUpdateSchemaCmd, getArgs) + g.Expect(execErr).Should(gomega.BeNil()) + g.Expect(out.String()).Should(gomega.Equal("true\n")) + }).Should(gomega.Succeed()) +} diff --git a/pkg/ctl/namespace/namespace.go b/pkg/ctl/namespace/namespace.go index 72c5d2b2..3183d629 100644 --- a/pkg/ctl/namespace/namespace.go +++ b/pkg/ctl/namespace/namespace.go @@ -92,5 +92,7 @@ func Command(flagGrouping *cmdutils.FlagGrouping) *cobra.Command { cmdutils.AddVerbCmd(flagGrouping, resourceCmd, SetSubscriptionAuthModeCmd) cmdutils.AddVerbCmd(flagGrouping, resourceCmd, GetPublishRateCmd) cmdutils.AddVerbCmd(flagGrouping, resourceCmd, SetPublishRateCmd) + cmdutils.AddVerbCmd(flagGrouping, resourceCmd, SetIsAllowAutoUpdateSchemaCmd) + cmdutils.AddVerbCmd(flagGrouping, resourceCmd, GetIsAllowAutoUpdateSchemaCmd) return resourceCmd } diff --git a/pkg/ctl/namespace/set_is_allow_auto_update_schema.go b/pkg/ctl/namespace/set_is_allow_auto_update_schema.go new file mode 100644 index 00000000..84cd63bd --- /dev/null +++ b/pkg/ctl/namespace/set_is_allow_auto_update_schema.go @@ -0,0 +1,83 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package namespace + +import ( + "github.com/pkg/errors" + "github.com/spf13/pflag" + "github.com/streamnative/pulsarctl/pkg/cmdutils" + "github.com/streamnative/pulsarctl/pkg/pulsar/utils" +) + +func SetIsAllowAutoUpdateSchemaCmd(vc *cmdutils.VerbCmd) { + var desc cmdutils.LongDescription + desc.CommandUsedFor = "Set the whether to allow auto update schema on a namespace" + desc.CommandPermission = "This command requires tenant admin permissions" + + var examples []cmdutils.Example + examples = append(examples, cmdutils.Example{ + Desc: "Enable automatically update schema on a namespace", + Command: "pulsarctl namespaces set-is-allow-auto-update-schema --enable (namespace-name)", + }) + examples = append(examples, cmdutils.Example{ + Desc: "Disable automatically update update schema on a namespace", + Command: "pulsarctl namespaces set-is-allow-auto-update-schema --disable (namespace-name)", + }) + desc.CommandExamples = examples + + vc.SetDescription( + "set-is-allow-auto-update-schema", + desc.CommandUsedFor, + desc.ToString(), + desc.ExampleToString()) + + var ( + enable bool + disable bool + ) + vc.FlagSetGroup.InFlagSet("IsAllowAutoUpdateSchema", func(set *pflag.FlagSet) { + set.BoolVar(&enable, "enable", false, "enable automatically update schema") + set.BoolVar(&disable, "disable", false, "disable automatically update schema") + }) + vc.EnableOutputFlagSet() + + vc.SetRunFuncWithNameArg(func() error { + if enable == disable { + return errors.New("specify only one of --enable or --disable") + } + return doSetIsAllowAutoUpdateSchema(vc, enable) + }, "the namespace name is not specified or the namespace name is specified more than one") +} + +func doSetIsAllowAutoUpdateSchema(vc *cmdutils.VerbCmd, isAllowUpdateSchema bool) error { + ns, err := utils.GetNamespaceName(vc.NameArg) + if err != nil { + return err + } + + admin := cmdutils.NewPulsarClient() + err = admin.Namespaces().SetIsAllowAutoUpdateSchema(*ns, isAllowUpdateSchema) + if err == nil { + action := "enable" + if !isAllowUpdateSchema { + action = "disable" + } + vc.Command.Printf("Successfully %s auto update schema on a namespace %s\n", action, ns.String()) + } + return err +} diff --git a/pkg/pulsar/namespace.go b/pkg/pulsar/namespace.go index cd3124ec..5ca34dd4 100644 --- a/pkg/pulsar/namespace.go +++ b/pkg/pulsar/namespace.go @@ -259,6 +259,12 @@ type Namespaces interface { // GetPublishRate gets the maximum rate or number of messages that producer can publish to topics in the namespace GetPublishRate(namespace utils.NameSpaceName) (utils.PublishRate, error) + + // SetIsAllowAutoUpdateSchema sets whether to allow auto update schema on a namespace + SetIsAllowAutoUpdateSchema(namespace utils.NameSpaceName, isAllowAutoUpdateSchema bool) error + + // GetIsAllowAutoUpdateSchema gets whether to allow auto update schema on a namespace + GetIsAllowAutoUpdateSchema(namespace utils.NameSpaceName) (bool, error) } type namespaces struct { @@ -830,3 +836,15 @@ func (n *namespaces) GetPublishRate(namespace utils.NameSpaceName) (utils.Publis err := n.pulsar.Client.Get(endpoint, &pubRate) return pubRate, err } + +func (n *namespaces) SetIsAllowAutoUpdateSchema(namespace utils.NameSpaceName, isAllowAutoUpdateSchema bool) error { + endpoint := n.pulsar.endpoint(n.basePath, namespace.String(), "isAllowAutoUpdateSchema") + return n.pulsar.Client.Post(endpoint, &isAllowAutoUpdateSchema) +} + +func (n *namespaces) GetIsAllowAutoUpdateSchema(namespace utils.NameSpaceName) (bool, error) { + endpoint := n.pulsar.endpoint(n.basePath, namespace.String(), "isAllowAutoUpdateSchema") + var result bool + err := n.pulsar.Client.Get(endpoint, &result) + return result, err +} diff --git a/pkg/pulsar/utils/policies.go b/pkg/pulsar/utils/policies.go index f72a1898..d847582b 100644 --- a/pkg/pulsar/utils/policies.go +++ b/pkg/pulsar/utils/policies.go @@ -54,6 +54,7 @@ type Policies struct { SchemaCompatibilityStrategy SchemaCompatibilityStrategy `json:"schema_auto_update_compatibility_strategy"` AuthPolicies common.AuthPolicies `json:"auth_policies"` SubscriptionAuthMode SubscriptionAuthMode `json:"subscription_auth_mode"` + IsAllowAutoUpdateSchema *bool `json:"is_allow_auto_update_schema"` } func NewDefaultPolicies() *Policies { From 21682acc99d020dcfa20b6d6840ef305375f9c25 Mon Sep 17 00:00:00 2001 From: Zixuan Liu Date: Fri, 11 Feb 2022 13:56:37 +0800 Subject: [PATCH 02/24] fix: create non-partitions topic (#577) Signed-off-by: Zixuan Liu --- pkg/pulsar/topic.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/pulsar/topic.go b/pkg/pulsar/topic.go index 31af8335..c857bf96 100644 --- a/pkg/pulsar/topic.go +++ b/pkg/pulsar/topic.go @@ -250,10 +250,13 @@ func (c *pulsarClient) Topics() Topics { func (t *topics) Create(topic utils.TopicName, partitions int) error { endpoint := t.pulsar.endpoint(t.basePath, topic.GetRestPath(), "partitions") + data := &partitions if partitions == 0 { endpoint = t.pulsar.endpoint(t.basePath, topic.GetRestPath()) + data = nil } - return t.pulsar.Client.Put(endpoint, partitions) + + return t.pulsar.Client.Put(endpoint, data) } func (t *topics) Delete(topic utils.TopicName, force bool, nonPartitioned bool) error { From 8900464e1cbe41a27531129d41cc8911d4762953 Mon Sep 17 00:00:00 2001 From: Zixuan Liu Date: Fri, 11 Feb 2022 17:54:29 +0800 Subject: [PATCH 03/24] ci: disable cgo (#584) Signed-off-by: Zixuan Liu --- scripts/entrypoint.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh index ee1b20c2..e1009e88 100755 --- a/scripts/entrypoint.sh +++ b/scripts/entrypoint.sh @@ -22,6 +22,9 @@ function checkFunctionWorker() { pushd ${PULSARCTL_HOME} # startup pulsar service scripts/pulsar-service-startup.sh + +# disable cgo +export CGO_ENABLED=0 # run tests case ${TEST_ARGS} in token) From dea53de8b628be72e02006761b89852b4127148d Mon Sep 17 00:00:00 2001 From: Qiang Zhao <74767115+mattisonchao@users.noreply.github.com> Date: Sat, 12 Feb 2022 16:46:44 +0800 Subject: [PATCH 04/24] Fix test compatibility issue. ## Motivation According to https://github.com/apache/pulsar/pull/14087, causing test compatibility issues. ## Modification - Change error info to be consistent. --- pkg/ctl/brokers/delete_dynamic_config_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/ctl/brokers/delete_dynamic_config_test.go b/pkg/ctl/brokers/delete_dynamic_config_test.go index 2698adb0..102d05a1 100644 --- a/pkg/ctl/brokers/delete_dynamic_config_test.go +++ b/pkg/ctl/brokers/delete_dynamic_config_test.go @@ -33,5 +33,5 @@ func TestDeleteDynamicConfig(t *testing.T) { failArgs := []string{"delete-dynamic-config", "--config", "errorName"} _, nameErr, _, _ := TestBrokersCommands(deleteDynamicConfigCmd, failArgs) assert.NotNil(t, nameErr) - assert.Equal(t, "code: 412 reason: Can't update non-dynamic configuration", nameErr.Error()) + assert.Equal(t, "code: 412 reason: Cannot update non-dynamic configuration", nameErr.Error()) } From 59ef9507870aa80ff40b64b1c7992341b99e7fbf Mon Sep 17 00:00:00 2001 From: Qiang Zhao <74767115+mattisonchao@users.noreply.github.com> Date: Sat, 12 Feb 2022 17:18:01 +0800 Subject: [PATCH 05/24] Revert "Fix test compatibility issue." (#588) This reverts commit dea53de8b628be72e02006761b89852b4127148d. --- pkg/ctl/brokers/delete_dynamic_config_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/ctl/brokers/delete_dynamic_config_test.go b/pkg/ctl/brokers/delete_dynamic_config_test.go index 102d05a1..2698adb0 100644 --- a/pkg/ctl/brokers/delete_dynamic_config_test.go +++ b/pkg/ctl/brokers/delete_dynamic_config_test.go @@ -33,5 +33,5 @@ func TestDeleteDynamicConfig(t *testing.T) { failArgs := []string{"delete-dynamic-config", "--config", "errorName"} _, nameErr, _, _ := TestBrokersCommands(deleteDynamicConfigCmd, failArgs) assert.NotNil(t, nameErr) - assert.Equal(t, "code: 412 reason: Cannot update non-dynamic configuration", nameErr.Error()) + assert.Equal(t, "code: 412 reason: Can't update non-dynamic configuration", nameErr.Error()) } From 0fdce6c48e4eb8f1b5773c2040e0940ad66465d3 Mon Sep 17 00:00:00 2001 From: Zixuan Liu Date: Mon, 14 Feb 2022 14:39:39 +0800 Subject: [PATCH 06/24] test: fix dynamic config assert (#591) Signed-off-by: Zixuan Liu --- pkg/ctl/brokers/delete_dynamic_config_test.go | 3 ++- pkg/ctl/brokers/update_dynamic_config_test.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/ctl/brokers/delete_dynamic_config_test.go b/pkg/ctl/brokers/delete_dynamic_config_test.go index 2698adb0..1cf9d858 100644 --- a/pkg/ctl/brokers/delete_dynamic_config_test.go +++ b/pkg/ctl/brokers/delete_dynamic_config_test.go @@ -18,6 +18,7 @@ package brokers import ( + "strings" "testing" "github.com/stretchr/testify/assert" @@ -33,5 +34,5 @@ func TestDeleteDynamicConfig(t *testing.T) { failArgs := []string{"delete-dynamic-config", "--config", "errorName"} _, nameErr, _, _ := TestBrokersCommands(deleteDynamicConfigCmd, failArgs) assert.NotNil(t, nameErr) - assert.Equal(t, "code: 412 reason: Can't update non-dynamic configuration", nameErr.Error()) + assert.True(t, strings.Contains(nameErr.Error(), "code: 412")) } diff --git a/pkg/ctl/brokers/update_dynamic_config_test.go b/pkg/ctl/brokers/update_dynamic_config_test.go index e8165e74..40e40c86 100644 --- a/pkg/ctl/brokers/update_dynamic_config_test.go +++ b/pkg/ctl/brokers/update_dynamic_config_test.go @@ -19,6 +19,7 @@ package brokers import ( "encoding/json" + "strings" "testing" "github.com/stretchr/testify/assert" @@ -34,7 +35,7 @@ func TestUpdateDynamicConfig(t *testing.T) { failArgs := []string{"update-dynamic-config", "--config", "errorName", "--value", "true"} _, nameErr, _, _ := TestBrokersCommands(updateDynamicConfig, failArgs) assert.NotNil(t, nameErr) - assert.Equal(t, "code: 412 reason: Can't update non-dynamic configuration", nameErr.Error()) + assert.True(t, strings.Contains(nameErr.Error(), "code: 412")) getArgs := []string{"get-all-dynamic-config"} getOut, execErr, _, _ := TestBrokersCommands(getAllDynamicConfigsCmd, getArgs) From 225855ad0829e1a73e9b36af2ac9192a98574caa Mon Sep 17 00:00:00 2001 From: Zixuan Liu Date: Mon, 14 Feb 2022 21:00:57 +0800 Subject: [PATCH 07/24] test: fix the get runtime config (#587) Signed-off-by: Zixuan Liu --- pkg/ctl/brokers/config_test.go | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/pkg/ctl/brokers/config_test.go b/pkg/ctl/brokers/config_test.go index 904c1fe3..b9cefd14 100644 --- a/pkg/ctl/brokers/config_test.go +++ b/pkg/ctl/brokers/config_test.go @@ -47,12 +47,5 @@ func TestGetRuntimeConfig(t *testing.T) { var runtimeConf map[string]string err := json.Unmarshal(runtimeOut.Bytes(), &runtimeConf) assert.Nil(t, err) - - assert.Equal(t, "false", runtimeConf["authenticateOriginalAuthData"]) - assert.Equal(t, "true", runtimeConf["backlogQuotaCheckEnabled"]) - assert.Equal(t, "0.0.0.0", runtimeConf["bindAddress"]) - assert.Equal(t, "127.0.0.1:2181", runtimeConf["zookeeperServers"]) - assert.Equal(t, "30000", runtimeConf["zooKeeperSessionTimeoutMillis"]) - assert.Equal(t, "300000", runtimeConf["webSocketSessionIdleTimeoutMillis"]) - assert.Equal(t, "30", runtimeConf["keepAliveIntervalSeconds"]) + assert.True(t, len(runtimeConf) != 0) } From 681e974cb84e56caa3f66a7395f02f136d421575 Mon Sep 17 00:00:00 2001 From: Zixuan Liu Date: Fri, 18 Feb 2022 10:59:51 +0800 Subject: [PATCH 08/24] fix: fix encode json body (#610) * fix: fix encode json body Signed-off-by: Zixuan Liu * test: fix get_ns_anti_affinity_group test Signed-off-by: Zixuan Liu * chore: fix license Signed-off-by: Zixuan Liu --- pkg/cli/client.go | 7 ++- pkg/cli/client_test.go | 47 +++++++++++++++++++ .../namespace/get_ns_anti_affinity_group.go | 2 +- pkg/ctl/namespace/ns_anti_affinity_test.go | 2 +- 4 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 pkg/cli/client_test.go diff --git a/pkg/cli/client.go b/pkg/cli/client.go index e3775f5e..42f91476 100644 --- a/pkg/cli/client.go +++ b/pkg/cli/client.go @@ -364,12 +364,11 @@ func endpoint(parts ...string) string { // encodeJSONBody is used to JSON encode a body func encodeJSONBody(obj interface{}) (io.Reader, error) { - buf := bytes.NewBuffer(nil) - enc := json.NewEncoder(buf) - if err := enc.Encode(obj); err != nil { + b, err := json.Marshal(obj) + if err != nil { return nil, err } - return buf, nil + return bytes.NewReader(b), nil } // decodeJSONBody is used to JSON decode a body diff --git a/pkg/cli/client_test.go b/pkg/cli/client_test.go new file mode 100644 index 00000000..f5335946 --- /dev/null +++ b/pkg/cli/client_test.go @@ -0,0 +1,47 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package cli + +import ( + "io/ioutil" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestEncodeJSONBody(t *testing.T) { + testcases := []struct { + obj interface{} + expected int + }{ + {obj: "1", expected: 3}, + {obj: "12", expected: 4}, + {obj: 1, expected: 1}, + {obj: 12, expected: 2}, + } + + for _, testcase := range testcases { + r, err := encodeJSONBody(testcase.obj) + require.NoError(t, err) + + b, err := ioutil.ReadAll(r) + require.NoError(t, err) + + require.Equal(t, testcase.expected, len(b)) + } +} diff --git a/pkg/ctl/namespace/get_ns_anti_affinity_group.go b/pkg/ctl/namespace/get_ns_anti_affinity_group.go index 9ba10a50..35986008 100644 --- a/pkg/ctl/namespace/get_ns_anti_affinity_group.go +++ b/pkg/ctl/namespace/get_ns_anti_affinity_group.go @@ -76,7 +76,7 @@ func doGetAntiAffinityGroup(vc *cmdutils.VerbCmd) error { admin := cmdutils.NewPulsarClient() res, err := admin.Namespaces().GetNamespaceAntiAffinityGroup(ns) if err == nil { - vc.Command.Print(res) + vc.Command.Println(res) } return err } diff --git a/pkg/ctl/namespace/ns_anti_affinity_test.go b/pkg/ctl/namespace/ns_anti_affinity_test.go index 80bb2f68..5415ab81 100644 --- a/pkg/ctl/namespace/ns_anti_affinity_test.go +++ b/pkg/ctl/namespace/ns_anti_affinity_test.go @@ -47,5 +47,5 @@ func TestNsAntiAffinityGroup(t *testing.T) { getArgs = []string{"get-anti-affinity-group", "public/test-anti-namespace"} getOut, execErr, _, _ = TestNamespaceCommands(getAntiAffinityGroup, getArgs) assert.Nil(t, execErr) - assert.Equal(t, getOut.String(), "") + assert.Equal(t, getOut.String(), "\n") } From 276ab61be10349814794de2f9cefd097249468c9 Mon Sep 17 00:00:00 2001 From: Zixuan Liu Date: Mon, 21 Feb 2022 19:45:57 +0800 Subject: [PATCH 09/24] ci: use root (#617) Signed-off-by: Zixuan Liu --- scripts/test-docker/Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/test-docker/Dockerfile b/scripts/test-docker/Dockerfile index 287f555d..04fe8fbe 100644 --- a/scripts/test-docker/Dockerfile +++ b/scripts/test-docker/Dockerfile @@ -1,6 +1,9 @@ ARG PULSAR_VERSION FROM streamnative/pulsar-all:$PULSAR_VERSION +# use root user +USER root + # install golang ENV GOLANG_VERSION 1.13.3 RUN curl -sSL https://storage.googleapis.com/golang/go$GOLANG_VERSION.linux-amd64.tar.gz \ From ee35e647761051fd6d829639ee12be46d3b2acc6 Mon Sep 17 00:00:00 2001 From: Lishen Yao Date: Tue, 15 Mar 2022 15:12:25 +0800 Subject: [PATCH 10/24] [CI] Add doc bot (#637) * [workflow] Add a pull request template * [CI] Add doc bot --- .github/PULL_REQUEST_TEMPLATE.md | 69 +++++++++++++++++++++++++++++++ .github/workflows/documentbot.yml | 51 +++++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/workflows/documentbot.yml diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..b6ae3502 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,69 @@ + + + +*(If this PR fixes a github issue, please add `Fixes #`.)* + +Fixes # + +*(or if this PR is one task of a github issue, please add `Master Issue: #` to link to the master issue.)* + +Master Issue: # + +### Motivation + +*Explain here the context, and why you're making that change. What is the problem you're trying to solve.* + +### Modifications + +*Describe the modifications you've done.* + +### Verifying this change + +- [ ] Make sure that the change passes the CI checks. + +*(Please pick either of the following options)* + +This change is a trivial rework / code cleanup without any test coverage. + +*(or)* + +This change is already covered by existing tests, such as *(please describe tests)*. + +*(or)* + +This change added tests and can be verified as follows: + +*(example:)* + - *Added integration tests for end-to-end deployment with large payloads (10MB)* + - *Extended integration test for recovery after broker failure* + +### Documentation + +Check the box below. + +Need to update docs? + +- [ ] `doc-required` + + (If you need help on updating docs, create a doc issue) + +- [ ] `no-need-doc` + + (Please explain why) + +- [ ] `doc` + + (If this PR contains doc changes) + diff --git a/.github/workflows/documentbot.yml b/.github/workflows/documentbot.yml new file mode 100644 index 00000000..e4914df2 --- /dev/null +++ b/.github/workflows/documentbot.yml @@ -0,0 +1,51 @@ + +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +name: Auto Labeling + +on: + pull_request_target : + types: + - opened + - edited + - labeled + + + +# A GitHub token created for a PR coming from a fork doesn't have +# 'admin' or 'write' permission (which is required to add labels) +# To avoid this issue, you can use the `scheduled` event and run +# this action on a certain interval.And check the label about the +# document. + +jobs: + labeling: + if: ${{ github.repository == 'streamnative/pulsarctl' }} + permissions: + pull-requests: write + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - uses: streamnative/github-workflow-libraries/doc-label-check@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + label-pattern: '- \[(.*?)\] ?`(.+?)`' # matches '- [x] `label`' + From 06d64a747f8e7705e33fed1ba161e9d6047ab428 Mon Sep 17 00:00:00 2001 From: Zixuan Liu Date: Mon, 21 Mar 2022 16:22:18 +0800 Subject: [PATCH 11/24] test: fix splite bundle test and update pulsar image (#663) Signed-off-by: Zixuan Liu --- pkg/ctl/namespace/split_bundle_test.go | 18 ++++++++---------- scripts/run-integration-tests.sh | 2 +- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/pkg/ctl/namespace/split_bundle_test.go b/pkg/ctl/namespace/split_bundle_test.go index 9682086d..e678d257 100644 --- a/pkg/ctl/namespace/split_bundle_test.go +++ b/pkg/ctl/namespace/split_bundle_test.go @@ -22,7 +22,7 @@ import ( "testing" "github.com/streamnative/pulsarctl/pkg/ctl/topic" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestSplitBundle(t *testing.T) { @@ -30,28 +30,26 @@ func TestSplitBundle(t *testing.T) { args := []string{"create", ns} _, execErr, _, _ := TestNamespaceCommands(createNs, args) - assert.Nil(t, execErr) + require.Nil(t, execErr) args = []string{"split-bundle", ns, "--bundle", "0x80000000_0xc0000000"} _, execErr, _, _ = TestNamespaceCommands(splitBundle, args) - assert.NotNil(t, execErr) - errMsg := "code: 412 reason: Failed to find ownership for ServiceUnit:" + ns + "/0x80000000_0xc0000000" - assert.Equal(t, execErr.Error(), errMsg) + require.Nil(t, execErr) args = []string{"create", ns + "/test-topic", "0"} _, _, argsErr, err := topic.TestTopicCommands(topic.CreateTopicCmd, args) - assert.Nil(t, argsErr) - assert.Nil(t, err) + require.Nil(t, argsErr) + require.Nil(t, err) args = []string{"bundle-range", ns + "/test-topic"} out, execErr, _, _ := topic.TestTopicCommands(topic.GetBundleRangeCmd, args) - assert.Nil(t, execErr) + require.Nil(t, execErr) bundle := strings.Split(out.String(), ":")[2] bundle = strings.TrimSpace(bundle) args = []string{"split-bundle", ns, "--bundle", bundle} splitOut, execErr, _, _ := TestNamespaceCommands(splitBundle, args) - assert.Nil(t, execErr) - assert.Equal(t, splitOut.String(), "Split a namespace bundle: "+bundle+" successfully\n") + require.Nil(t, execErr) + require.Equal(t, splitOut.String(), "Split a namespace bundle: "+bundle+" successfully\n") } diff --git a/scripts/run-integration-tests.sh b/scripts/run-integration-tests.sh index dec0dfa1..05cbf6a7 100755 --- a/scripts/run-integration-tests.sh +++ b/scripts/run-integration-tests.sh @@ -3,7 +3,7 @@ set -e readonly PROJECT_ROOT=`cd $(dirname $0)/..; pwd` readonly IMAGE_NAME=pulsarctl-test -readonly PULSAR_DEFAULT_VERSION="2.9.1.2" +readonly PULSAR_DEFAULT_VERSION="2.9.2.9" readonly PULSAR_VERSION=${PULSAR_VERSION:-${PULSAR_DEFAULT_VERSION}} docker build --build-arg PULSAR_VERSION=${PULSAR_VERSION} \ From 09f449b33265bc4ee697a2dddffcb81ec78de1a6 Mon Sep 17 00:00:00 2001 From: Zixuan Liu Date: Fri, 29 Apr 2022 23:18:07 +0800 Subject: [PATCH 12/24] fix: use nil instead of empty string as request body (#662) Signed-off-by: Zixuan Liu Co-authored-by: lipenghui --- pkg/pulsar/functions.go | 12 ++++++------ pkg/pulsar/namespace.go | 18 +++++++++--------- pkg/pulsar/sinks.go | 14 +++++++------- pkg/pulsar/sources.go | 14 +++++++------- pkg/pulsar/subscription.go | 10 +++++----- pkg/pulsar/topic.go | 6 +++--- 6 files changed, 37 insertions(+), 37 deletions(-) diff --git a/pkg/pulsar/functions.go b/pkg/pulsar/functions.go index 481ccdb5..f70ee39a 100644 --- a/pkg/pulsar/functions.go +++ b/pkg/pulsar/functions.go @@ -266,14 +266,14 @@ func (f *functions) CreateFuncWithURL(funcConf *utils.FunctionConfig, pkgURL str func (f *functions) StopFunction(tenant, namespace, name string) error { endpoint := f.pulsar.endpoint(f.basePath, tenant, namespace, name) - return f.pulsar.Client.Post(endpoint+"/stop", "") + return f.pulsar.Client.Post(endpoint+"/stop", nil) } func (f *functions) StopFunctionWithID(tenant, namespace, name string, instanceID int) error { id := fmt.Sprintf("%d", instanceID) endpoint := f.pulsar.endpoint(f.basePath, tenant, namespace, name, id) - return f.pulsar.Client.Post(endpoint+"/stop", "") + return f.pulsar.Client.Post(endpoint+"/stop", nil) } func (f *functions) DeleteFunction(tenant, namespace, name string) error { @@ -329,26 +329,26 @@ func (f *functions) DownloadFunctionByNs(destinationFile, tenant, namespace, fun func (f *functions) StartFunction(tenant, namespace, name string) error { endpoint := f.pulsar.endpoint(f.basePath, tenant, namespace, name) - return f.pulsar.Client.Post(endpoint+"/start", "") + return f.pulsar.Client.Post(endpoint+"/start", nil) } func (f *functions) StartFunctionWithID(tenant, namespace, name string, instanceID int) error { id := fmt.Sprintf("%d", instanceID) endpoint := f.pulsar.endpoint(f.basePath, tenant, namespace, name, id) - return f.pulsar.Client.Post(endpoint+"/start", "") + return f.pulsar.Client.Post(endpoint+"/start", nil) } func (f *functions) RestartFunction(tenant, namespace, name string) error { endpoint := f.pulsar.endpoint(f.basePath, tenant, namespace, name) - return f.pulsar.Client.Post(endpoint+"/restart", "") + return f.pulsar.Client.Post(endpoint+"/restart", nil) } func (f *functions) RestartFunctionWithID(tenant, namespace, name string, instanceID int) error { id := fmt.Sprintf("%d", instanceID) endpoint := f.pulsar.endpoint(f.basePath, tenant, namespace, name, id) - return f.pulsar.Client.Post(endpoint+"/restart", "") + return f.pulsar.Client.Post(endpoint+"/restart", nil) } func (f *functions) GetFunctions(tenant, namespace string) ([]string, error) { diff --git a/pkg/pulsar/namespace.go b/pkg/pulsar/namespace.go index 5ca34dd4..f7b2fb10 100644 --- a/pkg/pulsar/namespace.go +++ b/pkg/pulsar/namespace.go @@ -678,7 +678,7 @@ func (n *namespaces) Unload(namespace string) error { return err } endpoint := n.pulsar.endpoint(n.basePath, nsName.String(), "unload") - return n.pulsar.Client.Put(endpoint, "") + return n.pulsar.Client.Put(endpoint, nil) } func (n *namespaces) UnloadNamespaceBundle(namespace, bundle string) error { @@ -687,7 +687,7 @@ func (n *namespaces) UnloadNamespaceBundle(namespace, bundle string) error { return err } endpoint := n.pulsar.endpoint(n.basePath, nsName.String(), bundle, "unload") - return n.pulsar.Client.Put(endpoint, "") + return n.pulsar.Client.Put(endpoint, nil) } func (n *namespaces) SplitNamespaceBundle(namespace, bundle string, unloadSplitBundles bool) error { @@ -699,7 +699,7 @@ func (n *namespaces) SplitNamespaceBundle(namespace, bundle string, unloadSplitB params := map[string]string{ "unload": strconv.FormatBool(unloadSplitBundles), } - return n.pulsar.Client.PutWithQueryParams(endpoint, "", nil, params) + return n.pulsar.Client.PutWithQueryParams(endpoint, nil, nil, params) } func (n *namespaces) GetNamespacePermissions(namespace utils.NameSpaceName) (map[string][]common.AuthAction, error) { @@ -748,33 +748,33 @@ func (n *namespaces) SetEncryptionRequiredStatus(namespace utils.NameSpaceName, func (n *namespaces) UnsubscribeNamespace(namespace utils.NameSpaceName, sName string) error { endpoint := n.pulsar.endpoint(n.basePath, namespace.String(), "unsubscribe", url.QueryEscape(sName)) - return n.pulsar.Client.Post(endpoint, "") + return n.pulsar.Client.Post(endpoint, nil) } func (n *namespaces) UnsubscribeNamespaceBundle(namespace utils.NameSpaceName, bundle, sName string) error { endpoint := n.pulsar.endpoint(n.basePath, namespace.String(), bundle, "unsubscribe", url.QueryEscape(sName)) - return n.pulsar.Client.Post(endpoint, "") + return n.pulsar.Client.Post(endpoint, nil) } func (n *namespaces) ClearNamespaceBundleBacklogForSubscription(namespace utils.NameSpaceName, bundle, sName string) error { endpoint := n.pulsar.endpoint(n.basePath, namespace.String(), bundle, "clearBacklog", url.QueryEscape(sName)) - return n.pulsar.Client.Post(endpoint, "") + return n.pulsar.Client.Post(endpoint, nil) } func (n *namespaces) ClearNamespaceBundleBacklog(namespace utils.NameSpaceName, bundle string) error { endpoint := n.pulsar.endpoint(n.basePath, namespace.String(), bundle, "clearBacklog") - return n.pulsar.Client.Post(endpoint, "") + return n.pulsar.Client.Post(endpoint, nil) } func (n *namespaces) ClearNamespaceBacklogForSubscription(namespace utils.NameSpaceName, sName string) error { endpoint := n.pulsar.endpoint(n.basePath, namespace.String(), "clearBacklog", url.QueryEscape(sName)) - return n.pulsar.Client.Post(endpoint, "") + return n.pulsar.Client.Post(endpoint, nil) } func (n *namespaces) ClearNamespaceBacklog(namespace utils.NameSpaceName) error { endpoint := n.pulsar.endpoint(n.basePath, namespace.String(), "clearBacklog") - return n.pulsar.Client.Post(endpoint, "") + return n.pulsar.Client.Post(endpoint, nil) } func (n *namespaces) SetReplicatorDispatchRate(namespace utils.NameSpaceName, rate utils.DispatchRate) error { diff --git a/pkg/pulsar/sinks.go b/pkg/pulsar/sinks.go index 736e18b0..6f0231f9 100644 --- a/pkg/pulsar/sinks.go +++ b/pkg/pulsar/sinks.go @@ -390,38 +390,38 @@ func (s *sinks) GetSinkStatusWithID(tenant, namespace, sink string, id int) (uti func (s *sinks) RestartSink(tenant, namespace, sink string) error { endpoint := s.pulsar.endpoint(s.basePath, tenant, namespace, sink) - return s.pulsar.Client.Post(endpoint+"/restart", "") + return s.pulsar.Client.Post(endpoint+"/restart", nil) } func (s *sinks) RestartSinkWithID(tenant, namespace, sink string, instanceID int) error { id := fmt.Sprintf("%d", instanceID) endpoint := s.pulsar.endpoint(s.basePath, tenant, namespace, sink, id) - return s.pulsar.Client.Post(endpoint+"/restart", "") + return s.pulsar.Client.Post(endpoint+"/restart", nil) } func (s *sinks) StopSink(tenant, namespace, sink string) error { endpoint := s.pulsar.endpoint(s.basePath, tenant, namespace, sink) - return s.pulsar.Client.Post(endpoint+"/stop", "") + return s.pulsar.Client.Post(endpoint+"/stop", nil) } func (s *sinks) StopSinkWithID(tenant, namespace, sink string, instanceID int) error { id := fmt.Sprintf("%d", instanceID) endpoint := s.pulsar.endpoint(s.basePath, tenant, namespace, sink, id) - return s.pulsar.Client.Post(endpoint+"/stop", "") + return s.pulsar.Client.Post(endpoint+"/stop", nil) } func (s *sinks) StartSink(tenant, namespace, sink string) error { endpoint := s.pulsar.endpoint(s.basePath, tenant, namespace, sink) - return s.pulsar.Client.Post(endpoint+"/start", "") + return s.pulsar.Client.Post(endpoint+"/start", nil) } func (s *sinks) StartSinkWithID(tenant, namespace, sink string, instanceID int) error { id := fmt.Sprintf("%d", instanceID) endpoint := s.pulsar.endpoint(s.basePath, tenant, namespace, sink, id) - return s.pulsar.Client.Post(endpoint+"/start", "") + return s.pulsar.Client.Post(endpoint+"/start", nil) } func (s *sinks) GetBuiltInSinks() ([]*utils.ConnectorDefinition, error) { @@ -433,5 +433,5 @@ func (s *sinks) GetBuiltInSinks() ([]*utils.ConnectorDefinition, error) { func (s *sinks) ReloadBuiltInSinks() error { endpoint := s.pulsar.endpoint(s.basePath, "reloadBuiltInSinks") - return s.pulsar.Client.Post(endpoint, "") + return s.pulsar.Client.Post(endpoint, nil) } diff --git a/pkg/pulsar/sources.go b/pkg/pulsar/sources.go index 7fabfaca..c3484376 100644 --- a/pkg/pulsar/sources.go +++ b/pkg/pulsar/sources.go @@ -393,38 +393,38 @@ func (s *sources) GetSourceStatusWithID(tenant, namespace, source string, id int func (s *sources) RestartSource(tenant, namespace, source string) error { endpoint := s.pulsar.endpoint(s.basePath, tenant, namespace, source) - return s.pulsar.Client.Post(endpoint+"/restart", "") + return s.pulsar.Client.Post(endpoint+"/restart", nil) } func (s *sources) RestartSourceWithID(tenant, namespace, source string, instanceID int) error { id := fmt.Sprintf("%d", instanceID) endpoint := s.pulsar.endpoint(s.basePath, tenant, namespace, source, id) - return s.pulsar.Client.Post(endpoint+"/restart", "") + return s.pulsar.Client.Post(endpoint+"/restart", nil) } func (s *sources) StopSource(tenant, namespace, source string) error { endpoint := s.pulsar.endpoint(s.basePath, tenant, namespace, source) - return s.pulsar.Client.Post(endpoint+"/stop", "") + return s.pulsar.Client.Post(endpoint+"/stop", nil) } func (s *sources) StopSourceWithID(tenant, namespace, source string, instanceID int) error { id := fmt.Sprintf("%d", instanceID) endpoint := s.pulsar.endpoint(s.basePath, tenant, namespace, source, id) - return s.pulsar.Client.Post(endpoint+"/stop", "") + return s.pulsar.Client.Post(endpoint+"/stop", nil) } func (s *sources) StartSource(tenant, namespace, source string) error { endpoint := s.pulsar.endpoint(s.basePath, tenant, namespace, source) - return s.pulsar.Client.Post(endpoint+"/start", "") + return s.pulsar.Client.Post(endpoint+"/start", nil) } func (s *sources) StartSourceWithID(tenant, namespace, source string, instanceID int) error { id := fmt.Sprintf("%d", instanceID) endpoint := s.pulsar.endpoint(s.basePath, tenant, namespace, source, id) - return s.pulsar.Client.Post(endpoint+"/start", "") + return s.pulsar.Client.Post(endpoint+"/start", nil) } func (s *sources) GetBuiltInSources() ([]*utils.ConnectorDefinition, error) { @@ -436,5 +436,5 @@ func (s *sources) GetBuiltInSources() ([]*utils.ConnectorDefinition, error) { func (s *sources) ReloadBuiltInSources() error { endpoint := s.pulsar.endpoint(s.basePath, "reloadBuiltInSources") - return s.pulsar.Client.Post(endpoint, "") + return s.pulsar.Client.Post(endpoint, nil) } diff --git a/pkg/pulsar/subscription.go b/pkg/pulsar/subscription.go index 2def2868..0ac92468 100644 --- a/pkg/pulsar/subscription.go +++ b/pkg/pulsar/subscription.go @@ -111,34 +111,34 @@ func (s *subscriptions) ResetCursorToTimestamp(topic utils.TopicName, sName stri endpoint := s.pulsar.endpoint( s.basePath, topic.GetRestPath(), s.SubPath, url.PathEscape(sName), "resetcursor", strconv.FormatInt(timestamp, 10)) - return s.pulsar.Client.Post(endpoint, "") + return s.pulsar.Client.Post(endpoint, nil) } func (s *subscriptions) ClearBacklog(topic utils.TopicName, sName string) error { endpoint := s.pulsar.endpoint( s.basePath, topic.GetRestPath(), s.SubPath, url.PathEscape(sName), "skip_all") - return s.pulsar.Client.Post(endpoint, "") + return s.pulsar.Client.Post(endpoint, nil) } func (s *subscriptions) SkipMessages(topic utils.TopicName, sName string, n int64) error { endpoint := s.pulsar.endpoint( s.basePath, topic.GetRestPath(), s.SubPath, url.PathEscape(sName), "skip", strconv.FormatInt(n, 10)) - return s.pulsar.Client.Post(endpoint, "") + return s.pulsar.Client.Post(endpoint, nil) } func (s *subscriptions) ExpireMessages(topic utils.TopicName, sName string, expire int64) error { endpoint := s.pulsar.endpoint( s.basePath, topic.GetRestPath(), s.SubPath, url.PathEscape(sName), "expireMessages", strconv.FormatInt(expire, 10)) - return s.pulsar.Client.Post(endpoint, "") + return s.pulsar.Client.Post(endpoint, nil) } func (s *subscriptions) ExpireAllMessages(topic utils.TopicName, expire int64) error { endpoint := s.pulsar.endpoint( s.basePath, topic.GetRestPath(), "all_subscription", "expireMessages", strconv.FormatInt(expire, 10)) - return s.pulsar.Client.Post(endpoint, "") + return s.pulsar.Client.Post(endpoint, nil) } func (s *subscriptions) PeekMessages(topic utils.TopicName, sName string, n int) ([]*utils.Message, error) { diff --git a/pkg/pulsar/topic.go b/pkg/pulsar/topic.go index c857bf96..65defeae 100644 --- a/pkg/pulsar/topic.go +++ b/pkg/pulsar/topic.go @@ -401,7 +401,7 @@ func (t *topics) GetPartitionedStats(topic utils.TopicName, perPartition bool) ( func (t *topics) Terminate(topic utils.TopicName) (utils.MessageID, error) { endpoint := t.pulsar.endpoint(t.basePath, topic.GetRestPath(), "terminate") var messageID utils.MessageID - err := t.pulsar.Client.PostWithObj(endpoint, "", &messageID) + err := t.pulsar.Client.PostWithObj(endpoint, nil, &messageID) return messageID, err } @@ -419,12 +419,12 @@ func (t *topics) OffloadStatus(topic utils.TopicName) (utils.OffloadProcessStatu func (t *topics) Unload(topic utils.TopicName) error { endpoint := t.pulsar.endpoint(t.basePath, topic.GetRestPath(), "unload") - return t.pulsar.Client.Put(endpoint, "") + return t.pulsar.Client.Put(endpoint, nil) } func (t *topics) Compact(topic utils.TopicName) error { endpoint := t.pulsar.endpoint(t.basePath, topic.GetRestPath(), "compaction") - return t.pulsar.Client.Put(endpoint, "") + return t.pulsar.Client.Put(endpoint, nil) } func (t *topics) CompactStatus(topic utils.TopicName) (utils.LongRunningProcessStatus, error) { From 4fce5a901f98b16f290f976b44881c9c0d967f1d Mon Sep 17 00:00:00 2001 From: Rui Fu Date: Thu, 5 May 2022 23:07:02 +0800 Subject: [PATCH 13/24] support build with go 1.18 (#699) * support build with go 1.18 * update to 1.18 * drop darwin/386 support via go 1.15 * change 1.13 to 1.18 * use latest version of golangci-lint * fix style * address comment * address comment * address comment * fix --- .github/workflows/ci-bookie-checks.yml | 4 +- .github/workflows/ci-functions-checks.yml | 12 ++--- .github/workflows/ci-packages-checks.yml | 4 +- .github/workflows/ci-release-checks.yml | 6 ++- .github/workflows/ci-style-checks.yml | 6 +-- go.mod | 54 ++++++++++++++++++----- go.sum | 4 +- pkg/bookkeeper/bkdata/bookie_data.go | 2 +- pkg/cmdutils/cmdutils.go | 2 +- pkg/ctl/brokers/healthcheck_test.go | 2 +- pkg/ctl/context/internal/config_access.go | 4 +- pkg/ctl/functions/update_test.go | 2 +- pkg/ctl/functions/upload_test.go | 9 ++-- pkg/ctl/functions/util.go | 2 +- pkg/ctl/sources/create.go | 2 +- pkg/ctl/subscription/skip_test.go | 8 ++-- pkg/plugin/plugin.go | 2 +- pkg/pulsar/subscription.go | 2 +- pkg/pulsar/tenant.go | 2 +- pkg/pulsar/utils/namespace_name.go | 7 +-- pkg/pulsar/utils/resources.go | 2 +- pkg/pulsar/utils/topics_stats_stream.go | 2 +- scripts/test-docker/Dockerfile | 2 +- site/gen-pulsarctldocs/generators/gen.go | 26 +++++------ 24 files changed, 97 insertions(+), 71 deletions(-) diff --git a/.github/workflows/ci-bookie-checks.yml b/.github/workflows/ci-bookie-checks.yml index 0786305c..f42e3eca 100644 --- a/.github/workflows/ci-bookie-checks.yml +++ b/.github/workflows/ci-bookie-checks.yml @@ -11,10 +11,10 @@ jobs: bookie-ut-tests: runs-on: ubuntu-latest steps: - - name: Set up Go 1.13 + - name: Set up Go 1.18 uses: actions/setup-go@v1 with: - go-version: 1.13 + go-version: 1.18 id: go - name: Check out code into the Go module directory uses: actions/checkout@v2 diff --git a/.github/workflows/ci-functions-checks.yml b/.github/workflows/ci-functions-checks.yml index af7a70c2..1d209a77 100644 --- a/.github/workflows/ci-functions-checks.yml +++ b/.github/workflows/ci-functions-checks.yml @@ -11,10 +11,10 @@ jobs: function-tests: runs-on: ubuntu-latest steps: - - name: Set up Go 1.13 + - name: Set up Go 1.18 uses: actions/setup-go@v1 with: - go-version: 1.13 + go-version: 1.18 id: go - name: Check out code into the Go module directory uses: actions/checkout@v2 @@ -23,10 +23,10 @@ jobs: sink-tests: runs-on: ubuntu-latest steps: - - name: Set up Go 1.13 + - name: Set up Go 1.18 uses: actions/setup-go@v1 with: - go-version: 1.13 + go-version: 1.18 id: go - name: Check out code into the Go module directory uses: actions/checkout@v2 @@ -35,10 +35,10 @@ jobs: source-tests: runs-on: ubuntu-latest steps: - - name: Set up Go 1.13 + - name: Set up Go 1.18 uses: actions/setup-go@v1 with: - go-version: 1.13 + go-version: 1.18 id: go - name: Check out code into the Go module directory uses: actions/checkout@v2 diff --git a/.github/workflows/ci-packages-checks.yml b/.github/workflows/ci-packages-checks.yml index 391107f4..22548421 100644 --- a/.github/workflows/ci-packages-checks.yml +++ b/.github/workflows/ci-packages-checks.yml @@ -11,10 +11,10 @@ jobs: packages-tests: runs-on: ubuntu-latest steps: - - name: Set up Go 1.13 + - name: Set up Go 1.18 uses: actions/setup-go@v1 with: - go-version: 1.13 + go-version: 1.18 id: go - name: Check out code into the Go module directory uses: actions/checkout@v2 diff --git a/.github/workflows/ci-release-checks.yml b/.github/workflows/ci-release-checks.yml index 67f51733..ec8695d4 100644 --- a/.github/workflows/ci-release-checks.yml +++ b/.github/workflows/ci-release-checks.yml @@ -12,11 +12,14 @@ on: jobs: release-check: runs-on: ubuntu-latest + strategy: + matrix: + go-version: [ 1.13, 1.14, 1.15, 1.16, 1.17, 1.18 ] steps: - uses: actions/checkout@v2 - uses: actions/setup-go@v1 with: - go-version: 1.13 + go-version: ${{ matrix.go-version }} id: go - name: build @@ -25,7 +28,6 @@ jobs: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o pulsarctl-amd64-linux -ldflags "-X github.com/streamnative/pulsarctl/pkg/pulsar.ReleaseVersion=Pulsarctl-Go-$version" . CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -o pulsarctl-386-linux -ldflags "-X github.com/streamnative/pulsarctl/pkg/pulsar.ReleaseVersion=Pulsarctl-Go-$version" . CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o pulsarctl-amd64-darwin -ldflags "-X github.com/streamnative/pulsarctl/pkg/pulsar.ReleaseVersion=Pulsarctl-Go-$version" . - CGO_ENABLED=0 GOOS=darwin GOARCH=386 go build -o pulsarctl-386-darwin -ldflags "-X github.com/streamnative/pulsarctl/pkg/pulsar.ReleaseVersion=Pulsarctl-Go-$version" . CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o pulsarctl-amd64-windows.exe -ldflags "-X github.com/streamnative/pulsarctl/pkg/pulsar.ReleaseVersion=Pulsarctl-Go-$version" . CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -o pulsarctl-386-windows.exe -ldflags "-X github.com/streamnative/pulsarctl/pkg/pulsar.ReleaseVersion=Pulsarctl-Go-$version" . - name: build-site diff --git a/.github/workflows/ci-style-checks.yml b/.github/workflows/ci-style-checks.yml index cf875022..42a1ad2e 100644 --- a/.github/workflows/ci-style-checks.yml +++ b/.github/workflows/ci-style-checks.yml @@ -11,16 +11,16 @@ jobs: style-check: runs-on: ubuntu-latest steps: - - name: Set up Go 1.13 + - name: Set up Go 1.18 uses: actions/setup-go@v1 with: - go-version: 1.13 + go-version: 1.18 id: go - name: Check out code into the Go module directory uses: actions/checkout@v2 - name: InstallTool run: | - wget -O - -q https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s v1.18.0 + wget -O - -q https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s v1.45.2 ./bin/golangci-lint --version - name: Build run: go build . diff --git a/go.mod b/go.mod index f7672654..f75a2a1d 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/streamnative/pulsarctl -go 1.13 +go 1.18 require ( github.com/99designs/keyring v1.1.6 @@ -9,31 +9,65 @@ require ( github.com/fatih/color v1.7.0 github.com/form3tech-oss/jwt-go v3.2.3+incompatible github.com/ghodss/yaml v1.0.0 - github.com/go-sql-driver/mysql v1.5.0 // indirect - github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/protobuf v1.5.2 - github.com/gorilla/mux v1.7.4 // indirect github.com/imdario/mergo v0.3.8 - github.com/kr/pretty v0.2.0 // indirect github.com/kris-nova/logger v0.0.0-20181127235838-fd0d87064b06 github.com/kris-nova/lolgopher v0.0.0-20180921204813-313b3abb0d9b github.com/magiconair/properties v1.8.0 - github.com/mattn/go-colorable v0.1.2 // indirect - github.com/mattn/go-runewidth v0.0.4 // indirect github.com/olekukonko/tablewriter v0.0.1 github.com/onsi/gomega v1.18.0 github.com/pkg/errors v0.9.1 - github.com/sirupsen/logrus v1.4.2 // indirect github.com/spf13/cobra v0.0.5 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.5.1 github.com/testcontainers/testcontainers-go v0.0.10 golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93 + gopkg.in/yaml.v2 v2.4.0 +) + +require ( + github.com/Microsoft/go-winio v0.4.11 // indirect + github.com/Microsoft/hcsshim v0.8.6 // indirect + github.com/cenkalti/backoff v2.2.1+incompatible // indirect + github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc // indirect + github.com/danieljoos/wincred v1.0.2 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/docker/distribution v2.7.1-0.20190205005809-0d3efadf0154+incompatible // indirect + github.com/docker/docker v0.7.3-0.20190506211059-b20a14b54661 // indirect + github.com/docker/go-units v0.3.3 // indirect + github.com/dvsekhvalnov/jose2go v0.0.0-20200901110807-248326c1351b // indirect + github.com/go-sql-driver/mysql v1.5.0 // indirect + github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect + github.com/gogo/protobuf v1.3.2 // indirect + github.com/gorilla/mux v1.7.4 // indirect + github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect + github.com/inconshreveable/mousetrap v1.0.0 // indirect + github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d // indirect + github.com/konsorten/go-windows-terminal-sequences v1.0.1 // indirect + github.com/kr/pretty v0.2.0 // indirect + github.com/mattn/go-colorable v0.1.2 // indirect + github.com/mattn/go-isatty v0.0.8 // indirect + github.com/mattn/go-runewidth v0.0.4 // indirect + github.com/mitchellh/go-homedir v1.1.0 // indirect + github.com/mtibben/percent v0.2.1 // indirect + github.com/opencontainers/go-digest v1.0.0-rc1 // indirect + github.com/opencontainers/image-spec v1.0.1 // indirect + github.com/opencontainers/runc v0.1.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/satori/go.uuid v1.2.0 // indirect + github.com/sirupsen/logrus v1.4.2 // indirect + golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect + golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 // indirect + golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 // indirect + golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 // indirect + golang.org/x/text v0.3.6 // indirect google.golang.org/appengine v1.6.7 // indirect + google.golang.org/genproto v0.0.0-20200825200019-8632dd797987 // indirect + google.golang.org/grpc v1.31.0 // indirect + google.golang.org/protobuf v1.26.0 // indirect gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect - gopkg.in/yaml.v2 v2.4.0 ) replace github.com/apache/pulsar-client-go/oauth2 => github.com/apache/pulsar-client-go/oauth2 v0.0.0-20211006154457-742f1b107403 -replace golang.org/x/sys => golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 +replace golang.org/x/sys => golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 diff --git a/go.sum b/go.sum index aa7d578b..0a78f983 100644 --- a/go.sum +++ b/go.sum @@ -359,8 +359,8 @@ golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 h1:SQFwaSi55rU7vdNs9Yr0Z324VNlrF+0wMqRXT4St8ck= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 h1:xHms4gcpe1YE7A3yIllJXP16CMAGuqwO2lX1mTyyRRc= +golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/pkg/bookkeeper/bkdata/bookie_data.go b/pkg/bookkeeper/bkdata/bookie_data.go index 32b0409c..b8f8c8bd 100644 --- a/pkg/bookkeeper/bkdata/bookie_data.go +++ b/pkg/bookkeeper/bkdata/bookie_data.go @@ -22,7 +22,7 @@ type GCStatus struct { ForceCompacting bool `json:"forceCompacting"` // whether the GC thread is in major compacting MajorCompacting bool `json:"majorCompacting"` - //whether the GC thread is in minor compacting + // whether the GC thread is in minor compacting MinorCompacting bool `json:"minorCompacting"` LastMajorCompactionTime int64 `json:"lastMajorCompactionTime"` diff --git a/pkg/cmdutils/cmdutils.go b/pkg/cmdutils/cmdutils.go index 25d1b6f4..7861aa3f 100644 --- a/pkg/cmdutils/cmdutils.go +++ b/pkg/cmdutils/cmdutils.go @@ -77,7 +77,7 @@ func GetNameArgs(args []string, check func(args []string) error) ([]string, erro if err != nil { logger.Critical(err.Error()) CheckNameArgError(err) - //for testing + // for testing return nil, err } return args, nil diff --git a/pkg/ctl/brokers/healthcheck_test.go b/pkg/ctl/brokers/healthcheck_test.go index 3233a1ee..5828e0c1 100644 --- a/pkg/ctl/brokers/healthcheck_test.go +++ b/pkg/ctl/brokers/healthcheck_test.go @@ -28,6 +28,6 @@ func TestHealthCheck(t *testing.T) { args := []string{"healthcheck"} checkOut, execErr, _, _ := TestBrokersCommands(healthCheckCmd, args) assert.Nil(t, execErr) - str := strings.Replace(checkOut.String(), "\n", "", -1) + str := strings.ReplaceAll(checkOut.String(), "\n", "") assert.Equal(t, "ok", str) } diff --git a/pkg/ctl/context/internal/config_access.go b/pkg/ctl/context/internal/config_access.go index cbfc0f94..5dce572f 100644 --- a/pkg/ctl/context/internal/config_access.go +++ b/pkg/ctl/context/internal/config_access.go @@ -172,11 +172,11 @@ func ModifyConfig(configAccess ConfigAccess, newConfig cmdutils.Config, relativi t := *authInfo configToWrite.AuthInfos[key] = &t configToWrite.AuthInfos[key].LocationOfOrigin = destinationFile - //if relativizePaths { + // if relativizePaths { // if err := RelativizeAuthInfoLocalPaths(configToWrite.AuthInfos[key]); err != nil { // return err // } - //} + // } if err := WriteToFile(*configToWrite, destinationFile); err != nil { return err diff --git a/pkg/ctl/functions/update_test.go b/pkg/ctl/functions/update_test.go index cea26faf..9640acaf 100644 --- a/pkg/ctl/functions/update_test.go +++ b/pkg/ctl/functions/update_test.go @@ -99,7 +99,7 @@ func TestUpdateFunctionsFailure(t *testing.T) { failMsg := "Function not-exist doesn't exist" assert.True(t, strings.Contains(err.Error(), failMsg)) - //test no change for update + // test no change for update noChangeArgs := []string{"update", "--name", fname, "--output", "persistent://public/default/test-output-topic", diff --git a/pkg/ctl/functions/upload_test.go b/pkg/ctl/functions/upload_test.go index 5b16c360..e71ce993 100644 --- a/pkg/ctl/functions/upload_test.go +++ b/pkg/ctl/functions/upload_test.go @@ -81,16 +81,15 @@ exec $JAVA $OPTS org.apache.pulsar.admin.cli.PulsarAdminTool $PULSAR_CLIENT_CONF func TestUploadAndDownloadCommands(t *testing.T) { f, err := ioutil.TempFile(".", "test") - defer os.RemoveAll(f.Name()) if err != nil { log.Fatal(err) t.Fail() return } - + defer os.RemoveAll(f.Name()) err = ioutil.WriteFile(f.Name(), []byte(fileContent), os.ModePerm) if err != nil { - log.Fatal(err) + log.Panic(err) t.Fail() return } @@ -98,7 +97,7 @@ func TestUploadAndDownloadCommands(t *testing.T) { testFile := f.Name() fileHash, err := getFileSha256(testFile) if err != nil { - log.Fatal(err) + log.Panic(err) t.Fail() } @@ -125,7 +124,7 @@ func TestUploadAndDownloadCommands(t *testing.T) { downloadFileSha, err := getFileSha256(downloadFilePath) if err != nil { - log.Fatal(err) + log.Panic(err) t.Fail() } assert.Equal(t, fileHash, downloadFileSha) diff --git a/pkg/ctl/functions/util.go b/pkg/ctl/functions/util.go index 16c917c2..9a688730 100644 --- a/pkg/ctl/functions/util.go +++ b/pkg/ctl/functions/util.go @@ -280,7 +280,7 @@ func validateFunctionConfigs(functionConfig *util.FunctionConfig) error { return errors.New("either a Java jar or a Python file or a Go executable binary needs to " + "be specified for the function. Please specify one") case 1: - //proceed + // proceed default: return errors.New("either a Java jar or a Python file or a Go executable binary needs to " + "be specified for the function, cannot specify more than one") diff --git a/pkg/ctl/sources/create.go b/pkg/ctl/sources/create.go index 3ac9cc7c..e38b0195 100644 --- a/pkg/ctl/sources/create.go +++ b/pkg/ctl/sources/create.go @@ -108,7 +108,7 @@ func createSourcesCmd(vc *cmdutils.VerbCmd) { Out: "[✖] Source archive not specified", } - //Cannot specify both archive and source-type + // Cannot specify both archive and source-type sourceTypeOut := cmdutils.Output{ Desc: "Cannot specify both archive and source-type, please check --archive and --source-type args", Out: "[✖] Cannot specify both archive and source-type", diff --git a/pkg/ctl/subscription/skip_test.go b/pkg/ctl/subscription/skip_test.go index af959649..8b6a3fec 100644 --- a/pkg/ctl/subscription/skip_test.go +++ b/pkg/ctl/subscription/skip_test.go @@ -35,10 +35,10 @@ func TestSkipCmd(t *testing.T) { "persistent://public/default/test-skip-messages-topic successfully\n", out.String()) // TODO: reopen this when issue https://github.com/apache/pulsar/issues/9032 fixed. - //args = []string{"skip", "--all", "test-skip-messages-topic", "test-skip-messages-sub"} - //out, execErr, _, _ = TestSubCommands(SkipCmd, args) - //assert.Nil(t, execErr) - //assert.Equal(t, "The subscription test-skip-messages-sub skips -1 messages of the topic "+ + // args = []string{"skip", "--all", "test-skip-messages-topic", "test-skip-messages-sub"} + // out, execErr, _, _ = TestSubCommands(SkipCmd, args) + // assert.Nil(t, execErr) + // assert.Equal(t, "The subscription test-skip-messages-sub skips -1 messages of the topic "+ // "persistent://public/default/test-skip-messages-topic successfully\n", out.String()) } diff --git a/pkg/plugin/plugin.go b/pkg/plugin/plugin.go index 5b749223..e138394e 100644 --- a/pkg/plugin/plugin.go +++ b/pkg/plugin/plugin.go @@ -110,7 +110,7 @@ func HandlePluginCommand(pluginHandler Handler, cmdArgs []string) error { if strings.HasPrefix(cmdArgs[idx], "-") { break } - remainingArgs = append(remainingArgs, strings.Replace(cmdArgs[idx], "-", "_", -1)) + remainingArgs = append(remainingArgs, strings.ReplaceAll(cmdArgs[idx], "-", "_")) } foundBinaryPath := "" diff --git a/pkg/pulsar/subscription.go b/pkg/pulsar/subscription.go index 0ac92468..64b01521 100644 --- a/pkg/pulsar/subscription.go +++ b/pkg/pulsar/subscription.go @@ -261,7 +261,7 @@ func getIndividualMsgsFromBatch(topic utils.TopicName, msgID *utils.MessageID, d } } - //payload + // payload singlePayload := make([]byte, singleMeta.GetPayloadSize()) if _, err := io.ReadFull(rdBuf, singlePayload); err != nil { return nil, err diff --git a/pkg/pulsar/tenant.go b/pkg/pulsar/tenant.go index 1d85d97d..bcdbe696 100644 --- a/pkg/pulsar/tenant.go +++ b/pkg/pulsar/tenant.go @@ -32,7 +32,7 @@ type Tenants interface { // Update the admins for a tenant Update(utils.TenantData) error - //List returns the list of tenants + // List returns the list of tenants List() ([]string, error) // Get returns the config of the tenant. diff --git a/pkg/pulsar/utils/namespace_name.go b/pkg/pulsar/utils/namespace_name.go index f35c66ee..59fb8d47 100644 --- a/pkg/pulsar/utils/namespace_name.go +++ b/pkg/pulsar/utils/namespace_name.go @@ -81,13 +81,8 @@ func validateNamespaceName(tenant, namespace string) error { // allowed characters for property, namespace, cluster and topic // names are alphanumeric (a-zA-Z0-9) and these special chars -=:. // and % is allowed as part of valid URL encoding -const PATTEN = "^[-=:.\\w]*$" +var patten = regexp.MustCompile("^[-=:.\\w]*$") func CheckName(name string) bool { - patten, err := regexp.Compile(PATTEN) - if err != nil { - return false - } - return patten.MatchString(name) } diff --git a/pkg/pulsar/utils/resources.go b/pkg/pulsar/utils/resources.go index f5da7b87..d5b7f3f0 100644 --- a/pkg/pulsar/utils/resources.go +++ b/pkg/pulsar/utils/resources.go @@ -25,7 +25,7 @@ type Resources struct { func NewDefaultResources() *Resources { resources := &Resources{ - //Default cpu is 1 core + // Default cpu is 1 core CPU: 1, // Default memory is 1GB Disk: 1073741824, diff --git a/pkg/pulsar/utils/topics_stats_stream.go b/pkg/pulsar/utils/topics_stats_stream.go index 1af615a2..7554609e 100644 --- a/pkg/pulsar/utils/topics_stats_stream.go +++ b/pkg/pulsar/utils/topics_stats_stream.go @@ -17,7 +17,7 @@ package utils -//var TopicsMap map[string]map[string]map[string]TopicStats +// var TopicsMap map[string]map[string]map[string]TopicStats type TopicStatsStream struct { TopicsMap map[string]map[string]map[string]TopicStats `json:"topicStatsBuf"` diff --git a/scripts/test-docker/Dockerfile b/scripts/test-docker/Dockerfile index 04fe8fbe..8d317992 100644 --- a/scripts/test-docker/Dockerfile +++ b/scripts/test-docker/Dockerfile @@ -5,7 +5,7 @@ FROM streamnative/pulsar-all:$PULSAR_VERSION USER root # install golang -ENV GOLANG_VERSION 1.13.3 +ENV GOLANG_VERSION 1.18.1 RUN curl -sSL https://storage.googleapis.com/golang/go$GOLANG_VERSION.linux-amd64.tar.gz \ | tar -C /usr/local -xz ENV PATH /usr/local/go/bin:$PATH diff --git a/site/gen-pulsarctldocs/generators/gen.go b/site/gen-pulsarctldocs/generators/gen.go index edc04f87..67721388 100644 --- a/site/gen-pulsarctldocs/generators/gen.go +++ b/site/gen-pulsarctldocs/generators/gen.go @@ -22,6 +22,7 @@ import ( "flag" "fmt" "io/ioutil" + "log" "os" "path/filepath" "strings" @@ -228,7 +229,7 @@ func WriteCommandFiles(manifest *Manifest, toc ToC, params PulsarctlSpec) { manifest.Docs = append(manifest.Docs, Doc{strings.ToLower(c.Include)}) } else { // Write a general category include - fn := strings.Replace(c.Name, " ", "_", -1) + fn := strings.ReplaceAll(c.Name, " ", "_") manifest.Docs = append(manifest.Docs, Doc{strings.ToLower(fmt.Sprintf("_generated_category_%s.md", fn))}) WriteCategoryFile(c) } @@ -259,41 +260,36 @@ func WriteCategoryFile(c Category) { os.Exit(1) } - fn := strings.Replace(c.Name, " ", "_", -1) + fn := strings.ReplaceAll(c.Name, " ", "_") f, err := os.Create(*GenPulsarctlDir + "/includes/_generated_category_" + strings.ToLower(fmt.Sprintf("%s.md", fn))) + defer f.Close() if err != nil { - fmt.Printf("Failed to open index: %v", err) - os.Exit(1) + log.Panicf("Failed to open index: %v", err) } - defer f.Close() err = ct.Execute(f, c) if err != nil { - fmt.Printf("Failed to execute template: %v", err) - os.Exit(1) + log.Panicf("Failed to execute template: %v", err) } } func WriteCommandFile(manifest *Manifest, t *template.Template, params TopLevelCommand) { - params.MainCommand.Description = strings.Replace(params.MainCommand.Description, "|", "|", -1) + params.MainCommand.Description = strings.ReplaceAll(params.MainCommand.Description, "|", "|") for _, o := range params.MainCommand.Options { - o.Usage = strings.Replace(o.Usage, "|", "|", -1) + o.Usage = strings.ReplaceAll(o.Usage, "|", "|") } for _, sc := range params.SubCommands { for _, o := range sc.Options { - o.Usage = strings.Replace(o.Usage, "|", "|", -1) + o.Usage = strings.ReplaceAll(o.Usage, "|", "|") } } f, err := os.Create(*GenPulsarctlDir + "/includes/_generated_" + strings.ToLower(params.MainCommand.Name) + ".md") if err != nil { - fmt.Printf("Failed to open index: %v", err) - os.Exit(1) + log.Panicf("Failed to open index: %v", err) } defer f.Close() - err = t.Execute(f, params) if err != nil { - fmt.Printf("Failed to execute template: %v", err) - os.Exit(1) + log.Panicf("Failed to execute template: %v", err) } manifest.Docs = append(manifest.Docs, Doc{"_generated_" + strings.ToLower(params.MainCommand.Name) + ".md"}) } From 6a080241f0731a09b4c53be8c2df8dbc87a3a74f Mon Sep 17 00:00:00 2001 From: Huaming Rao <1218550+raohuaming@users.noreply.github.com> Date: Wed, 18 May 2022 10:19:30 +0800 Subject: [PATCH 14/24] fix: skip fix_mac_openssl for non-mac os in pulsarctl-security_tool (#710) --- plugins/pulsarctl-security_tool | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/pulsarctl-security_tool b/plugins/pulsarctl-security_tool index f3f2cf89..7dd0fb00 100755 --- a/plugins/pulsarctl-security_tool +++ b/plugins/pulsarctl-security_tool @@ -403,7 +403,9 @@ function ensure_dependencies() { fi done # fix open ssl if needed - fix_mac_openssl + if [[ "$OSTYPE" == "darwin"* ]]; then + fix_mac_openssl + fi } # if no args specified, show usage From 0230b47b22760ca6170df3b0ceaec6ba68f682aa Mon Sep 17 00:00:00 2001 From: AlvaroStream <102966649+AlvaroStream@users.noreply.github.com> Date: Wed, 1 Jun 2022 17:40:22 +0200 Subject: [PATCH 15/24] Add the update-auth data option to sink update and sources update (#728) * Add the update-auth data option to sink update and sources update * solve copy paste issue --- pkg/ctl/sinks/update.go | 6 ++++++ pkg/ctl/sources/update.go | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/pkg/ctl/sinks/update.go b/pkg/ctl/sinks/update.go index a7e2f7c3..3e26f2b1 100644 --- a/pkg/ctl/sinks/update.go +++ b/pkg/ctl/sinks/update.go @@ -249,6 +249,12 @@ func updateSinksCmd(vc *cmdutils.VerbCmd) { "timeout-ms", 0, "The message timeout in milliseconds") + + flagSet.BoolVar( + &sinkData.UpdateAuthData, + "update-auth-data", + false, + "Whether or not to update the auth data") }) vc.EnableOutputFlagSet() } diff --git a/pkg/ctl/sources/update.go b/pkg/ctl/sources/update.go index 4c721a86..e26abfe1 100644 --- a/pkg/ctl/sources/update.go +++ b/pkg/ctl/sources/update.go @@ -209,6 +209,12 @@ func updateSourcesCmd(vc *cmdutils.VerbCmd) { "source-config", "", "Source config key/values") + + flagSet.BoolVar( + &sourceData.UpdateAuthData, + "update-auth-data", + false, + "Whether or not to update the auth data") }) } From 64d37ff28ba41c77d2f0c5532e23201a0fd3a0a5 Mon Sep 17 00:00:00 2001 From: Zixuan Liu Date: Mon, 6 Jun 2022 18:04:37 +0800 Subject: [PATCH 16/24] fix: fix tls insecure connection (#731) Signed-off-by: Zixuan Liu --- pkg/auth/auth_provider.go | 4 +- pkg/pulsar/admin.go | 53 ++++++++++++------------ pkg/pulsar/admin_test.go | 75 +++++++++++++++++++++++++++++++++- pkg/pulsar/utils/utils_test.go | 6 +++ 4 files changed, 109 insertions(+), 29 deletions(-) diff --git a/pkg/auth/auth_provider.go b/pkg/auth/auth_provider.go index c0368637..90dda433 100644 --- a/pkg/auth/auth_provider.go +++ b/pkg/auth/auth_provider.go @@ -37,7 +37,7 @@ type Transport struct { T http.RoundTripper } -func GetAuthProvider(config *common.Config) (*Provider, error) { +func GetAuthProvider(config *common.Config) (Provider, error) { var provider Provider defaultTransport, err := NewDefaultTransport(config) if err != nil { @@ -65,7 +65,7 @@ func GetAuthProvider(config *common.Config) (*Provider, error) { config.IssuerEndpoint, config.ClientID, config.Audience, config.Scope, defaultTransport) } } - return &provider, err + return provider, err } // GetDefaultTransport gets a default transport. diff --git a/pkg/pulsar/admin.go b/pkg/pulsar/admin.go index 2e4f5ff3..be52e8d5 100644 --- a/pkg/pulsar/admin.go +++ b/pkg/pulsar/admin.go @@ -18,7 +18,6 @@ package pulsar import ( - "fmt" "net/http" "net/url" "path" @@ -61,28 +60,11 @@ type pulsarClient struct { // New returns a new client func New(config *common.Config) (Client, error) { - if len(config.WebServiceURL) == 0 { - config.WebServiceURL = DefaultWebServiceURL - } - - c := &pulsarClient{ - APIVersion: config.PulsarAPIVersion, - Client: &cli.Client{ - ServiceURL: config.WebServiceURL, - VersionInfo: ReleaseVersion, - HTTPClient: &http.Client{ - Timeout: DefaultHTTPTimeOutDuration, - }, - }, - } - authProvider, err := auth.GetAuthProvider(config) - if !utils.IsNilFixed(authProvider) { - c.Client.HTTPClient.Transport = *authProvider - } else { - fmt.Printf("No Auth Provider found\n") + if err != nil { + return nil, err } - return c, err + return NewPulsarClientWithAuthProvider(config, authProvider) } // NewWithAuthProvider creates a client with auth provider. @@ -98,12 +80,31 @@ func NewWithAuthProvider(config *common.Config, authProvider auth.Provider) Clie // NewPulsarClientWithAuthProvider create a client with auth provider. func NewPulsarClientWithAuthProvider(config *common.Config, authProvider auth.Provider) (Client, error) { - defaultTransport, err := auth.NewDefaultTransport(config) - if err != nil { - return nil, err + var transport http.RoundTripper + + if authProvider != nil { + transport = authProvider.Transport() + if transport != nil { + transport = authProvider + } + } + + if transport == nil { + defaultTransport, err := auth.NewDefaultTransport(config) + if err != nil { + return nil, err + } + if authProvider != nil { + authProvider.WithTransport(authProvider) + } else { + transport = defaultTransport + } } - authProvider.WithTransport(defaultTransport) + webServiceURL := config.WebServiceURL + if len(webServiceURL) == 0 { + config.WebServiceURL = DefaultWebServiceURL + } c := &pulsarClient{ APIVersion: config.PulsarAPIVersion, @@ -112,7 +113,7 @@ func NewPulsarClientWithAuthProvider(config *common.Config, VersionInfo: ReleaseVersion, HTTPClient: &http.Client{ Timeout: DefaultHTTPTimeOutDuration, - Transport: authProvider, + Transport: transport, }, }, } diff --git a/pkg/pulsar/admin_test.go b/pkg/pulsar/admin_test.go index 44a8b47e..8e3afef4 100644 --- a/pkg/pulsar/admin_test.go +++ b/pkg/pulsar/admin_test.go @@ -18,11 +18,13 @@ package pulsar import ( + "net/http" "testing" + "github.com/streamnative/pulsarctl/pkg/auth" "github.com/streamnative/pulsarctl/pkg/pulsar/common" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestPulsarClientEndpointEscapes(t *testing.T) { @@ -31,3 +33,74 @@ func TestPulsarClientEndpointEscapes(t *testing.T) { expected := "/admin/v2/myendpoint/abc%25%3F%20%2Fdef/ghi" assert.Equal(t, expected, actual) } + +func TestNew(t *testing.T) { + config := &common.Config{} + admin, err := New(config) + require.NoError(t, err) + require.NotNil(t, admin) +} + +func TestNewWithAuthProvider(t *testing.T) { + config := &common.Config{} + + tokenAuth, err := auth.NewAuthenticationToken("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9."+ + "eyJzdWIiOiJhZG1pbiIsImlhdCI6MTUxNjIzOTAyMn0.sVt6cyu3HKd89LcQvZVMNbqT0DTl3FvG9oYbj8hBDqU", nil) + require.NoError(t, err) + require.NotNil(t, tokenAuth) + + admin, err := NewPulsarClientWithAuthProvider(config, tokenAuth) + require.NoError(t, err) + require.NotNil(t, admin) +} + +type customAuthProvider struct { + transport http.RoundTripper +} + +var _ auth.Provider = &customAuthProvider{} + +func (c *customAuthProvider) RoundTrip(req *http.Request) (*http.Response, error) { + panic("implement me") +} + +func (c *customAuthProvider) Transport() http.RoundTripper { + return c.transport +} + +func (c *customAuthProvider) WithTransport(transport http.RoundTripper) { + c.transport = transport +} + +func TestNewWithCustomAuthProviderWithTransport(t *testing.T) { + config := &common.Config{} + defaultTransport, err := auth.NewDefaultTransport(config) + require.NoError(t, err) + + customAuthProvider := &customAuthProvider{ + transport: defaultTransport, + } + + admin, err := NewPulsarClientWithAuthProvider(config, customAuthProvider) + require.NoError(t, err) + require.NotNil(t, admin) + + // Expected the transport of customAuthProvider will not be overwritten. + require.Equal(t, defaultTransport, admin.(*pulsarClient).Client.HTTPClient.Transport) +} + +func TestNewWithTlsAllowInsecure(t *testing.T) { + config := &common.Config{ + TLSAllowInsecureConnection: true, + } + admin, err := New(config) + require.NoError(t, err) + require.NotNil(t, admin) + + pulsarClientS := admin.(*pulsarClient) + require.NotNil(t, pulsarClientS.Client.HTTPClient.Transport) + tr := pulsarClientS.Client.HTTPClient.Transport.(*http.Transport) + require.NotNil(t, tr) + require.NotNil(t, tr.TLSClientConfig) + require.True(t, tr.TLSClientConfig.InsecureSkipVerify) +} diff --git a/pkg/pulsar/utils/utils_test.go b/pkg/pulsar/utils/utils_test.go index b9ce770a..df88019d 100644 --- a/pkg/pulsar/utils/utils_test.go +++ b/pkg/pulsar/utils/utils_test.go @@ -58,4 +58,10 @@ func TestIsNilFixed(t *testing.T) { var ch chan string assert.True(t, IsNilFixed(ch)) + + var nilInterface People + assert.True(t, IsNilFixed(nilInterface)) + + // pointer to an interface, the IsNilFixed method cannot check this. + assert.False(t, IsNilFixed(&nilInterface)) } From 30be9e9489cb6a177078f24f8fcbe9dea4a49297 Mon Sep 17 00:00:00 2001 From: Zixuan Liu Date: Wed, 8 Jun 2022 15:37:27 +0800 Subject: [PATCH 17/24] Fix test new with custom auth provider (#734) * test: fix TestNewWithCustomAuthProviderWithTransport Signed-off-by: Zixuan Liu * test: fix test image Signed-off-by: Zixuan Liu --- pkg/pulsar/admin_test.go | 4 ++-- scripts/test-docker/Dockerfile | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/pulsar/admin_test.go b/pkg/pulsar/admin_test.go index 8e3afef4..bceaf81a 100644 --- a/pkg/pulsar/admin_test.go +++ b/pkg/pulsar/admin_test.go @@ -85,8 +85,8 @@ func TestNewWithCustomAuthProviderWithTransport(t *testing.T) { require.NoError(t, err) require.NotNil(t, admin) - // Expected the transport of customAuthProvider will not be overwritten. - require.Equal(t, defaultTransport, admin.(*pulsarClient).Client.HTTPClient.Transport) + // Expected the customAuthProvider will not be overwritten. + require.Equal(t, customAuthProvider, admin.(*pulsarClient).Client.HTTPClient.Transport) } func TestNewWithTlsAllowInsecure(t *testing.T) { diff --git a/scripts/test-docker/Dockerfile b/scripts/test-docker/Dockerfile index 8d317992..f6b14dbc 100644 --- a/scripts/test-docker/Dockerfile +++ b/scripts/test-docker/Dockerfile @@ -10,6 +10,10 @@ RUN curl -sSL https://storage.googleapis.com/golang/go$GOLANG_VERSION.linux-amd6 | tar -C /usr/local -xz ENV PATH /usr/local/go/bin:$PATH +# install git +RUN apt update +RUN apt install git -y + # copy the code into image COPY . /pulsarctl From 9ea6c6a70ce7fe42787f50043a05fd49624f55bf Mon Sep 17 00:00:00 2001 From: Zixuan Liu Date: Wed, 29 Jun 2022 16:11:09 +0800 Subject: [PATCH 18/24] test: upgrade the pulsar image (#765) Signed-off-by: Zixuan Liu --- pkg/ctl/namespace/persistence_test.go | 4 ++-- pkg/ctl/topic/persistence_test.go | 2 +- scripts/run-integration-tests.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/ctl/namespace/persistence_test.go b/pkg/ctl/namespace/persistence_test.go index b879a7aa..10bc3343 100644 --- a/pkg/ctl/namespace/persistence_test.go +++ b/pkg/ctl/namespace/persistence_test.go @@ -63,7 +63,7 @@ func TestFailurePersistence(t *testing.T) { } _, execErr, _, _ := TestNamespaceCommands(setPersistence, setArgs) assert.NotNil(t, execErr) - assert.Equal(t, execErr.Error(), "code: 400 reason: Bookkeeper Ensemble (2) >= WriteQuorum (5) >= AckQuoru (2)") + assert.Equal(t, execErr.Error(), "code: 400 reason: Bookkeeper Ensemble (2) >= WriteQuorum (5) >= AckQuorum (2)") setArgs = []string{"set-persistence", "public/test-persistent-namespace", "--ensemble-size", "2", @@ -73,5 +73,5 @@ func TestFailurePersistence(t *testing.T) { } _, execErr, _, _ = TestNamespaceCommands(setPersistence, setArgs) assert.NotNil(t, execErr) - assert.Equal(t, execErr.Error(), "code: 400 reason: Bookkeeper Ensemble (2) >= WriteQuorum (2) >= AckQuoru (3)") + assert.Equal(t, execErr.Error(), "code: 400 reason: Bookkeeper Ensemble (2) >= WriteQuorum (2) >= AckQuorum (3)") } diff --git a/pkg/ctl/topic/persistence_test.go b/pkg/ctl/topic/persistence_test.go index 87cf1259..c8cd9565 100644 --- a/pkg/ctl/topic/persistence_test.go +++ b/pkg/ctl/topic/persistence_test.go @@ -75,5 +75,5 @@ func TestPersistence(t *testing.T) { setArgs = []string{"set-persistence", topicName, "-e", "1", "-w", "4", "-a", "3", "-r", "2.2"} _, execErr, _, _ = TestTopicCommands(SetPersistenceCmd, setArgs) assert.NotNil(t, execErr) - assert.Equal(t, execErr.Error(), "code: 400 reason: Bookkeeper Ensemble (1) >= WriteQuorum (4) >= AckQuoru (3)") + assert.Equal(t, execErr.Error(), "code: 400 reason: Bookkeeper Ensemble (1) >= WriteQuorum (4) >= AckQuorum (3)") } diff --git a/scripts/run-integration-tests.sh b/scripts/run-integration-tests.sh index 05cbf6a7..b5429df8 100755 --- a/scripts/run-integration-tests.sh +++ b/scripts/run-integration-tests.sh @@ -3,7 +3,7 @@ set -e readonly PROJECT_ROOT=`cd $(dirname $0)/..; pwd` readonly IMAGE_NAME=pulsarctl-test -readonly PULSAR_DEFAULT_VERSION="2.9.2.9" +readonly PULSAR_DEFAULT_VERSION="2.10.1.1" readonly PULSAR_VERSION=${PULSAR_VERSION:-${PULSAR_DEFAULT_VERSION}} docker build --build-arg PULSAR_VERSION=${PULSAR_VERSION} \ From a0af09d52cd1e321f8a080557347b02a6ec9480a Mon Sep 17 00:00:00 2001 From: AlvaroStream <102966649+AlvaroStream@users.noreply.github.com> Date: Thu, 30 Jun 2022 08:07:11 +0200 Subject: [PATCH 19/24] Remove old releases mention (#771) The releases mentioned in the README.md are quite old. ### Motivation The releases mentioned in the README.md are quite old. ### Modifications Just remove the release. --- README.md | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/README.md b/README.md index 20be3325..70271f16 100644 --- a/README.md +++ b/README.md @@ -27,17 +27,6 @@ A CLI tool for the [Apache Pulsar](https://pulsar.incubator.apache.org/) project. -## Available Releases - -| Version | Reference | -| --------| --------- | -| [0.5.0](https://github.com/streamnative/pulsarctl/releases/tag/v0.5.0) | [Command Reference](https://docs.streamnative.io/pulsarctl/v0.5.0/) | -| [0.4.1](https://github.com/streamnative/pulsarctl/releases/tag/v0.4.1) | [Command Reference](https://docs.streamnative.io/pulsarctl/v0.4.1/) | -| [0.4.0](https://github.com/streamnative/pulsarctl/releases/tag/v0.4.0) | [Command Reference](https://docs.streamnative.io/pulsarctl/v0.4.0/)| -| [0.3.0](https://github.com/streamnative/pulsarctl/releases/tag/v0.3.0) | [Command Reference](https://docs.streamnative.io/pulsarctl/v0.3.0/) | -| [0.2.0](https://github.com/streamnative/pulsarctl/releases/tag/v0.2.0) | [Command Reference](https://docs.streamnative.io/pulsarctl/v0.2.0/) | -| [0.1.0](https://github.com/streamnative/pulsarctl/releases/tag/v0.1.0) | [Command Reference](https://docs.streamnative.io/pulsarctl/v0.1.0/) | - ## Install pulsarctl ### Mac operation system From b8befd16e64684349e44c1e8e4bb52f05bbe96e6 Mon Sep 17 00:00:00 2001 From: Zixuan Liu Date: Wed, 6 Jul 2022 15:01:00 +0800 Subject: [PATCH 20/24] fix: fix windows releases (#747) Signed-off-by: Zixuan Liu --- scripts/build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/build.sh b/scripts/build.sh index dde91440..3aeb62ac 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -33,8 +33,8 @@ build() { local dir=${base_dir}/${dirname} mkdir -p ${dir} CGO_ENABLED=0 GOOS=${os} GOARCH=${arch} go build \ - -ldflags "${LDFLAGS}" -o pulsarctl - mv pulsarctl ${dir} + -ldflags "${LDFLAGS}" + mv pulsarctl* ${dir} cp -r plugins ${dir} pushd $base_dir tar -czf ${dirname}.tar.gz ${dirname} From 88ec2c12d2235e70bf719cab297b5e8b5ac81a6e Mon Sep 17 00:00:00 2001 From: jiangpengcheng Date: Thu, 7 Jul 2022 11:29:33 +0800 Subject: [PATCH 21/24] Build docker image for amd64 linux (#774) --- docker/amd64-linux.Dockerfile | 6 ++++++ scripts/build.sh | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 docker/amd64-linux.Dockerfile diff --git a/docker/amd64-linux.Dockerfile b/docker/amd64-linux.Dockerfile new file mode 100644 index 00000000..9a044af5 --- /dev/null +++ b/docker/amd64-linux.Dockerfile @@ -0,0 +1,6 @@ +FROM alpine:3.16.0 + +ADD pulsarctl /usr/local/bin/pulsarctl + +RUN apk add tzdata ca-certificates --no-cache \ + && chmod +x /usr/local/bin/pulsarctl diff --git a/scripts/build.sh b/scripts/build.sh index 3aeb62ac..032bc46b 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -28,6 +28,7 @@ mkdir $ASSETS_DIR build() { local arch=${1} local os=${2} + local docker_tag=${3} local base_dir=dist local dirname=pulsarctl-${arch}-${os} local dir=${base_dir}/${dirname} @@ -40,6 +41,12 @@ build() { tar -czf ${dirname}.tar.gz ${dirname} mv ${dirname}.tar.gz ${ASSETS_DIR} popd + + if [[ "x${docker_tag}" != "x" ]]; then + docker build -f docker/${arch}-${os}.Dockerfile -t streamnative/pulsarctl:${docker_tag} ${dir} + docker login -u="${DOCKER_USERNAME}" -p="${DOCKER_PASSWORD}" + docker push streamnative/pulsarctl:${docker_tag} + fi } function build_doc() { @@ -48,7 +55,7 @@ function build_doc() { mv pulsarctl-site-${version}.tar.gz ${ASSETS_DIR} } -build amd64 linux +build amd64 linux ${version} build 386 linux build amd64 darwin build arm64 darwin From 66efc5fb0e7c59c68de7e853a54cd94d4cce5ee3 Mon Sep 17 00:00:00 2001 From: Zixuan Liu Date: Wed, 14 Sep 2022 10:30:34 +0800 Subject: [PATCH 22/24] test: fix get internal config test (#830) (cherry picked from commit d0406efc9c6b58966ed2d1c7d49546a711dcbae5) --- pkg/ctl/brokers/config_test.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pkg/ctl/brokers/config_test.go b/pkg/ctl/brokers/config_test.go index b9cefd14..8702f0c4 100644 --- a/pkg/ctl/brokers/config_test.go +++ b/pkg/ctl/brokers/config_test.go @@ -33,10 +33,6 @@ func TestGetInternalConfig(t *testing.T) { var internalData utils.InternalConfigurationData err := json.Unmarshal(internalOut.Bytes(), &internalData) assert.Nil(t, err) - - assert.Equal(t, "127.0.0.1:2181", internalData.ZookeeperServers) - assert.Equal(t, "127.0.0.1:2181", internalData.ConfigurationStoreServers) - assert.Equal(t, "/ledgers", internalData.LedgersRootPath) } func TestGetRuntimeConfig(t *testing.T) { From 2cb124c7e2378039c4e2019faab06cbf3a26c3ea Mon Sep 17 00:00:00 2001 From: Zixuan Liu Date: Wed, 14 Sep 2022 11:55:17 +0800 Subject: [PATCH 23/24] fix: Remove encoding for the topic (#828) Signed-off-by: Zixuan Liu (cherry picked from commit f1766171928401e5101fec547c9e5302860f9668) --- pkg/ctl/topic/create_test.go | 26 ++++++++++++++++++++++++++ pkg/pulsar/schema.go | 10 +++++----- pkg/pulsar/utils/topic_name.go | 2 +- pkg/pulsar/utils/topic_name_test.go | 18 ------------------ 4 files changed, 32 insertions(+), 24 deletions(-) diff --git a/pkg/ctl/topic/create_test.go b/pkg/ctl/topic/create_test.go index 9ead8f4b..8959573a 100644 --- a/pkg/ctl/topic/create_test.go +++ b/pkg/ctl/topic/create_test.go @@ -20,6 +20,7 @@ package topic import ( "testing" + "github.com/streamnative/pulsarctl/pkg/test" "github.com/stretchr/testify/assert" ) @@ -82,3 +83,28 @@ func TestCreateNonPersistentNonPartitionedTopic(t *testing.T) { assert.Nil(t, argsErr) assert.Nil(t, err) } + +func TestCreateTopicNameWithColons(t *testing.T) { + topic := "persistent://public/default/test:topic-" + test.RandomSuffix() + args := []string{"create", topic, "0"} + _, execErr, argsErr, err := TestTopicCommands(CreateTopicCmd, args) + assert.Nil(t, execErr) + assert.Nil(t, argsErr) + assert.Nil(t, err) + +} + +func TestCreateTopicNameWithEncodedColons(t *testing.T) { + topic := "persistent://public/default/test%3Atopic-" + test.RandomSuffix() + args := []string{"create", topic, "0"} + _, execErr, argsErr, err := TestTopicCommands(CreateTopicCmd, args) + assert.Nil(t, execErr) + assert.Nil(t, argsErr) + assert.Nil(t, err) + + args = []string{"get", topic} + _, execErr, argsErr, err = TestTopicCommands(GetTopicCmd, args) + assert.Nil(t, execErr) + assert.Nil(t, argsErr) + assert.Nil(t, err) +} diff --git a/pkg/pulsar/schema.go b/pkg/pulsar/schema.go index 5fd57ec4..49627be8 100644 --- a/pkg/pulsar/schema.go +++ b/pkg/pulsar/schema.go @@ -62,7 +62,7 @@ func (s *schemas) GetSchemaInfo(topic string) (*utils.SchemaInfo, error) { } var response utils.GetSchemaResponse endpoint := s.pulsar.endpoint(s.basePath, topicName.GetTenant(), topicName.GetNamespace(), - topicName.GetEncodedTopic(), "schema") + topicName.GetLocalName(), "schema") err = s.pulsar.Client.Get(endpoint, &response) if err != nil { @@ -80,7 +80,7 @@ func (s *schemas) GetSchemaInfoWithVersion(topic string) (*utils.SchemaInfoWithV } var response utils.GetSchemaResponse endpoint := s.pulsar.endpoint(s.basePath, topicName.GetTenant(), topicName.GetNamespace(), - topicName.GetEncodedTopic(), "schema") + topicName.GetLocalName(), "schema") err = s.pulsar.Client.Get(endpoint, &response) if err != nil { @@ -99,7 +99,7 @@ func (s *schemas) GetSchemaInfoByVersion(topic string, version int64) (*utils.Sc } var response utils.GetSchemaResponse - endpoint := s.pulsar.endpoint(s.basePath, topicName.GetTenant(), topicName.GetNamespace(), topicName.GetEncodedTopic(), + endpoint := s.pulsar.endpoint(s.basePath, topicName.GetTenant(), topicName.GetNamespace(), topicName.GetLocalName(), "schema", strconv.FormatInt(version, 10)) err = s.pulsar.Client.Get(endpoint, &response) @@ -118,7 +118,7 @@ func (s *schemas) DeleteSchema(topic string) error { } endpoint := s.pulsar.endpoint(s.basePath, topicName.GetTenant(), topicName.GetNamespace(), - topicName.GetEncodedTopic(), "schema") + topicName.GetLocalName(), "schema") fmt.Println(endpoint) @@ -132,7 +132,7 @@ func (s *schemas) CreateSchemaByPayload(topic string, schemaPayload utils.PostSc } endpoint := s.pulsar.endpoint(s.basePath, topicName.GetTenant(), topicName.GetNamespace(), - topicName.GetEncodedTopic(), "schema") + topicName.GetLocalName(), "schema") return s.pulsar.Client.Post(endpoint, &schemaPayload) } diff --git a/pkg/pulsar/utils/topic_name.go b/pkg/pulsar/utils/topic_name.go index 52c44aae..268abd73 100644 --- a/pkg/pulsar/utils/topic_name.go +++ b/pkg/pulsar/utils/topic_name.go @@ -119,7 +119,7 @@ func (t *TopicName) IsPersistent() bool { } func (t *TopicName) GetRestPath() string { - return fmt.Sprintf("%s/%s/%s/%s", t.domain, t.tenant, t.namespace, t.GetEncodedTopic()) + return fmt.Sprintf("%s/%s/%s/%s", t.domain, t.tenant, t.namespace, t.topic) } func (t *TopicName) GetEncodedTopic() string { diff --git a/pkg/pulsar/utils/topic_name_test.go b/pkg/pulsar/utils/topic_name_test.go index 8eba39ce..27e50024 100644 --- a/pkg/pulsar/utils/topic_name_test.go +++ b/pkg/pulsar/utils/topic_name_test.go @@ -18,7 +18,6 @@ package utils import ( - "net/url" "testing" "github.com/stretchr/testify/assert" @@ -74,20 +73,3 @@ func TestGetTopicName(t *testing.T) { assert.Equal(t, "topic name can not be empty", err.Error()) assert.Nil(t, fail) } - -func TestTopicNameEncodeTest(t *testing.T) { - encodedName := "a%3Aen-in_in_business_content_item_20150312173022_https%5C%3A%2F%2Fin.news.example.com%2Fr" - rawName := "a:en-in_in_business_content_item_20150312173022_https\\://in.news.example.com/r" - - assert.Equal(t, encodedName, url.QueryEscape(rawName)) - o, err := url.QueryUnescape(encodedName) - assert.Nil(t, err) - assert.Equal(t, rawName, o) - - topicName, err := GetTopicName("persistent://prop/ns/" + rawName) - assert.Nil(t, err) - - assert.Equal(t, rawName, topicName.topic) - assert.Equal(t, encodedName, topicName.GetEncodedTopic()) - assert.Equal(t, "persistent/prop/ns/"+encodedName, topicName.GetRestPath()) -} From 6f14a58a83ad416d0d6db2334bb2496782c7c4bf Mon Sep 17 00:00:00 2001 From: streamnativebot Date: Fri, 16 Sep 2022 03:29:54 +0000 Subject: [PATCH 24/24] "Created by snbot" --- .github/workflows/ci-auth-checks.yml | 25 ++++--- .github/workflows/ci-bookie-checks.yml | 15 +++-- .github/workflows/ci-checks.yml | 15 +++-- .github/workflows/ci-functions-checks.yml | 65 ++++++++++++------- .../workflows/ci-install-script-checks.yml | 13 +++- .github/workflows/ci-packages-checks.yml | 33 ++++++---- .github/workflows/ci-release-checks.yml | 49 ++++++++------ .github/workflows/ci-style-checks.yml | 47 ++++++++------ .github/workflows/documentbot.yml | 32 +++++---- .github/workflows/release-note.yml | 23 ++++--- scripts/run-integration-tests.sh | 2 +- scripts/test-docker/Dockerfile | 2 +- 12 files changed, 202 insertions(+), 119 deletions(-) diff --git a/.github/workflows/ci-auth-checks.yml b/.github/workflows/ci-auth-checks.yml index 5bd4047c..3b1b9e14 100644 --- a/.github/workflows/ci-auth-checks.yml +++ b/.github/workflows/ci-auth-checks.yml @@ -2,17 +2,24 @@ name: Pulsarctl on: pull_request: branches: - - '*' + - '*' path-ignores: - - 'docs/**' - - 'README.md' - - 'CONTRIBUTING.md' + - 'docs/**' + - 'README.md' + - 'CONTRIBUTING.md' jobs: auth-tests: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Run token tests - run: scripts/run-integration-tests.sh token - - name: Run TLS tests - run: scripts/run-integration-tests.sh tls + - uses: s4u/maven-settings-action@v2.6.0 + with: + servers: '[{"id": "ossrh", "username": "${{ secrets.SONATYPE_USERNAME }}", + "password": "${{ secrets.SONATYPE_PASSWORD }}"}]' + - name: Login to cloudsmith + run: docker login -u="${{ secrets.CLOUDSMITH_USERNAME }}" -p="${{ secrets.CLOUDSMITH_API_KEY + }}" docker.cloudsmith.io + - uses: actions/checkout@v2 + - name: Run token tests + run: scripts/run-integration-tests.sh token + - name: Run TLS tests + run: scripts/run-integration-tests.sh tls diff --git a/.github/workflows/ci-bookie-checks.yml b/.github/workflows/ci-bookie-checks.yml index f42e3eca..b2c14a4e 100644 --- a/.github/workflows/ci-bookie-checks.yml +++ b/.github/workflows/ci-bookie-checks.yml @@ -2,15 +2,22 @@ name: Pulsarctl on: pull_request: branches: - - '*' + - '*' path-ignores: - - 'docs/**' - - 'README.md' - - 'CONTRIBUTING.md' + - 'docs/**' + - 'README.md' + - 'CONTRIBUTING.md' jobs: bookie-ut-tests: runs-on: ubuntu-latest steps: + - uses: s4u/maven-settings-action@v2.6.0 + with: + servers: '[{"id": "ossrh", "username": "${{ secrets.SONATYPE_USERNAME }}", + "password": "${{ secrets.SONATYPE_PASSWORD }}"}]' + - name: Login to cloudsmith + run: docker login -u="${{ secrets.CLOUDSMITH_USERNAME }}" -p="${{ secrets.CLOUDSMITH_API_KEY + }}" docker.cloudsmith.io - name: Set up Go 1.18 uses: actions/setup-go@v1 with: diff --git a/.github/workflows/ci-checks.yml b/.github/workflows/ci-checks.yml index 047ee0ea..584a6dc9 100644 --- a/.github/workflows/ci-checks.yml +++ b/.github/workflows/ci-checks.yml @@ -2,15 +2,22 @@ name: Pulsarctl on: pull_request: branches: - - '*' + - '*' path-ignores: - - 'docs/**' - - 'README.md' - - 'CONTRIBUTING.md' + - 'docs/**' + - 'README.md' + - 'CONTRIBUTING.md' jobs: ut-tests: runs-on: ubuntu-latest steps: + - uses: s4u/maven-settings-action@v2.6.0 + with: + servers: '[{"id": "ossrh", "username": "${{ secrets.SONATYPE_USERNAME }}", + "password": "${{ secrets.SONATYPE_PASSWORD }}"}]' + - name: Login to cloudsmith + run: docker login -u="${{ secrets.CLOUDSMITH_USERNAME }}" -p="${{ secrets.CLOUDSMITH_API_KEY + }}" docker.cloudsmith.io - uses: actions/checkout@v2 - name: Run tests run: scripts/run-integration-tests.sh diff --git a/.github/workflows/ci-functions-checks.yml b/.github/workflows/ci-functions-checks.yml index 1d209a77..0ff4bfb6 100644 --- a/.github/workflows/ci-functions-checks.yml +++ b/.github/workflows/ci-functions-checks.yml @@ -2,15 +2,22 @@ name: Pulsarctl on: pull_request: branches: - - '*' + - '*' path-ignores: - - 'docs/**' - - 'README.md' - - 'CONTRIBUTING.md' + - 'docs/**' + - 'README.md' + - 'CONTRIBUTING.md' jobs: function-tests: runs-on: ubuntu-latest steps: + - uses: s4u/maven-settings-action@v2.6.0 + with: + servers: '[{"id": "ossrh", "username": "${{ secrets.SONATYPE_USERNAME }}", + "password": "${{ secrets.SONATYPE_PASSWORD }}"}]' + - name: Login to cloudsmith + run: docker login -u="${{ secrets.CLOUDSMITH_USERNAME }}" -p="${{ secrets.CLOUDSMITH_API_KEY + }}" docker.cloudsmith.io - name: Set up Go 1.18 uses: actions/setup-go@v1 with: @@ -23,24 +30,38 @@ jobs: sink-tests: runs-on: ubuntu-latest steps: - - name: Set up Go 1.18 - uses: actions/setup-go@v1 - with: - go-version: 1.18 - id: go - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - name: Sink tests - run: scripts/run-integration-tests.sh sink + - uses: s4u/maven-settings-action@v2.6.0 + with: + servers: '[{"id": "ossrh", "username": "${{ secrets.SONATYPE_USERNAME }}", + "password": "${{ secrets.SONATYPE_PASSWORD }}"}]' + - name: Login to cloudsmith + run: docker login -u="${{ secrets.CLOUDSMITH_USERNAME }}" -p="${{ secrets.CLOUDSMITH_API_KEY + }}" docker.cloudsmith.io + - name: Set up Go 1.18 + uses: actions/setup-go@v1 + with: + go-version: 1.18 + id: go + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + - name: Sink tests + run: scripts/run-integration-tests.sh sink source-tests: runs-on: ubuntu-latest steps: - - name: Set up Go 1.18 - uses: actions/setup-go@v1 - with: - go-version: 1.18 - id: go - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - name: Source tests - run: scripts/run-integration-tests.sh source + - uses: s4u/maven-settings-action@v2.6.0 + with: + servers: '[{"id": "ossrh", "username": "${{ secrets.SONATYPE_USERNAME }}", + "password": "${{ secrets.SONATYPE_PASSWORD }}"}]' + - name: Login to cloudsmith + run: docker login -u="${{ secrets.CLOUDSMITH_USERNAME }}" -p="${{ secrets.CLOUDSMITH_API_KEY + }}" docker.cloudsmith.io + - name: Set up Go 1.18 + uses: actions/setup-go@v1 + with: + go-version: 1.18 + id: go + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + - name: Source tests + run: scripts/run-integration-tests.sh source diff --git a/.github/workflows/ci-install-script-checks.yml b/.github/workflows/ci-install-script-checks.yml index 0d3963d5..9d62a4a2 100644 --- a/.github/workflows/ci-install-script-checks.yml +++ b/.github/workflows/ci-install-script-checks.yml @@ -2,14 +2,21 @@ name: Pulsarctl on: pull_request: branches: - - '*' + - '*' paths: - - 'install.sh' - - 'stable.txt' + - 'install.sh' + - 'stable.txt' jobs: install-script-check: runs-on: ubuntu-latest steps: + - uses: s4u/maven-settings-action@v2.6.0 + with: + servers: '[{"id": "ossrh", "username": "${{ secrets.SONATYPE_USERNAME }}", + "password": "${{ secrets.SONATYPE_PASSWORD }}"}]' + - name: Login to cloudsmith + run: docker login -u="${{ secrets.CLOUDSMITH_USERNAME }}" -p="${{ secrets.CLOUDSMITH_API_KEY + }}" docker.cloudsmith.io - name: Check out code into the Go module directory uses: actions/checkout@v2 - name: Test install diff --git a/.github/workflows/ci-packages-checks.yml b/.github/workflows/ci-packages-checks.yml index 22548421..4bc8adf8 100644 --- a/.github/workflows/ci-packages-checks.yml +++ b/.github/workflows/ci-packages-checks.yml @@ -2,21 +2,28 @@ name: Pulsarctl on: pull_request: branches: - - '*' + - '*' path-ignores: - - 'docs/**' - - 'README.md' - - 'CONTRIBUTING.md' + - 'docs/**' + - 'README.md' + - 'CONTRIBUTING.md' jobs: packages-tests: runs-on: ubuntu-latest steps: - - name: Set up Go 1.18 - uses: actions/setup-go@v1 - with: - go-version: 1.18 - id: go - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - name: Packages tests - run: scripts/run-integration-tests.sh packages + - uses: s4u/maven-settings-action@v2.6.0 + with: + servers: '[{"id": "ossrh", "username": "${{ secrets.SONATYPE_USERNAME }}", + "password": "${{ secrets.SONATYPE_PASSWORD }}"}]' + - name: Login to cloudsmith + run: docker login -u="${{ secrets.CLOUDSMITH_USERNAME }}" -p="${{ secrets.CLOUDSMITH_API_KEY + }}" docker.cloudsmith.io + - name: Set up Go 1.18 + uses: actions/setup-go@v1 + with: + go-version: 1.18 + id: go + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + - name: Packages tests + run: scripts/run-integration-tests.sh packages diff --git a/.github/workflows/ci-release-checks.yml b/.github/workflows/ci-release-checks.yml index ec8695d4..fd882dc8 100644 --- a/.github/workflows/ci-release-checks.yml +++ b/.github/workflows/ci-release-checks.yml @@ -3,33 +3,40 @@ name: Pulsarctl on: pull_request: branches: - - '*' + - '*' path-ignores: - - 'docs/**' - - 'README.md' - - 'CONTRIBUTING.md' + - 'docs/**' + - 'README.md' + - 'CONTRIBUTING.md' jobs: release-check: runs-on: ubuntu-latest strategy: matrix: - go-version: [ 1.13, 1.14, 1.15, 1.16, 1.17, 1.18 ] + go-version: [1.13, 1.14, 1.15, 1.16, 1.17, 1.18] steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v1 - with: - go-version: ${{ matrix.go-version }} - id: go + - uses: s4u/maven-settings-action@v2.6.0 + with: + servers: '[{"id": "ossrh", "username": "${{ secrets.SONATYPE_USERNAME }}", + "password": "${{ secrets.SONATYPE_PASSWORD }}"}]' + - name: Login to cloudsmith + run: docker login -u="${{ secrets.CLOUDSMITH_USERNAME }}" -p="${{ secrets.CLOUDSMITH_API_KEY + }}" docker.cloudsmith.io + - uses: actions/checkout@v2 + - uses: actions/setup-go@v1 + with: + go-version: ${{ matrix.go-version }} + id: go - - name: build - run: | - version=`cat VERSION` - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o pulsarctl-amd64-linux -ldflags "-X github.com/streamnative/pulsarctl/pkg/pulsar.ReleaseVersion=Pulsarctl-Go-$version" . - CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -o pulsarctl-386-linux -ldflags "-X github.com/streamnative/pulsarctl/pkg/pulsar.ReleaseVersion=Pulsarctl-Go-$version" . - CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o pulsarctl-amd64-darwin -ldflags "-X github.com/streamnative/pulsarctl/pkg/pulsar.ReleaseVersion=Pulsarctl-Go-$version" . - CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o pulsarctl-amd64-windows.exe -ldflags "-X github.com/streamnative/pulsarctl/pkg/pulsar.ReleaseVersion=Pulsarctl-Go-$version" . - CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -o pulsarctl-386-windows.exe -ldflags "-X github.com/streamnative/pulsarctl/pkg/pulsar.ReleaseVersion=Pulsarctl-Go-$version" . - - name: build-site - run: | - make cli + - name: build + run: | + version=`cat VERSION` + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o pulsarctl-amd64-linux -ldflags "-X github.com/streamnative/pulsarctl/pkg/pulsar.ReleaseVersion=Pulsarctl-Go-$version" . + CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -o pulsarctl-386-linux -ldflags "-X github.com/streamnative/pulsarctl/pkg/pulsar.ReleaseVersion=Pulsarctl-Go-$version" . + CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o pulsarctl-amd64-darwin -ldflags "-X github.com/streamnative/pulsarctl/pkg/pulsar.ReleaseVersion=Pulsarctl-Go-$version" . + CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o pulsarctl-amd64-windows.exe -ldflags "-X github.com/streamnative/pulsarctl/pkg/pulsar.ReleaseVersion=Pulsarctl-Go-$version" . + CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -o pulsarctl-386-windows.exe -ldflags "-X github.com/streamnative/pulsarctl/pkg/pulsar.ReleaseVersion=Pulsarctl-Go-$version" . + - name: build-site + run: | + make cli diff --git a/.github/workflows/ci-style-checks.yml b/.github/workflows/ci-style-checks.yml index 42a1ad2e..a62f7913 100644 --- a/.github/workflows/ci-style-checks.yml +++ b/.github/workflows/ci-style-checks.yml @@ -2,28 +2,35 @@ name: Pulsarctl on: pull_request: branches: - - '*' + - '*' path-ignores: - - 'docs/**' - - 'README.md' - - 'CONTRIBUTING.md' + - 'docs/**' + - 'README.md' + - 'CONTRIBUTING.md' jobs: style-check: runs-on: ubuntu-latest steps: - - name: Set up Go 1.18 - uses: actions/setup-go@v1 - with: - go-version: 1.18 - id: go - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - name: InstallTool - run: | - wget -O - -q https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s v1.45.2 - ./bin/golangci-lint --version - - name: Build - run: go build . - - name: CheckStyle - run: | - ./bin/golangci-lint run -c ./golangci.yml ./... + - uses: s4u/maven-settings-action@v2.6.0 + with: + servers: '[{"id": "ossrh", "username": "${{ secrets.SONATYPE_USERNAME }}", + "password": "${{ secrets.SONATYPE_PASSWORD }}"}]' + - name: Login to cloudsmith + run: docker login -u="${{ secrets.CLOUDSMITH_USERNAME }}" -p="${{ secrets.CLOUDSMITH_API_KEY + }}" docker.cloudsmith.io + - name: Set up Go 1.18 + uses: actions/setup-go@v1 + with: + go-version: 1.18 + id: go + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + - name: InstallTool + run: | + wget -O - -q https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s v1.45.2 + ./bin/golangci-lint --version + - name: Build + run: go build . + - name: CheckStyle + run: | + ./bin/golangci-lint run -c ./golangci.yml ./... diff --git a/.github/workflows/documentbot.yml b/.github/workflows/documentbot.yml index e4914df2..9aac06cc 100644 --- a/.github/workflows/documentbot.yml +++ b/.github/workflows/documentbot.yml @@ -1,4 +1,3 @@ - # # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file @@ -21,13 +20,13 @@ name: Auto Labeling on: - pull_request_target : + pull_request_target: types: - - opened - - edited - - labeled + - opened + - edited + - labeled + - # A GitHub token created for a PR coming from a fork doesn't have # 'admin' or 'write' permission (which is required to add labels) @@ -39,13 +38,20 @@ jobs: labeling: if: ${{ github.repository == 'streamnative/pulsarctl' }} permissions: - pull-requests: write + pull-requests: write runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - - uses: streamnative/github-workflow-libraries/doc-label-check@master - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - label-pattern: '- \[(.*?)\] ?`(.+?)`' # matches '- [x] `label`' + - uses: s4u/maven-settings-action@v2.6.0 + with: + servers: '[{"id": "ossrh", "username": "${{ secrets.SONATYPE_USERNAME }}", + "password": "${{ secrets.SONATYPE_PASSWORD }}"}]' + - name: Login to cloudsmith + run: docker login -u="${{ secrets.CLOUDSMITH_USERNAME }}" -p="${{ secrets.CLOUDSMITH_API_KEY + }}" docker.cloudsmith.io + - uses: actions/checkout@v2 + + - uses: streamnative/github-workflow-libraries/doc-label-check@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + label-pattern: '- \[(.*?)\] ?`(.+?)`' # matches '- [x] `label`' diff --git a/.github/workflows/release-note.yml b/.github/workflows/release-note.yml index 08aa5ce6..79381a20 100644 --- a/.github/workflows/release-note.yml +++ b/.github/workflows/release-note.yml @@ -3,18 +3,25 @@ name: Pulsarctl Release Note on: push: branches: - - master + - master path-ignores: - - 'docs/**' - - 'README.md' - - 'CONTRIBUTING.md' + - 'docs/**' + - 'README.md' + - 'CONTRIBUTING.md' jobs: build: runs-on: ubuntu-latest steps: - - name: release note - uses: release-drafter/release-drafter@v5 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - uses: s4u/maven-settings-action@v2.6.0 + with: + servers: '[{"id": "ossrh", "username": "${{ secrets.SONATYPE_USERNAME }}", + "password": "${{ secrets.SONATYPE_PASSWORD }}"}]' + - name: Login to cloudsmith + run: docker login -u="${{ secrets.CLOUDSMITH_USERNAME }}" -p="${{ secrets.CLOUDSMITH_API_KEY + }}" docker.cloudsmith.io + - name: release note + uses: release-drafter/release-drafter@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/scripts/run-integration-tests.sh b/scripts/run-integration-tests.sh index b5429df8..1da0f02b 100755 --- a/scripts/run-integration-tests.sh +++ b/scripts/run-integration-tests.sh @@ -3,7 +3,7 @@ set -e readonly PROJECT_ROOT=`cd $(dirname $0)/..; pwd` readonly IMAGE_NAME=pulsarctl-test -readonly PULSAR_DEFAULT_VERSION="2.10.1.1" +readonly PULSAR_DEFAULT_VERSION="2.11.0.0-rc3" readonly PULSAR_VERSION=${PULSAR_VERSION:-${PULSAR_DEFAULT_VERSION}} docker build --build-arg PULSAR_VERSION=${PULSAR_VERSION} \ diff --git a/scripts/test-docker/Dockerfile b/scripts/test-docker/Dockerfile index f6b14dbc..10b4fff3 100644 --- a/scripts/test-docker/Dockerfile +++ b/scripts/test-docker/Dockerfile @@ -1,5 +1,5 @@ ARG PULSAR_VERSION -FROM streamnative/pulsar-all:$PULSAR_VERSION +FROM docker.cloudsmith.io/streamnative/staging/pulsar-all:$PULSAR_VERSION # use root user USER root