From 64a04316f0dddc02a63326c729a51020a7c67b52 Mon Sep 17 00:00:00 2001 From: Andrew Pantuso Date: Thu, 27 Oct 2022 07:30:44 -0400 Subject: [PATCH 1/2] Revert "test: adding integration suite (#196)" This reverts commit 9b953dc79b349afb2eaffb66bafafb0ac81b2827. --- go.mod | 3 - go.sum | 58 +++------- integration/deployment_test.go | 193 -------------------------------- integration/helpers.go | 121 -------------------- integration/suite_test.go | 133 ---------------------- internal/testing/client.go | 89 --------------- internal/testing/loader.go | 39 ------- internal/testing/prom_client.go | 84 -------------- 8 files changed, 13 insertions(+), 707 deletions(-) delete mode 100644 integration/deployment_test.go delete mode 100644 integration/helpers.go delete mode 100644 integration/suite_test.go delete mode 100644 internal/testing/client.go delete mode 100644 internal/testing/loader.go delete mode 100644 internal/testing/prom_client.go diff --git a/go.mod b/go.mod index 5103d44e..4507a4ab 100644 --- a/go.mod +++ b/go.mod @@ -7,12 +7,9 @@ require ( github.com/go-logr/logr v0.4.0 github.com/go-openapi/swag v0.19.15 // indirect github.com/mcuadros/go-defaults v1.2.0 - github.com/onsi/ginkgo/v2 v2.3.1 - github.com/onsi/gomega v1.22.0 github.com/openshift/api v3.9.0+incompatible github.com/prometheus/client_golang v1.12.0 github.com/prometheus/client_model v0.2.0 - github.com/prometheus/common v0.32.1 github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.9.0 github.com/stretchr/testify v1.7.0 diff --git a/go.sum b/go.sum index 25a3e559..31afaace 100644 --- a/go.sum +++ b/go.sum @@ -554,9 +554,8 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= -github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g= github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -576,7 +575,6 @@ github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= @@ -893,11 +891,6 @@ github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9k github.com/onsi/ginkgo v1.16.2/go.mod h1:CObGmKUOKaSC0RjmoAK7tKyn4Azo5P2IWuoMnvwxz1E= 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.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= -github.com/onsi/ginkgo/v2 v2.1.4/go.mod h1:um6tUpWM/cxCK3/FK8BXqEiUMUwRgSM4JXG47RKZmLU= -github.com/onsi/ginkgo/v2 v2.1.6/go.mod h1:MEH45j8TBi6u9BMogfbp0stKC5cdGjumZj5Y7AG4VIk= -github.com/onsi/ginkgo/v2 v2.3.1 h1:8SbseP7qM32WcvE6VaN6vfXxv698izmsJ1UQX9ve7T8= -github.com/onsi/ginkgo/v2 v2.3.1/go.mod h1:Sv4yQXwG5VmF7tm3Q5Z+RWUpPo24LF1mpnz2crUb8Ys= github.com/onsi/gomega v0.0.0-20151007035656-2152b45fa28a/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= @@ -905,12 +898,8 @@ github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7J github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.10.3/go.mod h1:V9xEwhxec5O8UDM77eCW8vLymOMltsqPVYWrpDsH8xc= github.com/onsi/gomega v1.13.0/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je41yGY= +github.com/onsi/gomega v1.15.0 h1:WjP/FQ/sk43MRmnEcT+MlDw2TFvkrXlprrPST/IudjU= github.com/onsi/gomega v1.15.0/go.mod h1:cIuvLEne0aoVhAgh/O6ac0Op8WWw9H6eYCriF+tEHG0= -github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= -github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro= -github.com/onsi/gomega v1.20.1/go.mod h1:DtrZpjmvpn2mPm4YWQa0/ALMDj9v4YxLgojwPeREyVo= -github.com/onsi/gomega v1.22.0 h1:AIg2/OntwkBiCg5Tt1ayyiF1ArFrWFoCSMtMi/wdApk= -github.com/onsi/gomega v1.22.0/go.mod h1:iYAIXgPSaDHak0LCMA+AWBpIKBr8WZicMxnE8luStNc= github.com/opencontainers/go-digest v0.0.0-20170106003457-a6d0ee40d420/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= @@ -1169,8 +1158,6 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yvasiyarov/go-metrics v0.0.0-20140926110328-57bccd1ccd43 h1:+lm10QQTNSBd8DVTNGHx7o/IKu9HYDvLMffDhbyLccI= github.com/yvasiyarov/go-metrics v0.0.0-20140926110328-57bccd1ccd43/go.mod h1:aX5oPXxHm3bOH+xeAttToC8pqch2ScQN/JoXYupl6xs= github.com/yvasiyarov/gorelic v0.0.0-20141212073537-a9bba5b9ab50 h1:hlE8//ciYMztlGpl/VA+Zm1AcTPHYkHJPbHqE6WJUXE= @@ -1261,9 +1248,8 @@ golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWP golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= +golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ= golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -1300,10 +1286,8 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -1361,12 +1345,8 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210520170846-37e1c6afe023/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20210525063256-abc453219eb5 h1:wjuX4b5yYQnEQHzd+CBcrcC6OVR2J1CN6mUy0oSxIPo= golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= -golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= 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= @@ -1395,9 +1375,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/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 h1:uVc8UZUe6tr40fFVnUP5Oj+veunVezqYl9z7DYw9xzw= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 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= @@ -1499,19 +1478,12 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210817190340-bfb29a6856f2/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 h1:XfKQ4OlFl8okEOr5UvAqFRVj8pY/4yfcXrddB8qAbU0= golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d h1:SZxvLBoTP5yHO3Frd4z4vrF+DBX9vMVanchswa69toE= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= 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= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1519,9 +1491,8 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/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/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 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= @@ -1631,13 +1602,12 @@ golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.5 h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= -golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= 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= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.stackrox.io/kube-linter v0.0.0-20210928184316-5e1ead387f43 h1:95LZGFY6g5qzanlxSwd5KhHrib0HMCq2D/CupIiDZzY= golang.stackrox.io/kube-linter v0.0.0-20210928184316-5e1ead387f43/go.mod h1:RMqnUjr0ftLtdg1CpWpZbHhbO2T9FyideA6j+2bfijw= @@ -1791,9 +1761,8 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj 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/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= -google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -1837,9 +1806,8 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk= diff --git a/integration/deployment_test.go b/integration/deployment_test.go deleted file mode 100644 index dd0a235f..00000000 --- a/integration/deployment_test.go +++ /dev/null @@ -1,193 +0,0 @@ -package integration - -import ( - "context" - "errors" - "os/exec" - - internaltesting "github.com/app-sre/deployment-validation-operator/internal/testing" - io_prometheus_client "github.com/prometheus/client_model/go" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - . "github.com/onsi/gomega/gexec" - appsv1 "k8s.io/api/apps/v1" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -var ErrNilMetric = errors.New("nil metric") - -var _ = Describe("deployments", func() { - var ( - ctx context.Context - cancel context.CancelFunc - namespace string - namespaceGen = nameGenerator("deployment-test-namespace") - ) - - prom := internaltesting.NewPromClient() - - BeforeEach(func() { - ctx, cancel = context.WithCancel(context.Background()) - - namespace = namespaceGen() - - By("Starting manager") - - manager := exec.Command(_binPath, - "--kubeconfig", _kubeConfigPath, - ) - - manager.Env = []string{ - "WATCH_NAMESPACE=" + namespace, - } - - session, err := Start(manager, GinkgoWriter, GinkgoWriter) - Expect(err).ToNot(HaveOccurred()) - - By("Creating the watch namespace") - - ns := newNamespace(namespace) - - _client.Create(ctx, &ns) - - rbac, err := getRBAC(namespace, managerGroup) - Expect(err).ToNot(HaveOccurred()) - - for _, obj := range rbac { - _client.Create(ctx, obj) - } - - DeferCleanup(func() { - cancel() - - By("Stopping the managers") - - session.Interrupt() - - if usingExistingCluster() { - By("Deleting watch namspace") - - _client.Delete(ctx, &ns) - } - }) - }) - - When("created with missing resource requirements", func() { - It("should generate metrics", func() { - _client.Create(ctx, newDeployment("test", namespace)) - - var ( - deploymentMemReqMetric *io_prometheus_client.Metric - deploymentCPUReqMetric *io_prometheus_client.Metric - ) - - Eventually(func() error { - metrics, err := prom.GetDVOMetrics(ctx, "http://localhost:8383/metrics") - if err != nil { - return err - } - - memReqMetrics := metrics["unset_memory_requirements"] - deploymentMemReqMetric = searchableMetrics( - memReqMetrics, - ).FindDVOMetric("Deployment", "test", namespace) - if deploymentMemReqMetric == nil { - return ErrNilMetric - } - - cpuReqMetrics := metrics["unset_cpu_requirements"] - deploymentCPUReqMetric = searchableMetrics( - cpuReqMetrics, - ).FindDVOMetric("Deployment", "test", namespace) - if deploymentCPUReqMetric == nil { - return ErrNilMetric - } - - return nil - }, "10s").Should(Succeed()) - - Expect(deploymentMemReqMetric.Gauge.GetValue()).To(Equal(float64(1))) - Expect(deploymentCPUReqMetric.Gauge.GetValue()).To(Equal(float64(1))) - }) - }) - -}) - -func newNamespace(name string) corev1.Namespace { - return corev1.Namespace{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - }, - } -} - -func newDeployment(name, namespace string) *appsv1.Deployment { - return &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - Namespace: namespace, - Labels: map[string]string{ - "app": "test", - }, - }, - Spec: appsv1.DeploymentSpec{ - Replicas: int32Ptr(1), - Selector: &metav1.LabelSelector{ - MatchLabels: map[string]string{ - "app": "test", - }, - }, - Template: corev1.PodTemplateSpec{ - ObjectMeta: metav1.ObjectMeta{ - Labels: map[string]string{ - "app": "test", - }, - }, - Spec: corev1.PodSpec{ - Containers: []corev1.Container{ - { - Name: "test", - Image: "test", - }, - }, - }, - }, - }, - } -} - -func int32Ptr(i int32) *int32 { return &i } - -type searchableMetrics []*io_prometheus_client.Metric - -func (ms searchableMetrics) FindDVOMetric(kind, name, namespace string) *io_prometheus_client.Metric { - for _, m := range ms { - labels := searchableLables(m.GetLabel()) - - if labels.Contains("kind", kind) && - labels.Contains("name", name) && - labels.Contains("namespace", namespace) { - return m - } - } - - return nil -} - -type searchableLables []*io_prometheus_client.LabelPair - -func (ls searchableLables) Contains(name, val string) bool { - for _, l := range ls { - if l.GetName() != name { - continue - } - - if l.GetValue() == val { - return true - } - } - - return false -} diff --git a/integration/helpers.go b/integration/helpers.go deleted file mode 100644 index c264aad3..00000000 --- a/integration/helpers.go +++ /dev/null @@ -1,121 +0,0 @@ -package integration - -import ( - "bytes" - "errors" - "fmt" - "io" - "os" - "os/exec" - "path/filepath" - "strings" - - internaltesting "github.com/app-sre/deployment-validation-operator/internal/testing" - - rbacv1 "k8s.io/api/rbac/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "sigs.k8s.io/controller-runtime/pkg/client" -) - -func nameGenerator(pfx string) func() string { - i := 0 - - return func() string { - name := fmt.Sprintf("%s-%d", pfx, i) - - i++ - - return name - } -} - -func getClusterRBAC(group string) ([]client.Object, error) { - root, err := projectRoot() - if err != nil { - return nil, err - } - - path := filepath.Join(root, "deploy", "openshift", "cluster-role.yaml") - - role, err := internaltesting.LoadUnstructuredFromFile(path) - if err != nil { - return nil, fmt.Errorf("loading role: %w", err) - } - - return []client.Object{ - role, - &rbacv1.ClusterRoleBinding{ - ObjectMeta: metav1.ObjectMeta{ - Name: role.GetName(), - }, - Subjects: []rbacv1.Subject{ - { - Kind: "Group", - Name: group, - }, - }, - RoleRef: rbacv1.RoleRef{ - Kind: "ClusterRole", - Name: role.GetName(), - }, - }, - }, nil -} - -func getRBAC(namespace, group string) ([]client.Object, error) { - root, err := projectRoot() - if err != nil { - return nil, err - } - - role, err := internaltesting.LoadUnstructuredFromFile(filepath.Join(root, "deploy", "openshift", "role.yaml")) - if err != nil { - return nil, fmt.Errorf("loading role: %w", err) - } - - role.SetNamespace(namespace) - - return []client.Object{ - role, - &rbacv1.RoleBinding{ - ObjectMeta: metav1.ObjectMeta{ - Name: role.GetName(), - Namespace: namespace, - }, - Subjects: []rbacv1.Subject{ - { - Kind: "Group", - Name: group, - }, - }, - RoleRef: rbacv1.RoleRef{ - Kind: "Role", - Name: role.GetName(), - }, - }, - }, nil -} - -func projectRoot() (string, error) { - var buf bytes.Buffer - - cmd := exec.Command("git", "rev-parse", "--show-toplevel") - cmd.Stdout = &buf - cmd.Stderr = io.Discard - - if err := cmd.Run(); err != nil { - return "", fmt.Errorf("determining top level directory from git: %w", errSetup) - } - - return strings.TrimSpace(buf.String()), nil -} - -var errSetup = errors.New("test setup failed") - -func remove(path string) error { - if _, err := os.Stat(path); err != nil && os.IsNotExist(err) { - return nil - } - - return os.Remove(path) -} diff --git a/integration/suite_test.go b/integration/suite_test.go deleted file mode 100644 index 1eb7e258..00000000 --- a/integration/suite_test.go +++ /dev/null @@ -1,133 +0,0 @@ -package integration - -import ( - "context" - "os" - "path/filepath" - "testing" - - internaltesting "github.com/app-sre/deployment-validation-operator/internal/testing" - "github.com/app-sre/deployment-validation-operator/pkg/apis" - osappsv1 "github.com/openshift/api/apps/v1" - "k8s.io/apimachinery/pkg/runtime" - clientgoscheme "k8s.io/client-go/kubernetes/scheme" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - "github.com/onsi/gomega/gexec" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/envtest" -) - -const ( - managerUser = "deployment-validation-operator" - managerGroup = "deployment-validation-operator" -) - -var ( - _binPath string - _client *internaltesting.TestClient - _kubeConfigPath string - _testEnv *envtest.Environment -) - -// To run these tests with an external cluster -// set the following environment variables: -// USE_EXISTING_CLUSTER=true -// KUBECONFIG=. -// The external cluster must have authentication -// enabled on the API server. -func TestSuite(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "DVO suite") -} - -var _ = BeforeSuite(func() { - root, err := projectRoot() - Expect(err).ToNot(HaveOccurred()) - - By("Registering schemes") - - scheme := runtime.NewScheme() - Expect(clientgoscheme.AddToScheme(scheme)).Should(Succeed()) - Expect(osappsv1.AddToScheme(scheme)).Should(Succeed()) - Expect(apis.AddToScheme(scheme)).Should(Succeed()) - - By("Starting test environment") - - _testEnv = &envtest.Environment{ - Scheme: scheme, - } - - cfg, err := _testEnv.Start() - Expect(err).ToNot(HaveOccurred()) - Expect(cfg).ToNot(BeNil()) - - DeferCleanup(cleanup(_testEnv)) - - By("Initializing k8s client") - - client, err := client.New(cfg, client.Options{ - Scheme: scheme, - }) - Expect(err).ToNot(HaveOccurred()) - - _client = internaltesting.NewTestClient(client) - - By("Applying Cluster Scope RBAC") - - rbac, err := getClusterRBAC(managerGroup) - Expect(err).ToNot(HaveOccurred()) - - for _, obj := range rbac { - _client.Create(context.Background(), obj) - } - - By("Building manager binary") - - _binPath, err = gexec.BuildWithEnvironment( - filepath.Join(root, "cmd", "manager"), - []string{"CGO_ENABLED=0"}, - ) - Expect(err).ToNot(HaveOccurred()) - - By("writing kube.config") - - user, err := _testEnv.AddUser( - envtest.User{ - Name: managerUser, - Groups: []string{managerGroup}, - }, - nil, - ) - Expect(err).ToNot(HaveOccurred()) - - configFile, err := os.CreateTemp("", "dvo-integration-*") - Expect(err).ToNot(HaveOccurred()) - - data, err := user.KubeConfig() - Expect(err).ToNot(HaveOccurred()) - - _, err = configFile.Write(data) - Expect(err).ToNot(HaveOccurred()) - - _kubeConfigPath = configFile.Name() -}) - -func cleanup(env *envtest.Environment) func() { - return func() { - By("Stopping the test environment") - - Expect(env.Stop()).Should(Succeed()) - - By("Cleaning up test artifacts") - - gexec.CleanupBuildArtifacts() - - Expect(remove(_kubeConfigPath)).Should(Succeed()) - } -} - -func usingExistingCluster() bool { - return _testEnv.UseExistingCluster != nil && *_testEnv.UseExistingCluster -} diff --git a/internal/testing/client.go b/internal/testing/client.go deleted file mode 100644 index 1867c96b..00000000 --- a/internal/testing/client.go +++ /dev/null @@ -1,89 +0,0 @@ -package testing - -import ( - "context" - "fmt" - "time" - - "github.com/onsi/gomega" - "k8s.io/apimachinery/pkg/api/errors" - "sigs.k8s.io/controller-runtime/pkg/client" -) - -func NewTestClient(client client.Client) *TestClient { - return &TestClient{ - client: client, - } -} - -type TestClient struct { - client client.Client -} - -func (c *TestClient) Create(ctx context.Context, obj client.Object, opts ...RequestOption) { - if err := c.client.Get(ctx, client.ObjectKeyFromObject(obj), obj); errors.IsNotFound(err) { - gomega.ExpectWithOffset(1, c.client.Create(ctx, obj)).Should(gomega.Succeed()) - c.EventuallyObjectExists(ctx, obj, opts...) - } -} - -func (c *TestClient) Update(ctx context.Context, obj client.Object, opts ...RequestOption) { - gomega.ExpectWithOffset(1, c.client.Update(ctx, obj)).Should(gomega.Succeed()) -} - -func (c *TestClient) Delete(ctx context.Context, obj client.Object, opts ...RequestOption) { - gomega.ExpectWithOffset(1, client.IgnoreNotFound(c.client.Delete(ctx, obj))).Should(gomega.Succeed()) - c.EventuallyObjectDoesNotExist(ctx, obj, opts...) -} - -func (c *TestClient) EventuallyObjectExists(ctx context.Context, obj client.Object, opts ...RequestOption) bool { - var cfg RequestConfig - - cfg.Option(opts...) - cfg.Default() - - get := func() error { - return c.client.Get(ctx, client.ObjectKeyFromObject(obj), obj) - } - - return gomega.EventuallyWithOffset(1, get, fmt.Sprint(cfg.Timeout)).Should(gomega.Succeed()) -} - -func (c *TestClient) EventuallyObjectDoesNotExist(ctx context.Context, obj client.Object, opts ...RequestOption) bool { - var cfg RequestConfig - - cfg.Option(opts...) - cfg.Default() - - get := func() error { - return c.client.Get(ctx, client.ObjectKeyFromObject(obj), obj) - } - - return gomega.EventuallyWithOffset(1, get, fmt.Sprint(cfg.Timeout)).ShouldNot(gomega.Succeed()) -} - -type RequestConfig struct { - Timeout time.Duration -} - -func (c *RequestConfig) Option(opts ...RequestOption) { - for _, opt := range opts { - opt.ConfigureRequest(c) - } -} - -func (c *RequestConfig) Default() { - if c.Timeout == 0 { - c.Timeout = 1 * time.Second - } -} - -type RequestOption interface { - ConfigureRequest(*RequestConfig) -} - -type WithTimeout time.Duration - -func (w WithTimeout) ConfigureRequest(c *RequestConfig) { - c.Timeout = time.Duration(w) -} diff --git a/internal/testing/loader.go b/internal/testing/loader.go deleted file mode 100644 index 69b4882e..00000000 --- a/internal/testing/loader.go +++ /dev/null @@ -1,39 +0,0 @@ -package testing - -import ( - "bytes" - "fmt" - "os" - - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/serializer/yaml" - yamlutil "k8s.io/apimachinery/pkg/util/yaml" - "sigs.k8s.io/controller-runtime/pkg/client" -) - -func LoadUnstructuredFromFile(path string) (client.Object, error) { - data, err := os.ReadFile(path) - if err != nil { - return nil, fmt.Errorf("reading file: %w", err) - } - - decoder := yamlutil.NewYAMLOrJSONDecoder(bytes.NewBuffer(data), 100) - - var rawObj runtime.RawExtension - if err = decoder.Decode(&rawObj); err != nil { - return nil, fmt.Errorf("decoding raw object: %w", err) - } - - obj, _, err := yaml.NewDecodingSerializer(unstructured.UnstructuredJSONScheme).Decode(rawObj.Raw, nil, nil) - if err != nil { - return nil, fmt.Errorf("decoding runtime object: %w", err) - } - - unstructuredMap, err := runtime.DefaultUnstructuredConverter.ToUnstructured(obj) - if err != nil { - return nil, fmt.Errorf("converting to unstructured object: %w", err) - } - - return &unstructured.Unstructured{Object: unstructuredMap}, nil -} diff --git a/internal/testing/prom_client.go b/internal/testing/prom_client.go deleted file mode 100644 index 336447d3..00000000 --- a/internal/testing/prom_client.go +++ /dev/null @@ -1,84 +0,0 @@ -package testing - -import ( - "context" - "errors" - "fmt" - "io" - "net/http" - "strings" - - "github.com/app-sre/deployment-validation-operator/config" - dto "github.com/prometheus/client_model/go" - io_prometheus_client "github.com/prometheus/client_model/go" - "github.com/prometheus/common/expfmt" -) - -type TextParser interface { - TextToMetricFamilies(in io.Reader) (map[string]*dto.MetricFamily, error) -} - -func NewPromClient() *PromClient { - var cfg PromClientConfig - - cfg.Default() - - return &PromClient{ - cfg: cfg, - } -} - -type PromClient struct { - cfg PromClientConfig -} - -var ErrFailedRequest = errors.New("failed request") - -func (c *PromClient) GetDVOMetrics(ctx context.Context, url string) (map[string][]*io_prometheus_client.Metric, error) { - req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) - if err != nil { - return nil, fmt.Errorf("creating metrics request: %w", err) - } - - res, err := c.cfg.Client.Do(req) - if err != nil { - return nil, fmt.Errorf("requesting metrics from %q: %w", url, err) - } - - defer res.Body.Close() - - if res.StatusCode != http.StatusOK { - return nil, ErrFailedRequest - } - - mfs, err := c.cfg.Parser.TextToMetricFamilies(res.Body) - if err != nil { - return nil, fmt.Errorf("parsing metrics: %w", err) - } - - metrics := make(map[string][]*io_prometheus_client.Metric) - pfx := strings.ReplaceAll(config.OperatorName, "-", "_") + "_" - - for name, mf := range mfs { - if strings.HasPrefix(name, pfx) { - metrics[strings.TrimPrefix(name, pfx)] = mf.GetMetric() - } - } - - return metrics, nil -} - -type PromClientConfig struct { - Client *http.Client - Parser TextParser -} - -func (c *PromClientConfig) Default() { - if c.Client == nil { - c.Client = http.DefaultClient - } - - if c.Parser == nil { - c.Parser = &expfmt.TextParser{} - } -} From d3d3d2246061024549a554eaf3ef3fa6fad7225b Mon Sep 17 00:00:00 2001 From: Andrew Pantuso Date: Thu, 27 Oct 2022 07:31:15 -0400 Subject: [PATCH 2/2] Revert "Boilerplate: Update to a6c27570590858412f03ce4b84e7d6bb1ecfdc7a (#194)" This reverts commit e648b6a94bd9aebc3dbe795ea699236aadd8f9ff. --- .ci-operator.yaml | 2 +- .codecov.yml | 4 - boilerplate/_data/backing-image-tag | 2 +- boilerplate/_data/last-boilerplate-commit | 2 +- boilerplate/_lib/container-make | 15 +- boilerplate/_lib/subscriber-propose | 1 + .../golang-osd-operator/.codecov.yml | 4 - .../openshift/golang-osd-operator/README.md | 61 ++--- .../app-sre-build-deploy.sh | 2 +- .../openshift/golang-osd-operator/app-sre.md | 11 - .../golang-osd-operator/build-opm-catalog.sh | 8 - .../codecov-secret-mapping | 62 +++++ .../golang-osd-operator/configure-fips.sh | 18 -- .../csv-generate/catalog-build.sh | 27 +-- .../csv-generate/catalog-publish.sh | 15 +- .../common-generate-operator-bundle.py | 42 +--- .../csv-generate/csv-generate.mk | 66 ++++-- .../csv-generate/csv-generate.sh | 222 ++++++++++-------- .../openshift/golang-osd-operator/ensure.sh | 53 +++++ .../golang-osd-operator/fips.go.tmplt | 15 -- .../golang-osd-operator/golangci.yml | 1 - .../operator-sdk-generate.sh | 47 ++++ .../openshift/golang-osd-operator/standard.mk | 178 ++------------ .../openshift/golang-osd-operator/update | 5 +- build/Dockerfile | 2 +- 25 files changed, 410 insertions(+), 455 deletions(-) create mode 100755 boilerplate/openshift/golang-osd-operator/codecov-secret-mapping delete mode 100755 boilerplate/openshift/golang-osd-operator/configure-fips.sh delete mode 100644 boilerplate/openshift/golang-osd-operator/fips.go.tmplt create mode 100755 boilerplate/openshift/golang-osd-operator/operator-sdk-generate.sh diff --git a/.ci-operator.yaml b/.ci-operator.yaml index 22d2bf05..5061986f 100644 --- a/.ci-operator.yaml +++ b/.ci-operator.yaml @@ -1,4 +1,4 @@ build_root_image: name: boilerplate namespace: openshift - tag: image-v2.3.2 + tag: image-v1.0.0 diff --git a/.codecov.yml b/.codecov.yml index ba05647a..844b447e 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -24,7 +24,3 @@ comment: layout: "reach,diff,flags,tree" behavior: default require_changes: no - -ignore: - - "**/mocks" - - "**/zz_generated*.go" diff --git a/boilerplate/_data/backing-image-tag b/boilerplate/_data/backing-image-tag index bb65150a..69c23d74 100644 --- a/boilerplate/_data/backing-image-tag +++ b/boilerplate/_data/backing-image-tag @@ -1 +1 @@ -image-v2.3.2 +image-v1.0.0 diff --git a/boilerplate/_data/last-boilerplate-commit b/boilerplate/_data/last-boilerplate-commit index 60a5d960..06f06555 100644 --- a/boilerplate/_data/last-boilerplate-commit +++ b/boilerplate/_data/last-boilerplate-commit @@ -1 +1 @@ -a6c27570590858412f03ce4b84e7d6bb1ecfdc7a +b0a20637c47d7d94d6bdadbb2660b4f081526015 diff --git a/boilerplate/_lib/container-make b/boilerplate/_lib/container-make index ddcfedb5..7ef0f1bf 100755 --- a/boilerplate/_lib/container-make +++ b/boilerplate/_lib/container-make @@ -9,9 +9,11 @@ fi source ${0%/*}/common.sh -CONTAINER_ENGINE="${CONTAINER_ENGINE:-$(command -v podman || command -v docker)}" +CONTAINER_ENGINE=$(command -v podman || command -v docker) [[ -n "$CONTAINER_ENGINE" ]] || err "Couldn't find a container engine. Are you already in a container?" +CONTAINER_ENGINE_SHORT=${CONTAINER_ENGINE##*/} + # Make sure the mount inside the container is named in such a way that # - openapi-gen (which relies on GOPATH) produces absolute paths; and # - other go-ish paths are writeable, e.g. for `go mod download`. @@ -19,16 +21,11 @@ CONTAINER_MOUNT=/go/src/$(repo_import $REPO_ROOT) # First set up a detached container with the repo mounted. banner "Starting the container" -if [[ "${CONTAINER_ENGINE##*/}" == "podman" ]]; then - if [[ $OSTYPE == *"darwin"* ]]; then - CE_OPTS="--userns keep-id -v $REPO_ROOT:$CONTAINER_MOUNT" - else - CE_OPTS="--userns keep-id -v $REPO_ROOT:$CONTAINER_MOUNT:Z" - fi +if [[ $CONTAINER_ENGINE_SHORT == "podman" ]]; then + container_id=$($CONTAINER_ENGINE run --userns keep-id -d -v "$REPO_ROOT":"$CONTAINER_MOUNT":Z $IMAGE_PULL_PATH tail -f /dev/null) else - CE_OPTS="-v $REPO_ROOT:$CONTAINER_MOUNT" + container_id=$($CONTAINER_ENGINE run -d -v "$REPO_ROOT":"$CONTAINER_MOUNT" $IMAGE_PULL_PATH tail -f /dev/null) fi -container_id=$($CONTAINER_ENGINE run -d ${CE_OPTS} $IMAGE_PULL_PATH sleep infinity) if [[ $? -ne 0 ]] || [[ -z "$container_id" ]]; then err "Couldn't start detached container" diff --git a/boilerplate/_lib/subscriber-propose b/boilerplate/_lib/subscriber-propose index 8fb05768..cc57b961 100755 --- a/boilerplate/_lib/subscriber-propose +++ b/boilerplate/_lib/subscriber-propose @@ -7,6 +7,7 @@ declare -A SUBCOMMANDS SUBCOMMANDS=( # TODO: # [bootstrap]='Bootstrap a new subscriber' + # [codecov-secret-mapping]='Propose codecov secret mapping to openshift/release' # [prow-config]='Propose standardized prow configuration to openshift/release' [update]='Update an already-onboarded subscriber' ) diff --git a/boilerplate/openshift/golang-osd-operator/.codecov.yml b/boilerplate/openshift/golang-osd-operator/.codecov.yml index ba05647a..844b447e 100644 --- a/boilerplate/openshift/golang-osd-operator/.codecov.yml +++ b/boilerplate/openshift/golang-osd-operator/.codecov.yml @@ -24,7 +24,3 @@ comment: layout: "reach,diff,flags,tree" behavior: default require_changes: no - -ignore: - - "**/mocks" - - "**/zz_generated*.go" diff --git a/boilerplate/openshift/golang-osd-operator/README.md b/boilerplate/openshift/golang-osd-operator/README.md index edee6acb..4f6d5777 100644 --- a/boilerplate/openshift/golang-osd-operator/README.md +++ b/boilerplate/openshift/golang-osd-operator/README.md @@ -14,7 +14,6 @@ This convention is suitable for both cluster- and hive-deployed operators. The following components are included: ## `make` targets and functions. - **Note:** Your repository's main `Makefile` needs to be edited to include the "nexus makefile include": @@ -29,7 +28,7 @@ following: ### Prow | Test name / `make` target | Purpose | -| ------------------------- | --------------------------------------------------------------------------------------------------------------- | +|---------------------------|-----------------------------------------------------------------------------------------------------------------| | `validate` | Ensure code generation has not been forgotten; and ensure generated and boilerplate code has not been modified. | | `lint` | Perform static analysis. | | `test` | "Local" unit and functional testing. | @@ -49,26 +48,18 @@ $ make RELEASE_CLONE=/home/me/github/openshift/release prow-config ``` This will generate a delta configuring prow to: - - Build your `build/Dockerfile`. - Run the above targets in presubmit tests. - Run the `coverage` target in a postsubmit. This is the step that updates your coverage report in codecov.io. #### Local Testing - You can run these `make` targets locally during development to test your code changes. However, differences in platforms and environments may lead to unpredictable results. Therefore boilerplate provides a utility to run targets in a container environment that is designed to be as similar as possible to CI: -```shell -$ make container-{target} -``` - -or - ```shell $ ./boilerplate/_lib/container-make {target} ``` @@ -81,15 +72,27 @@ By default it is configured to be run from the app-sre jenkins pipelines. Consult [this doc](app-sre.md) for information on local execution/testing. ## Code coverage - - A `codecov.sh` script, referenced by the `coverage` `make` target, to - run code coverage analysis per [this SOP](https://github.com/openshift/ops-sop/blob/93d100347746ce04ad552591136818f82043c648/services/codecov.md). +run code coverage analysis per [this SOP](https://github.com/openshift/ops-sop/blob/93d100347746ce04ad552591136818f82043c648/services/codecov.md). - A `.codecov.yml` configuration file for [codecov.io](https://docs.codecov.io/docs/codecov-yaml). Note that this is copied into the repository root, because that's [where codecov.io expects it](https://docs.codecov.io/docs/codecov-yaml#can-i-name-the-file-codecovyml). +- A `make` target to [request the secret mapping in openshift/release](https://github.com/openshift/ops-sop/blob/be43125239deb1f2bbc1ef54f010410e97ff6146/services/codecov.md#openshiftrelease-pr-1---secret-mapping): + +```shell +$ make codecov-secret-mapping +``` + +If you already have the openshift/release repository cloned locally, you +may specify its path via `$RELEASE_CLONE`: + +```shell +$ make RELEASE_CLONE=/home/me/github/openshift/release codecov-secret-mapping +``` + ## Linting and other static analysis with `golangci-lint` - A `go-check` `make` target, which @@ -104,35 +107,13 @@ The convention embeds default checks to ensure generated code generation is curr To trigger the check, you can use `make generate-check` provided your Makefile properly includes the boilerplate-generated include `boilerplate/generated-includes.mk`. Checks consist of: - -- Checking all files are committed to ensure a safe point to revert to in case of error -- Running the `make generate` command (see below) to regenerate the needed code -- Checking if this results in any new uncommitted files in the git project or if all is clean. +* Checking all files are committed to ensure a safe point to revert to in case of error +* Running the `make generate` command (see below) to regenerate the needed code +* Checking if this results in any new uncommitted files in the git project or if all is clean. `make generate` does the following: - -- generate crds and deepcopy via controller-gen. This is a no-op if your +* `operator-sdk generate crds` and `k8s`. This is a no-op if your operator has no APIs. -- `openapi-gen`. This is a no-op if your operator has no APIs. -- `go generate`. This is a no-op if you have no `//go:generate` +* `openapi-gen`. This is a no-op if your operator has no APIs. +* `go generate`. This is a no-op if you have no `//go:generate` directives in your code. - -## FIPS (Federal Information Processing Standards) - -To enable FIPS in your build there is a `make ensure-fips` target. - -Add `FIPS_ENABLED=true` to your repos Makefile. Please ensure that this variable is added **before** including boilerplate Makefiles. - -e.g. - -```.mk -FIPS_ENABLED=true - -include boilerplate/generated-includes.mk -``` - -`ensure-fips` will add a [fips.go](./fips.go) file in the same directory as the `main.go` file. (Please commit this file as normal) - -`fips.go` will import the necessary packages to restrict all TLS configuration to FIPS-approved settings. - -With `FIPS_ENABLED=true`, `ensure-fips` is always run before `make go-build` diff --git a/boilerplate/openshift/golang-osd-operator/app-sre-build-deploy.sh b/boilerplate/openshift/golang-osd-operator/app-sre-build-deploy.sh index 0aa6dd79..1af16793 100755 --- a/boilerplate/openshift/golang-osd-operator/app-sre-build-deploy.sh +++ b/boilerplate/openshift/golang-osd-operator/app-sre-build-deploy.sh @@ -68,6 +68,6 @@ for channel in staging production; do echo "properly. Nothing to do!" else # build the CSV and create & push image catalog for the appropriate channel - make ${channel}-csv-build ${channel}-catalog-build ${channel}-catalog-publish + make ${channel}-common-csv-build ${channel}-catalog-build ${channel}-catalog-publish fi done diff --git a/boilerplate/openshift/golang-osd-operator/app-sre.md b/boilerplate/openshift/golang-osd-operator/app-sre.md index dfd9ede7..2c4d59cc 100644 --- a/boilerplate/openshift/golang-osd-operator/app-sre.md +++ b/boilerplate/openshift/golang-osd-operator/app-sre.md @@ -21,17 +21,6 @@ If not, you will need to set the `IMAGE_REGISTRY` environment variable (see [bel The SaaS bundle repository for `$OPERATOR_NAME` should be located at `https://gitlab.cee.redhat.com/service/saas-{operator}-bundle`, e.g. https://gitlab.cee.redhat.com/service/saas-deadmanssnitch-operator-bundle. Fork it to your personal namespace. -If you have already forked it to your personal namespace and/or used your fork for testing app-sre scripts at some time in the past, it is recommended that you bring your fork in sync with how upstream appears, or else the catalog you test with may not work correctly when deployed. - -An example of how to do this for the `staging` branch is below (`production` steps are the same): - -``` -git checkout staging -git pull upstream staging -git reset --hard upstream/staging -git push origin staging --force -``` - ## Set environment variables ```bash # The process creates artifacts in your git clone. Some of the make targets diff --git a/boilerplate/openshift/golang-osd-operator/build-opm-catalog.sh b/boilerplate/openshift/golang-osd-operator/build-opm-catalog.sh index 196d07a7..f856aae9 100755 --- a/boilerplate/openshift/golang-osd-operator/build-opm-catalog.sh +++ b/boilerplate/openshift/golang-osd-operator/build-opm-catalog.sh @@ -320,14 +320,6 @@ function main() { local versions # shellcheck disable=SC2207 versions=($(get_prev_operator_version "$bundle_versions_file")) - # This condition is triggered when an operator is built for the first time. In such case the - # get_prev_operator_version returns an empty string and causes undefined variables failures - # in a few lines below. - if [ -z ${versions+x} ] - then - versions[0]="" - versions[1]="" - fi local prev_operator_version="${versions[0]}" local prev_good_operator_version="${versions[1]}" local skip_versions=("${versions[@]:2}") diff --git a/boilerplate/openshift/golang-osd-operator/codecov-secret-mapping b/boilerplate/openshift/golang-osd-operator/codecov-secret-mapping new file mode 100755 index 00000000..d75dcbeb --- /dev/null +++ b/boilerplate/openshift/golang-osd-operator/codecov-secret-mapping @@ -0,0 +1,62 @@ +#!/usr/bin/env bash + +set -e + +REPO_ROOT=$(git rev-parse --show-toplevel) +source $REPO_ROOT/boilerplate/_lib/common.sh +source $REPO_ROOT/boilerplate/_lib/release.sh + +cmd=${0##*/} + +usage() { + cat <> $mapping_file +- from: + namespace: sd-sre-secrets + name: $secret_name + to: + namespace: ci + name: $secret_name +EOF + +release_branch=$CONSUMER_ORG-$CONSUMER_NAME-$DEFAULT_BRANCH-boilerplate-$cmd + +release_done_msg $release_branch diff --git a/boilerplate/openshift/golang-osd-operator/configure-fips.sh b/boilerplate/openshift/golang-osd-operator/configure-fips.sh deleted file mode 100755 index e506a00d..00000000 --- a/boilerplate/openshift/golang-osd-operator/configure-fips.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash - -set -e - -REPO_ROOT=$(git rev-parse --show-toplevel) -CONVENTION_DIR="$REPO_ROOT/boilerplate/openshift/golang-osd-operator" -PRE_V1_SDK_MANAGER_DIR="$REPO_ROOT/cmd/manager" - -if [[ -d "$PRE_V1_SDK_MANAGER_DIR" ]] -then - MAIN_DIR=$PRE_V1_SDK_MANAGER_DIR -else - MAIN_DIR=$REPO_ROOT -fi - -echo "Writing fips file at $MAIN_DIR/fips.go" - -cp $CONVENTION_DIR/fips.go.tmplt "$MAIN_DIR/fips.go" \ No newline at end of file diff --git a/boilerplate/openshift/golang-osd-operator/csv-generate/catalog-build.sh b/boilerplate/openshift/golang-osd-operator/csv-generate/catalog-build.sh index 8b5f1d52..8012940c 100755 --- a/boilerplate/openshift/golang-osd-operator/csv-generate/catalog-build.sh +++ b/boilerplate/openshift/golang-osd-operator/csv-generate/catalog-build.sh @@ -23,13 +23,6 @@ while getopts "o:c:r:" option; do esac done -# Detect the container engine to use, allowing override from the env -CONTAINER_ENGINE=${CONTAINER_ENGINE:-$(command -v podman || command -v docker || true)} -if [[ -z "$CONTAINER_ENGINE" ]]; then - echo "WARNING: Couldn't find a container engine! Defaulting to docker." - CONTAINER_ENGINE=docker -fi - # Checking parameters check_mandatory_params operator_channel operator_name @@ -63,29 +56,13 @@ EOF # Build registry cat < $DOCKERFILE_REGISTRY -FROM quay.io/openshift/origin-operator-registry:4.10.0 AS builder +FROM quay.io/openshift/origin-operator-registry:4.8.0 COPY $SAAS_OPERATOR_DIR manifests RUN initializer --permissive - -FROM registry.access.redhat.com/ubi8/ubi-micro:8.6-484 - -COPY --from=builder /bin/registry-server /bin/registry-server -COPY --from=builder /bin/grpc_health_probe /bin/grpc_health_probe -COPY --from=builder /bin/initializer /bin/initializer - -WORKDIR /registry -RUN chgrp -R 0 /registry && chmod -R g+rwx /registry - -USER 1001 - -COPY --from=builder /registry /registry - -EXPOSE 50051 - CMD ["registry-server", "-t", "/tmp/terminate.log"] EOF -${CONTAINER_ENGINE} build --pull -f $DOCKERFILE_REGISTRY --tag "${registry_image}:${operator_channel}-latest" . +docker build -f $DOCKERFILE_REGISTRY --tag "${registry_image}:${operator_channel}-latest" . if [ $? -ne 0 ] ; then echo "docker build failed, exiting..." diff --git a/boilerplate/openshift/golang-osd-operator/csv-generate/catalog-publish.sh b/boilerplate/openshift/golang-osd-operator/csv-generate/catalog-publish.sh index 16205295..b5665f8a 100755 --- a/boilerplate/openshift/golang-osd-operator/csv-generate/catalog-publish.sh +++ b/boilerplate/openshift/golang-osd-operator/csv-generate/catalog-publish.sh @@ -41,17 +41,6 @@ BUNDLE_DIR="${SAAS_OPERATOR_DIR}/${operator_name}" OPERATOR_NEW_VERSION=$(ls "${BUNDLE_DIR}" | sort -t . -k 3 -g | tail -n 1) OPERATOR_PREV_VERSION=$(ls "${BUNDLE_DIR}" | sort -t . -k 3 -g | tail -n 2 | head -n 1) -# Get container engine -CONTAINER_ENGINE=$(command -v podman || command -v docker || true) -[[ -n "$CONTAINER_ENGINE" ]] || echo "WARNING: Couldn't find a container engine. Assuming you already in a container, running unit tests." >&2 - -# Set SRC container transport based on container engine -if [[ "${CONTAINER_ENGINE##*/}" == "podman" ]]; then - SRC_CONTAINER_TRANSPORT="containers-storage" -else - SRC_CONTAINER_TRANSPORT="docker-daemon" -fi - # Checking SAAS_OPERATOR_DIR exist if [ ! -d "${SAAS_OPERATOR_DIR}/.git" ] ; then echo "${SAAS_OPERATOR_DIR} should exist and be a git repository" @@ -96,7 +85,7 @@ popd if [ "$push_catalog" = true ] ; then # push image skopeo copy --dest-creds "${QUAY_USER}:${QUAY_TOKEN}" \ - "${SRC_CONTAINER_TRANSPORT}:${registry_image}:${operator_channel}-latest" \ + "docker-daemon:${registry_image}:${operator_channel}-latest" \ "docker://${registry_image}:${operator_channel}-latest" if [ $? -ne 0 ] ; then @@ -105,7 +94,7 @@ if [ "$push_catalog" = true ] ; then fi skopeo copy --dest-creds "${QUAY_USER}:${QUAY_TOKEN}" \ - "${SRC_CONTAINER_TRANSPORT}:${registry_image}:${operator_channel}-latest" \ + "docker-daemon:${registry_image}:${operator_channel}-latest" \ "docker://${registry_image}:${operator_channel}-${operator_commit_hash}" if [ $? -ne 0 ] ; then diff --git a/boilerplate/openshift/golang-osd-operator/csv-generate/common-generate-operator-bundle.py b/boilerplate/openshift/golang-osd-operator/csv-generate/common-generate-operator-bundle.py index 3bf6c0a1..d27fc736 100755 --- a/boilerplate/openshift/golang-osd-operator/csv-generate/common-generate-operator-bundle.py +++ b/boilerplate/openshift/golang-osd-operator/csv-generate/common-generate-operator-bundle.py @@ -44,7 +44,7 @@ parser = argparse.ArgumentParser() parser.add_argument("-o", "--operator-name", type=str, help="Name of the operator", required=True) parser.add_argument("-d", "--output-dir", type=str, help="Directory for the CSV generation", required=True) -parser.add_argument("-p", "--previous-version", type=str, help="Semver of the version being replaced", required=False) +parser.add_argument("-p", "--previous-version", type=str, help="Semver of the version being replaced", required=True) parser.add_argument("-i", "--operator-image", type=str, help="Base index image to be used", required=True) parser.add_argument("-V", "--operator-version", type=str, help="The full version of the operator (without the leading `v`): {major}.{minor}.{commit-number}-{hash}", required=True) args = parser.parse_args() @@ -240,18 +240,16 @@ def trim_index(index, kind, item): csv['spec']['customresourcedefinitions'] = {'owned': []} for crd in by_kind.get('CustomResourceDefinition', []): log_resource(crd) - # And register the CRD as "owned" in the CSV - for version in crd["spec"]["versions"]: - csv['spec']['customresourcedefinitions']['owned'].append( - { - "name": crd["metadata"]["name"], - "description": crd["spec"]["names"]["kind"], - "displayName": crd["spec"]["names"]["kind"], - "kind": crd["spec"]["names"]["kind"], - "version": version["name"] - } - ) + csv['spec']['customresourcedefinitions']['owned'].append( + { + "name": crd["metadata"]["name"], + "description": crd["spec"]["names"]["kind"], + "displayName": crd["spec"]["names"]["kind"], + "kind": crd["spec"]["names"]["kind"], + "version": crd["spec"]["version"] + } + ) # These will be written to the bundle at the end along with generic resources ## Process [Cluster]Role[Binding]s (TODO: Match up ServiceAccounts) @@ -307,7 +305,7 @@ def trim_index(index, kind, item): csv['spec']['install']['spec']['permissions'].append( { 'rules': role['rules'], - 'serviceAccountName': role_binding['subjects'][0]['name'] + 'serviceAccountName': role_binding['subjects'][0]['name'] } ) trim_index(by_kind, 'Role', role) @@ -318,21 +316,6 @@ def trim_index(index, kind, item): deploy = by_kind['Deployment'][0] # Use the operator image pull spec we were passed deploy['spec']['template']['spec']['containers'][0]['image'] = operator_image -# Add or replace OPERATOR_IMAGE env var -env = deploy['spec']['template']['spec']['containers'][0].get('env') -if env: - # Does OPERATOR_IMAGE key already exist in spec? If so, update value - for entry in env: - if entry['name'] == 'OPERATOR_IMAGE': - entry['value'] = operator_image - break - # If not, add it - else: - env.append(dict(name='OPERATOR_IMAGE', value=operator_image)) -else: - # The container has no environment variables, so just set this one - env = dict(name='OPERATOR_IMAGE', value=operator_image) - csv['spec']['install']['spec']['deployments'] = [ { 'name': deploy['metadata']['name'], @@ -363,8 +346,7 @@ def trim_index(index, kind, item): # Update the versions to include git hash: csv['metadata']['name'] = f"{OPERATOR_NAME}.v{full_version}" csv['spec']['version'] = full_version -if prev_version: - csv['spec']['replaces'] = f"{OPERATOR_NAME}.v{prev_version}" +csv['spec']['replaces'] = f"{OPERATOR_NAME}.v{prev_version}" # Set the CSV createdAt annotation: now = datetime.datetime.now() diff --git a/boilerplate/openshift/golang-osd-operator/csv-generate/csv-generate.mk b/boilerplate/openshift/golang-osd-operator/csv-generate/csv-generate.mk index 21e9ea43..8aeff43b 100644 --- a/boilerplate/openshift/golang-osd-operator/csv-generate/csv-generate.mk +++ b/boilerplate/openshift/golang-osd-operator/csv-generate/csv-generate.mk @@ -1,47 +1,67 @@ + + +.PHONY: staging-hack-csv-build +staging-hack-csv-build: + @${CONVENTION_DIR}/csv-generate/csv-generate.sh -o $(OPERATOR_NAME) -i $(OPERATOR_IMAGE) -V $(OPERATOR_VERSION) -c staging -H $(CURRENT_COMMIT) -n $(COMMIT_NUMBER) -g hack + +.PHONY: staging-common-csv-build +staging-common-csv-build: + @${CONVENTION_DIR}/csv-generate/csv-generate.sh -o $(OPERATOR_NAME) -i $(OPERATOR_IMAGE) -V $(OPERATOR_VERSION) -c staging -H $(CURRENT_COMMIT) -n $(COMMIT_NUMBER) -g common + .PHONY: staging-csv-build -staging-csv-build: - @${CONVENTION_DIR}/csv-generate/csv-generate.sh -o $(OPERATOR_NAME) -i $(OPERATOR_IMAGE) -V $(OPERATOR_VERSION) -c staging -H $(CURRENT_COMMIT) -n $(COMMIT_NUMBER) +staging-csv-build: staging-hack-csv-build + +.PHONY: staging-common-csv-build-and-diff +staging-common-csv-build-and-diff: + @${CONVENTION_DIR}/csv-generate/csv-generate.sh -o $(OPERATOR_NAME) -i $(OPERATOR_IMAGE) -V $(OPERATOR_VERSION) -c staging -H $(CURRENT_COMMIT) -n $(COMMIT_NUMBER) -g common -d .PHONY: staging-catalog-build -staging-catalog-build: +staging-catalog-build: @${CONVENTION_DIR}/csv-generate/catalog-build.sh -o $(OPERATOR_NAME) -c staging -r ${REGISTRY_IMAGE} - + .PHONY: staging-saas-bundle-push -staging-saas-bundle-push: +staging-saas-bundle-push: @${CONVENTION_DIR}/csv-generate/catalog-publish.sh -o $(OPERATOR_NAME) -c staging -H $(CURRENT_COMMIT) -n $(COMMIT_NUMBER) -r ${REGISTRY_IMAGE} - + .PHONY: staging-catalog-publish -staging-catalog-publish: +staging-catalog-publish: @${CONVENTION_DIR}/csv-generate/catalog-publish.sh -o $(OPERATOR_NAME) -c staging -H $(CURRENT_COMMIT) -n $(COMMIT_NUMBER) -p -r ${REGISTRY_IMAGE} - + .PHONY: staging-catalog-build-and-publish -staging-catalog-build-and-publish: +staging-catalog-build-and-publish: @$(MAKE) -s staging-csv-build --no-print-directory @$(MAKE) -s staging-catalog-build --no-print-directory - @$(MAKE) -s staging-catalog-publish --no-print-directory - + @$(MAKE) -s staging-catalog-publish --no-print-directory + .PHONY: production-hack-csv-build -production-hack-csv-build: +production-hack-csv-build: @${CONVENTION_DIR}/csv-generate/csv-generate.sh -o $(OPERATOR_NAME) -i $(OPERATOR_IMAGE) -V $(OPERATOR_VERSION) -c production -H $(CURRENT_COMMIT) -n $(COMMIT_NUMBER) -g hack - + +.PHONY: production-common-csv-build +production-common-csv-build: + @${CONVENTION_DIR}/csv-generate/csv-generate.sh -o $(OPERATOR_NAME) -i $(OPERATOR_IMAGE) -V $(OPERATOR_VERSION) -c production -H $(CURRENT_COMMIT) -n $(COMMIT_NUMBER) -g common + .PHONY: production-csv-build -production-csv-build: - @${CONVENTION_DIR}/csv-generate/csv-generate.sh -o $(OPERATOR_NAME) -i $(OPERATOR_IMAGE) -V $(OPERATOR_VERSION) -c production -H $(CURRENT_COMMIT) -n $(COMMIT_NUMBER) +production-csv-build: production-hack-csv-build + +.PHONY: production-common-csv-build-and-diff +production-common-csv-build-and-diff: + @${CONVENTION_DIR}/csv-generate/csv-generate.sh -o $(OPERATOR_NAME) -i $(OPERATOR_IMAGE) -V $(OPERATOR_VERSION) -c production -H $(CURRENT_COMMIT) -n $(COMMIT_NUMBER) -g common -d .PHONY: production-catalog-build -production-catalog-build: +production-catalog-build: @${CONVENTION_DIR}/csv-generate/catalog-build.sh -o $(OPERATOR_NAME) -c production -r ${REGISTRY_IMAGE} - + .PHONY: production-saas-bundle-push -production-saas-bundle-push: +production-saas-bundle-push: @${CONVENTION_DIR}/csv-generate/catalog-publish.sh -o $(OPERATOR_NAME) -c production -H $(CURRENT_COMMIT) -n $(COMMIT_NUMBER) -r ${REGISTRY_IMAGE} - + .PHONY: production-catalog-publish -production-catalog-publish: +production-catalog-publish: @${CONVENTION_DIR}/csv-generate/catalog-publish.sh -o $(OPERATOR_NAME) -c production -H $(CURRENT_COMMIT) -n $(COMMIT_NUMBER) -p -r ${REGISTRY_IMAGE} - + .PHONY: production-catalog-build-and-publish -production-catalog-build-and-publish: +production-catalog-build-and-publish: @$(MAKE) -s production-csv-build --no-print-directory @$(MAKE) -s production-catalog-build --no-print-directory - @$(MAKE) -s production-catalog-publish --no-print-directory + @$(MAKE) -s production-catalog-publish --no-print-directory diff --git a/boilerplate/openshift/golang-osd-operator/csv-generate/csv-generate.sh b/boilerplate/openshift/golang-osd-operator/csv-generate/csv-generate.sh index 5e7a7104..668e1fa5 100755 --- a/boilerplate/openshift/golang-osd-operator/csv-generate/csv-generate.sh +++ b/boilerplate/openshift/golang-osd-operator/csv-generate/csv-generate.sh @@ -4,7 +4,7 @@ set -e source `dirname $0`/common.sh -usage() { echo "Usage: $0 -o operator-name -c saas-repository-channel -H operator-commit-hash -n operator-commit-number -i operator-image -V operator-version" 1>&2; exit 1; } +usage() { echo "Usage: $0 -o operator-name -c saas-repository-channel -H operator-commit-hash -n operator-commit-number -i operator-image -V operator-version -g [hack|common][-d]" 1>&2; exit 1; } # TODO : Add support of long-options while getopts "c:dg:H:i:n:o:V:" option; do @@ -12,6 +12,17 @@ while getopts "c:dg:H:i:n:o:V:" option; do c) operator_channel=${OPTARG} ;; + d) + diff_generate=true + ;; + g) + if [ "${OPTARG}" = "hack" ] || [ "${OPTARG}" = "common" ] ; then + generate_script=${OPTARG} + else + # TODO : Case to be tested + echo "Incorrect value for '-g'. Expecting 'hack' or 'common'. Got ${OPTARG}" + fi + ;; H) operator_commit_hash=${OPTARG} ;; @@ -38,7 +49,7 @@ while getopts "c:dg:H:i:n:o:V:" option; do done # Checking parameters -check_mandatory_params operator_channel operator_image operator_version operator_name operator_commit_hash operator_commit_number +check_mandatory_params operator_channel operator_image operator_version operator_name operator_commit_hash operator_commit_number generate_script # Use set container engine or select one from available binaries if [[ -z "$CONTAINER_ENGINE" ]]; then @@ -68,112 +79,135 @@ fi SAAS_OPERATOR_DIR="saas-${operator_name}-bundle" BUNDLE_DIR="$SAAS_OPERATOR_DIR/${operator_name}/" -rm -rf "$SAAS_OPERATOR_DIR" -git clone --branch "$operator_channel" ${GIT_PATH} "$SAAS_OPERATOR_DIR" +if [ "$diff_generate" = true ] ; then + OPERATOR_NEW_VERSION=$(ls "$BUNDLE_DIR" | sort -t . -k 3 -g | tail -n 1) + OPERATOR_PREV_VERSION=$(ls "${BUNDLE_DIR}" | sort -t . -k 3 -g | tail -n 2 | head -n 1) + OUTPUT_DIR="output-comparison" -# If this is a brand new SaaS setup, then set up accordingly -if [[ ! -d "${BUNDLE_DIR}" ]]; then - echo "Setting up new SaaS operator dir: ${BUNDLE_DIR}" - mkdir "${BUNDLE_DIR}" -fi - -# For testing purposes, support disabling anything that relies on -# querying the saas file in app-interface. This includes pruning -# undeployed commits in production. -# FIXME -- This should go away when we're querying app-interface via -# graphql. -if [[ -z "$SKIP_SAAS_FILE_CHECKS" ]]; then - # PATH to saas file in app-interface - SAAS_FILE_URL="https://gitlab.cee.redhat.com/service/app-interface/raw/master/data/services/osd-operators/cicd/saas/saas-${operator_name}.yaml" - - # MANAGED_RESOURCE_TYPE - # SAAS files contain the type of resources managed within the OC templates that - # are being applied to hive. - # For customer cluster resources this should always be of type "SelectorSyncSet" resources otherwise - # can't be sync'd to the customer cluster. We're explicity selecting the first element in the array. - # We can safely assume anything that is not of type "SelectorSyncSet" is being applied to hive only - # since it matches ClusterDeployment resources. - # From this we'll assume that the namespace reference in resourceTemplates to be: - # For customer clusters: /services/osd-operators/namespace//namespaces/cluster-scope.yaml - # For hive clusters: /services/osd-operators/namespace//namespaces/.yaml - MANAGED_RESOURCE_TYPE=$(curl -s "${SAAS_FILE_URL}" | \ - $YQ_CMD r - "managedResourceTypes[0]" - ) - if [[ "${MANAGED_RESOURCE_TYPE}" == "" ]]; then - echo "Unabled to determine if SAAS file managed resource type" + # For diff usecase, checking there is already a generated CSV + if [ ! -f ${BUNDLE_DIR}/${OPERATOR_NEW_VERSION}/*.clusterserviceversion.yaml ] ; then + echo "You need to generate CSV with your legacy script before trying to run the diff option" exit 1 fi +else + rm -rf "$SAAS_OPERATOR_DIR" + git clone --branch "$operator_channel" ${GIT_PATH} "$SAAS_OPERATOR_DIR" + + # For testing purposes, support disabling anything that relies on + # querying the saas file in app-interface. This includes pruning + # undeployed commits in production. + # FIXME -- This should go away when we're querying app-interface via + # graphql. + if [[ -z "$SKIP_SAAS_FILE_CHECKS" ]]; then + # PATH to saas file in app-interface + SAAS_FILE_URL="https://gitlab.cee.redhat.com/service/app-interface/raw/master/data/services/osd-operators/cicd/saas/saas-${operator_name}.yaml" + + # MANAGED_RESOURCE_TYPE + # SAAS files contain the type of resources managed within the OC templates that + # are being applied to hive. + # For customer cluster resources this should always be of type "SelectorSyncSet" resources otherwise + # can't be sync'd to the customer cluster. We're explicity selecting the first element in the array. + # We can safely assume anything that is not of type "SelectorSyncSet" is being applied to hive only + # since it matches ClusterDeployment resources. + # From this we'll assume that the namespace reference in resourceTemplates to be: + # For customer clusters: /services/osd-operators/namespace//namespaces/cluster-scope.yaml + # For hive clusters: /services/osd-operators/namespace//namespaces/.yaml + MANAGED_RESOURCE_TYPE=$(curl -s "${SAAS_FILE_URL}" | \ + $YQ_CMD r - "managedResourceTypes[0]" + ) + + if [[ "${MANAGED_RESOURCE_TYPE}" == "" ]]; then + echo "Unabled to determine if SAAS file managed resource type" + exit 1 + fi - # Determine namespace reference path, output resource type - if [[ "${MANAGED_RESOURCE_TYPE}" == "SelectorSyncSet" ]]; then - echo "SAAS file is NOT applied to Hive, MANAGED_RESOURCE_TYPE=$MANAGED_RESOURCE_TYPE" - resource_template_ns_path="/services/osd-operators/namespaces/hivep01ue1/cluster-scope.yml" - else - echo "SAAS file is applied to Hive, MANAGED_RESOURCE_TYPE=$MANAGED_RESOURCE_TYPE" - resource_template_ns_path="/services/osd-operators/namespaces/hivep01ue1/${operator_name}.yml" - fi - - # remove any versions more recent than deployed hash - if [[ "$operator_channel" == "production" ]]; then - if [ -z "$DEPLOYED_HASH" ] ; then - DEPLOYED_HASH=$( - curl -s "${SAAS_FILE_URL}" | \ - $YQ_CMD r - "resourceTemplates[*].targets(namespace.\$ref==${resource_template_ns_path}).ref" - ) + # Determine namespace reference path, output resource type + if [[ "${MANAGED_RESOURCE_TYPE}" == "SelectorSyncSet" ]]; then + echo "SAAS file is NOT applied to Hive, MANAGED_RESOURCE_TYPE=$MANAGED_RESOURCE_TYPE" + resource_template_ns_path="/services/osd-operators/namespaces/hivep01ue1/cluster-scope.yml" + else + echo "SAAS file is applied to Hive, MANAGED_RESOURCE_TYPE=$MANAGED_RESOURCE_TYPE" + resource_template_ns_path="/services/osd-operators/namespaces/hivep01ue1/${operator_name}.yml" fi - # Ensure that our query for the current deployed hash worked - # Validate that our DEPLOYED_HASH var isn't empty. - # Although we have `set -e` defined the docker container isn't returning - # an error and allowing the script to continue - echo "Current deployed production HASH: $DEPLOYED_HASH" + # remove any versions more recent than deployed hash + if [[ "$operator_channel" == "production" ]]; then + if [ -z "$DEPLOYED_HASH" ] ; then + DEPLOYED_HASH=$( + curl -s "${SAAS_FILE_URL}" | \ + $YQ_CMD r - "resourceTemplates[*].targets(namespace.\$ref==${resource_template_ns_path}).ref" + ) + fi + + # Ensure that our query for the current deployed hash worked + # Validate that our DEPLOYED_HASH var isn't empty. + # Although we have `set -e` defined the docker container isn't returning + # an error and allowing the script to continue + echo "Current deployed production HASH: $DEPLOYED_HASH" - if [[ ! "${DEPLOYED_HASH}" =~ [0-9a-f]{40} ]]; then - echo "Error discovering current production deployed HASH" - exit 1 - fi + if [[ ! "${DEPLOYED_HASH}" =~ [0-9a-f]{40} ]]; then + echo "Error discovering current production deployed HASH" + exit 1 + fi - delete=false - # Sort based on commit number - for version in $(ls $BUNDLE_DIR | sort -t . -k 3 -g); do - # skip if not directory - [ -d "$BUNDLE_DIR/$version" ] || continue + delete=false + # Sort based on commit number + for version in $(ls $BUNDLE_DIR | sort -t . -k 3 -g); do + # skip if not directory + [ -d "$BUNDLE_DIR/$version" ] || continue - if [[ "$delete" == false ]]; then - short_hash=$(echo "$version" | cut -d- -f2) + if [[ "$delete" == false ]]; then + short_hash=$(echo "$version" | cut -d- -f2) - if [[ "$DEPLOYED_HASH" == "${short_hash}"* ]]; then - delete=true + if [[ "$DEPLOYED_HASH" == "${short_hash}"* ]]; then + delete=true + fi + else + rm -rf "${BUNDLE_DIR:?BUNDLE_DIR var not set}/$version" fi - else - rm -rf "${BUNDLE_DIR:?BUNDLE_DIR var not set}/$version" - fi - done + done + fi + fi # End of SKIP_SAAS_FILE_CHECKS granny switch + + OPERATOR_PREV_VERSION=$(ls "$BUNDLE_DIR" | sort -t . -k 3 -g | tail -n 1) + OPERATOR_NEW_VERSION="${operator_version}" + OUTPUT_DIR=${BUNDLE_DIR} +fi + +if [[ "$generate_script" = "common" ]] ; then + # Jenkins can't be relied upon to have py3, so run the generator in + # a container. + # ...Unless we're already in a container, which is how boilerplate + # CI runs. We have py3 there, so run natively in that case. + if [[ -z "$CONTAINER_ENGINE" ]]; then + ./boilerplate/openshift/golang-osd-operator/csv-generate/common-generate-operator-bundle.py -o ${operator_name} -d ${OUTPUT_DIR} -p ${OPERATOR_PREV_VERSION} -i ${REPO_DIGEST} -V ${operator_version} + else + $CONTAINER_ENGINE run --rm -v `pwd`:`pwd` -u `id -u`:0 -w `pwd` registry.access.redhat.com/ubi8/python-36:1-134 /bin/bash -c "python -m pip install oyaml; python ./boilerplate/openshift/golang-osd-operator/csv-generate/common-generate-operator-bundle.py -o ${operator_name} -d ${OUTPUT_DIR} -p ${OPERATOR_PREV_VERSION} -i ${REPO_DIGEST} -V ${operator_version}" + fi +elif [[ "$generate_script" = "hack" ]] ; then + if [ -z "$OPERATOR_PREV_VERSION" ] ; then + OPERATOR_PREV_VERSION="no-version" + DELETE_REPLACE=true fi -fi # End of SKIP_SAAS_FILE_CHECKS granny switch -OPERATOR_PREV_VERSION=$(ls "$BUNDLE_DIR" | sort -t . -k 3 -g | tail -n 1) -OPERATOR_NEW_VERSION="${operator_version}" -OUTPUT_DIR=${BUNDLE_DIR} + ./hack/generate-operator-bundle.py ${OUTPUT_DIR} ${OPERATOR_PREV_VERSION} ${operator_commit_number} ${operator_commit_hash} ${REPO_DIGEST} -# If setting up a new SaaS repo, there is no previous version when building a bundle -# Optionally pass it to the bundle generator in that case. -if [[ -z "${OPERATOR_PREV_VERSION}" ]]; then - PREV_VERSION_OPTS="" -else - PREV_VERSION_OPTS="-p ${OPERATOR_PREV_VERSION}" + if [ ! -z "${DELETE_REPLACE}" ] ; then + yq d -i output-comparison/${OPERATOR_NEW_VERSION}/*.clusterserviceversion.yaml 'spec.replaces' + fi fi -# Jenkins can't be relied upon to have py3, so run the generator in -# a container. -# ...Unless we're already in a container, which is how boilerplate -# CI runs. We have py3 there, so run natively in that case. -if [[ -z "$CONTAINER_ENGINE" ]]; then - ./boilerplate/openshift/golang-osd-operator/csv-generate/common-generate-operator-bundle.py -o ${operator_name} -d ${OUTPUT_DIR} ${PREV_VERSION_OPTS} -i ${REPO_DIGEST} -V ${operator_version} -else - if [[ ${CONTAINER_ENGINE##*/} == "podman" ]]; then - CE_OPTS="--userns keep-id -v `pwd`:`pwd`:Z" - else - CE_OPTS="-v `pwd`:`pwd`" + +if [ "$diff_generate" = true ] ; then + # TODO : Current hack script does not allow to generate the CSV for the comparison (it will generate a different version that the common one because there is 1 extra version in the history) + if [[ "$generate_script" = "hack" ]] ; then + echo "Generating with the common script and after, generating with the hack script is not supported yet. For comparison, please first generate with hack script, and then build/compare with the common script" + exit 1 + # Preparing yamls for the diff by removing the creation timestamp + elif [ -f ${BUNDLE_DIR}/${OPERATOR_NEW_VERSION}/*.clusterserviceversion.yaml ] ; then + yq d ${BUNDLE_DIR}/${OPERATOR_NEW_VERSION}/*.clusterserviceversion.yaml 'metadata.annotations.createdAt' > output-comparison/hack_generate.yaml + yq d output-comparison/${OPERATOR_NEW_VERSION}/*.clusterserviceversion.yaml 'metadata.annotations.createdAt' > output-comparison/common_generate.yaml + # Diff on the filtered files + diff output-comparison/hack_generate.yaml output-comparison/common_generate.yaml fi - $CONTAINER_ENGINE run --rm ${CE_OPTS} -u `id -u`:0 -w `pwd` registry.access.redhat.com/ubi8/python-36:1-134 /bin/bash -c "python -m pip install oyaml; python ./boilerplate/openshift/golang-osd-operator/csv-generate/common-generate-operator-bundle.py -o ${operator_name} -d ${OUTPUT_DIR} ${PREV_VERSION_OPTS} -i ${REPO_DIGEST} -V ${operator_version}" fi + diff --git a/boilerplate/openshift/golang-osd-operator/ensure.sh b/boilerplate/openshift/golang-osd-operator/ensure.sh index a0a97575..36e24e47 100755 --- a/boilerplate/openshift/golang-osd-operator/ensure.sh +++ b/boilerplate/openshift/golang-osd-operator/ensure.sh @@ -30,6 +30,59 @@ golangci-lint) fi ;; +operator-sdk) + ######################################################### + # Ensure operator-sdk is installed at the desired version + # When done, ./.operator-sdk/bin/operator-sdk will be a + # symlink to the appropriate executable. + ######################################################### + # First discover the desired version from go.mod + # The following properly takes `replace` directives into account. + wantver=$(go list -json -m github.com/operator-framework/operator-sdk | jq -r 'if .Replace != null then .Replace.Version else .Version end') + echo "go.mod says you want operator-sdk $wantver" + # Where we'll put our (binary and) symlink + mkdir -p .operator-sdk/bin + cd .operator-sdk/bin + # Discover existing, giving preference to one already installed in + # this path, because that has a higher probability of being the + # right one. + if [[ -x ./operator-sdk ]] && [[ "$(osdk_version ./operator-sdk)" == "$wantver" ]]; then + echo "operator-sdk $wantver already installed" + exit 0 + fi + # Is there one in $PATH? + if which operator-sdk && [[ $(osdk_version $(which operator-sdk)) == "$wantver" ]]; then + osdk=$(realpath $(which operator-sdk)) + echo "Found at $osdk" + else + case "$(uname -s)" in + Linux*) + binary="operator-sdk-${wantver}-x86_64-linux-gnu" + ;; + Darwin*) + binary="operator-sdk-${wantver}-x86_64-apple-darwin" + ;; + *) + echo "OS unsupported" + exit 1 + ;; + esac + # The boilerplate backing image sets up binaries with the full + # name in /usr/local/bin, so look for the right one of those + if which $binary; then + osdk=$(realpath $(which $binary)) + else + echo "Downloading $binary" + curl -OJL https://github.com/operator-framework/operator-sdk/releases/download/${wantver}/${binary} + chmod +x ${binary} + osdk=${binary} + fi + fi + # Create (or overwrite) the symlink to the binary we discovered or + # downloaded above. + ln -sf $osdk operator-sdk + ;; + opm) mkdir -p .opm/bin cd .opm/bin diff --git a/boilerplate/openshift/golang-osd-operator/fips.go.tmplt b/boilerplate/openshift/golang-osd-operator/fips.go.tmplt deleted file mode 100644 index bc0d4547..00000000 --- a/boilerplate/openshift/golang-osd-operator/fips.go.tmplt +++ /dev/null @@ -1,15 +0,0 @@ -// +build fips_enabled - -// BOILERPLATE GENERATED -- DO NOT EDIT -// Run 'make ensure-fips' to regenerate - -package main - -import ( - _ "crypto/tls/fipsonly" - "fmt" -) - -func init() { - fmt.Println("***** Starting with FIPS crypto enabled *****") -} diff --git a/boilerplate/openshift/golang-osd-operator/golangci.yml b/boilerplate/openshift/golang-osd-operator/golangci.yml index e4a3f2d7..77ff6450 100644 --- a/boilerplate/openshift/golang-osd-operator/golangci.yml +++ b/boilerplate/openshift/golang-osd-operator/golangci.yml @@ -18,7 +18,6 @@ linters: enable: - deadcode - errcheck - - gosec - gosimple - govet - ineffassign diff --git a/boilerplate/openshift/golang-osd-operator/operator-sdk-generate.sh b/boilerplate/openshift/golang-osd-operator/operator-sdk-generate.sh new file mode 100755 index 00000000..6aadb666 --- /dev/null +++ b/boilerplate/openshift/golang-osd-operator/operator-sdk-generate.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +set -eo pipefail + +### +# Run operator-sdk generate commands appropriate to the version of +# operator-sdk configured in the consuming repository. +### + +REPO_ROOT=$(git rev-parse --show-toplevel) + +source $REPO_ROOT/boilerplate/_lib/common.sh + +# There's nothing to generate if pkg/apis is empty (other than apis.go). +# And instead of succeeding gracefully, `operator-sdk generate` will +# fail if you try. So do our own check. +if ! /bin/ls -1 pkg/apis | grep -Fqv apis.go; then + echo "No APIs! Skipping operator-sdk generate." + exit 0 +fi + +$HERE/ensure.sh operator-sdk + +# Symlink to operator-sdk binary set up by `ensure.sh operator-sdk`: +OSDK=$REPO_ROOT/.operator-sdk/bin/operator-sdk + +VER=$(osdk_version $OSDK) + +# This explicitly lists the versions we know about. We don't support +# anything outside of that. +# NOTE: We are gluing to CRD v1beta1 for the moment. Support for v1 +# needs to be considered carefully in the context of +# - Hive v3 (which doesn't support v1) +# - When OCP will remove support for v1beta1 (currently we know it's +# deprecated in 4.6, but don't know when it's actually removed). +case $VER in + 'v0.15.1'|'v0.16.0') + # No-op: just declare support for these osdk versions. + ;; + 'v0.17.0'|'v0.17.1'|'v0.17.2'|'v0.18.2') + # The --crd-version flag was introduced in 0.17. v1beta1 is the + # default until 0.18, but let's be explicit. + _osdk_generate_crds_flags='--crd-version v1beta1' + ;; + *) err "Unsupported operator-sdk version $VER" ;; +esac +$OSDK generate crds $_osdk_generate_crds_flags +$OSDK generate k8s diff --git a/boilerplate/openshift/golang-osd-operator/standard.mk b/boilerplate/openshift/golang-osd-operator/standard.mk index 69dcb8b8..802109e7 100644 --- a/boilerplate/openshift/golang-osd-operator/standard.mk +++ b/boilerplate/openshift/golang-osd-operator/standard.mk @@ -15,24 +15,8 @@ ifndef VERSION_MINOR $(error VERSION_MINOR is not set; check project.mk file) endif -### Accommodate docker or podman -# -# The docker/podman creds cache needs to be in a location unique to this -# invocation; otherwise it could collide across jenkins jobs. We'll use -# a .docker folder relative to pwd (the repo root). -CONTAINER_ENGINE_CONFIG_DIR = .docker -# But docker and podman use different options to configure it :eyeroll: -# ==> Podman uses --authfile=PATH *after* the `login` subcommand; but -# also accepts REGISTRY_AUTH_FILE from the env. See -# https://www.mankier.com/1/podman-login#Options---authfile=path -export REGISTRY_AUTH_FILE = ${CONTAINER_ENGINE_CONFIG_DIR}/config.json -# ==> Docker uses --config=PATH *before* (any) subcommand; so we'll glue -# that to the CONTAINER_ENGINE variable itself. (NOTE: I tried half a -# dozen other ways to do this. This was the least ugly one that actually -# works.) -ifndef CONTAINER_ENGINE -CONTAINER_ENGINE=$(shell command -v podman 2>/dev/null || echo docker --config=$(CONTAINER_ENGINE_CONFIG_DIR)) -endif +# Accommodate docker or podman +CONTAINER_ENGINE=$(shell command -v podman 2>/dev/null || command -v docker 2>/dev/null) # Generate version and tag information from inputs COMMIT_NUMBER=$(shell git rev-list `git rev-list --parents HEAD | egrep "^[a-f0-9]{40}$$"`..HEAD --count) @@ -46,9 +30,6 @@ OPERATOR_IMAGE_URI=${IMG} OPERATOR_IMAGE_URI_LATEST=$(IMAGE_REGISTRY)/$(IMAGE_REPOSITORY)/$(IMAGE_NAME):latest OPERATOR_DOCKERFILE ?=build/Dockerfile REGISTRY_IMAGE=$(IMAGE_REGISTRY)/$(IMAGE_REPOSITORY)/$(IMAGE_NAME)-registry -#The api dir that latest osdk generated -NEW_API_DIR=./api -USE_OLD_SDK=$(shell if [[ -d "$(NEW_API_DIR)" ]];then echo FALSE;else echo TRUE;fi) # Consumer can optionally define ADDITIONAL_IMAGE_SPECS like: # define ADDITIONAL_IMAGE_SPECS @@ -68,37 +49,18 @@ OLM_CHANNEL ?= alpha REGISTRY_USER ?= REGISTRY_TOKEN ?= +CONTAINER_ENGINE_CONFIG_DIR = .docker BINFILE=build/_output/bin/$(OPERATOR_NAME) -MAINPACKAGE = ./ -API_DIR = $(NEW_API_DIR) -ifeq ($(USE_OLD_SDK), TRUE) -MAINPACKAGE = ./cmd/manager -API_DIR = ./pkg/apis -endif +MAINPACKAGE ?= ./cmd/manager GOOS?=$(shell go env GOOS) GOARCH?=$(shell go env GOARCH) -GOBIN?=$(shell go env GOBIN) # Consumers may override GOFLAGS_MOD e.g. to use `-mod=vendor` unexport GOFLAGS GOFLAGS_MOD ?= - -# In openshift ci (Prow), we need to set $HOME to a writable directory else tests will fail -# because they don't have permissions to create /.local or /.cache directories -# as $HOME is set to "/" by default. -ifeq ($(HOME),/) -export HOME=/tmp/home -endif -PWD=$(shell pwd) - -ifeq (${FIPS_ENABLED}, true) -GOFLAGS_MOD+=-tags=fips_enabled -GOFLAGS_MOD:=$(strip ${GOFLAGS_MOD}) -endif - -GOENV=GOOS=${GOOS} GOARCH=${GOARCH} CGO_ENABLED=0 GOFLAGS="${GOFLAGS_MOD}" +GOENV=GOOS=${GOOS} GOARCH=${GOARCH} CGO_ENABLED=0 GOFLAGS=${GOFLAGS_MOD} GOBUILDFLAGS=-gcflags="all=-trimpath=${GOPATH}" -asmflags="all=-trimpath=${GOPATH}" @@ -118,7 +80,6 @@ ALLOW_DIRTY_CHECKOUT?=false # TODO: Figure out how to discover this dynamically CONVENTION_DIR := boilerplate/openshift/golang-osd-operator -BOILERPLATE_CONTAINER_MAKE := boilerplate/_lib/container-make # Set the default goal in a way that works for older & newer versions of `make`: # Older versions (<=3.8.0) will pay attention to the `default` target. @@ -141,20 +102,20 @@ isclean: docker-build-push-one: isclean docker-login @(if [[ -z "${IMAGE_URI}" ]]; then echo "Must specify IMAGE_URI"; exit 1; fi) @(if [[ -z "${DOCKERFILE_PATH}" ]]; then echo "Must specify DOCKERFILE_PATH"; exit 1; fi) - ${CONTAINER_ENGINE} build --pull -f $(DOCKERFILE_PATH) -t $(IMAGE_URI) . - ${CONTAINER_ENGINE} push ${IMAGE_URI} + ${CONTAINER_ENGINE} build . -f $(DOCKERFILE_PATH) -t $(IMAGE_URI) + ${CONTAINER_ENGINE} --config=${CONTAINER_ENGINE_CONFIG_DIR} push ${IMAGE_URI} # TODO: Get rid of docker-build. It's only used by opm-build-push .PHONY: docker-build docker-build: isclean - ${CONTAINER_ENGINE} build --pull -f $(OPERATOR_DOCKERFILE) -t $(OPERATOR_IMAGE_URI) . + ${CONTAINER_ENGINE} build . -f $(OPERATOR_DOCKERFILE) -t $(OPERATOR_IMAGE_URI) ${CONTAINER_ENGINE} tag $(OPERATOR_IMAGE_URI) $(OPERATOR_IMAGE_URI_LATEST) # TODO: Get rid of docker-push. It's only used by opm-build-push .PHONY: docker-push docker-push: docker-login docker-build - ${CONTAINER_ENGINE} push ${OPERATOR_IMAGE_URI} - ${CONTAINER_ENGINE} push ${OPERATOR_IMAGE_URI_LATEST} + ${CONTAINER_ENGINE} --config=${CONTAINER_ENGINE_CONFIG_DIR} push ${OPERATOR_IMAGE_URI} + ${CONTAINER_ENGINE} --config=${CONTAINER_ENGINE_CONFIG_DIR} push ${OPERATOR_IMAGE_URI_LATEST} # TODO: Get rid of push. It's not used. .PHONY: push @@ -164,7 +125,7 @@ push: docker-push docker-login: @test "${REGISTRY_USER}" != "" && test "${REGISTRY_TOKEN}" != "" || (echo "REGISTRY_USER and REGISTRY_TOKEN must be defined" && exit 1) mkdir -p ${CONTAINER_ENGINE_CONFIG_DIR} - @${CONTAINER_ENGINE} login -u="${REGISTRY_USER}" -p="${REGISTRY_TOKEN}" quay.io + @${CONTAINER_ENGINE} --config=${CONTAINER_ENGINE_CONFIG_DIR} login -u="${REGISTRY_USER}" -p="${REGISTRY_TOKEN}" quay.io .PHONY: go-check go-check: ## Golang linting and other static analysis @@ -177,87 +138,38 @@ go-generate: ${GOENV} go generate $(TESTTARGETS) # Don't forget to commit generated files -# go-get-tool will 'go install' any package $2 and install it to $1. -define go-get-tool -@{ \ -set -e ;\ -TMP_DIR=$$(mktemp -d) ;\ -cd $$TMP_DIR ;\ -go mod init tmp ;\ -echo "Downloading $(2)" ;\ -GOBIN=$(shell dirname $(1)) go install $(2) ;\ -echo "Installed in $(1)" ;\ -rm -rf $$TMP_DIR ;\ -} -endef - -# Deciding on the binary versions -CONTROLLER_GEN_VERSION = v0.8.0 -CONTROLLER_GEN = controller-gen-$(CONTROLLER_GEN_VERSION) - -OPENAPI_GEN_VERSION = v0.23.0 -OPENAPI_GEN = openapi-gen-$(OPENAPI_GEN_VERSION) - -ifeq ($(USE_OLD_SDK), TRUE) -#If we are using the old osdk, we use the default controller-gen and openapi-gen versions. -# Default version is 0.3.0 for now. -CONTROLLER_GEN = controller-gen -# Default version is 0.19.4 for now. -OPENAPI_GEN = openapi-gen -endif - .PHONY: op-generate -## CRD v1beta1 is no longer supported. op-generate: - cd $(API_DIR); $(CONTROLLER_GEN) crd:crdVersions=v1 paths=./... output:dir=$(PWD)/deploy/crds - cd $(API_DIR); $(CONTROLLER_GEN) object paths=./... - -API_DIR_MIN_DEPTH = 1 -ifeq ($(USE_OLD_SDK), TRUE) -API_DIR_MIN_DEPTH = 2 -endif + ${CONVENTION_DIR}/operator-sdk-generate.sh + # HACK: Due to an OLM bug in 3.11, we need to remove the + # spec.validation.openAPIV3Schema.type from CRDs. Remove once + # 3.11 is no longer supported. + find deploy/ -name '*_crd.yaml' | xargs -n1 -I{} yq d -i {} spec.validation.openAPIV3Schema.type + # Don't forget to commit generated files .PHONY: openapi-generate openapi-generate: - find $(API_DIR) -maxdepth 2 -mindepth $(API_DIR_MIN_DEPTH) -type d | xargs -t -I% \ - $(OPENAPI_GEN) --logtostderr=true \ + find ./pkg/apis/ -maxdepth 2 -mindepth 2 -type d | xargs -t -n1 -I% \ + openapi-gen --logtostderr=true \ -i % \ -o "" \ -O zz_generated.openapi \ -p % \ -h /dev/null \ -r "-" - + .PHONY: generate generate: op-generate go-generate openapi-generate -ifeq (${FIPS_ENABLED}, true) -go-build: ensure-fips -endif - .PHONY: go-build go-build: ## Build binary # Force GOOS=linux as we may want to build containers in other *nix-like systems (ie darwin). # This is temporary until a better container build method is developed ${GOENV} GOOS=linux go build ${GOBUILDFLAGS} -o ${BINFILE} ${MAINPACKAGE} -# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. -ENVTEST_K8S_VERSION = 1.23 -SETUP_ENVTEST = setup-envtest - -.PHONY: setup-envtest -setup-envtest: - $(eval KUBEBUILDER_ASSETS := "$(shell $(SETUP_ENVTEST) use $(ENVTEST_K8S_VERSION) -p path --bin-dir /tmp/envtest/bin)") - -# Setting SHELL to bash allows bash commands to be executed by recipes. -# This is a requirement for 'setup-envtest.sh' in the test target. -# Options are set to exit when a recipe line exits non-zero or a piped command fails. -SHELL = /usr/bin/env bash -o pipefail -.SHELLFLAGS = -ec - .PHONY: go-test -go-test: setup-envtest - KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test $(TESTOPTS) $(TESTTARGETS) +go-test: + ${GOENV} go test $(TESTOPTS) $(TESTTARGETS) .PHONY: python-venv python-venv: @@ -283,6 +195,10 @@ olm-deploy-yaml-validate: python-venv prow-config: ${CONVENTION_DIR}/prow-config ${RELEASE_CLONE} +.PHONY: codecov-secret-mapping +codecov-secret-mapping: + ${CONVENTION_DIR}/codecov-secret-mapping ${RELEASE_CLONE} + ###################### # Targets used by prow @@ -330,45 +246,3 @@ opm-build-push: docker-push OPERATOR_IMAGE_TAG="${OPERATOR_IMAGE_TAG}" \ OLM_CHANNEL="${OLM_CHANNEL}" \ ${CONVENTION_DIR}/build-opm-catalog.sh - -.PHONY: ensure-fips -ensure-fips: - ${CONVENTION_DIR}/configure-fips.sh - -# You will need to export the forked/cloned operator repository directory as OLD_SDK_REPO_DIR to make this work. -# Example: export OLD_SDK_REPO_DIR=~/Projects/My-Operator-Fork -.PHONY: migrate-to-osdk1 -migrate-to-osdk1: -ifndef OLD_SDK_REPO_DIR - $(error OLD_SDK_REPO_DIR is not set) -endif - # Copying files & folders from old repository to current project - rm -rf config - rsync -a $(OLD_SDK_REPO_DIR)/deploy . --exclude=crds - rsync -a $(OLD_SDK_REPO_DIR)/pkg . --exclude={'apis','controller'} - rsync -a $(OLD_SDK_REPO_DIR)/Makefile . - rsync -a $(OLD_SDK_REPO_DIR)/.gitignore . - rsync -a $(OLD_SDK_REPO_DIR)/ . --exclude={'cmd','version','boilerplate','deploy','pkg'} --ignore-existing - -# Boilerplate container-make targets. -# Runs 'make' in the boilerplate backing container. -# If the command fails, starts a shell in the container so you can debug. -.PHONY: container-test -container-test: - ${BOILERPLATE_CONTAINER_MAKE} test - -.PHONY: container-generate -container-generate: - ${BOILERPLATE_CONTAINER_MAKE} generate - -.PHONY: container-lint -container-lint: - ${BOILERPLATE_CONTAINER_MAKE} lint - -.PHONY: container-validate -container-validate: - ${BOILERPLATE_CONTAINER_MAKE} validate - -.PHONY: container-coverage -container-coverage: - ${BOILERPLATE_CONTAINER_MAKE} coverage \ No newline at end of file diff --git a/boilerplate/openshift/golang-osd-operator/update b/boilerplate/openshift/golang-osd-operator/update index bed4cc8d..5db57dd9 100755 --- a/boilerplate/openshift/golang-osd-operator/update +++ b/boilerplate/openshift/golang-osd-operator/update @@ -14,9 +14,8 @@ echo "Copying .codecov.yml to your repository root." cp ${HERE}/.codecov.yml $REPO_ROOT # TODO: boilerplate more of Dockerfile -DOCKERFILE=build/Dockerfile -echo "Overwriting $DOCKERFILE's initial FROM with $IMAGE_PULL_PATH" -${SED?} -i "1s,.*,FROM $IMAGE_PULL_PATH AS builder," $DOCKERFILE +echo "Overwriting build/Dockerfile's initial FROM with $IMAGE_PULL_PATH" +${SED?} -i "1s,.*,FROM $IMAGE_PULL_PATH AS builder," build/Dockerfile echo "Writing .ci-operator.yaml in your repository root with:" echo " namespace: $IMAGE_NAMESPACE" diff --git a/build/Dockerfile b/build/Dockerfile index 56924fad..29d2c702 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -1,4 +1,4 @@ -FROM quay.io/app-sre/boilerplate:image-v2.3.2 AS builder +FROM quay.io/app-sre/boilerplate:image-v1.0.0 AS builder RUN mkdir -p /workdir COPY . /workdir