diff --git a/go.mod b/go.mod index f316afe..9e31271 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/hashicorp/go-multierror v1.1.1 github.com/jaypipes/ghw v0.12.0 github.com/joho/godotenv v1.5.1 - github.com/kairos-io/kairos-sdk v0.0.26 + github.com/kairos-io/kairos-sdk v0.0.27-0.20240301083517-b3dfedfacbf4 github.com/kairos-io/kcrypt v0.9.1 github.com/labstack/echo/v4 v4.11.4 github.com/mitchellh/mapstructure v1.5.0 diff --git a/go.sum b/go.sum index b2cab94..99fdbe2 100644 --- a/go.sum +++ b/go.sum @@ -379,11 +379,10 @@ github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfV github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/kairos-io/kairos-sdk v0.0.25 h1:/wQ8lHmmqJgKPaxzLllTgMQNWRje80XKdj8F0XlFXl0= github.com/kairos-io/kairos-sdk v0.0.25/go.mod h1:btSB2QAds/WSyIyPxnQ3jueMbkkZ75pHUUCj+yHpthQ= -github.com/kairos-io/kairos-sdk v0.0.26 h1:whaKHSspkugnn25xVSEJnnG9bu/7jBjxRx5D6QXY1Uw= -github.com/kairos-io/kairos-sdk v0.0.26/go.mod h1:btSB2QAds/WSyIyPxnQ3jueMbkkZ75pHUUCj+yHpthQ= +github.com/kairos-io/kairos-sdk v0.0.27-0.20240301083517-b3dfedfacbf4 h1:4DTdqVpHhiwCZ5RD67zT/OxT/wQOwDQq/aZi4rPSxvg= +github.com/kairos-io/kairos-sdk v0.0.27-0.20240301083517-b3dfedfacbf4/go.mod h1:btSB2QAds/WSyIyPxnQ3jueMbkkZ75pHUUCj+yHpthQ= github.com/kairos-io/kcrypt v0.9.1 h1:bMDXZ8MiPY/fgLe5CXQPfUIRchzxErlJ8nfZM/JPfEU= github.com/kairos-io/kcrypt v0.9.1/go.mod h1:odsVL3ab2GJUgDnvDGJi54jrWUe6tjfW9875knT/ltU= -github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs= github.com/kbinani/screenshot v0.0.0-20210720154843-7d3a670d8329 h1:qq2nCpSrXrmvDGRxW0ruW9BVEV1CN2a9YDOExdt+U0o= github.com/kbinani/screenshot v0.0.0-20210720154843-7d3a670d8329/go.mod h1:2VPVQDR4wO7KXHwP+DAypEy67rXf+okUx2zjgpCxZw4= github.com/kendru/darwin/go/depgraph v0.0.0-20221105232959-877d6a81060c h1:eKb4PqwAMhlqwXw0W3atpKaYaPGlXE/Fwh+xpCEYaPk= @@ -399,23 +398,19 @@ github.com/klauspost/compress v1.16.5/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQs github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.0.10/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c= github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c= -github.com/klauspost/cpuid/v2 v2.2.3 h1:sxCkb+qR91z4vsqw4vGGZlDgPz3G7gjaLyK3V8y70BU= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= 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/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/labstack/echo/v4 v4.11.4 h1:vDZmA+qNeh1pd/cCkEicDMrjtrnMGQ1QFI9gWN1zGq8= github.com/labstack/echo/v4 v4.11.4/go.mod h1:noh7EvLwqDsmh/X/HWKPUl1AjzJrhyptRyEbQJfxen8= github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0= github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU= -github.com/linuxkit/virtsock v0.0.0-20201010232012-f8cee7dfc7a3/go.mod h1:3r6x7q95whyfWQpmGZTu3gk3v2YkMi05HEzl7Tf7YEo= github.com/lithammer/fuzzysearch v1.1.8 h1:/HIuJnjHuXS8bKaiTMeeDlW2/AyIWk2brx1V8LFgLN4= github.com/lithammer/fuzzysearch v1.1.8/go.mod h1:IdqeyBClc3FFqSzYq/MXESsS4S0FsZ5ajtkr5xPLts4= github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= @@ -428,7 +423,6 @@ github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0V github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/makiuchi-d/gozxing v0.1.1 h1:xxqijhoedi+/lZlhINteGbywIrewVdVv2wl9r5O9S1I= github.com/makiuchi-d/gozxing v0.1.1/go.mod h1:eRIHbOjX7QWxLIDJoQuMLhuXg9LAuw6znsUtRkNw9DU= -github.com/matryer/is v1.2.0 h1:92UTHpy8CDwaJ08GqLDzhhuixiBUUD1p3AU6PHddz4A= github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= @@ -455,18 +449,12 @@ github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RR github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= -github.com/moby/locker v1.0.1/go.mod h1:S7SDdo5zpBK84bzzVlKr2V0hz+7x9hWbYC/kq7oQppc= github.com/moby/moby v23.0.2+incompatible h1:W9l+1HGV+mZ4a6RW9ZAHzSYPpqAZ96/ft5gFJAaeh9c= github.com/moby/moby v23.0.2+incompatible/go.mod h1:fDXVQ6+S340veQPv35CzDahGBmHsiclFwfEygB/TWMc= -github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c= github.com/moby/sys/mountinfo v0.6.2 h1:BzJjoreD5BMFNmD9Rus6gdd1pLuecOFPt8wC+Vygl78= github.com/moby/sys/mountinfo v0.6.2/go.mod h1:IJb6JQeOklcdMU9F5xQ8ZALD+CUr5VlGpwtX+VE0rpI= github.com/moby/sys/sequential v0.5.0 h1:OPvI35Lzn9K04PBbCLW0g4LcFAJgHsvXsRyewg5lXtc= github.com/moby/sys/sequential v0.5.0/go.mod h1:tH2cOOs5V9MlPiXcQzRC+eEyab644PWKGRYaaV5ZZlo= -github.com/moby/term v0.0.0-20221205130635-1aeaba878587 h1:HfkjXDfhgVaN5rmueG8cL8KKeFNecRCXFhaJ2qZ5SKA= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= -github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/mudler/entities v0.0.0-20220905203055-68348bae0f49 h1:P1QgHLh0hX935j6m9K6rlSxc0mkD1UuIAOQEu+1VCW4= github.com/mudler/entities v0.0.0-20220905203055-68348bae0f49/go.mod h1:qquFT9tYp+/NO7tTotto4BT9zSRYSMDxo2PGZwujpFA= github.com/mudler/go-nodepair v0.0.0-20221223092639-ba399a66fdfb h1:F6TP0DW7C0U9sgm9g4uAs0Vp2JSkhn2umlyrNlxUKXw= @@ -486,7 +474,6 @@ github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKt github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo= github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= -github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= @@ -501,7 +488,6 @@ github.com/onsi/ginkgo v1.12.0/go.mod h1:oUhWkIvk5aDxtKvDDuw8gItl8pKl42LzjC9KZE0 github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= github.com/onsi/ginkgo v1.14.2/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= -github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo/v2 v2.12.1 h1:uHNEO1RP2SpuZApSkel9nEh1/Mu+hmQe7Q+Pepg5OYA= github.com/onsi/ginkgo/v2 v2.12.1/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= @@ -520,14 +506,12 @@ github.com/otiai10/copy v1.9.0/go.mod h1:hsfX19wcn0UWIHUQ3/4fHuehhk2UyArQ9dVFAn3 github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE= github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs= github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo= -github.com/otiai10/mint v1.4.0 h1:umwcf7gbpEwf7WFzqmWwSv0CzbeMsae2u9ZvpP8j2q4= github.com/otiai10/mint v1.4.0/go.mod h1:gifjb2MYOoULtKLqUAEILUG/9KONW6f7YsJ6vQLTlFI= github.com/packethost/packngo v0.29.0 h1:gRIhciVZQ/zLNrIdIdbOUyB/Tw5IgoaXyhP4bvE+D2s= github.com/packethost/packngo v0.29.0/go.mod h1:/UHguFdPs6Lf6FOkkSEPnRY5tgS0fsVM+Zv/bvBrmt0= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= -github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= github.com/phayes/permbits v0.0.0-20190612203442-39d7c581d2ee h1:P6U24L02WMfj9ymZTxl7CxS73JC99x3ukk+DBkgQGQs= github.com/phayes/permbits v0.0.0-20190612203442-39d7c581d2ee/go.mod h1:3uODdxMgOaPYeWU7RzZLxVtJHZ/x1f/iHkBZuKJDzuY= github.com/pierrec/lz4 v2.3.0+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= @@ -542,7 +526,6 @@ github.com/pkg/xattr v0.4.1/go.mod h1:W2cGD0TBEus7MkUgv0tNZ9JutLtVO3cXu+IBRuHqnF github.com/pkg/xattr v0.4.9 h1:5883YPCtkSd8LFbs13nXplj9g9tlrwoJRjgpgMu1/fE= github.com/pkg/xattr v0.4.9/go.mod h1:di8WF84zAKk8jzR1UBTEWh9AUlIZZ7M/JNt8e9B6ktU= github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= @@ -573,7 +556,6 @@ github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0= github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= @@ -627,11 +609,9 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= github.com/spf13/viper v1.16.0 h1:rGGH0XDZhdUOryiDWjmIvUSWpbNqisK8Wk0Vyefw8hc= github.com/spf13/viper v1.16.0/go.mod h1:yg78JgCJcbrQOvV9YLXgkLaZqUidkY9K+Dd1FofRzQg= -github.com/stefanberger/go-pkcs11uri v0.0.0-20201008174630-78d3cae3a980/go.mod h1:AO3tvPzVZ/ayst6UlUKUv6rcPQInYe3IknH3jYhAKu8= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/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 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v0.0.0-20161117074351-18a02ba4a312/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= @@ -644,17 +624,13 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8= github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= -github.com/swaggest/assertjson v1.9.0 h1:dKu0BfJkIxv/xe//mkCrK5yZbs79jL7OVf9Ija7o2xQ= github.com/swaggest/jsonschema-go v0.3.62 h1:eIE0aRklWa2eLJg2L/zqyWpKvgUPbq2oKOtrJGJkPH0= github.com/swaggest/jsonschema-go v0.3.62/go.mod h1:DYuKqdpms/edvywsX6p1zHXCZkdwB28wRaBdFCe3Duw= github.com/swaggest/refl v1.3.0 h1:PEUWIku+ZznYfsoyheF97ypSduvMApYyGkYF3nabS0I= github.com/swaggest/refl v1.3.0/go.mod h1:3Ujvbmh1pfSbDYjC6JGG7nMgPvpG0ehQL4iNonnLNbg= -github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/tmc/scp v0.0.0-20170824174625-f7b48647feef h1:7D6Nm4D6f0ci9yttWaKjM1TMAXrH5Su72dojqYGntFY= github.com/tredoe/osutil/v2 v2.0.0-rc.16 h1:5A2SKvyB2c3lhPYUIHyFtu6jbaXlaA3Hu5gWIam8Pik= github.com/tredoe/osutil/v2 v2.0.0-rc.16/go.mod h1:uLRVx/3pb7Y4RQhG8cQFbPE9ha5r81e6MXpBsxbTAYc= github.com/twpayne/go-vfs v1.7.2 h1:ZNYMAXcu2Av8c109USrSGYm8dIIIV0xPlG19I2088Kw= @@ -686,7 +662,6 @@ github.com/willdonnelly/passwd v0.0.0-20141013001024-7935dab3074c/go.mod h1:xcvf github.com/xanzy/ssh-agent v0.3.0/go.mod h1:3s9xbODqPuuhK9JV1R321M/FlMZSBvE5aY6eAcqrDh0= github.com/xanzy/ssh-agent v0.3.1 h1:AmzO1SSWxw73zxFZPRwaMN1MohDw8UyHnmuxyceTEGo= github.com/xanzy/ssh-agent v0.3.1/go.mod h1:QIE4lCeL7nkC25x+yA3LBIYfwCc1TFziCtG7cBAac6w= -github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs= github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= @@ -694,8 +669,6 @@ github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJu github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= -github.com/yudai/gojsondiff v1.0.0 h1:27cbfqXLVEJ1o8I6v3y9lg8Ydm53EKqHXAOMxEGlCOA= -github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -704,7 +677,6 @@ github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5t github.com/zcalusic/sysinfo v1.0.1 h1:cVh8q3codjh43AGRTa54dJ2Zq+qPejv8n2VWpxKViwc= github.com/zcalusic/sysinfo v1.0.1/go.mod h1:LxwKwtQdbTIQc65drhjQzYzt0o7jfB80LrrZm7SWn8o= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= -go.mozilla.org/pkcs7 v0.0.0-20200128120323-432b2356ecb1/go.mod h1:SNgMg+EgDFwmvSmLRTNKC5fegJjB7v23qTQ0XLGUNHk= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= @@ -947,7 +919,6 @@ golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 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= @@ -1113,20 +1084,17 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 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-20200227125254-8fa46927fb4f/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/djherbis/times.v1 v1.2.0/go.mod h1:AQlg6unIsrsCEdQYhTzERy542dz6SFdQFZFv6mUY0P8= gopkg.in/djherbis/times.v1 v1.3.0 h1:uxMS4iMtH6Pwsxog094W0FYldiNnfY/xba00vq6C2+o= gopkg.in/djherbis/times.v1 v1.3.0/go.mod h1:AQlg6unIsrsCEdQYhTzERy542dz6SFdQFZFv6mUY0P8= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= -gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473/go.mod h1:N1eN2tsCx0Ydtgjl4cqmbRCsY4/+z4cYDeqwZTk6zog= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= -gopkg.in/square/go-jose.v2 v2.5.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= @@ -1145,8 +1113,6 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C 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/v3 v3.0.3 h1:4AuOwCGf4lLR9u3YOe2awrHygurzhO/HeQ6laiA6Sx0= -gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/internal/agent/hooks/gruboptions.go b/internal/agent/hooks/gruboptions.go index 73472b9..d389d7d 100644 --- a/internal/agent/hooks/gruboptions.go +++ b/internal/agent/hooks/gruboptions.go @@ -11,6 +11,9 @@ import ( type GrubOptions struct{} func (b GrubOptions) Run(c config.Config, _ v1.Spec) error { + if len(c.Install.GrubOptions) == 0 { + return nil + } c.Logger.Debugf("Setting grub options: %s", c.Install.GrubOptions) err := system.Apply(system.SetGRUBOptions(c.Install.GrubOptions)) if err != nil { diff --git a/internal/agent/hooks/kcrypt_uki.go b/internal/agent/hooks/kcrypt_uki.go index 015bfe0..cbde04f 100644 --- a/internal/agent/hooks/kcrypt_uki.go +++ b/internal/agent/hooks/kcrypt_uki.go @@ -3,8 +3,10 @@ package hook import ( "fmt" "os" + "path/filepath" "strconv" "strings" + "syscall" "time" "github.com/kairos-io/kairos-agent/v2/pkg/config" @@ -59,7 +61,7 @@ func (k KcryptUKI) Run(c config.Config, _ v1.Spec) error { _ = machine.Umount(constants.PersistentDir) //nolint:errcheck // Backup oem as we already copied files on there and on luksify it will be wiped - err = machine.Mount("COS_OEM", constants.OEMDir) + err = machine.Mount(constants.OEMLabel, constants.OEMDir) if err != nil { return err } @@ -80,7 +82,7 @@ func (k KcryptUKI) Run(c config.Config, _ v1.Spec) error { return err } - for _, p := range append([]string{"COS_OEM", "COS_PERSISTENT"}, c.Install.Encrypt...) { + for _, p := range append([]string{constants.OEMLabel, constants.PersistentLabel}, c.Install.Encrypt...) { c.Logger.Infof("Encrypting %s", p) utils.SH("udevadm settle") //nolint:errcheck utils.SH("sync") //nolint:errcheck @@ -105,7 +107,7 @@ func (k KcryptUKI) Run(c config.Config, _ v1.Spec) error { } // Close the unlocked partitions after dealing with them, otherwise we leave them open and they can be mounted by anyone defer func() { - for _, p := range append([]string{"COS_OEM", "COS_PERSISTENT"}, c.Install.Encrypt...) { + for _, p := range append([]string{constants.OEMLabel, constants.PersistentLabel}, c.Install.Encrypt...) { c.Logger.Debugf("Closing unencrypted /dev/disk/by-label/%s", p) out, err := utils.SH(fmt.Sprintf("cryptsetup close /dev/disk/by-label/%s", p)) // There is a known error with cryptsetup that it can't close the device because of a semaphore @@ -119,19 +121,23 @@ func (k KcryptUKI) Run(c config.Config, _ v1.Spec) error { // Here it can take the oem partition a bit of time to appear after unlocking so we need to retry a couple of time with some waiting // retry + backoff - for i := 0; i < 10; i++ { - c.Logger.Infof("Waiting for unlocked partition to appear") - _, _ = utils.SH("sync") - part, _ := utils.SH("blkid -L COS_OEM") - if part == "" { - c.Logger.Infof("Partition not found, waiting %d seconds before retrying", i) - time.Sleep(time.Duration(i) * time.Second) - continue + // Check all encrypted partitions are unlocked + for _, p := range append([]string{constants.OEMLabel, constants.PersistentLabel}) { + for i := 0; i < 10; i++ { + c.Logger.Infof("Waiting for unlocked partition %s to appear", p) + _, _ = utils.SH("sync") + part, _ := utils.SH(fmt.Sprintf("blkid -L %s", p)) + if part == "" { + c.Logger.Infof("Partition %s not found, waiting %d seconds before retrying", p, i) + time.Sleep(time.Duration(i) * time.Second) + continue + } + c.Logger.Infof("Partition found, continuing") + break } - c.Logger.Infof("Partition found, continuing") - break } - err = machine.Mount("COS_OEM", constants.OEMDir) + + err = machine.Mount(constants.OEMLabel, constants.OEMDir) if err != nil { return err } @@ -143,5 +149,33 @@ func (k KcryptUKI) Run(c config.Config, _ v1.Spec) error { if err != nil { return err } + + // Copy logs to persistent partition + c.Logger.Debug("Copying logs to persistent partition") + err = machine.Mount(constants.PersistentLabel, constants.PersistentDir) + if err != nil { + c.Logger.Errorf("could not mount persistent partition: %s", err) + return nil + } + varLog := filepath.Join(constants.PersistentDir, ".state", "var-log.bind") + // Create the directory on persistent + err = fsutils.MkdirAll(c.Fs, varLog, 0755) + if err != nil { + c.Logger.Errorf("could not create directory on persistent partition: %s", err) + return nil + } + // Copy all current logs to the persistent partition + err = internalutils.SyncData(c.Logger, c.Runner, c.Fs, "/var/log/", varLog, []string{}...) + if err != nil { + c.Logger.Errorf("could not copy logs to persistent partition: %s", err) + return nil + } + err = machine.Umount(constants.PersistentDir) + if err != nil { + c.Logger.Errorf("could not unmount persistent partition: %s", err) + return nil + } + syscall.Sync() + c.Logger.Debug("Logs copied to persistent partition") return nil } diff --git a/internal/agent/hooks/logs.go b/internal/agent/hooks/logs.go new file mode 100644 index 0000000..a423435 --- /dev/null +++ b/internal/agent/hooks/logs.go @@ -0,0 +1,51 @@ +package hook + +import ( + "github.com/kairos-io/kairos-agent/v2/pkg/config" + "github.com/kairos-io/kairos-agent/v2/pkg/constants" + v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1" + internalutils "github.com/kairos-io/kairos-agent/v2/pkg/utils" + fsutils "github.com/kairos-io/kairos-agent/v2/pkg/utils/fs" + "github.com/kairos-io/kairos-sdk/machine" + "path/filepath" + "syscall" +) + +// CopyLogs copies all current logs to the persistent partition +// useful during install to keep the livecd logs +// best effort, no error handling +type CopyLogs struct{} + +func (k CopyLogs) Run(c config.Config, _ v1.Spec) error { + c.Logger.Debugf("Copying logs to persistent partition") + _ = machine.Umount(constants.PersistentDir) + + err := machine.Mount(constants.PersistentLabel, constants.PersistentDir) + if err != nil { + c.Logger.Errorf("could not mount persistent partition: %s", err) + return nil + } + + // Create the directory on persistent + varLog := filepath.Join(constants.PersistentDir, ".state", "var-log.bind") + + err = fsutils.MkdirAll(c.Fs, varLog, 0755) + if err != nil { + c.Logger.Errorf("could not create directory on persistent partition: %s", err) + return nil + } + // Copy all current logs to the persistent partition + err = internalutils.SyncData(c.Logger, c.Runner, c.Fs, "/var/log/", varLog, []string{}...) + if err != nil { + c.Logger.Errorf("could not copy logs to persistent partition: %s", err) + return nil + } + err = machine.Umount(constants.PersistentDir) + if err != nil { + c.Logger.Errorf("could not unmount persistent partition: %s", err) + return nil + } + syscall.Sync() + c.Logger.Debugf("Logs copied to persistent partition") + return nil +} diff --git a/internal/agent/install.go b/internal/agent/install.go index 32d129b..3b2b213 100644 --- a/internal/agent/install.go +++ b/internal/agent/install.go @@ -292,7 +292,7 @@ func runInstall(c *config.Config) error { func dumpCCStringToFile(c *config.Config) (string, error) { f, err := fsutils.TempFile(c.Fs, "", "kairos-install-config-xxx.yaml") if err != nil { - c.Logger.Error("Error creating temporary file for install config: %s\n", err.Error()) + c.Logger.Errorf("Error creating temporary file for install config: %s", err.Error()) return "", err } defer func(f *os.File) { diff --git a/main.go b/main.go index 070fbf6..406b13c 100644 --- a/main.go +++ b/main.go @@ -5,17 +5,16 @@ import ( "encoding/json" "errors" "fmt" + "github.com/kairos-io/kairos-agent/v2/pkg/action" "github.com/kairos-io/kairos-agent/v2/pkg/constants" + "github.com/kairos-io/kairos-agent/v2/pkg/utils" + "github.com/mudler/go-pluggable" "os" "path/filepath" "regexp" "runtime" "strings" - "github.com/kairos-io/kairos-agent/v2/pkg/action" - "github.com/kairos-io/kairos-agent/v2/pkg/utils" - "github.com/mudler/go-pluggable" - "github.com/kairos-io/kairos-agent/v2/internal/agent" "github.com/kairos-io/kairos-agent/v2/internal/bus" "github.com/kairos-io/kairos-agent/v2/internal/common" @@ -30,8 +29,6 @@ import ( "github.com/kairos-io/kairos-sdk/state" "github.com/kairos-io/kairos-sdk/versioneer" "github.com/sanity-io/litter" - "github.com/sirupsen/logrus" - "github.com/spf13/viper" "github.com/urfave/cli/v2" "gopkg.in/yaml.v3" @@ -662,7 +659,7 @@ The validate command expects a configuration file as its only argument. Local fi config.CloudInitPaths = append(config.CloudInitPaths, c.StringSlice("cloud-init-paths")...) } if c.Bool("debug") { - config.Logger.SetLevel(logrus.DebugLevel) + config.Logger.SetLevel("debug") } if err != nil { @@ -800,6 +797,8 @@ The kairos agent is a component to abstract away node ops, providing a common fe viper.Set("debug", c.Bool("debug")) if c.Bool("debug") { litter.Config.HidePrivateFields = false + // Hide logger and client fields from litter as otherwise the config dumps are huge and a bit useless + litter.Config.FieldExclusions = regexp.MustCompile(`Logger|logger|Client`) } return nil }, diff --git a/pkg/action/bootentries_test.go b/pkg/action/bootentries_test.go index e98d645..bc817dd 100644 --- a/pkg/action/bootentries_test.go +++ b/pkg/action/bootentries_test.go @@ -9,6 +9,7 @@ import ( fsutils "github.com/kairos-io/kairos-agent/v2/pkg/utils/fs" v1mock "github.com/kairos-io/kairos-agent/v2/tests/mocks" "github.com/kairos-io/kairos-sdk/collector" + sdkTypes "github.com/kairos-io/kairos-sdk/types" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/twpayne/go-vfs" @@ -20,7 +21,7 @@ import ( var _ = Describe("Bootentries tests", Label("bootentry"), func() { var config *agentConfig.Config var fs vfs.FS - var logger v1.Logger + var logger sdkTypes.KairosLogger var runner *v1mock.FakeRunner var mounter *v1mock.ErrorMounter var syscallMock *v1mock.FakeSyscall @@ -37,9 +38,9 @@ var _ = Describe("Bootentries tests", Label("bootentry"), func() { mounter = v1mock.NewErrorMounter() client = &v1mock.FakeHTTPClient{} memLog = &bytes.Buffer{} - logger = v1.NewBufferLogger(memLog) + logger = sdkTypes.NewBufferLogger(memLog) extractor = v1mock.NewFakeImageExtractor(logger) - logger.SetLevel(v1.DebugLevel()) + logger.SetLevel("debug") var err error fs, cleanup, err = vfst.NewTestFS(map[string]interface{}{}) // Create proper dir structure for our EFI partition contentens diff --git a/pkg/action/common_test.go b/pkg/action/common_test.go index 37c362c..0d7f93d 100644 --- a/pkg/action/common_test.go +++ b/pkg/action/common_test.go @@ -4,9 +4,9 @@ import ( "bytes" "fmt" agentConfig "github.com/kairos-io/kairos-agent/v2/pkg/config" - v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1" v1mock "github.com/kairos-io/kairos-agent/v2/tests/mocks" "github.com/kairos-io/kairos-sdk/collector" + sdkTypes "github.com/kairos-io/kairos-sdk/types" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/twpayne/go-vfs" @@ -19,7 +19,7 @@ var _ = Describe("Common action tests", func() { Describe("createExtraDirsInRootfs", func() { var config *agentConfig.Config var fs vfs.FS - var logger v1.Logger + var logger sdkTypes.KairosLogger var runner *v1mock.FakeRunner var mounter *v1mock.ErrorMounter var syscall *v1mock.FakeSyscall @@ -35,9 +35,9 @@ var _ = Describe("Common action tests", func() { mounter = v1mock.NewErrorMounter() client = &v1mock.FakeHTTPClient{} memLog = &bytes.Buffer{} - logger = v1.NewBufferLogger(memLog) + logger = sdkTypes.NewBufferLogger(memLog) extractor = v1mock.NewFakeImageExtractor(logger) - logger.SetLevel(v1.DebugLevel()) + logger.SetLevel("debug") var err error fs, cleanup, err = vfst.NewTestFS(map[string]interface{}{}) Expect(err).Should(BeNil()) diff --git a/pkg/action/install_test.go b/pkg/action/install_test.go index 39bac2f..c82d833 100644 --- a/pkg/action/install_test.go +++ b/pkg/action/install_test.go @@ -19,6 +19,7 @@ package action_test import ( "bytes" "fmt" + sdkTypes "github.com/kairos-io/kairos-sdk/types" "path/filepath" "regexp" @@ -47,7 +48,7 @@ var _ = Describe("Install action tests", func() { var config *agentConfig.Config var runner *v1mock.FakeRunner var fs vfs.FS - var logger v1.Logger + var logger sdkTypes.KairosLogger var mounter *v1mock.ErrorMounter var syscall *v1mock.FakeSyscall var client *v1mock.FakeHTTPClient @@ -63,9 +64,9 @@ var _ = Describe("Install action tests", func() { mounter = v1mock.NewErrorMounter() client = &v1mock.FakeHTTPClient{} memLog = &bytes.Buffer{} - logger = v1.NewBufferLogger(memLog) + logger = sdkTypes.NewBufferLogger(memLog) extractor = v1mock.NewFakeImageExtractor(logger) - //logger.SetLevel(v1.DebugLevel()) + logger.SetLevel("debug") var err error fs, cleanup, err = vfst.NewTestFS(map[string]interface{}{}) Expect(err).Should(BeNil()) diff --git a/pkg/action/reset_test.go b/pkg/action/reset_test.go index 9bb54c5..4a25001 100644 --- a/pkg/action/reset_test.go +++ b/pkg/action/reset_test.go @@ -22,6 +22,7 @@ import ( "fmt" agentConfig "github.com/kairos-io/kairos-agent/v2/pkg/config" "github.com/kairos-io/kairos-agent/v2/pkg/utils/fs" + sdkTypes "github.com/kairos-io/kairos-sdk/types" "path/filepath" "regexp" @@ -41,7 +42,7 @@ var _ = Describe("Reset action tests", func() { var config *agentConfig.Config var runner *v1mock.FakeRunner var fs vfs.FS - var logger v1.Logger + var logger sdkTypes.KairosLogger var mounter *v1mock.ErrorMounter var syscall *v1mock.FakeSyscall var client *v1mock.FakeHTTPClient @@ -57,7 +58,7 @@ var _ = Describe("Reset action tests", func() { mounter = v1mock.NewErrorMounter() client = &v1mock.FakeHTTPClient{} memLog = &bytes.Buffer{} - logger = v1.NewBufferLogger(memLog) + logger = sdkTypes.NewBufferLogger(memLog) extractor = v1mock.NewFakeImageExtractor(logger) var err error fs, cleanup, err = vfst.NewTestFS(map[string]interface{}{}) diff --git a/pkg/action/upgrade.go b/pkg/action/upgrade.go index 7bc3f10..694c3e2 100644 --- a/pkg/action/upgrade.go +++ b/pkg/action/upgrade.go @@ -175,7 +175,7 @@ func (u *UpgradeAction) Run() (err error) { u.Debug("mounting persistent partition") umount, err = e.MountRWPartition(persistentPart) if err != nil { - u.config.Logger.Warn("could not mount persistent partition: %s", err.Error()) + u.config.Logger.Warnf("could not mount persistent partition: %s", err.Error()) } } } @@ -259,7 +259,7 @@ func (u *UpgradeAction) Run() (err error) { out, err := u.config.Runner.Run("tune2fs", "-L", u.spec.Passive.Label, u.spec.Passive.File) if err != nil { u.Error("Error while labeling the passive image %s: %s", u.spec.Passive.File, err) - u.Debug("Error while labeling the passive image %s, command output: %s", out) + u.Debug("Error while labeling the passive image %s, command output: %s", u.spec.Passive.File, out) return err } _, _ = u.config.Runner.Run("sync") diff --git a/pkg/action/upgrade_test.go b/pkg/action/upgrade_test.go index a01fd71..9a10ca9 100644 --- a/pkg/action/upgrade_test.go +++ b/pkg/action/upgrade_test.go @@ -19,6 +19,7 @@ package action_test import ( "bytes" "fmt" + sdkTypes "github.com/kairos-io/kairos-sdk/types" "path/filepath" agentConfig "github.com/kairos-io/kairos-agent/v2/pkg/config" @@ -31,7 +32,6 @@ import ( v1mock "github.com/kairos-io/kairos-agent/v2/tests/mocks" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/sirupsen/logrus" "github.com/twpayne/go-vfs" "github.com/twpayne/go-vfs/vfst" ) @@ -40,7 +40,7 @@ var _ = Describe("Runtime Actions", func() { var config *agentConfig.Config var runner *v1mock.FakeRunner var fs vfs.FS - var logger v1.Logger + var logger sdkTypes.KairosLogger var mounter *v1mock.ErrorMounter var syscall *v1mock.FakeSyscall var client *v1mock.FakeHTTPClient @@ -56,8 +56,8 @@ var _ = Describe("Runtime Actions", func() { mounter = v1mock.NewErrorMounter() client = &v1mock.FakeHTTPClient{} memLog = &bytes.Buffer{} - logger = v1.NewBufferLogger(memLog) - logger.SetLevel(logrus.DebugLevel) + logger = sdkTypes.NewBufferLogger(memLog) + logger.SetLevel("debug") extractor = v1mock.NewFakeImageExtractor(logger) var err error fs, cleanup, err = vfst.NewTestFS(map[string]interface{}{}) @@ -92,11 +92,11 @@ var _ = Describe("Runtime Actions", func() { BeforeEach(func() { memLog = &bytes.Buffer{} - logger = v1.NewBufferLogger(memLog) + logger = sdkTypes.NewBufferLogger(memLog) extractor = v1mock.NewFakeImageExtractor(logger) config.Logger = logger config.ImageExtractor = extractor - logger.SetLevel(logrus.DebugLevel) + logger.SetLevel("debug") // Create paths used by tests fsutils.MkdirAll(fs, fmt.Sprintf("%s/cOS", constants.RunningStateDir), constants.DirPerm) diff --git a/pkg/cloudinit/cloudinit.go b/pkg/cloudinit/cloudinit.go index 4184b3d..8b51ad8 100644 --- a/pkg/cloudinit/cloudinit.go +++ b/pkg/cloudinit/cloudinit.go @@ -18,6 +18,7 @@ package cloudinit import ( v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1" + sdkTypes "github.com/kairos-io/kairos-sdk/types" "github.com/mudler/yip/pkg/executor" "github.com/mudler/yip/pkg/plugins" "github.com/mudler/yip/pkg/schema" @@ -32,7 +33,7 @@ type YipCloudInitRunner struct { // NewYipCloudInitRunner returns a default yip cloud init executor with the Elemental plugin set. // It accepts a logger which is used inside the runner. -func NewYipCloudInitRunner(l v1.Logger, r v1.Runner, fs vfs.FS) *YipCloudInitRunner { +func NewYipCloudInitRunner(l sdkTypes.KairosLogger, r v1.Runner, fs vfs.FS) *YipCloudInitRunner { exec := executor.NewExecutor( executor.WithConditionals( plugins.NodeConditional, diff --git a/pkg/cloudinit/cloudinit_test.go b/pkg/cloudinit/cloudinit_test.go index 44a3156..bb3b8ac 100644 --- a/pkg/cloudinit/cloudinit_test.go +++ b/pkg/cloudinit/cloudinit_test.go @@ -21,6 +21,7 @@ import ( "errors" "fmt" "github.com/kairos-io/kairos-agent/v2/pkg/utils/fs" + sdkTypes "github.com/kairos-io/kairos-sdk/types" "io/ioutil" "log" "os" @@ -47,7 +48,7 @@ const printOutput = `BYT; var _ = Describe("CloudRunner", Label("CloudRunner", "types", "cloud-init"), func() { // unit test stolen from yip Describe("loading yaml files", func() { - logger := v1.NewNullLogger() + logger := sdkTypes.NewNullLogger() It("executes commands", func() { @@ -104,10 +105,10 @@ stages: var partNum int var cleanup func() var logs *bytes.Buffer - var logger v1.Logger + var logger sdkTypes.KairosLogger BeforeEach(func() { logs = &bytes.Buffer{} - logger = v1.NewBufferLogger(logs) + logger = sdkTypes.NewBufferLogger(logs) afs, cleanup, _ = vfst.NewTestFS(nil) err := fsutils.MkdirAll(afs, "/some/yip", constants.DirPerm) diff --git a/pkg/cloudinit/console.go b/pkg/cloudinit/console.go index 35daffc..ac577b0 100644 --- a/pkg/cloudinit/console.go +++ b/pkg/cloudinit/console.go @@ -18,6 +18,7 @@ package cloudinit import ( "fmt" + sdkTypes "github.com/kairos-io/kairos-sdk/types" "os/exec" "github.com/hashicorp/go-multierror" @@ -28,12 +29,12 @@ import ( // the elemental v1.Runner interface. type cloudInitConsole struct { runner v1.Runner - logger v1.Logger + logger sdkTypes.KairosLogger } // newCloudInitConsole returns an instance of the cloudInitConsole based on the // given v1.Runner and v1.Logger. -func newCloudInitConsole(l v1.Logger, r v1.Runner) *cloudInitConsole { +func newCloudInitConsole(l sdkTypes.KairosLogger, r v1.Runner) *cloudInitConsole { return &cloudInitConsole{logger: l, runner: r} } diff --git a/pkg/config/config.go b/pkg/config/config.go index 5bc564f..fb5e171 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -8,6 +8,8 @@ import ( "strings" "unicode" + "github.com/joho/godotenv" + version "github.com/kairos-io/kairos-agent/v2/internal/common" "github.com/kairos-io/kairos-agent/v2/pkg/cloudinit" "github.com/kairos-io/kairos-agent/v2/pkg/constants" "github.com/kairos-io/kairos-agent/v2/pkg/http" @@ -15,6 +17,7 @@ import ( "github.com/kairos-io/kairos-sdk/bundles" "github.com/kairos-io/kairos-sdk/collector" "github.com/kairos-io/kairos-sdk/schema" + sdkTypes "github.com/kairos-io/kairos-sdk/types" yip "github.com/mudler/yip/pkg/schema" "github.com/sanity-io/litter" "github.com/spf13/viper" @@ -45,7 +48,7 @@ type Install struct { } func NewConfig(opts ...GenericOptions) *Config { - log := v1.NewLogger() + log := sdkTypes.NewKairosLogger("agent", "info", false) hostPlatform, err := v1.NewPlatformFromArch(runtime.GOARCH) if err != nil { @@ -78,13 +81,14 @@ func NewConfig(opts ...GenericOptions) *Config { // delay runner creation after we have run over the options in case we use WithRunner if c.Runner == nil { - c.Runner = &v1.RealRunner{Logger: c.Logger} + c.Runner = &v1.RealRunner{Logger: &c.Logger} } // Now check if the runner has a logger inside, otherwise point our logger into it // This can happen if we set the WithRunner option as that doesn't set a logger - if c.Runner.GetLogger() == nil { - c.Runner.SetLogger(c.Logger) + l := c.Runner.GetLogger() + if &l == nil { + c.Runner.SetLogger(&c.Logger) } // Delay the yip runner creation, so we set the proper logger instead of blindly setting it to the logger we create @@ -110,32 +114,32 @@ func NewConfig(opts ...GenericOptions) *Config { type Config struct { Install *Install `yaml:"install,omitempty"` collector.Config `yaml:"-"` - ConfigURL string `yaml:"config_url,omitempty"` - Options map[string]string `yaml:"options,omitempty"` - FailOnBundleErrors bool `yaml:"fail_on_bundles_errors,omitempty"` - Bundles Bundles `yaml:"bundles,omitempty"` - GrubOptions map[string]string `yaml:"grub_options,omitempty"` - Env []string `yaml:"env,omitempty"` - Debug bool `yaml:"debug,omitempty" mapstructure:"debug"` - Strict bool `yaml:"strict,omitempty" mapstructure:"strict"` - CloudInitPaths []string `yaml:"cloud-init-paths,omitempty" mapstructure:"cloud-init-paths"` - EjectCD bool `yaml:"eject-cd,omitempty" mapstructure:"eject-cd"` - Logger v1.Logger `yaml:"-"` - Fs v1.FS `yaml:"-"` - Mounter mount.Interface `yaml:"-"` - Runner v1.Runner `yaml:"-"` - Syscall v1.SyscallInterface `yaml:"-"` - CloudInitRunner v1.CloudInitRunner `yaml:"-"` - ImageExtractor v1.ImageExtractor `yaml:"-"` - Client v1.HTTPClient `yaml:"-"` - Platform *v1.Platform `yaml:"-"` - Cosign bool `yaml:"cosign,omitempty" mapstructure:"cosign"` - Verify bool `yaml:"verify,omitempty" mapstructure:"verify"` - CosignPubKey string `yaml:"cosign-key,omitempty" mapstructure:"cosign-key"` - Arch string `yaml:"arch,omitempty" mapstructure:"arch"` - SquashFsCompressionConfig []string `yaml:"squash-compression,omitempty" mapstructure:"squash-compression"` - SquashFsNoCompression bool `yaml:"squash-no-compression,omitempty" mapstructure:"squash-no-compression"` - UkiMaxEntries int `yaml:"uki-max-entries,omitempty" mapstructure:"uki-max-entries"` + ConfigURL string `yaml:"config_url,omitempty"` + Options map[string]string `yaml:"options,omitempty"` + FailOnBundleErrors bool `yaml:"fail_on_bundles_errors,omitempty"` + Bundles Bundles `yaml:"bundles,omitempty"` + GrubOptions map[string]string `yaml:"grub_options,omitempty"` + Env []string `yaml:"env,omitempty"` + Debug bool `yaml:"debug,omitempty" mapstructure:"debug"` + Strict bool `yaml:"strict,omitempty" mapstructure:"strict"` + CloudInitPaths []string `yaml:"cloud-init-paths,omitempty" mapstructure:"cloud-init-paths"` + EjectCD bool `yaml:"eject-cd,omitempty" mapstructure:"eject-cd"` + Logger sdkTypes.KairosLogger `yaml:"-"` + Fs v1.FS `yaml:"-"` + Mounter mount.Interface `yaml:"-"` + Runner v1.Runner `yaml:"-"` + Syscall v1.SyscallInterface `yaml:"-"` + CloudInitRunner v1.CloudInitRunner `yaml:"-"` + ImageExtractor v1.ImageExtractor `yaml:"-"` + Client v1.HTTPClient `yaml:"-"` + Platform *v1.Platform `yaml:"-"` + Cosign bool `yaml:"cosign,omitempty" mapstructure:"cosign"` + Verify bool `yaml:"verify,omitempty" mapstructure:"verify"` + CosignPubKey string `yaml:"cosign-key,omitempty" mapstructure:"cosign-key"` + Arch string `yaml:"arch,omitempty" mapstructure:"arch"` + SquashFsCompressionConfig []string `yaml:"squash-compression,omitempty" mapstructure:"squash-compression"` + SquashFsNoCompression bool `yaml:"squash-no-compression,omitempty" mapstructure:"squash-no-compression"` + UkiMaxEntries int `yaml:"uki-max-entries,omitempty" mapstructure:"uki-max-entries"` } // WriteInstallState writes the state.yaml file to the given state and recovery paths @@ -209,7 +213,7 @@ func WithFs(fs v1.FS) func(r *Config) { } } -func WithLogger(logger v1.Logger) func(r *Config) { +func WithLogger(logger sdkTypes.KairosLogger) func(r *Config) { return func(r *Config) { r.Logger = logger } @@ -375,7 +379,24 @@ func Scan(opts ...collector.Option) (c *Config, err error) { viper.Set("debug", true) } // Config the logger - configLogger(result.Logger, result.Fs) + if viper.GetBool("debug") { + result.Logger.SetLevel("debug") + } + + result.Logger.Logger.Info().Interface("version", version.GetVersion()).Msg("Kairos Agent") + result.Logger.Logger.Debug().Interface("version", version.Get()).Msg("Kairos Agent") + + // Try to load the kairos version from the os-release file + // Best effort, if it fails, we just ignore it + f, err := result.Fs.Open("/etc/os-release") + defer f.Close() + osRelease, err := godotenv.Parse(f) + if err == nil { + v := osRelease["KAIROS_VERSION"] + if v != "" { + result.Logger.Logger.Info().Str("version", v).Msg("Kairos System") + } + } result.Logger.Debugf("Loaded config: %s", litter.Sdump(result)) diff --git a/pkg/config/spec.go b/pkg/config/spec.go index 937261b..2862276 100644 --- a/pkg/config/spec.go +++ b/pkg/config/spec.go @@ -18,6 +18,7 @@ package config import ( "fmt" + sdkTypes "github.com/kairos-io/kairos-sdk/types" "io/fs" "os" "path/filepath" @@ -27,14 +28,12 @@ import ( "github.com/google/go-containerregistry/pkg/crane" "golang.org/x/sys/unix" - "github.com/kairos-io/kairos-agent/v2/internal/common" "github.com/kairos-io/kairos-agent/v2/pkg/constants" v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1" fsutils "github.com/kairos-io/kairos-agent/v2/pkg/utils/fs" "github.com/kairos-io/kairos-agent/v2/pkg/utils/partitions" "github.com/mitchellh/mapstructure" "github.com/sanity-io/litter" - "github.com/sirupsen/logrus" "github.com/spf13/viper" ) @@ -132,7 +131,7 @@ func NewInstallSpec(cfg *Config) (*v1.InstallSpec, error) { return spec, nil } -func NewInstallElementalPartitions(log v1.Logger, spec *v1.InstallSpec) v1.ElementalPartitions { +func NewInstallElementalPartitions(log sdkTypes.KairosLogger, spec *v1.InstallSpec) v1.ElementalPartitions { pt := v1.ElementalPartitions{} var oemSize uint if spec.Partitions.OEM != nil && spec.Partitions.OEM.Size != 0 { @@ -633,7 +632,7 @@ func NewUkiInstallSpec(cfg *Config) (*v1.InstallUkiSpec, error) { // Get the actual source size to calculate the image size and partitions size size, err := GetSourceSize(cfg, spec.Active.Source) if err != nil { - cfg.Logger.Warnf("Failed to infer size for images, leaving it as default size (%sMb): %s", spec.Partitions.EFI.Size, err.Error()) + cfg.Logger.Warnf("Failed to infer size for images, leaving it as default size (%dMb): %s", spec.Partitions.EFI.Size, err.Error()) } else { // Only override if the calculated size is bigger than the default size, otherwise stay with 15Gb minimum if uint(size*3) > spec.Partitions.EFI.Size { @@ -855,50 +854,6 @@ func ReadSpecFromCloudConfig(r *Config, spec string) (v1.Spec, error) { return sp, nil } -func configLogger(log v1.Logger, vfs v1.FS) { - // Set debug level - if viper.GetBool("debug") { - log.SetLevel(v1.DebugLevel()) - } - - // Set formatter so both file and stdout format are equal - log.SetFormatter(&logrus.TextFormatter{ - ForceColors: true, - DisableColors: false, - DisableTimestamp: false, - FullTimestamp: true, - }) - - // Logfile - // Not being used for now, disable it until we plug it again in our cli - /* - logfile := viper.GetString("logfile") - if logfile != "" { - o, err := vfs.OpenFile(logfile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, fs.ModePerm) - - if err != nil { - log.Errorf("Could not open %s for logging to file: %s", logfile, err.Error()) - } - - if viper.GetBool("quiet") { // if quiet is set, only set the log to the file - log.SetOutput(o) - } else { // else set it to both stdout and the file - mw := io.MultiWriter(os.Stdout, o) - log.SetOutput(mw) - } - } else { // no logfile - if viper.GetBool("quiet") { // quiet is enabled so discard all logging - log.SetOutput(io.Discard) - } else { // default to stdout - log.SetOutput(os.Stdout) - } - } - */ - - v := common.GetVersion() - log.Infof("kairos-agent version %s", v) -} - var decodeHook = viper.DecodeHook( mapstructure.ComposeDecodeHookFunc( UnmarshalerHook(), diff --git a/pkg/config/spec_test.go b/pkg/config/spec_test.go index af15fed..c56c84e 100644 --- a/pkg/config/spec_test.go +++ b/pkg/config/spec_test.go @@ -18,6 +18,8 @@ package config_test import ( "fmt" + sdkTypes "github.com/kairos-io/kairos-sdk/types" + "github.com/rs/zerolog" "os" "path/filepath" @@ -31,7 +33,6 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/sanity-io/litter" - "github.com/sirupsen/logrus" "github.com/twpayne/go-vfs/vfst" "k8s.io/mount-utils" ) @@ -45,7 +46,7 @@ var _ = Describe("Types", Label("types", "config"), func() { var runner *v1mock.FakeRunner var client *v1mock.FakeHTTPClient var sysc *v1mock.FakeSyscall - var logger v1.Logger + var logger sdkTypes.KairosLogger var ci *v1mock.FakeCloudInitRunner var c *config.Config BeforeEach(func() { @@ -55,7 +56,7 @@ var _ = Describe("Types", Label("types", "config"), func() { runner = v1mock.NewFakeRunner() client = &v1mock.FakeHTTPClient{} sysc = &v1mock.FakeSyscall{} - logger = v1.NewNullLogger() + logger = sdkTypes.NewNullLogger() ci = &v1mock.FakeCloudInitRunner{} c = config.NewConfig( config.WithFs(fs), @@ -120,7 +121,7 @@ var _ = Describe("Types", Label("types", "config"), func() { It("should use the default mounter", Label("systemctl"), func() { runner := v1mock.NewFakeRunner() sysc := &v1mock.FakeSyscall{} - logger := v1.NewNullLogger() + logger := sdkTypes.NewNullLogger() c := config.NewConfig( config.WithRunner(runner), config.WithSyscall(sysc), @@ -598,7 +599,7 @@ cloud-init-paths: // Now again but with no config cfg, err := config.Scan(collector.Directories([]string{""}...), collector.NoLogs) Expect(err).ToNot(HaveOccurred()) - Expect(cfg.Logger.GetLevel()).To(Equal(logrus.InfoLevel)) + Expect(cfg.Logger.GetLevel()).To(Equal(zerolog.InfoLevel)) }) It("Sets debug level if its on the cloud-config", func() { ccdata := []byte(`#cloud-config @@ -608,7 +609,7 @@ debug: true Expect(err).ToNot(HaveOccurred()) cfg, err := config.Scan(collector.Directories([]string{dir}...), collector.NoLogs) Expect(err).ToNot(HaveOccurred()) - Expect(cfg.Logger.GetLevel()).To(Equal(logrus.DebugLevel)) + Expect(cfg.Logger.GetLevel()).To(Equal(zerolog.DebugLevel)) }) }) @@ -655,7 +656,7 @@ var _ = Describe("GetSourceSize", func() { var tempDir string var tempFilePath string var err error - var logger v1.Logger + var logger sdkTypes.KairosLogger var conf *config.Config var imageSource *v1.ImageSource @@ -663,7 +664,7 @@ var _ = Describe("GetSourceSize", func() { tempDir, err = os.MkdirTemp("/tmp", "kairos-test") Expect(err).To(BeNil()) - logger = v1.NewNullLogger() + logger = sdkTypes.NewNullLogger() conf = config.NewConfig( config.WithLogger(logger), ) diff --git a/pkg/elemental/elemental.go b/pkg/elemental/elemental.go index 80d65fc..a4cd2dc 100644 --- a/pkg/elemental/elemental.go +++ b/pkg/elemental/elemental.go @@ -175,7 +175,7 @@ func (e Elemental) MountRWPartition(part *v1.Partition) (umount func() error, er } else { err = e.MountPartition(part, "rw") if err != nil { - e.config.Logger.Error("failed mounting %s partition: %v", part.Name, err) + e.config.Logger.Errorf("failed mounting %s partition: %v", part.Name, err) return nil, err } umount = func() error { return e.UnmountPartition(part) } @@ -336,7 +336,7 @@ func (e *Elemental) DeployImage(img *v1.Image, leaveMounted bool) (info interfac } else if img.Label != "" && img.FS != cnst.SquashFs { _, err = e.config.Runner.Run("tune2fs", "-L", img.Label, img.File) if err != nil { - e.config.Logger.Errorf("Failed to apply label %s to $s", img.Label, img.File) + e.config.Logger.Errorf("Failed to apply label %s to %s", img.Label, img.File) _ = e.config.Fs.Remove(img.File) return nil, err } @@ -362,10 +362,10 @@ func (e *Elemental) DumpSource(target string, imgSrc *v1.ImageSource) (info inte if imgSrc.IsDocker() { if e.config.Cosign { - e.config.Logger.Infof("Running cosing verification for %s", imgSrc.Value()) + e.config.Logger.Infof("Running cosign verification for %s", imgSrc.Value()) out, err := utils.CosignVerify( e.config.Fs, e.config.Runner, imgSrc.Value(), - e.config.CosignPubKey, v1.IsDebugLevel(e.config.Logger), + e.config.CosignPubKey, ) if err != nil { e.config.Logger.Errorf("Cosign verification failed: %s", out) diff --git a/pkg/elemental/elemental_test.go b/pkg/elemental/elemental_test.go index f361dcf..ba6bed2 100644 --- a/pkg/elemental/elemental_test.go +++ b/pkg/elemental/elemental_test.go @@ -19,6 +19,7 @@ package elemental_test import ( "errors" "fmt" + sdkTypes "github.com/kairos-io/kairos-sdk/types" "os" "path/filepath" "testing" @@ -52,7 +53,7 @@ func TestElementalSuite(t *testing.T) { var _ = Describe("Elemental", Label("elemental"), func() { var config *agentConfig.Config var runner *v1mock.FakeRunner - var logger v1.Logger + var logger sdkTypes.KairosLogger var syscall v1.SyscallInterface var client *v1mock.FakeHTTPClient var mounter *v1mock.ErrorMounter @@ -65,7 +66,7 @@ var _ = Describe("Elemental", Label("elemental"), func() { syscall = &v1mock.FakeSyscall{} mounter = v1mock.NewErrorMounter() client = &v1mock.FakeHTTPClient{} - logger = v1.NewNullLogger() + logger = sdkTypes.NewNullLogger() fs, cleanup, _ = vfst.NewTestFS(nil) extractor = v1mock.NewFakeImageExtractor(logger) config = agentConfig.NewConfig( diff --git a/pkg/http/client.go b/pkg/http/client.go index 771458a..6e32341 100644 --- a/pkg/http/client.go +++ b/pkg/http/client.go @@ -17,12 +17,12 @@ limitations under the License. package http import ( + sdkTypes "github.com/kairos-io/kairos-sdk/types" "net/http" "time" "github.com/cavaliergopher/grab/v3" "github.com/kairos-io/kairos-agent/v2/pkg/constants" - v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1" ) type Client struct { @@ -37,7 +37,7 @@ func NewClient() *Client { } // GetURL attempts to download the contents of the given URL to the given destination -func (c Client) GetURL(log v1.Logger, url string, destination string) error { // nolint:revive +func (c Client) GetURL(log sdkTypes.KairosLogger, url string, destination string) error { // nolint:revive req, err := grab.NewRequest(destination, url) if err != nil { log.Errorf("Failed creating a request to '%s'", url) @@ -45,7 +45,7 @@ func (c Client) GetURL(log v1.Logger, url string, destination string) error { // } // start download - log.Infof("Downloading %v...\n", req.URL()) + log.Infof("Downloading %v...", req.URL()) resp := c.client.Do(req) // start UI loop @@ -58,7 +58,7 @@ Loop: case <-t.C: log.Debugf(" transferred %v / %v bytes (%.2f%%)\n", resp.BytesComplete(), - resp.Size, + resp.Size(), 100*resp.Progress()) case <-resp.Done: diff --git a/pkg/http/client_test.go b/pkg/http/client_test.go index c401e68..b58702c 100644 --- a/pkg/http/client_test.go +++ b/pkg/http/client_test.go @@ -17,12 +17,11 @@ limitations under the License. package http_test import ( + sdkTypes "github.com/kairos-io/kairos-sdk/types" "os" "path/filepath" "github.com/kairos-io/kairos-agent/v2/pkg/http" - "github.com/kairos-io/kairos-agent/v2/pkg/types/v1" - . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) @@ -31,11 +30,11 @@ const source = "https://github.com/kairos-io/kairos/releases/download/v2.0.0/cor var _ = Describe("HTTPClient", Label("http"), func() { var client *http.Client - var log v1.Logger + var log sdkTypes.KairosLogger var destDir string BeforeEach(func() { client = http.NewClient() - log = v1.NewNullLogger() + log = sdkTypes.NewNullLogger() destDir, _ = os.MkdirTemp("", "elemental-test") }) AfterEach(func() { diff --git a/pkg/partitioner/disk.go b/pkg/partitioner/disk.go index 6f9ae3b..5db139c 100644 --- a/pkg/partitioner/disk.go +++ b/pkg/partitioner/disk.go @@ -21,6 +21,7 @@ import ( "fmt" "github.com/kairos-io/kairos-agent/v2/pkg/utils/fs" "github.com/kairos-io/kairos-agent/v2/pkg/utils/partitions" + sdkTypes "github.com/kairos-io/kairos-sdk/types" "os" "regexp" "strings" @@ -46,7 +47,7 @@ type Disk struct { label string runner v1.Runner fs v1.FS - logger v1.Logger + logger sdkTypes.KairosLogger } // MiBToSectors returns the number of sectors that correspond to the given amount @@ -81,8 +82,9 @@ func NewDisk(device string, opts ...DiskOptions) *Disk { dev.fs = vfs.OSFS } - if dev.logger == nil { - dev.logger = v1.NewLogger() + l := dev.logger + if &l == nil { + dev.logger = sdkTypes.NewKairosLogger("partitioner", "info", false) } return dev diff --git a/pkg/partitioner/options.go b/pkg/partitioner/options.go index 62e40f3..8559b47 100644 --- a/pkg/partitioner/options.go +++ b/pkg/partitioner/options.go @@ -18,6 +18,7 @@ package partitioner import ( v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1" + sdkTypes "github.com/kairos-io/kairos-sdk/types" ) type DiskOptions func(d *Disk) error @@ -36,7 +37,7 @@ func WithRunner(runner v1.Runner) func(d *Disk) error { } } -func WithLogger(logger v1.Logger) func(d *Disk) error { +func WithLogger(logger sdkTypes.KairosLogger) func(d *Disk) error { return func(d *Disk) error { d.logger = logger return nil diff --git a/pkg/types/v1/http.go b/pkg/types/v1/http.go index 38190a4..9aa740a 100644 --- a/pkg/types/v1/http.go +++ b/pkg/types/v1/http.go @@ -16,6 +16,8 @@ limitations under the License. package v1 +import sdkTypes "github.com/kairos-io/kairos-sdk/types" + type HTTPClient interface { - GetURL(log Logger, url string, destination string) error + GetURL(log sdkTypes.KairosLogger, url string, destination string) error } diff --git a/pkg/types/v1/logger.go b/pkg/types/v1/logger.go deleted file mode 100644 index b7dd7ef..0000000 --- a/pkg/types/v1/logger.go +++ /dev/null @@ -1,73 +0,0 @@ -/* -Copyright © 2022 SUSE LLC - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1 - -import ( - "bytes" - log "github.com/sirupsen/logrus" - "io" -) - -// Logger is the interface we want for our logger, so we can plug different ones easily -type Logger interface { - Info(...interface{}) - Warn(...interface{}) - Debug(...interface{}) - Error(...interface{}) - Fatal(...interface{}) - Warning(...interface{}) - Panic(...interface{}) - Trace(...interface{}) - Infof(string, ...interface{}) - Warnf(string, ...interface{}) - Debugf(string, ...interface{}) - Errorf(string, ...interface{}) - Fatalf(string, ...interface{}) - Panicf(string, ...interface{}) - Tracef(string, ...interface{}) - SetLevel(level log.Level) - GetLevel() log.Level - SetOutput(writer io.Writer) - SetFormatter(formatter log.Formatter) -} - -func DebugLevel() log.Level { - l, _ := log.ParseLevel("debug") - return l -} - -func IsDebugLevel(l Logger) bool { - return l.GetLevel() == DebugLevel() -} - -func NewLogger() Logger { - return log.New() -} - -// NewNullLogger will return a logger that discards all logs, used mainly for testing -func NewNullLogger() Logger { - logger := log.New() - logger.SetOutput(io.Discard) - return logger -} - -// NewBufferLogger will return a logger that stores all logs in a buffer, used mainly for testing -func NewBufferLogger(b *bytes.Buffer) Logger { - logger := log.New() - logger.SetOutput(b) - return logger -} diff --git a/pkg/types/v1/logger_test.go b/pkg/types/v1/logger_test.go deleted file mode 100644 index 4a9a851..0000000 --- a/pkg/types/v1/logger_test.go +++ /dev/null @@ -1,56 +0,0 @@ -/* -Copyright © 2021 SUSE LLC - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1_test - -import ( - "bytes" - v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - "github.com/sirupsen/logrus" - "reflect" -) - -var _ = Describe("logger", Label("log", "logger", "types"), func() { - It("TestNewLogger returns a logger interface", func() { - l1 := v1.NewLogger() - l2 := logrus.New() - Expect(reflect.TypeOf(l1).Kind()).To(Equal(reflect.TypeOf(l2).Kind())) - }) - It("TestNewNullLogger returns logger interface", func() { - l1 := v1.NewNullLogger() - l2 := logrus.New() - Expect(reflect.TypeOf(l1).Kind()).To(Equal(reflect.TypeOf(l2).Kind())) - }) - It("DebugLevel returns the proper log level for debug output", func() { - Expect(v1.DebugLevel()).To(Equal(logrus.DebugLevel)) - }) - It("Returns true on IsDebugLevel when log level is set to debug", func() { - l := v1.NewLogger() - l.SetLevel(v1.DebugLevel()) - Expect(v1.IsDebugLevel(l)).To(BeTrue()) - }) - It("Returns false on IsDebugLevel when log level is not set to debug", func() { - Expect(v1.IsDebugLevel(v1.NewLogger())).To(BeFalse()) - }) - It("NewBufferLogger stores content in a buffer", func() { - b := &bytes.Buffer{} - l1 := v1.NewBufferLogger(b) - l1.Info("TEST") - Expect(b).To(ContainSubstring("TEST")) - }) -}) diff --git a/pkg/types/v1/runner.go b/pkg/types/v1/runner.go index f42c4a5..3e64396 100644 --- a/pkg/types/v1/runner.go +++ b/pkg/types/v1/runner.go @@ -17,6 +17,7 @@ limitations under the License. package v1 import ( + sdkTypes "github.com/kairos-io/kairos-sdk/types" "os/exec" "strings" ) @@ -25,12 +26,12 @@ type Runner interface { InitCmd(string, ...string) *exec.Cmd Run(string, ...string) ([]byte, error) RunCmd(cmd *exec.Cmd) ([]byte, error) - GetLogger() Logger - SetLogger(logger Logger) + GetLogger() *sdkTypes.KairosLogger + SetLogger(logger *sdkTypes.KairosLogger) } type RealRunner struct { - Logger Logger + Logger *sdkTypes.KairosLogger } func (r RealRunner) InitCmd(command string, args ...string) *exec.Cmd { @@ -49,10 +50,10 @@ func (r RealRunner) Run(command string, args ...string) ([]byte, error) { return r.RunCmd(cmd) } -func (r RealRunner) GetLogger() Logger { +func (r *RealRunner) GetLogger() *sdkTypes.KairosLogger { return r.Logger } -func (r *RealRunner) SetLogger(logger Logger) { +func (r *RealRunner) SetLogger(logger *sdkTypes.KairosLogger) { r.Logger = logger } diff --git a/pkg/types/v1/runner_test.go b/pkg/types/v1/runner_test.go index 8c6cadd..c4a104f 100644 --- a/pkg/types/v1/runner_test.go +++ b/pkg/types/v1/runner_test.go @@ -20,9 +20,9 @@ import ( "bytes" v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1" v1mock "github.com/kairos-io/kairos-agent/v2/tests/mocks" + sdkTypes "github.com/kairos-io/kairos-sdk/types" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/sirupsen/logrus" ) var _ = Describe("Runner", Label("types", "runner"), func() { @@ -39,24 +39,24 @@ var _ = Describe("Runner", Label("types", "runner"), func() { It("Sets and gets the logger on the fake runner", func() { r := v1mock.NewFakeRunner() Expect(r.GetLogger()).To(BeNil()) - logger := v1.NewNullLogger() - r.SetLogger(logger) - Expect(r.GetLogger()).To(Equal(logger)) + logger := sdkTypes.NewNullLogger() + r.SetLogger(&logger) + Expect(r.GetLogger()).ToNot(BeNil()) }) It("Sets and gets the logger on the real runner", func() { r := v1.RealRunner{} Expect(r.GetLogger()).To(BeNil()) - logger := v1.NewNullLogger() - r.SetLogger(logger) - Expect(r.GetLogger()).To(Equal(logger)) + logger := sdkTypes.NewNullLogger() + r.SetLogger(&logger) + Expect(r.GetLogger()).ToNot(BeNil()) }) It("logs the command when on debug", func() { memLog := &bytes.Buffer{} - logger := v1.NewBufferLogger(memLog) - logger.SetLevel(logrus.DebugLevel) - r := v1.RealRunner{Logger: logger} + logger := sdkTypes.NewBufferLogger(memLog) + logger.SetLevel("debug") + r := v1.RealRunner{Logger: &logger} _, err := r.Run("command", "with", "args") Expect(err).ToNot(BeNil()) // Command will fail Expect(memLog.String()).To(ContainSubstring("command with args")) diff --git a/pkg/uki/common.go b/pkg/uki/common.go index 1b6b9e9..6bcefe2 100644 --- a/pkg/uki/common.go +++ b/pkg/uki/common.go @@ -2,6 +2,7 @@ package uki import ( "fmt" + sdkTypes "github.com/kairos-io/kairos-sdk/types" "io" "os" "strings" @@ -19,7 +20,7 @@ const UnassignedArtifactRole = "norole" // the artifacts prefixed with oldRole as newRole. // E.g. removes "passive" and moved "active" to "passive" // This is a step that should happen before a new passive is installed on upgrades. -func overwriteArtifactSetRole(fs v1.FS, dir, oldRole, newRole string, logger v1.Logger) error { +func overwriteArtifactSetRole(fs v1.FS, dir, oldRole, newRole string, logger sdkTypes.KairosLogger) error { if err := removeArtifactSetWithRole(fs, dir, newRole); err != nil { return fmt.Errorf("deleting role %s: %w", newRole, err) } @@ -47,7 +48,7 @@ func removeArtifactSetWithRole(fs v1.FS, artifactDir, role string) error { }) } -func copyArtifactSetRole(fs v1.FS, artifactDir, oldRole, newRole string, logger v1.Logger) error { +func copyArtifactSetRole(fs v1.FS, artifactDir, oldRole, newRole string, logger sdkTypes.KairosLogger) error { return fsutils.WalkDirFs(fs, artifactDir, func(path string, info os.DirEntry, err error) error { if err != nil { return err @@ -70,7 +71,7 @@ func copyArtifactSetRole(fs v1.FS, artifactDir, oldRole, newRole string, logger }) } -func replaceRoleInKey(path, key, oldRole, newRole string, logger v1.Logger) (err error) { +func replaceRoleInKey(path, key, oldRole, newRole string, logger sdkTypes.KairosLogger) (err error) { // Extract the values conf, err := sdkutils.SystemdBootConfReader(path) if err != nil { diff --git a/pkg/utils/common.go b/pkg/utils/common.go index d8a1d21..f4d7790 100644 --- a/pkg/utils/common.go +++ b/pkg/utils/common.go @@ -21,6 +21,7 @@ import ( "crypto/sha256" "errors" "fmt" + sdkTypes "github.com/kairos-io/kairos-sdk/types" "io" random "math/rand" "net/url" @@ -155,7 +156,7 @@ func CreateDirStructure(fs v1.FS, target string) error { // SyncData rsync's source folder contents to a target folder content, // both are expected to exist beforehand. -func SyncData(log v1.Logger, runner v1.Runner, fs v1.FS, source string, target string, excludes ...string) error { +func SyncData(log sdkTypes.KairosLogger, runner v1.Runner, fs v1.FS, source string, target string, excludes ...string) error { if fs != nil { if s, err := fs.RawPath(source); err == nil { source = s @@ -196,7 +197,7 @@ func SyncData(log v1.Logger, runner v1.Runner, fs v1.FS, source string, target s return nil } -func displayProgress(log v1.Logger, tick time.Duration, message string) chan bool { +func displayProgress(log sdkTypes.KairosLogger, tick time.Duration, message string) chan bool { ticker := time.NewTicker(tick) done := make(chan bool) @@ -231,12 +232,9 @@ func Shutdown(runner v1.Runner, delay time.Duration) error { // CosignVerify runs a cosign validation for the give image and given public key. If no // key is provided then it attempts a keyless validation (experimental feature). -func CosignVerify(fs v1.FS, runner v1.Runner, image string, publicKey string, debug bool) (string, error) { +func CosignVerify(fs v1.FS, runner v1.Runner, image string, publicKey string) (string, error) { args := []string{} - if debug { - args = append(args, "-d=true") - } if publicKey != "" { args = append(args, "-key", publicKey) } else { @@ -264,7 +262,7 @@ func CosignVerify(fs v1.FS, runner v1.Runner, image string, publicKey string, de // CreateSquashFS creates a squash file at destination from a source, with options // TODO: Check validity of source maybe? -func CreateSquashFS(runner v1.Runner, logger v1.Logger, source string, destination string, options []string) error { +func CreateSquashFS(runner v1.Runner, logger sdkTypes.KairosLogger, source string, destination string, options []string) error { // create args args := []string{source, destination} // append options passed to args in order to have the correct order diff --git a/pkg/utils/runstage_test.go b/pkg/utils/runstage_test.go index 322a526..88e1f27 100644 --- a/pkg/utils/runstage_test.go +++ b/pkg/utils/runstage_test.go @@ -21,6 +21,7 @@ import ( "fmt" agentConfig "github.com/kairos-io/kairos-agent/v2/pkg/config" "github.com/kairos-io/kairos-agent/v2/pkg/utils/fs" + sdkTypes "github.com/kairos-io/kairos-sdk/types" "os" "github.com/kairos-io/kairos-agent/v2/pkg/cloudinit" @@ -29,7 +30,6 @@ import ( v1mock "github.com/kairos-io/kairos-agent/v2/tests/mocks" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - log "github.com/sirupsen/logrus" "github.com/twpayne/go-vfs" "github.com/twpayne/go-vfs/vfst" ) @@ -44,7 +44,7 @@ func writeCmdline(s string, fs v1.FS) error { var _ = Describe("run stage", Label("RunStage"), func() { var config *agentConfig.Config var runner *v1mock.FakeRunner - var logger v1.Logger + var logger sdkTypes.KairosLogger var syscall *v1mock.FakeSyscall var client *v1mock.FakeHTTPClient var mounter *v1mock.ErrorMounter @@ -58,8 +58,8 @@ var _ = Describe("run stage", Label("RunStage"), func() { // Use a different config with a buffer for logger, so we can check the output // We also use the real fs memLog = &bytes.Buffer{} - logger = v1.NewBufferLogger(memLog) - logger.SetLevel(log.DebugLevel) + logger = sdkTypes.NewBufferLogger(memLog) + logger.SetLevel("debug") fs, cleanup, _ = vfst.NewTestFS(nil) config = agentConfig.NewConfig( @@ -86,7 +86,7 @@ var _ = Describe("run stage", Label("RunStage"), func() { It("does not fail but prints errors by default", Label("strict"), func() { writeCmdline("stages.c3po[0].datasource", fs) - config.Logger.SetLevel(log.DebugLevel) + config.Logger.SetLevel("debug") out := utils.RunStage(config, "c3po") Expect(out).To(BeNil()) Expect(memLog.String()).To(ContainSubstring("parsing returned errors")) @@ -95,7 +95,7 @@ var _ = Describe("run stage", Label("RunStage"), func() { It("Goes over extra paths", func() { d, err := fsutils.TempDir(fs, "", "elemental") Expect(err).ToNot(HaveOccurred()) - config.Logger.SetLevel(log.DebugLevel) + config.Logger.SetLevel("debug") config.CloudInitPaths = []string{d} Expect(utils.RunStage(config, "luke")).To(BeNil()) @@ -118,7 +118,7 @@ var _ = Describe("run stage", Label("RunStage"), func() { It("parses cmdline uri with dotnotation", func() { writeCmdline("stages.leia[0].commands[0]='echo beepboop'", fs) - config.Logger.SetLevel(log.DebugLevel) + config.Logger.SetLevel("debug") Expect(utils.RunStage(config, "leia")).To(BeNil()) Expect(memLog).To(ContainSubstring("leia")) Expect(memLog).To(ContainSubstring("running command `echo beepboop`")) @@ -133,7 +133,7 @@ var _ = Describe("run stage", Label("RunStage"), func() { }) It("ignores YAML errors", func() { - config.Logger.SetLevel(log.DebugLevel) + config.Logger.SetLevel("debug") writeCmdline("BOOT=death-star sing1!~@$%6^&**le /varlib stag_#var