Skip to content

Commit

Permalink
incorporate review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
patilpankaj212 committed May 17, 2021
1 parent 9b7055d commit e78d01b
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ e2e-tests: build
./scripts/run-e2e.sh

# run e2e validating webhook
e2e-validating-webhook: build
./scripts/e2e-validating-webhook.sh
e2e-admission-control-tests: build
./scripts/e2e-admission-control.sh

# install kind
install-kind:
Expand Down
2 changes: 1 addition & 1 deletion pkg/http-server/file-scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (

// scanFile accepts uploaded file and runs scan on it
func (g *APIHandler) scanFile(w http.ResponseWriter, r *http.Request) {
zap.S().Info("handle: file scan request")
zap.S().Debug("handle: file scan request")

// get url params
params := mux.Vars(r)
Expand Down
2 changes: 1 addition & 1 deletion pkg/http-server/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ import (

// Health returns the health of the http server
func (g *APIHandler) Health(w http.ResponseWriter, r *http.Request) {
zap.S().Info("handle: health check request")
zap.S().Debug("handle: health check request")
w.WriteHeader(http.StatusOK)
}
2 changes: 1 addition & 1 deletion pkg/http-server/remote-repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type scanRemoteRepoReq struct {
// scanRemoteRepo downloads the remote Iac repository and scans it for
// violations
func (g *APIHandler) scanRemoteRepo(w http.ResponseWriter, r *http.Request) {
zap.S().Info("handle: remote repository scan request")
zap.S().Debug("handle: remote repository scan request")

// get url params
params := mux.Vars(r)
Expand Down
2 changes: 1 addition & 1 deletion pkg/http-server/webhook-scan-logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type webhookDisplayedShowLog struct {
}

func (g *APIHandler) getLogs(w http.ResponseWriter, r *http.Request) {
zap.S().Info("handle: validating webhook's get logs request")
zap.S().Debug("handle: validating webhook's get logs request")

if !config.GetK8sAdmissionControl().Dashboard {
apiErrorResponse(w, ErrDashboardDisabled.Error(), http.StatusBadRequest)
Expand Down
2 changes: 1 addition & 1 deletion pkg/http-server/webhook-scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +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")
zap.S().Debug("handle: validating webhook request")

var (
params = mux.Vars(r)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion test/e2e/validatingwebhook/certgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func GenerateCertificates(certFilePath, privateKeyPath string) error {
template := x509.Certificate{
SerialNumber: big.NewInt(1),
Subject: pkix.Name{
Organization: []string{"Accurics"},
Organization: []string{"acme.org"},
Country: []string{"IN"},
},
IPAddresses: []net.IP{ipAddr},
Expand Down
8 changes: 2 additions & 6 deletions test/e2e/validatingwebhook/kubeclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func NewKubernetesClient() (*KubernetesClient, error) {
func (k *KubernetesClient) getK8sClient() (*kubernetes.Clientset, error) {
home, err := homedir.Dir()
if err != nil {
fmt.Println("home directory not found", err)
return nil, fmt.Errorf("home directory not found, error: %s", err.Error())
}

Expand Down Expand Up @@ -110,7 +109,6 @@ func (k *KubernetesClient) CreateValidatingWebhookConfiguration(webhookFile, cer

createdWebhookConfig, err := admr.ValidatingWebhookConfigurations().Create(context.TODO(), &webhooks, metav1.CreateOptions{})
if err != nil {
fmt.Println(err)
return nil, err
}
return createdWebhookConfig, nil
Expand All @@ -137,10 +135,9 @@ func (k *KubernetesClient) CreatePod(resourceFile string) (*v1.Pod, error) {

createdPod, err := k.client.CoreV1().Pods(namespace).Create(context.TODO(), &pod, metav1.CreateOptions{})
if err != nil {
fmt.Println(err)
return nil, err
}
return createdPod, err
return createdPod, nil
}

// DeletePod will delete the specified pod name
Expand All @@ -164,10 +161,9 @@ func (k *KubernetesClient) CreateService(resourceFile string) (*v1.Service, erro

createdService, err := k.client.CoreV1().Services(namespace).Create(context.TODO(), &service, metav1.CreateOptions{})
if err != nil {
fmt.Println(err)
return nil, err
}
return createdService, err
return createdService, nil
}

// DeleteService will delete the specified service name
Expand Down
12 changes: 6 additions & 6 deletions test/e2e/validatingwebhook/validating_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ var _ = Describe("ValidatingWebhook", func() {
Expect(err).NotTo(HaveOccurred())

os.Setenv(k8sWebhookAPIKey, apiKeyValue)
args := []string{"server", "-c", configFileName, "--cert-path", certFileAbsPath, "--key-path", privKeyFileAbsPath}
args := []string{"server", "-c", configFileName, "--cert-path", certFileAbsPath, "--key-path", privKeyFileAbsPath, "-l", "debug"}
session = helper.RunCommand(terrascanBinaryPath, outWriter, errWriter, args...)
Eventually(session.Err, defaultTimeout).Should(gbytes.Say("http server listening at port 9010"))
})
Expand Down Expand Up @@ -176,7 +176,7 @@ var _ = Describe("ValidatingWebhook", func() {
Expect(err).NotTo(HaveOccurred())

os.Setenv(k8sWebhookAPIKey, apiKeyValue)
args := []string{"server", "-c", configFileName, "--cert-path", certFileAbsPath, "--key-path", privKeyFileAbsPath, "-p", port}
args := []string{"server", "-c", configFileName, "--cert-path", certFileAbsPath, "--key-path", privKeyFileAbsPath, "-p", port, "-l", "debug"}
session = helper.RunCommand(terrascanBinaryPath, outWriter, errWriter, args...)
Eventually(session.Err, defaultTimeout).Should(gbytes.Say("http server listening at port 9011"))
})
Expand Down Expand Up @@ -225,7 +225,7 @@ var _ = Describe("ValidatingWebhook", func() {
Expect(err).NotTo(HaveOccurred())

os.Setenv(k8sWebhookAPIKey, apiKeyValue)
args := []string{"server", "-c", configFileName, "--cert-path", certFileAbsPath, "--key-path", privKeyFileAbsPath, "-p", port}
args := []string{"server", "-c", configFileName, "--cert-path", certFileAbsPath, "--key-path", privKeyFileAbsPath, "-p", port, "-l", "debug"}
session = helper.RunCommand(terrascanBinaryPath, outWriter, errWriter, args...)
Eventually(session.Err, defaultTimeout).Should(gbytes.Say("http server listening at port 9012"))
})
Expand Down Expand Up @@ -272,7 +272,7 @@ var _ = Describe("ValidatingWebhook", func() {
Expect(err).NotTo(HaveOccurred())

os.Setenv(k8sWebhookAPIKey, apiKeyValue)
args := []string{"server", "-c", configFileName, "--cert-path", certFileAbsPath, "--key-path", privKeyFileAbsPath, "-p", port}
args := []string{"server", "-c", configFileName, "--cert-path", certFileAbsPath, "--key-path", privKeyFileAbsPath, "-p", port, "-l", "debug"}
session = helper.RunCommand(terrascanBinaryPath, outWriter, errWriter, args...)
Eventually(session.Err, defaultTimeout).Should(gbytes.Say("http server listening at port 9013"))
})
Expand Down Expand Up @@ -321,7 +321,7 @@ var _ = Describe("ValidatingWebhook", func() {
Expect(err).NotTo(HaveOccurred())

os.Setenv(k8sWebhookAPIKey, apiKeyValue)
args := []string{"server", "-c", configFileName, "--cert-path", certFileAbsPath, "--key-path", privKeyFileAbsPath, "-p", port}
args := []string{"server", "-c", configFileName, "--cert-path", certFileAbsPath, "--key-path", privKeyFileAbsPath, "-p", port, "-l", "debug"}
session = helper.RunCommand(terrascanBinaryPath, outWriter, errWriter, args...)
Eventually(session.Err, defaultTimeout).Should(gbytes.Say("http server listening at port 9014"))
})
Expand Down Expand Up @@ -368,7 +368,7 @@ var _ = Describe("ValidatingWebhook", func() {
Expect(err).NotTo(HaveOccurred())

os.Setenv(k8sWebhookAPIKey, apiKeyValue)
args := []string{"server", "-c", configFileName, "--cert-path", certFileAbsPath, "--key-path", privKeyFileAbsPath, "-p", port}
args := []string{"server", "-c", configFileName, "--cert-path", certFileAbsPath, "--key-path", privKeyFileAbsPath, "-p", port, "-l", "debug"}
session = helper.RunCommand(terrascanBinaryPath, outWriter, errWriter, args...)
Eventually(session.Err, defaultTimeout).Should(gbytes.Say("http server listening at port 9015"))
})
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/validatingwebhook/validatingwebhook_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func CreateCertificate(certsFolder, certFileName, privKeyFileName string) (strin
// DeleteDefaultKindCluster deletes the default kind cluster
func DeleteDefaultKindCluster() error {
cmd := exec.Command("kind", "delete", "cluster")
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
return err
Expand All @@ -98,6 +99,7 @@ func DeleteDefaultKindCluster() error {
// CreateDefaultKindCluster creates the default kind cluster
func CreateDefaultKindCluster() error {
cmd := exec.Command("kind", "create", "cluster")
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
return err
Expand Down

0 comments on commit e78d01b

Please sign in to comment.