Skip to content

Commit

Permalink
Kubeconform improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
nirsht committed Oct 6, 2022
1 parent 29a6130 commit 4d6d42f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
15 changes: 2 additions & 13 deletions backend/api/kubeconform/kubeconform.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package kubeconform

import (
"fmt"
"io/ioutil"
"net/http"
"os/exec"
Expand All @@ -23,17 +22,9 @@ func kubeconformWrapper(inputYaml []byte) ([]byte, error) {
if err := utils.WriteFile("/tmp/yaml/target_yaml.yaml", inputYaml); err != nil {
return nil, err
}
cmd := exec.Command("kubeconform", "-output", "json", "/tmp/yaml/target_yaml.yaml")
stderr, err := cmd.StderrPipe()
if err != nil {
fmt.Println(stderr)
return nil, fmt.Errorf("error in StderrPipe(), err: %s", err.Error())
}
outputFromKubeconformAsJson, err := cmd.Output()
if err != nil {
return nil, err
}

outputFromKubeconformAsJson, _ := exec.Command("kubeconform", "-output", "json", "/tmp/yaml/target_yaml.yaml").Output()
// We don't wanna check error here because the default error code here is like the error from the kubeconform code
outputFromKubeconformAsYaml, err := yaml.JSONToYAML(outputFromKubeconformAsJson)
if err != nil {
return nil, err
Expand All @@ -44,7 +35,6 @@ func kubeconformWrapper(inputYaml []byte) ([]byte, error) {
func ProcessRequest(c *gin.Context) {
body, err := ioutil.ReadAll(c.Request.Body)
if err != nil {
fmt.Printf("error has with reading request body: %v", err)
c.JSON(http.StatusOK, gin.H{"data": "", "err": err.Error()})
return
}
Expand All @@ -56,7 +46,6 @@ func ProcessRequest(c *gin.Context) {
yamlAsInterface := bodyAsMap["yaml"]
KubeconformOutput, err := kubeconformWrapper(utils.InterfaceToBytes(yamlAsInterface))
if err != nil {
fmt.Printf("got error while parsing result from kubeconform: %s \n", err.Error())
c.JSON(http.StatusOK, gin.H{"data": "", "err": err.Error()})
return
}
Expand Down
2 changes: 1 addition & 1 deletion serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package:
exclude:
- ./**
include:
- ./bin/**
- ./backend/**

# Endpoint config
functions:
Expand Down

0 comments on commit 4d6d42f

Please sign in to comment.