Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package pluto for openSUSE:Factory checked in at 2022-09-25 15:35:42 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/pluto (Old) and /work/SRC/openSUSE:Factory/.pluto.new.2275 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "pluto" Sun Sep 25 15:35:42 2022 rev:17 rq:1005846 version:5.11.0 Changes: -------- --- /work/SRC/openSUSE:Factory/pluto/pluto.changes 2022-09-14 13:45:00.061897109 +0200 +++ /work/SRC/openSUSE:Factory/.pluto.new.2275/pluto.changes 2022-09-25 15:36:08.191743374 +0200 @@ -1,0 +2,9 @@ +Sun Sep 25 06:54:38 UTC 2022 - ka...@b1-systems.de + +- Update to version 5.11.0: + * Feature : Detect depcreated API's on a live cluster resources (#367) + * Bump github.com/spf13/viper from 1.12.0 to 1.13.0 (#379) + * Bump k8s.io/client-go from 0.25.0 to 0.25.1 (#381) + * Bump k8s.io/klog/v2 from 2.70.1 to 2.80.1 (#378) + +------------------------------------------------------------------- Old: ---- pluto-5.10.7.tar.gz New: ---- pluto-5.11.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ pluto.spec ++++++ --- /var/tmp/diff_new_pack.dJq5EG/_old 2022-09-25 15:36:08.763744752 +0200 +++ /var/tmp/diff_new_pack.dJq5EG/_new 2022-09-25 15:36:08.767744762 +0200 @@ -19,7 +19,7 @@ %define __arch_install_post export NO_BRP_STRIP_DEBUG=true Name: pluto -Version: 5.10.7 +Version: 5.11.0 Release: 0 Summary: A cli tool to help discover deprecated apiVersions in Kubernetes License: Apache-2.0 ++++++ _service ++++++ --- /var/tmp/diff_new_pack.dJq5EG/_old 2022-09-25 15:36:08.799744838 +0200 +++ /var/tmp/diff_new_pack.dJq5EG/_new 2022-09-25 15:36:08.803744849 +0200 @@ -3,7 +3,7 @@ <param name="url">https://github.com/FairwindsOps/pluto</param> <param name="scm">git</param> <param name="exclude">.git</param> - <param name="revision">v5.10.7</param> + <param name="revision">v5.11.0</param> <param name="versionformat">@PARENT_TAG@</param> <param name="changesgenerate">enable</param> <param name="versionrewrite-pattern">v(.*)</param> @@ -16,7 +16,7 @@ <param name="compression">gz</param> </service> <service name="go_modules" mode="disabled"> - <param name="archive">pluto-5.10.7.tar.gz</param> + <param name="archive">pluto-5.11.0.tar.gz</param> </service> </services> ++++++ _servicedata ++++++ --- /var/tmp/diff_new_pack.dJq5EG/_old 2022-09-25 15:36:08.819744887 +0200 +++ /var/tmp/diff_new_pack.dJq5EG/_new 2022-09-25 15:36:08.823744897 +0200 @@ -1,6 +1,6 @@ <servicedata> <service name="tar_scm"> <param name="url">https://github.com/FairwindsOps/pluto</param> - <param name="changesrevision">62c93482d6e48b1e526b54db64de8dc6854ac907</param></service></servicedata> + <param name="changesrevision">7dc487a855dc5612ea31d62de42e594bb1cfec16</param></service></servicedata> (No newline at EOF) ++++++ pluto-5.10.7.tar.gz -> pluto-5.11.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pluto-5.10.7/.github/pull_request_template.md new/pluto-5.11.0/.github/pull_request_template.md --- old/pluto-5.10.7/.github/pull_request_template.md 2022-09-12 17:42:16.000000000 +0200 +++ new/pluto-5.11.0/.github/pull_request_template.md 2022-09-22 21:28:19.000000000 +0200 @@ -1,8 +1,4 @@ ---- -name: PR Request -description: Submit a PR request -labels: [triage] ---- + This PR fixes # ## Checklist diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pluto-5.10.7/cmd/root.go new/pluto-5.11.0/cmd/root.go --- old/pluto-5.10.7/cmd/root.go 2022-09-12 17:42:16.000000000 +0200 +++ new/pluto-5.11.0/cmd/root.go 2022-09-22 21:28:19.000000000 +0200 @@ -36,6 +36,7 @@ "strings" "github.com/fairwindsops/pluto/v5/pkg/api" + discoveryapi "github.com/fairwindsops/pluto/v5/pkg/discovery-api" "github.com/fairwindsops/pluto/v5/pkg/finder" "github.com/fairwindsops/pluto/v5/pkg/helm" "github.com/rogpeppe/go-internal/semver" @@ -98,6 +99,8 @@ rootCmd.AddCommand(listVersionsCmd) rootCmd.AddCommand(detectCmd) + rootCmd.AddCommand(detectApiResourceCmd) + klog.InitFlags(nil) pflag.CommandLine.AddGoFlag(flag.CommandLine.Lookup("v")) } @@ -395,6 +398,34 @@ }, } +var detectApiResourceCmd = &cobra.Command{ + Use: "detect-api-resources", + Short: "detect-api-resources", + Long: `Detect Kubernetes apiVersions from an active cluster.`, + Run: func(cmd *cobra.Command, args []string) { + + disCl, err := discoveryapi.NewDiscoveryClient(apiInstance) + if err != nil { + fmt.Println("Error creating Discovery REST Client: ", err) + os.Exit(1) + } + err = disCl.GetApiResources() + if err != nil { + fmt.Println("Error getting API resources using discovery client:", err) + os.Exit(1) + } + + err = apiInstance.DisplayOutput() + if err != nil { + fmt.Println("Error Parsing Output:", err) + os.Exit(1) + } + retCode := apiInstance.GetReturnCode() + klog.V(5).Infof("retCode: %d", retCode) + os.Exit(retCode) + }, +} + // Execute the stuff func Execute(VERSION string, COMMIT string, versionsFile []byte) { version = VERSION diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pluto-5.10.7/docs/faq.md new/pluto-5.11.0/docs/faq.md --- old/pluto-5.10.7/docs/faq.md 2022-09-12 17:42:16.000000000 +0200 +++ new/pluto-5.11.0/docs/faq.md 2022-09-22 21:28:19.000000000 +0200 @@ -9,14 +9,14 @@ See above in the [Purpose](/#purpose) section of this doc. Kubectl is likely lying to you because it only tells you what the default is for the given kubernetes version even if an object was deployed with a newer API version. -### Why doesn't Pluto check the last-applied-configuration annotation? - -If you see the annotation `kubectl.kubernetes.io/last-applied-configuration` on an object in your cluster it means that object was updated with `kubectl apply`. We don't consider this an entirely reliable solution for checking. In fact, others have pointed out that updating the same object with `kubectl patch` will **remove** the annotation. Due to the flaky behavior here, we will not plan on supporting this. - ### I don't use helm, how can I do in cluster checks? Currently, the only in-cluster check we are confident in supporting is helm. If your deployment method can generate yaml manifests for kubernetes, you should be able to use the `detect` or `detect-files` functionality described below after the manifest files have been generated. ### I updated the API version of an object, but pluto still reports that the apiVersion needs to be updated. -Pluto looks at the API Versions of objects in releases that are in a `Deployed` state, and Helm has an issue where it might list old revisions of a release as still being in a `Deployed` state. To fix this, look at the release revision history with `helm history <release name>`, and determine if older releases still show a `Deployed` state. If so, delete the Helm release secret(s) associated with the revision number(s). For example, `kubectl delete secret sh.helm.release.v1.my-release.v10` where `10` corresponds to the release number. Then run Pluto again to see if the object has been removed from the report. \ No newline at end of file +Pluto looks at the API Versions of objects in releases that are in a `Deployed` state, and Helm has an issue where it might list old revisions of a release as still being in a `Deployed` state. To fix this, look at the release revision history with `helm history <release name>`, and determine if older releases still show a `Deployed` state. If so, delete the Helm release secret(s) associated with the revision number(s). For example, `kubectl delete secret sh.helm.release.v1.my-release.v10` where `10` corresponds to the release number. Then run Pluto again to see if the object has been removed from the report. + +### Why API version check on a live cluster using the "last-applied-configuration" annotation is not reliable? + +The annotation `kubectl.kubernetes.io/last-applied-configuration` on an object in your cluster holds the API version by which it was created. In fact, others have pointed out that updating the same object with `kubectl patch` will **remove** the annotation. Hence this is not a reliable method to detect deprecated API's from a live cluster. \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pluto-5.10.7/docs/quickstart.md new/pluto-5.11.0/docs/quickstart.md --- old/pluto-5.10.7/docs/quickstart.md 2022-09-12 17:42:16.000000000 +0200 +++ new/pluto-5.11.0/docs/quickstart.md 2022-09-22 21:28:19.000000000 +0200 @@ -52,3 +52,12 @@ KIND VERSION DEPRECATED DEPRECATED IN RESOURCE NAME Deployment extensions/v1beta1 true v1.16.0 RELEASE-NAME-helm3chart-v1beta1 ``` + +### API resources (in-cluster) +``` +$ pluto detect-api-resources -owide +NAME NAMESPACE KIND VERSION REPLACEMENT DEPRECATED DEPRECATED IN REMOVED REMOVED IN +psp <UNKNOWN> PodSecurityPolicy policy/v1beta1 true v1.21.0 false v1.25.0 +``` + +This indicates that the PodSecurityPolicy was deployed with apps/v1beta1 which is deprecated in 1.21 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pluto-5.10.7/go.mod new/pluto-5.11.0/go.mod --- old/pluto-5.10.7/go.mod 2022-09-12 17:42:16.000000000 +0200 +++ new/pluto-5.11.0/go.mod 2022-09-22 21:28:19.000000000 +0200 @@ -9,17 +9,17 @@ github.com/rogpeppe/go-internal v1.9.0 github.com/spf13/cobra v1.5.0 github.com/spf13/pflag v1.0.5 - github.com/spf13/viper v1.12.0 + github.com/spf13/viper v1.13.0 github.com/stretchr/testify v1.8.0 golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 golang.org/x/sys v0.0.0-20220817070843-5a390386f1f2 // indirect golang.org/x/text v0.3.7 // indirect gopkg.in/yaml.v3 v3.0.1 helm.sh/helm/v3 v3.9.4 - k8s.io/api v0.25.0 - k8s.io/apimachinery v0.25.0 - k8s.io/client-go v0.25.0 - k8s.io/klog/v2 v2.70.1 + k8s.io/api v0.25.1 + k8s.io/apimachinery v0.25.1 + k8s.io/client-go v0.25.1 + k8s.io/klog/v2 v2.80.1 sigs.k8s.io/controller-runtime v0.13.0 ) @@ -68,14 +68,14 @@ github.com/modern-go/reflect2 v1.0.2 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/pelletier/go-toml v1.9.5 // indirect - github.com/pelletier/go-toml/v2 v2.0.3 // indirect + github.com/pelletier/go-toml/v2 v2.0.5 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rubenv/sql-migrate v1.1.2 // indirect github.com/spf13/afero v1.9.2 // indirect github.com/spf13/cast v1.5.0 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect - github.com/subosito/gotenv v1.4.0 // indirect + github.com/subosito/gotenv v1.4.1 // indirect github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect github.com/xeipuuv/gojsonschema v1.2.0 // indirect diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pluto-5.10.7/go.sum new/pluto-5.11.0/go.sum --- old/pluto-5.10.7/go.sum 2022-09-12 17:42:16.000000000 +0200 +++ new/pluto-5.11.0/go.sum 2022-09-22 21:28:19.000000000 +0200 @@ -339,14 +339,14 @@ github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= -github.com/onsi/ginkgo/v2 v2.1.4 h1:GNapqRSid3zijZ9H77KrgVG4/8KqiyRsxcSxe+7ApXY= -github.com/onsi/gomega v1.19.0 h1:4ieX6qQjPP/BfC3mpsAtIGGlxTWPeA3Inl/7DtXw1tw= +github.com/onsi/ginkgo/v2 v2.1.6 h1:Fx2POJZfKRQcM1pH49qSZiYeu319wji004qX+GDovrU= +github.com/onsi/gomega v1.20.1 h1:PA/3qinGoukvymdIDV8pii6tiZgC8kbmJO6Z5+b002Q= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8= github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= -github.com/pelletier/go-toml/v2 v2.0.3 h1:h9JoA60e1dVEOpp0PFwJSmt1Htu057NUq9/bUwaO61s= -github.com/pelletier/go-toml/v2 v2.0.3/go.mod h1:OMHamSCAODeSsVrwwvcJOaoN0LIUIaFVNZzmWyNfXas= +github.com/pelletier/go-toml/v2 v2.0.5 h1:ipoSadvV8oGUjnUbMub59IDPPwfxF694nG/jwbMiyQg= +github.com/pelletier/go-toml/v2 v2.0.5/go.mod h1:OMHamSCAODeSsVrwwvcJOaoN0LIUIaFVNZzmWyNfXas= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -394,8 +394,8 @@ 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/spf13/viper v1.8.1/go.mod h1:o0Pch8wJ9BVSWGQMbra6iw0oQ5oktSIBaujf1rJH9Ns= -github.com/spf13/viper v1.12.0 h1:CZ7eSOd3kZoaYDLbXnmzgQI5RlciuXBMA+18HwHRfZQ= -github.com/spf13/viper v1.12.0/go.mod h1:b6COn30jlNxbm/V2IqWiNWkJ+vZNiMNksliPCiuKtSI= +github.com/spf13/viper v1.13.0 h1:BWSJ/M+f+3nmdz9bxB+bWX28kkALN2ok11D0rSo8EJU= +github.com/spf13/viper v1.13.0/go.mod h1:Icm2xNL3/8uyh/wFuB1jI7TiTNKp8632Nwegu+zgdYw= 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= @@ -409,8 +409,8 @@ github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= -github.com/subosito/gotenv v1.4.0 h1:yAzM1+SmVcz5R4tXGsNMu1jUl2aOJXoiWUCEwwnGrvs= -github.com/subosito/gotenv v1.4.0/go.mod h1:mZd6rFysKEcUhUHXJk0C/08wAgyDBFuwEYL7vWWGaGo= +github.com/subosito/gotenv v1.4.1 h1:jyEFiXpy21Wm81FBN71l9VoMMV8H8jG+qIK3GCpY6Qs= +github.com/subosito/gotenv v1.4.1/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= github.com/thoas/go-funk v0.9.2 h1:oKlNYv0AY5nyf9g+/GhMgS/UO2ces0QRdPKwkhY3VCk= github.com/thoas/go-funk v0.9.2/go.mod h1:+IWnUfUmFO1+WVYQWQtIJHeRRdaIyyYglZN7xzUPe4Q= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= @@ -832,17 +832,17 @@ honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= -k8s.io/api v0.25.0 h1:H+Q4ma2U/ww0iGB78ijZx6DRByPz6/733jIuFpX70e0= -k8s.io/api v0.25.0/go.mod h1:ttceV1GyV1i1rnmvzT3BST08N6nGt+dudGrquzVQWPk= +k8s.io/api v0.25.1 h1:yL7du50yc93k17nH/Xe9jujAYrcDkI/i5DL1jPz4E3M= +k8s.io/api v0.25.1/go.mod h1:hh4itDvrWSJsmeUc28rIFNri8MatNAAxJjKcQmhX6TU= k8s.io/apiextensions-apiserver v0.25.0 h1:CJ9zlyXAbq0FIW8CD7HHyozCMBpDSiH7EdrSTCZcZFY= k8s.io/apiextensions-apiserver v0.25.0/go.mod h1:3pAjZiN4zw7R8aZC5gR0y3/vCkGlAjCazcg1me8iB/E= -k8s.io/apimachinery v0.25.0 h1:MlP0r6+3XbkUG2itd6vp3oxbtdQLQI94fD5gCS+gnoU= -k8s.io/apimachinery v0.25.0/go.mod h1:qMx9eAk0sZQGsXGu86fab8tZdffHbwUfsvzqKn4mfB0= -k8s.io/client-go v0.25.0 h1:CVWIaCETLMBNiTUta3d5nzRbXvY5Hy9Dpl+VvREpu5E= -k8s.io/client-go v0.25.0/go.mod h1:lxykvypVfKilxhTklov0wz1FoaUZ8X4EwbhS6rpRfN8= +k8s.io/apimachinery v0.25.1 h1:t0XrnmCEHVgJlR2arwO8Awp9ylluDic706WePaYCBTI= +k8s.io/apimachinery v0.25.1/go.mod h1:hqqA1X0bsgsxI6dXsJ4HnNTBOmJNxyPp8dw3u2fSHwA= +k8s.io/client-go v0.25.1 h1:uFj4AJKtE1/ckcSKz8IhgAuZTdRXZDKev8g387ndD58= +k8s.io/client-go v0.25.1/go.mod h1:rdFWTLV/uj2C74zGbQzOsmXPUtMAjSf7ajil4iJUNKo= k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= -k8s.io/klog/v2 v2.70.1 h1:7aaoSdahviPmR+XkS7FyxlkkXs6tHISSG03RxleQAVQ= -k8s.io/klog/v2 v2.70.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= +k8s.io/klog/v2 v2.80.1 h1:atnLQ121W371wYYFawwYx1aEY2eUfs4l3J72wtgAwV4= +k8s.io/klog/v2 v2.80.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= k8s.io/kube-openapi v0.0.0-20220803164354-a70c9af30aea h1:3QOH5+2fGsY8e1qf+GIFpg+zw/JGNrgyZRQR7/m6uWg= k8s.io/kube-openapi v0.0.0-20220803164354-a70c9af30aea/go.mod h1:C/N6wCaBHeBHkHUesQOQy2/MZqGgMAFPqGsGQLdbZBU= k8s.io/utils v0.0.0-20220812165043-ad590609e2e5 h1:XmRqFcQlCy/lKRZ39j+RVpokYNroHPqV3mcBRfnhT5o= diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pluto-5.10.7/pkg/api/versions.go new/pluto-5.11.0/pkg/api/versions.go --- old/pluto-5.10.7/pkg/api/versions.go 2022-09-12 17:42:16.000000000 +0200 +++ new/pluto-5.11.0/pkg/api/versions.go 2022-09-22 21:28:19.000000000 +0200 @@ -181,7 +181,7 @@ // expandList checks if we have a List manifest. // If it is the case, the manifests inside are expanded, otherwise we just return the single manifest func expandList(stubs *[]*Stub, currentStub *Stub) { - if currentStub.Items != nil { + if len(currentStub.Items) > 0 { klog.V(5).Infof("found a list with %d items, attempting to expand", len(currentStub.Items)) for _, stub := range currentStub.Items { currentItem := stub diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pluto-5.10.7/pkg/discovery-api/discovery_api.go new/pluto-5.11.0/pkg/discovery-api/discovery_api.go --- old/pluto-5.10.7/pkg/discovery-api/discovery_api.go 1970-01-01 01:00:00.000000000 +0100 +++ new/pluto-5.11.0/pkg/discovery-api/discovery_api.go 2022-09-22 21:28:19.000000000 +0200 @@ -0,0 +1,182 @@ +// Copyright 2022 FairwindsOps Inc +// +// 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. + +// Copyright 2020 Fairwinds +// +// 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 discoveryapi + +import ( + "context" + "encoding/json" + + apierrors "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/client-go/discovery" + "k8s.io/client-go/dynamic" + "k8s.io/client-go/rest" + "k8s.io/client-go/tools/clientcmd" + "k8s.io/klog/v2" + + "github.com/fairwindsops/pluto/v5/pkg/api" +) + +// DiscoveryClient is the declaration to hold objects needed for client-go/discovery. +type DiscoveryClient struct { + ClientSet dynamic.Interface + restConfig *rest.Config + DiscoveryClient discovery.DiscoveryInterface + Instance *api.Instance +} + +// NewDiscoveryClient returns a new struct with config portions complete. +func NewDiscoveryClient(instance *api.Instance) (*DiscoveryClient, error) { + cl := &DiscoveryClient{ + Instance: instance, + } + + var err error + cl.restConfig, err = NewRestClientConfig(rest.InClusterConfig) + if err != nil { + return nil, err + } + + if cl.DiscoveryClient, err = discovery.NewDiscoveryClientForConfig(cl.restConfig); err != nil { + return nil, err + } + + cl.ClientSet, err = dynamic.NewForConfig(cl.restConfig) + if err != nil { + return nil, err + } + return cl, nil +} + +// NewRestClientConfig returns a new Rest Client config portions complete. +func NewRestClientConfig(inClusterFn func() (*rest.Config, error)) (*rest.Config, error) { + + if restConfig, err := inClusterFn(); err == nil { + return restConfig, nil + } + + pathOptions := clientcmd.NewDefaultPathOptions() + + config, err := pathOptions.GetStartingConfig() + if err != nil { + return nil, err + } + + configOverrides := clientcmd.ConfigOverrides{} + + clientConfig := clientcmd.NewDefaultClientConfig(*config, &configOverrides) + restConfig, err := clientConfig.ClientConfig() + if err != nil { + return nil, err + } + + return restConfig, nil +} + +// GetApiResources discovers the api-resources for a cluster +func (cl *DiscoveryClient) GetApiResources() error { + + resourcelist, err := cl.DiscoveryClient.ServerPreferredResources() + if err != nil { + if apierrors.IsNotFound(err) { + return err + } + if apierrors.IsForbidden(err) { + klog.Error("Failed to list objects for Name discovery. Permission denied! Please check if you have the proper authorization") + return err + } + } + + gvrs := []schema.GroupVersionResource{} + for _, rl := range resourcelist { + for i := range rl.APIResources { + gv, _ := schema.ParseGroupVersion(rl.GroupVersion) + ResourceName := rl.APIResources[i].Name + g := schema.GroupVersionResource{Group: gv.Group, Version: gv.Version, Resource: ResourceName} + gvrs = append(gvrs, g) + } + } + + var results []map[string]interface{} + for _, g := range gvrs { + ri := cl.ClientSet.Resource(g) + klog.V(2).Infof("Retrieving : %s.%s.%s", g.Resource, g.Version, g.Group) + rs, err := ri.List(context.TODO(), metav1.ListOptions{}) + if err != nil { + klog.Error("Failed to retrieve: ", g, err) + continue + } + + if len(rs.Items) == 0 { + klog.V(2).Infof("No annotations for ResourceVer %s", rs.GetAPIVersion()) + obj := rs.UnstructuredContent() + data, err := json.Marshal(obj) + if err != nil { + klog.Error("Failed to marshal data ", err.Error()) + return err + } + output, err := cl.Instance.IsVersioned(data) + if err != nil { + return err + } + if output == nil { + continue + } + cl.Instance.Outputs = append(cl.Instance.Outputs, output...) + + } else { + for _, r := range rs.Items { + if jsonManifest, ok := r.GetAnnotations()["kubectl.kubernetes.io/last-applied-configuration"]; ok { + var manifest map[string]interface{} + + err := json.Unmarshal([]byte(jsonManifest), &manifest) + if err != nil { + klog.Error("failed to parse 'last-applied-configuration' annotation of resource %s/%s: %s", r.GetNamespace(), r.GetName(), err.Error()) + continue + } + data, err := json.Marshal(manifest) + if err != nil { + klog.Error("Failed to marshal data ", err.Error()) + return err + } + output, err := cl.Instance.IsVersioned(data) + if err != nil { + return err + } + cl.Instance.Outputs = append(cl.Instance.Outputs, output...) + } + } + } + + } + + klog.V(6).Infof("Result from resources: %d", len(results)) + return nil +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pluto-5.10.7/pkg/discovery-api/discovery_api_test.go new/pluto-5.11.0/pkg/discovery-api/discovery_api_test.go --- old/pluto-5.10.7/pkg/discovery-api/discovery_api_test.go 1970-01-01 01:00:00.000000000 +0100 +++ new/pluto-5.11.0/pkg/discovery-api/discovery_api_test.go 2022-09-22 21:28:19.000000000 +0200 @@ -0,0 +1,54 @@ +// Copyright 2022 FairwindsOps Inc +// +// 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. + +// Copyright 2020 Fairwinds +// +// 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 discoveryapi + +import ( + "testing" + + "k8s.io/apimachinery/pkg/runtime" + discoveryFake "k8s.io/client-go/discovery/fake" + "k8s.io/client-go/dynamic/fake" +) + +func TestNewDiscoveryAPIClientValidEmpty(t *testing.T) { + + scheme := runtime.NewScheme() + clientset := fake.NewSimpleDynamicClient(scheme) + discoveryClient := discoveryFake.FakeDiscovery{} + testOpts := DiscoveryClient{ + ClientSet: clientset, + DiscoveryClient: &discoveryClient, + } + + err := testOpts.GetApiResources() + if err != nil { + t.Errorf("Unable to fetch API Resources") + } + +} ++++++ vendor.tar.gz ++++++ /work/SRC/openSUSE:Factory/pluto/vendor.tar.gz /work/SRC/openSUSE:Factory/.pluto.new.2275/vendor.tar.gz differ: char 5, line 1