diff --git a/cmd/vpa_butler/main.go b/cmd/vpa_butler/main.go index 10470a1..ff5fbdf 100644 --- a/cmd/vpa_butler/main.go +++ b/cmd/vpa_butler/main.go @@ -82,13 +82,12 @@ func main() { }) handleError(err, "unable to start manager") - handleError(controllers.SetupForAppsV1(mgr, controllers.GenericControllerParams{ + handleError(controllers.SetupForAppsV1(mgr), "unable to setup apps/v1 controllers") + vpaController := controllers.VpaController{ + Client: mgr.GetClient(), + Version: Version, MinAllowedCPU: minAllowedCPU, MinAllowedMemory: minAllowedMemory, - }), "unable to setup apps/v1 controllers") - vpaController := controllers.VpaController{ - Client: mgr.GetClient(), - Version: Version, } handleError(vpaController.SetupWithManager(mgr), "unable to setup vpa controller") vpaRunnable := controllers.VpaRunnable{ diff --git a/go.mod b/go.mod index f26b774..683608c 100644 --- a/go.mod +++ b/go.mod @@ -31,7 +31,6 @@ require ( github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.3 // indirect - github.com/google/gnostic v0.5.7-v3refs // indirect github.com/google/gnostic-models v0.6.8 // indirect github.com/google/go-cmp v0.5.9 // indirect github.com/google/gofuzz v1.2.0 // indirect diff --git a/go.sum b/go.sum index c6ce4da..8153e14 100644 --- a/go.sum +++ b/go.sum @@ -1,27 +1,20 @@ -cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= -github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE= github.com/emicklei/go-restful/v3 v3.10.1 h1:rc42Y5YTp7Am7CS630D7JmhRjq4UlEUuEKfrDac4bSQ= github.com/emicklei/go-restful/v3 v3.10.1/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= -github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH5pOlLGNtQ5lPWQu84= -github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= +github.com/evanphx/json-patch v5.6.0+incompatible h1:jBYDEEiFBPxA0v50tFdvOzQQTCvpL6mnFh5mB2/l16U= +github.com/evanphx/json-patch v5.6.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/evanphx/json-patch/v5 v5.6.0 h1:b91NhWfaz02IuVxO9faSllyAtNXHMPkC5J8sJCLunww= github.com/evanphx/json-patch/v5 v5.6.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2VvlbKOFpnXhI9Bw4= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= @@ -41,31 +34,15 @@ github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEe github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -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.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/google/gnostic v0.5.7-v3refs h1:FhTMOKj2VhjpouxvWJAV1TL304uMlb9zcDqkl6cEI54= -github.com/google/gnostic v0.5.7-v3refs/go.mod h1:73MKFl6jIHelAJNaBGFzt3SPtZULs9dYrGFt8OiIsHQ= github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I= github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/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.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= @@ -87,7 +64,6 @@ github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHm github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= @@ -106,8 +82,6 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= -github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU= -github.com/onsi/ginkgo/v2 v2.11.0/go.mod h1:ZhrRA5XmEE3x3rhlzamx/JJvujdZoJ2uvgI7kR0iZvM= github.com/onsi/ginkgo/v2 v2.12.0 h1:UIVDowFPwpg6yMUpPjGkYvf06K3RAiJXUhCxEwQVHRI= github.com/onsi/ginkgo/v2 v2.12.0/go.mod h1:ZNEzXISYlqpb8S36iN71ifqLi3vVD1rVJGvWRCJOUpQ= github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= @@ -119,29 +93,27 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v1.15.1 h1:8tXpTmJbyH5lydzFPoxSIJ0J46jdh3tylbvM1xCv0LI= github.com/prometheus/client_golang v1.15.1/go.mod h1:e9yaBhRPU2pPNsZwE+JdQl0KEt1N9XgF6zxWmaC0xOk= -github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.4.0 h1:5lQXD3cAg1OXBf4Wq03gTrXHeaV0TQvGfUooCfx1yqY= github.com/prometheus/client_model v0.4.0/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU= github.com/prometheus/common v0.42.0 h1:EKsfXEYo4JpWMHH5cg+KOUWeuJSov1Id8zGR8eeI1YM= github.com/prometheus/common v0.42.0/go.mod h1:xBwqVerjNdUDjgODMpudtOMwlOwf2SaTr1yjz4b7Zbc= github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJfhI= github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY= -github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= -github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= +github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/yuin/goldmark v1.1.27/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= @@ -157,19 +129,12 @@ go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= -golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 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.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk= -golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -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-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= +golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= @@ -177,21 +142,15 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/net v0.13.0 h1:Nvo8UFsZ8X3BhAC9699Z1j7XQ3rsZnUUm7jfBEk1ueY= -golang.org/x/net v0.13.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14= golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.8.0 h1:6dkIjl3j3LtZ/O3sTgZTMsLKSftL/B8Zgq4huOIIUu8= golang.org/x/oauth2 v0.8.0/go.mod h1:yr7u4HXZRm1R1kBWqr/xKNqewf0plRYoB7sla+BCIXE= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/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-20210220032951-036812b2e83c/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-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -200,35 +159,24 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= -golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.10.0 h1:3R7pNqamzBraeqj/Tj8qt1aQ2HpmlC+Cx/qL/7hn4/c= -golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o= golang.org/x/term v0.11.0 h1:F9tnn/DA/Im8nCwm+fX+1/eBwi4qFjRT++MhtVC4ZX0= golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU= golang.org/x/text v0.3.0/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/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= -golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc= golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.9.3 h1:Gn1I8+64MsuTb/HpH+LmQtNas23LhUVr3rYZ0eKuaMM= -golang.org/x/tools v0.9.3/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc= golang.org/x/tools v0.12.0 h1:YW6HUoUmYBpwSgyaGaZq1fHjrBjX1rlpZ54T6mu2kss= golang.org/x/tools v0.12.0/go.mod h1:Sc0INKfu04TlqNoRA1hgpFZbhYXHPr4V5DzpSBTPqQM= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -237,75 +185,41 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gomodules.xyz/jsonpatch/v2 v2.3.0 h1:8NFhfS6gzxNqjLIYnZxg319wZ5Qjnx4m/CcX+Klzazc= gomodules.xyz/jsonpatch/v2 v2.3.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuBJT4moAY= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto v0.0.0-20201019141844-1ed22bb0c154/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.22.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.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.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= 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/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 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= 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.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -k8s.io/api v0.27.4 h1:0pCo/AN9hONazBKlNUdhQymmnfLRbSZjd5H5H3f0bSs= -k8s.io/api v0.27.4/go.mod h1:O3smaaX15NfxjzILfiln1D8Z3+gEYpjEpiNA/1EVK1Y= k8s.io/api v0.28.1 h1:i+0O8k2NPBCPYaMB+uCkseEbawEt/eFaiRqUx8aB108= k8s.io/api v0.28.1/go.mod h1:uBYwID+66wiL28Kn2tBjBYQdEU0Xk0z5qF8bIBqk/Dg= k8s.io/apiextensions-apiserver v0.27.2 h1:iwhyoeS4xj9Y7v8YExhUwbVuBhMr3Q4bd/laClBV6Bo= k8s.io/apiextensions-apiserver v0.27.2/go.mod h1:Oz9UdvGguL3ULgRdY9QMUzL2RZImotgxvGjdWRq6ZXQ= -k8s.io/apimachinery v0.27.4 h1:CdxflD4AF61yewuid0fLl6bM4a3q04jWel0IlP+aYjs= -k8s.io/apimachinery v0.27.4/go.mod h1:XNfZ6xklnMCOGGFNqXG7bUrQCoR04dh/E7FprV6pb+E= k8s.io/apimachinery v0.28.1 h1:EJD40og3GizBSV3mkIoXQBsws32okPOy+MkRyzh6nPY= k8s.io/apimachinery v0.28.1/go.mod h1:X0xh/chESs2hP9koe+SdIAcXWcQ+RM5hy0ZynB+yEvw= k8s.io/autoscaler/vertical-pod-autoscaler v0.14.0 h1:HkQHkcuwVP3BgJpVqTGeYHro83qGBj8mWotygHZND1k= k8s.io/autoscaler/vertical-pod-autoscaler v0.14.0/go.mod h1:w6/LjLR3DPQd57vlgvgbpzpuJKsCiily0+OzQI+nyfI= -k8s.io/client-go v0.27.4 h1:vj2YTtSJ6J4KxaC88P4pMPEQECWMY8gqPqsTgUKzvjk= -k8s.io/client-go v0.27.4/go.mod h1:ragcly7lUlN0SRPk5/ZkGnDjPknzb37TICq07WhI6Xc= k8s.io/client-go v0.28.1 h1:pRhMzB8HyLfVwpngWKE8hDcXRqifh1ga2Z/PU9SXVK8= k8s.io/client-go v0.28.1/go.mod h1:pEZA3FqOsVkCc07pFVzK076R+P/eXqsgx5zuuRWukNE= k8s.io/component-base v0.27.2 h1:neju+7s/r5O4x4/txeUONNTS9r1HsPbyoPBAtHsDCpo= k8s.io/component-base v0.27.2/go.mod h1:5UPk7EjfgrfgRIuDBFtsEFAe4DAvP3U+M8RTzoSJkpo= -k8s.io/component-helpers v0.27.4 h1:l1hn/Zx9mWXflo5xz1mo5RRW2g8b6rptWCG7My6rYoE= -k8s.io/component-helpers v0.27.4/go.mod h1:ayW5btpTdJkVv+CcxhzNRfWT+oPrV6T6qZ1Ay6NEJNI= k8s.io/component-helpers v0.28.1 h1:ts/vykhyUmPLhUl/hdLdf+a4BWA0giQ3f25HAIhl+RI= k8s.io/component-helpers v0.28.1/go.mod h1:rHFPj33uXNbgppg+ilmjJ4oR73prZQNRRmg+utVOAb0= -k8s.io/klog/v2 v2.90.1 h1:m4bYOKall2MmOiRaR1J+We67Do7vm9KiQVlT96lnHUw= -k8s.io/klog/v2 v2.90.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg= k8s.io/klog/v2 v2.100.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= -k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f h1:2kWPakN3i/k81b0gvD5C5FJ2kxm1WrQFanWchyKuqGg= -k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f/go.mod h1:byini6yhqGC14c3ebc/QwanvYwhuMWF6yz2F8uwW8eg= k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 h1:LyMgNKD2P8Wn1iAwQU5OhxCKlKJy0sHc+PcDwFB24dQ= k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9/go.mod h1:wZK2AVp1uHCp4VamDVgBP2COHZjqD1T68Rf0CM3YjSM= k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI= diff --git a/internal/common/vpa.go b/internal/common/vpa.go index 913c939..e826db4 100644 --- a/internal/common/vpa.go +++ b/internal/common/vpa.go @@ -1,7 +1,9 @@ package common import ( + autoscaling "k8s.io/api/autoscaling/v1" vpav1 "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1" + "sigs.k8s.io/controller-runtime/pkg/client" ) const ( @@ -21,3 +23,18 @@ func ManagedByButler(vpa *vpav1.VerticalPodAutoscaler) bool { v, ok := vpa.Annotations[AnnotationManagedBy] return ok && v == AnnotationVpaButler } + +func ConfigureVpaBaseline(vpa *vpav1.VerticalPodAutoscaler, owner client.Object, updateMode vpav1.UpdateMode) { + vpa.Spec.TargetRef = &autoscaling.CrossVersionObjectReference{ + Kind: owner.GetObjectKind().GroupVersionKind().Kind, + Name: owner.GetName(), + APIVersion: owner.GetObjectKind().GroupVersionKind().Version, + } + vpa.Spec.UpdatePolicy = &vpav1.PodUpdatePolicy{ + UpdateMode: &updateMode, + } + if vpa.Annotations == nil { + vpa.Annotations = make(map[string]string, 0) + } + vpa.Annotations[AnnotationManagedBy] = AnnotationVpaButler +} diff --git a/internal/controllers/constants.go b/internal/controllers/constants.go new file mode 100644 index 0000000..378ab3a --- /dev/null +++ b/internal/controllers/constants.go @@ -0,0 +1,7 @@ +package controllers + +const ( + DaemonSetStr string = "DaemonSet" + StatefulSetStr string = "StatefulSet" + DeploymentStr string = "Deployment" +) diff --git a/internal/controllers/generic_controller.go b/internal/controllers/generic_controller.go index 15b2020..16566b8 100644 --- a/internal/controllers/generic_controller.go +++ b/internal/controllers/generic_controller.go @@ -7,22 +7,15 @@ import ( "strings" "github.com/go-logr/logr" - "github.com/pkg/errors" "github.com/sapcc/vpa_butler/internal/common" appsv1 "k8s.io/api/apps/v1" - autoscaling "k8s.io/api/autoscaling/v1" - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/equality" apierrors "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/api/meta" - "k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" vpav1 "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller" - "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" ) const ( @@ -31,15 +24,9 @@ const ( maxNameLength = 63 ) -type GenericControllerParams struct { - MinAllowedCPU resource.Quantity - MinAllowedMemory resource.Quantity -} - type GenericController struct { client.Client typeName string - params GenericControllerParams Log logr.Logger Scheme *runtime.Scheme instance client.Object @@ -68,11 +55,6 @@ func (v *GenericController) Reconcile(ctx context.Context, req ctrl.Request) (ct return ctrl.Result{}, client.IgnoreNotFound(err) } - v.Log.Info("Reconciling potential vpa target", - "namespace", instance.GetNamespace(), - "name", instance.GetName(), - "kind", instance.GetObjectKind().GroupVersionKind().Kind, - ) serve, err := v.shouldServeVpa(ctx, instance) if err != nil { return ctrl.Result{}, err @@ -81,11 +63,18 @@ func (v *GenericController) Reconcile(ctx context.Context, req ctrl.Request) (ct err = v.ensureVpaDeleted(ctx, instance) return ctrl.Result{}, err } - - if v.reconcileVpa(ctx, instance) != nil { - return ctrl.Result{}, err + var vpa = new(vpav1.VerticalPodAutoscaler) + vpa.Namespace = instance.GetNamespace() + vpa.Name = getVpaName(instance) + if err := v.Client.Get(ctx, client.ObjectKeyFromObject(vpa), vpa); err != nil { + if !apierrors.IsNotFound(err) { + return ctrl.Result{}, err + } + // vpa does not exist so create it + // set off here, as the vpa is to be fully configured by the VpaController + common.ConfigureVpaBaseline(vpa, instance, vpav1.UpdateModeOff) + return ctrl.Result{}, v.Client.Create(ctx, vpa) } - return ctrl.Result{}, nil } @@ -116,83 +105,6 @@ func (v *GenericController) shouldServeVpa(ctx context.Context, vpaOwner client. return true, nil } -func (v *GenericController) reconcileVpa(ctx context.Context, vpaOwner client.Object) error { - var vpa = new(vpav1.VerticalPodAutoscaler) - vpa.Namespace = vpaOwner.GetNamespace() - vpa.Name = getVpaName(vpaOwner) - exists := true - if err := v.Client.Get(ctx, client.ObjectKeyFromObject(vpa), vpa); err != nil { - // Return any other error. - if !apierrors.IsNotFound(err) { - return err - } - exists = false - } - - if o, err := meta.Accessor(vpa); err == nil { - if o.GetDeletionTimestamp() != nil { - return fmt.Errorf("the resource %s/%s already exists but is marked for deletion", - o.GetNamespace(), o.GetName()) - } - } - - before, ok := vpa.DeepCopyObject().(client.Object) - if !ok { - return fmt.Errorf("failed to cast object to client.Object") - } - if err := v.configureVpa(vpaOwner, vpa); err != nil { - return errors.Wrap(err, "mutating object failed") - } - - if !exists { - v.Log.Info("Creating vpa", "name", vpa.Name, "namespace", vpa.Namespace) - return v.Client.Create(ctx, vpa) - } - - if equality.Semantic.DeepEqual(before, vpa) { - return nil - } - patch := client.MergeFrom(before) - v.Log.Info("Patching vpa", "name", vpa.Name, "namespace", vpa.Namespace) - if err := v.Client.Patch(ctx, vpa, patch); err != nil { - return err - } - return nil -} - -func (v *GenericController) configureVpa(vpaOwner client.Object, vpa *vpav1.VerticalPodAutoscaler) error { - vpaSpec := &vpa.Spec - vpaSpec.TargetRef = &autoscaling.CrossVersionObjectReference{ - Kind: vpaOwner.GetObjectKind().GroupVersionKind().Kind, - Name: vpaOwner.GetName(), - APIVersion: vpaOwner.GetObjectKind().GroupVersionKind().Version, - } - vpaSpec.UpdatePolicy = &vpav1.PodUpdatePolicy{ - UpdateMode: &common.VpaUpdateMode, - } - - resourceList := []corev1.ResourceName{corev1.ResourceCPU, corev1.ResourceMemory} - vpaSpec.ResourcePolicy = &vpav1.PodResourcePolicy{ - ContainerPolicies: []vpav1.ContainerResourcePolicy{ - { - ContainerName: "*", - ControlledResources: &resourceList, - ControlledValues: &common.VpaControlledValues, - MinAllowed: corev1.ResourceList{ - corev1.ResourceCPU: v.params.MinAllowedCPU, - corev1.ResourceMemory: v.params.MinAllowedMemory, - }, - }, - }, - } - if vpa.Annotations == nil { - vpa.Annotations = make(map[string]string, 0) - } - vpa.Annotations[common.AnnotationManagedBy] = common.AnnotationVpaButler - - return controllerutil.SetOwnerReference(vpaOwner, vpa, v.Scheme) -} - func (v *GenericController) ensureVpaDeleted(ctx context.Context, vpaOwner client.Object) error { var vpa vpav1.VerticalPodAutoscaler ref := types.NamespacedName{Namespace: vpaOwner.GetNamespace(), Name: getVpaName(vpaOwner)} @@ -215,10 +127,9 @@ func getVpaName(vpaOwner client.Object) string { return fmt.Sprintf("%s-%s", name, kind) } -func SetupForAppsV1(mgr ctrl.Manager, params GenericControllerParams) error { +func SetupForAppsV1(mgr ctrl.Manager) error { deploymentController := GenericController{ Client: mgr.GetClient(), - params: params, } err := deploymentController.SetupWithManager(mgr, &appsv1.Deployment{}) if err != nil { @@ -226,7 +137,6 @@ func SetupForAppsV1(mgr ctrl.Manager, params GenericControllerParams) error { } daemonsetController := GenericController{ Client: mgr.GetClient(), - params: params, } err = daemonsetController.SetupWithManager(mgr, &appsv1.DaemonSet{}) if err != nil { @@ -234,7 +144,6 @@ func SetupForAppsV1(mgr ctrl.Manager, params GenericControllerParams) error { } statefulSetController := GenericController{ Client: mgr.GetClient(), - params: params, } err = statefulSetController.SetupWithManager(mgr, &appsv1.StatefulSet{}) if err != nil { diff --git a/internal/controllers/generic_controller_test.go b/internal/controllers/generic_controller_test.go index 62a5261..a443ca7 100644 --- a/internal/controllers/generic_controller_test.go +++ b/internal/controllers/generic_controller_test.go @@ -3,12 +3,11 @@ package controllers_test import ( "context" "fmt" - "time" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/sapcc/vpa_butler/internal/common" - "sigs.k8s.io/controller-runtime/pkg/client" + "github.com/sapcc/vpa_butler/internal/controllers" appsv1 "k8s.io/api/apps/v1" autoscalingv1 "k8s.io/api/autoscaling/v1" @@ -57,6 +56,13 @@ func expectVpa(name string) { if mangedBy != common.AnnotationVpaButler { return fmt.Errorf("vpa has wrong managed-by annotation") } + // the min resources stuff technically belongs to vpa_controller.go + if vpa.Spec.ResourcePolicy == nil { + return fmt.Errorf("vpa resource policy is nil") + } + if len(vpa.Spec.ResourcePolicy.ContainerPolicies) != 1 { + return fmt.Errorf("vpa has wrong amount of container policies") + } minAllowed := vpa.Spec.ResourcePolicy.ContainerPolicies[0].MinAllowed if !minAllowed.Cpu().Equal(testMinAllowedCPU) { return fmt.Errorf("vpa minAllowed CPU does not match") @@ -149,27 +155,6 @@ var _ = Describe("GenericController", func() { It("should create a vpa", func() { expectVpa("test-deployment-deployment") }) - - It("patches the served vpa", func() { - // need to sleep here to ensure the a vpa is created before the update - // to this global variable - time.Sleep(100 * time.Millisecond) - common.VpaUpdateMode = vpav1.UpdateModeAuto - unmodified := deployment.DeepCopy() - deployment.Spec.Replicas = ptr.To[int32](2) - Expect(k8sClient.Patch(context.Background(), deployment, client.MergeFrom(unmodified))).To(Succeed()) - Eventually(func() vpav1.UpdateMode { - var vpa vpav1.VerticalPodAutoscaler - err := k8sClient.Get(context.Background(), types.NamespacedName{ - Name: "test-deployment-deployment", - Namespace: metav1.NamespaceDefault, - }, &vpa) - if err != nil { - return vpav1.UpdateMode("") - } - return *vpa.Spec.UpdatePolicy.UpdateMode - }).Should(Equal(common.VpaUpdateMode)) - }) }) Context("when creating a statefulset", func() { @@ -218,7 +203,7 @@ var _ = Describe("GenericController", func() { vpa.Namespace = metav1.NamespaceDefault vpa.Spec.TargetRef = &autoscalingv1.CrossVersionObjectReference{ Name: deploymentName, - Kind: "Deployment", + Kind: controllers.DeploymentStr, APIVersion: "v1", } Expect(k8sClient.Create(context.Background(), vpa)).To(Succeed()) diff --git a/internal/controllers/suite_test.go b/internal/controllers/suite_test.go index 20b836c..becd3a1 100644 --- a/internal/controllers/suite_test.go +++ b/internal/controllers/suite_test.go @@ -59,17 +59,16 @@ var _ = BeforeSuite(func() { Expect(err).ToNot(HaveOccurred()) err = (&controllers.VpaController{ - Client: k8sManager.GetClient(), - Log: GinkgoLogr.WithName("vpa-controller"), - Scheme: k8sManager.GetScheme(), - Version: "test", + Client: k8sManager.GetClient(), + Log: GinkgoLogr.WithName("vpa-controller"), + Scheme: k8sManager.GetScheme(), + Version: "test", + MinAllowedCPU: testMinAllowedCPU, + MinAllowedMemory: testMinAllowedMemory, }).SetupWithManager(k8sManager) Expect(err).ToNot(HaveOccurred()) - Expect(controllers.SetupForAppsV1(k8sManager, controllers.GenericControllerParams{ - MinAllowedCPU: testMinAllowedCPU, - MinAllowedMemory: testMinAllowedMemory, - })).To(Succeed()) + Expect(controllers.SetupForAppsV1(k8sManager)).To(Succeed()) Expect(k8sManager.Add(&controllers.VpaRunnable{ Client: k8sManager.GetClient(), diff --git a/internal/controllers/vpa_controller.go b/internal/controllers/vpa_controller.go index 75a20b7..60ec182 100644 --- a/internal/controllers/vpa_controller.go +++ b/internal/controllers/vpa_controller.go @@ -2,18 +2,25 @@ package controllers import ( "context" + "fmt" "strings" "github.com/go-logr/logr" + "github.com/pkg/errors" "github.com/sapcc/vpa_butler/internal/common" appsv1 "k8s.io/api/apps/v1" - "k8s.io/apimachinery/pkg/api/errors" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/equality" + apierrors "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/api/meta" + "k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" vpav1 "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller" + "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" ) const ( @@ -22,9 +29,11 @@ const ( type VpaController struct { client.Client - Log logr.Logger - Scheme *runtime.Scheme - Version string + Log logr.Logger + Scheme *runtime.Scheme + MinAllowedCPU resource.Quantity + MinAllowedMemory resource.Quantity + Version string } func (v *VpaController) SetupWithManager(mgr ctrl.Manager) error { @@ -46,30 +55,67 @@ func (v *VpaController) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.R return ctrl.Result{}, client.IgnoreNotFound(err) } - abort, err := v.cleanupServedVpa(ctx, vpa) + deleted, err := v.cleanupServedVpa(ctx, vpa) if err != nil { return ctrl.Result{}, err } - if abort || !common.ManagedByButler(vpa) { + if deleted || !common.ManagedByButler(vpa) { return ctrl.Result{}, nil } - if err := v.patchVersionAnnotation(ctx, vpa); err != nil { + deleted, err = v.deleteOldVpa(ctx, vpa) + if err != nil || deleted { return ctrl.Result{}, err } - if err := v.deleteOldVpa(ctx, vpa); err != nil { + deleted, err = v.deleteOrphanedVpa(ctx, vpa) + if err != nil || deleted { return ctrl.Result{}, err } - if err := v.deleteOrphanedVpa(ctx, vpa); err != nil { + + target, err := v.extractTarget(ctx, vpa) + if err != nil { return ctrl.Result{}, err } - return ctrl.Result{}, nil + return ctrl.Result{}, v.reconcileVpa(ctx, target) +} + +func (v *VpaController) extractTarget(ctx context.Context, vpa *vpav1.VerticalPodAutoscaler) (client.Object, error) { + if vpa.Spec.TargetRef == nil { + return nil, fmt.Errorf("vpa %s/%s has nil target ref", vpa.Namespace, vpa.Name) + } + ref := *vpa.Spec.TargetRef + switch ref.Kind { + case DeploymentStr: + var deployment appsv1.Deployment + err := v.Client.Get(ctx, types.NamespacedName{Name: ref.Name, Namespace: vpa.Namespace}, &deployment) + if err != nil { + return nil, fmt.Errorf("failed to fetch target %s/%s of kind %s for vpa", + vpa.Namespace, ref.Name, ref.Kind) + } + return &deployment, nil + case StatefulSetStr: + var sts appsv1.StatefulSet + err := v.Client.Get(ctx, types.NamespacedName{Name: ref.Name, Namespace: vpa.Namespace}, &sts) + if err != nil { + return nil, fmt.Errorf("failed to fetch target %s/%s of kind %s for vpa", + vpa.Namespace, ref.Name, ref.Kind) + } + return &sts, nil + case DaemonSetStr: + var ds appsv1.DaemonSet + err := v.Client.Get(ctx, types.NamespacedName{Name: ref.Name, Namespace: vpa.Namespace}, &ds) + if err != nil { + return nil, fmt.Errorf("failed to fetch target %s/%s of kind %s for vpa", + vpa.Namespace, ref.Name, ref.Kind) + } + return &ds, nil + } + return nil, fmt.Errorf("unknown target kind %s for vpa %s/%s encountered", + ref.Kind, vpa.Namespace, vpa.Name) } // When there is a hand-crafted vpa targeting the same object as a served vpa the served one needs to be deleted. // This functions returns true, when vpa currently being reconciled has been deleted. func (v *VpaController) cleanupServedVpa(ctx context.Context, reconcileVpa *vpav1.VerticalPodAutoscaler) (bool, error) { - v.Log.Info("Checking for deletion as a custom vpa was created", - "namespace", reconcileVpa.GetNamespace(), "name", reconcileVpa.GetName()) if reconcileVpa.Spec.TargetRef == nil { return false, nil } @@ -113,59 +159,111 @@ func (v *VpaController) cleanupServedVpa(ctx context.Context, reconcileVpa *vpav } // Clean-up vpa resources with old naming schema. -func (v *VpaController) deleteOldVpa(ctx context.Context, vpa *vpav1.VerticalPodAutoscaler) error { +func (v *VpaController) deleteOldVpa(ctx context.Context, vpa *vpav1.VerticalPodAutoscaler) (bool, error) { if !isNewNamingSchema(vpa.GetName()) { err := v.Delete(ctx, vpa) if err != nil { - return err + return false, err } v.Log.Info("Cleanup old vpa successful", "namespace", vpa.GetNamespace(), "name", vpa.GetName()) + return true, nil } - return nil + return false, nil } // Cleanup-up served Vpas, which target have been removed. // Compared to finalizers on the targets (deployments,...) this approach is more // lazy as the vpa needs to be reconciled, but it does not put finalizers on critical resources. -func (v *VpaController) deleteOrphanedVpa(ctx context.Context, vpa *vpav1.VerticalPodAutoscaler) error { +func (v *VpaController) deleteOrphanedVpa(ctx context.Context, vpa *vpav1.VerticalPodAutoscaler) (bool, error) { if vpa.Spec.TargetRef == nil { v.Log.Info("Deleting Vpa with orphaned target") - return v.Delete(ctx, vpa) + return true, v.Delete(ctx, vpa) } name := types.NamespacedName{Namespace: vpa.Namespace, Name: vpa.Spec.TargetRef.Name} var obj client.Object switch vpa.Spec.TargetRef.Kind { - case "Deployment": + case DeploymentStr: obj = &appsv1.Deployment{} - case "StatefulSet": + case StatefulSetStr: obj = &appsv1.StatefulSet{} - case "DaemonSet": + case DaemonSetStr: obj = &appsv1.DaemonSet{} } err := v.Get(ctx, name, obj) - if errors.IsNotFound(err) { + if apierrors.IsNotFound(err) { v.Log.Info("Deleting Vpa with orphaned target") - return v.Delete(ctx, vpa) + return true, v.Delete(ctx, vpa) } - return err + return false, err } -func (v *VpaController) patchVersionAnnotation(ctx context.Context, vpa *vpav1.VerticalPodAutoscaler) error { - if v.Version != "" { - version, ok := vpa.Annotations[annotationVpaButlerVersion] - if !ok || version != v.Version { - original := vpa.DeepCopy() - vpa.Annotations[annotationVpaButlerVersion] = v.Version - err := v.Client.Patch(ctx, vpa, client.MergeFrom(original)) - if err != nil { - return err - } - v.Log.Info("Patched version annotation", "namespace", vpa.GetNamespace(), "name", vpa.GetName()) +func (v *VpaController) reconcileVpa(ctx context.Context, vpaOwner client.Object) error { + var vpa = new(vpav1.VerticalPodAutoscaler) + vpa.Namespace = vpaOwner.GetNamespace() + vpa.Name = getVpaName(vpaOwner) + exists := true + if err := v.Client.Get(ctx, client.ObjectKeyFromObject(vpa), vpa); err != nil { + // Return any other error. + if !apierrors.IsNotFound(err) { + return err } + exists = false + } + + if o, err := meta.Accessor(vpa); err == nil { + if o.GetDeletionTimestamp() != nil { + return fmt.Errorf("the resource %s/%s already exists but is marked for deletion", + o.GetNamespace(), o.GetName()) + } + } + + before := vpa.DeepCopy() + if err := v.configureVpa(vpaOwner, vpa); err != nil { + return errors.Wrap(err, "mutating object failed") + } + + if !exists { + v.Log.Info("Creating vpa", "name", vpa.Name, "namespace", vpa.Namespace) + return v.Client.Create(ctx, vpa) + } + + if equality.Semantic.DeepEqual(before, vpa) { + return nil + } + patch := client.MergeFrom(before) + v.Log.Info("Patching vpa", "name", vpa.Name, "namespace", vpa.Namespace) + if err := v.Client.Patch(ctx, vpa, patch); err != nil { + return err } return nil } +func (v *VpaController) configureVpa(vpaOwner client.Object, vpa *vpav1.VerticalPodAutoscaler) error { + common.ConfigureVpaBaseline(vpa, vpaOwner, common.VpaUpdateMode) + + resourceList := []corev1.ResourceName{corev1.ResourceCPU, corev1.ResourceMemory} + containerResourcePolicy := vpav1.ContainerResourcePolicy{ + ContainerName: "*", + ControlledResources: &resourceList, + ControlledValues: &common.VpaControlledValues, + MinAllowed: corev1.ResourceList{ + corev1.ResourceCPU: v.MinAllowedCPU, + corev1.ResourceMemory: v.MinAllowedMemory, + }, + } + if vpa.Spec.ResourcePolicy != nil && len(vpa.Spec.ResourcePolicy.ContainerPolicies) > 0 { + oldPolicy := vpa.Spec.ResourcePolicy.ContainerPolicies[0] + containerResourcePolicy.MaxAllowed = oldPolicy.MaxAllowed.DeepCopy() + } + + vpa.Spec.ResourcePolicy = &vpav1.PodResourcePolicy{ + ContainerPolicies: []vpav1.ContainerResourcePolicy{containerResourcePolicy}, + } + vpa.Annotations[annotationVpaButlerVersion] = v.Version + + return controllerutil.SetOwnerReference(vpaOwner, vpa, v.Scheme) +} + func isNewNamingSchema(name string) bool { suffixes := []string{"-daemonset", "-statefulset", "-deployment"} for _, prefix := range suffixes { diff --git a/internal/controllers/vpa_controller_test.go b/internal/controllers/vpa_controller_test.go index 228405f..f2e2b3a 100644 --- a/internal/controllers/vpa_controller_test.go +++ b/internal/controllers/vpa_controller_test.go @@ -2,9 +2,12 @@ package controllers_test import ( "context" + "time" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "github.com/sapcc/vpa_butler/internal/common" + "github.com/sapcc/vpa_butler/internal/controllers" appsv1 "k8s.io/api/apps/v1" autoscalingv1 "k8s.io/api/autoscaling/v1" "k8s.io/apimachinery/pkg/api/errors" @@ -28,7 +31,7 @@ var _ = Describe("VpaController", func() { vpa.Namespace = metav1.NamespaceDefault vpa.Spec.TargetRef = &autoscalingv1.CrossVersionObjectReference{ Name: deploymentName, - Kind: "Deployment", + Kind: controllers.DeploymentStr, APIVersion: "v1", } Expect(k8sClient.Create(context.Background(), vpa)).To(Succeed()) @@ -56,14 +59,19 @@ var _ = Describe("VpaController", func() { When("creating a deployment", func() { var deployment *appsv1.Deployment + var defaultUpdateMode vpav1.UpdateMode BeforeEach(func() { + defaultUpdateMode = common.VpaUpdateMode deployment = makeDeployment() Expect(k8sClient.Create(context.Background(), deployment)).To(Succeed()) }) AfterEach(func() { + // failsafe: there is a deletion in the tests, so we drop the error here + _ = k8sClient.Delete(context.Background(), deployment) deleteVpa("test-deployment-deployment") + common.VpaUpdateMode = defaultUpdateMode }) It("deletes Vpas with an orphaned target on reconciliation", func() { @@ -90,5 +98,31 @@ var _ = Describe("VpaController", func() { }).Should(BeTrue()) }) + It("patches the served vpa", func() { + // need to sleep here to ensure the a vpa is created before the update + // to this global variable + time.Sleep(100 * time.Millisecond) + common.VpaUpdateMode = vpav1.UpdateModeAuto + var unmodified vpav1.VerticalPodAutoscaler + Expect(k8sClient.Get(context.Background(), types.NamespacedName{ + Namespace: metav1.NamespaceDefault, + Name: "test-deployment-deployment", + }, &unmodified)).To(Succeed()) + changed := unmodified.DeepCopy() + changed.Labels = map[string]string{"changed": "true"} + Expect(k8sClient.Patch(context.Background(), changed, client.MergeFrom(&unmodified))).To(Succeed()) + Eventually(func() vpav1.UpdateMode { + var vpa vpav1.VerticalPodAutoscaler + err := k8sClient.Get(context.Background(), types.NamespacedName{ + Name: "test-deployment-deployment", + Namespace: metav1.NamespaceDefault, + }, &vpa) + if err != nil { + return vpav1.UpdateMode("") + } + return *vpa.Spec.UpdatePolicy.UpdateMode + }).Should(Equal(common.VpaUpdateMode)) + }) + }) }) diff --git a/internal/controllers/vpa_runnable.go b/internal/controllers/vpa_runnable.go index fe6b567..75055d5 100644 --- a/internal/controllers/vpa_runnable.go +++ b/internal/controllers/vpa_runnable.go @@ -67,6 +67,7 @@ func (v *VpaRunnable) reconcile(ctx context.Context) { v.Log.Error(err, "failed to determine valid nodes", "namespace", target.Vpa.Namespace, "name", target.Vpa.Name) } if len(viable) == 0 { + v.Log.Error(err, "no valid nodes found", "namespace", target.Vpa.Namespace, "name", target.Vpa.Name) return } largest := maxByMemory(viable) @@ -93,7 +94,7 @@ func (v *VpaRunnable) extractTarget(ctx context.Context, vpa *vpav1.VerticalPodA } ref := *vpa.Spec.TargetRef switch ref.Kind { - case "Deployment": + case DeploymentStr: var deployment appsv1.Deployment err := v.Client.Get(ctx, types.NamespacedName{Name: ref.Name, Namespace: vpa.Namespace}, &deployment) if err != nil { @@ -105,7 +106,7 @@ func (v *VpaRunnable) extractTarget(ctx context.Context, vpa *vpav1.VerticalPodA PodSpec: deployment.Spec.Template.Spec, Selector: *deployment.Spec.Selector, }, nil - case "StatefulSet": + case StatefulSetStr: var sts appsv1.StatefulSet err := v.Client.Get(ctx, types.NamespacedName{Name: ref.Name, Namespace: vpa.Namespace}, &sts) if err != nil { @@ -117,7 +118,7 @@ func (v *VpaRunnable) extractTarget(ctx context.Context, vpa *vpav1.VerticalPodA PodSpec: sts.Spec.Template.Spec, Selector: *sts.Spec.Selector, }, nil - case "DaemonSet": + case DaemonSetStr: var ds appsv1.DaemonSet err := v.Client.Get(ctx, types.NamespacedName{Name: ref.Name, Namespace: vpa.Namespace}, &ds) if err != nil { diff --git a/internal/controllers/vpa_runnable_test.go b/internal/controllers/vpa_runnable_test.go index 6885cec..002cd79 100644 --- a/internal/controllers/vpa_runnable_test.go +++ b/internal/controllers/vpa_runnable_test.go @@ -7,6 +7,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/sapcc/vpa_butler/internal/common" + "github.com/sapcc/vpa_butler/internal/controllers" appsv1 "k8s.io/api/apps/v1" autoscalingv1 "k8s.io/api/autoscaling/v1" @@ -35,6 +36,9 @@ func expectMaxResources(name, cpu, mem string) { if mangedBy != common.AnnotationVpaButler { return fmt.Errorf("vpa has wrong managed-by annotation") } + if vpa.Spec.ResourcePolicy == nil { + return fmt.Errorf("vpa resource policy is nil") + } if len(vpa.Spec.ResourcePolicy.ContainerPolicies) != 1 { return fmt.Errorf("vpa has wrong amount of container policies") } @@ -129,7 +133,7 @@ var _ = Describe("VpaRunnable", func() { vpa.Namespace = metav1.NamespaceDefault vpa.Spec.TargetRef = &autoscalingv1.CrossVersionObjectReference{ Name: deploymentName, - Kind: "Deployment", + Kind: controllers.DeploymentStr, APIVersion: "v1", } vpa.Spec.ResourcePolicy = &vpav1.PodResourcePolicy{