Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds e2e tests for validating webhook #772

Merged
merged 9 commits into from
May 25, 2021

Conversation

patilpankaj212
Copy link
Contributor

No description provided.

@codecov
Copy link

codecov bot commented May 11, 2021

Codecov Report

Merging #772 (fa106ce) into master (01c8d78) will increase coverage by 1.08%.
The diff coverage is 66.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #772      +/-   ##
==========================================
+ Coverage   73.78%   74.87%   +1.08%     
==========================================
  Files         110      110              
  Lines        3285     3315      +30     
==========================================
+ Hits         2424     2482      +58     
+ Misses        677      648      -29     
- Partials      184      185       +1     
Impacted Files Coverage Δ
pkg/http-server/webhook-scan-logs.go 0.00% <0.00%> (ø)
pkg/http-server/file-scan.go 81.18% <100.00%> (+0.18%) ⬆️
pkg/http-server/health.go 100.00% <100.00%> (ø)
pkg/http-server/remote-repo.go 70.14% <100.00%> (+0.45%) ⬆️
pkg/http-server/webhook-scan.go 70.73% <100.00%> (+0.73%) ⬆️
pkg/config/global.go 79.45% <0.00%> (-7.09%) ⬇️
pkg/writer/human_readable.go 78.68% <0.00%> (-4.08%) ⬇️
pkg/results/types.go 100.00% <0.00%> (ø)
pkg/http-server/handler.go 100.00% <0.00%> (ø)
pkg/iac-providers/output/types.go 100.00% <0.00%> (ø)
... and 5 more

@patilpankaj212 patilpankaj212 linked an issue May 12, 2021 that may be closed by this pull request
@patilpankaj212 patilpankaj212 requested review from devang-gaur, jlk and kanchwala-yusuf and removed request for jlk May 12, 2021 05:55
Makefile Outdated Show resolved Hide resolved
pkg/http-server/file-scan.go Outdated Show resolved Hide resolved
test/e2e/validatingwebhook/kubeclient.go Outdated Show resolved Hide resolved
@@ -31,6 +31,7 @@ import (

// validateK8SWebhook handles the incoming validating admission webhook from kubernetes API server
func (g *APIHandler) validateK8SWebhook(w http.ResponseWriter, r *http.Request) {
zap.S().Info("handle: validating webhook request")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly feel this should be logged in debug mode level and not in info

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, for logging in the incoming requests, we should work on #784

Copy link
Contributor Author

@patilpankaj212 patilpankaj212 May 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is an informational log and hence to be logged in info.
Also, I had a discussion with @kanchwala-yusuf that we should handle it in separate PR. And, any other logging related changes can be taken up with #784.

test/e2e/validatingwebhook/certgen.go Outdated Show resolved Hide resolved
test/e2e/validatingwebhook/kubeclient.go Show resolved Hide resolved

# install kind
install-kind:
./scripts/install-kind.sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make this script accomodating for multiple OS types? This script currently only cover linux amd64 as of now

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not, then we should not include it in makefile atleast

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

installing kind is a required step of the validate job in our github pipeline.
also, all are scripts are for linux.

test/e2e/validatingwebhook/validatingwebhook_utils.go Outdated Show resolved Hide resolved
limitations under the License.
*/

package validatingwebhook
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this package name is confusing. all of the functions inside are utilities that deal with kubernetes and kind clusters. so naming the package validatingwebhook is a bit misleading. maybe just call it util or kube_util

@devang-gaur
Copy link
Contributor

@patilpankaj212 I have sent a PR on your branch which changes the code to use a deterministic kubeconfig.

patilpankaj212#27

@sonarcloud
Copy link

sonarcloud bot commented May 18, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@@ -134,6 +135,7 @@ func (g *APIHandler) getLogs(w http.ResponseWriter, r *http.Request) {
}

func (g *APIHandler) getLogByUID(w http.ResponseWriter, r *http.Request) {
zap.S().Info("handle: validating webhook's get log by uid request")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to make this Debug?

@@ -134,6 +135,7 @@ func (g *APIHandler) getLogs(w http.ResponseWriter, r *http.Request) {
}

func (g *APIHandler) getLogByUID(w http.ResponseWriter, r *http.Request) {
zap.S().Info("handle: validating webhook's get log by uid request")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
zap.S().Info("handle: validating webhook's get log by uid request")
zap.S().Debug("handle: validating webhook's get log by uid request")

}

// getK8sClient creates a kubernetes clientset with default config path
func (k *KubernetesClient) getK8sClient() (*kubernetes.Clientset, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to associate this method with KubernetesClient object? I can't see this method using any context from the KubernetesClient object.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe shift it to a util file

func NewKubernetesClient() (*KubernetesClient, error) {
kubernetesClient := new(KubernetesClient)
var err error
kubernetesClient.client, err = kubernetesClient.getK8sClient()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line looks wierd to me. object.property = object.GetProperty( ).
rather can we just do object.InitiateProperty( ) ?
In this case, kubernetes.InitiateK8sClient( ) .
Or let's remove the association betweek KubernetesClient type and getK8sClient( ) method at all.

@kanchwala-yusuf kanchwala-yusuf merged commit 0a1912f into tenable:master May 25, 2021
@patilpankaj212 patilpankaj212 deleted the e2e-vw branch May 5, 2022 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Admission Controller e2e tests
3 participants