Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Adds in-mem `PolicyReportStore` implementation (#107) Part of #107 As specified in the original issue, this commit: - Create a store Go interface that satisfies the current store implementation at report/store.go - Refactor current report/store.go into report/store_kubernetes.go, as an implementation of the store interface - Adds a new memory store with 2 maps, one with `ClusterPolicyReports` and another one with `PolicyReports` - Provide an optional cli flag, --store TYPE, with possible types memory, kubernetes. Defaults to --store kubernetes for ease on first Kubewarden installations. Besides that, this commit also: - Changes `printJSON` to `outputScan` to make it more aligned with what the input params is - `outputScan` only outputs at the end of the flow, to prevent having a lot of logs whenever someone scans the entire cluster (we were outputting the entire store on each namespace loop) It also seems that running `make fmt` introduced a couple of unwanted changes that I'm happy to revert to keep this commit smaller. Finally, I also had to do a couple of tweaks to make golangci lint happy. Signed-off-by: Nuno Nelas <nuno.nelas@icloud.com> * Review improvements: - Removes `RetryOnConflict` since we will only need them for Kubernetes backend - Changes "enums" to lower-case (and updates README accordingly) Signed-off-by: Nuno Nelas <nuno.nelas@icloud.com> * Review improvements: - Removes Update methods from PolicyReportStore interface since there's no current usage for them Signed-off-by: Nuno Nelas <nuno.nelas@icloud.com> * Review improvements: - Removes `mutex` since there's no parallel processing - Changes logLevels for both `PolicyReportStore` to debug to prevent output of non-relevant information by default. Also, aligns what is logged between `PolicyReport` and `ClusterPolicyReport` and also `MemoryPolicyReportStore` and `KubernetesPolicyReportStore` Signed-off-by: Nuno Nelas <nuno.nelas@icloud.com> * Review improvements: - Removes `require` dependency from unit-tests. Instead, uses if-clauses to validate the returning errors - Given that I was changing go.mod, I also updated some of our dependencies - Still struggling with `ireturn`. Sometimes it works and build succeeds, sometimes it doesn't Signed-off-by: Nuno Nelas <nuno.nelas@icloud.com> * Review improvements: - Changes godocs since it doesn't make much sense to have an interface knowing about it's implementations Signed-off-by: Nuno Nelas <nuno.nelas@icloud.com> * Review improvements: - Simplifies cmd/root.go logic, since it should only read cmd flags and thus shouldn't have any business logic. There's still an `outputScan` that should also be moved after clarification of #150 (comment) Signed-off-by: Nuno Nelas <nuno.nelas@icloud.com> * Review improvements: - As discussed in #150 (comment), this commit removes `outputScan` logic from `cmd` and moves it to `scanner.go` where it originally was. This ensures we don't add more business logic into a package that should only handle commands Signed-off-by: Nuno Nelas <nuno.nelas@icloud.com> * Review improvements: - Removes "dumb" comment to try to fix golangci. The solution that @jvanz gave [here](#150 (comment)) worked like a charm! - Removes unused methods from `PolicyReportStore` interface Signed-off-by: Nuno Nelas <nuno.nelas@icloud.com> * Review improvements: - Simplifies `NewMemoryPolicyReportStore` method signature, by removing `error` which is never used Signed-off-by: Nuno Nelas <nuno.nelas@icloud.com> * Review improvements: - Reverts `wg-policy-prototypes` upgrade since this library is not correctly tagged nor has proper releases, so it's best to separate the upgrade to another PR that we can properly test Signed-off-by: Nuno Nelas <nuno.nelas@icloud.com> --------- Signed-off-by: Nuno Nelas <nuno.nelas@icloud.com>
- Loading branch information