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

feat: ⬆️ Increase ram buffer & upgrade deps #1

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"github.com/spf13/cobra"
"io"
"io/ioutil"
jsonutil "k8s.io/apimachinery/pkg/util/json"
yamlutil "k8s.io/apimachinery/pkg/util/yaml"
"os"
Expand Down Expand Up @@ -32,7 +31,11 @@ gatekeeper's constraint templates allowing you to reuse the policies with confte
Run: func(cmd *cobra.Command, args []string) {
if len(args) < 1 {
fmt.Println("Error: Missing input.\n\nHelp:")
cmd.Help()
err := cmd.Help()
if err != nil {
fmt.Printf("Error: %s\n", err)
}

os.Exit(5)
}
err := runTests(args, parametersFile)
Expand All @@ -56,10 +59,6 @@ func init() {
rootCmd.Flags().StringVarP(&parametersFile, "parameters", "p", "", "path to file conatining paramater values used in constraint templates")
}

func createFile(filename string, contents string) {

}

func runTests(args []string, parametersFile string) error {
inputFile := args[0]

Expand Down Expand Up @@ -91,10 +90,19 @@ func runTests(args []string, parametersFile string) error {
return fmt.Errorf("Expecting file for parameters. Got directory.")
}

parametersYaml, err := ioutil.ReadFile(parametersFile)
// Open the file for reading
file, err := os.Open(parametersFile)
if err != nil {
return fmt.Errorf("open parameters file: %w", err)
}
defer file.Close()

// Read the file contents
parametersYaml, err := io.ReadAll(file)
if err != nil {
return fmt.Errorf("read parameters file: %w", err)
}

parametersJson, err := yamlutil.ToJSON(parametersYaml)
if err != nil {
return fmt.Errorf("convert parameters yaml to json: %w", err)
Expand Down Expand Up @@ -129,7 +137,7 @@ func runTests(args []string, parametersFile string) error {
}

yamlReader := yamlutil.NewDocumentDecoder(inputFileReader)
yamlBuf := make([]byte, 1024*1024)
yamlBuf := make([]byte, 2048*1024)

// build gatekeeper compatible input object for each yaml document found in input manifest
for {
Expand Down