diff --git a/pkg/safeguards/preprocessing/preprocessing.go b/pkg/safeguards/preprocessing/preprocessing.go index 37d5bad4..53568d8f 100644 --- a/pkg/safeguards/preprocessing/preprocessing.go +++ b/pkg/safeguards/preprocessing/preprocessing.go @@ -2,7 +2,6 @@ package preprocessing import ( "fmt" - "os" "path/filepath" sgTypes "github.com/Azure/draft/pkg/safeguards/types" @@ -67,16 +66,6 @@ func RenderHelmChart(isFile bool, mainChartPath string, opt chartutil.ReleaseOpt return manifestFiles, nil } -// CreateTempDir creates a temporary directory on the user's file system for rendering templates -func CreateTempDir(p string) error { - err := os.MkdirAll(p, 0755) - if err != nil { - log.Fatal(err) - } - - return err -} - // Given a kustomization manifest file within kustomizationPath, RenderKustomizeManifest will return render templates func RenderKustomizeManifest(kustomizationPath string) ([]sgTypes.ManifestFile, error) { log.Debugf("Rendering kustomization.yaml...") diff --git a/pkg/safeguards/preprocessing/preprocessing_helpers.go b/pkg/safeguards/preprocessing/preprocessing_helpers.go index 0ae79946..9f65799f 100644 --- a/pkg/safeguards/preprocessing/preprocessing_helpers.go +++ b/pkg/safeguards/preprocessing/preprocessing_helpers.go @@ -27,6 +27,7 @@ func getValues(chart *chart.Chart, valuesPath string, opt chartutil.ReleaseOptio return mergedValues, err } +// Extracts release options from either CLI flags, values.yaml, or name of containing directory func getReleaseOptions(chart *chart.Chart, vals map[string]interface{}, opt chartutil.ReleaseOptions, dirName string) (chartutil.Values, error) { // Extract release options from values var options chartutil.ReleaseOptions diff --git a/pkg/safeguards/preprocessing/preprocessing_test.go b/pkg/safeguards/preprocessing/preprocessing_test.go index c0ba8943..5da6cd6e 100644 --- a/pkg/safeguards/preprocessing/preprocessing_test.go +++ b/pkg/safeguards/preprocessing/preprocessing_test.go @@ -96,7 +96,7 @@ func TestSubCharts(t *testing.T) { assert.Nil(t, err) // Given a Chart.yaml in the main directory, main chart and subcharts should be evaluated - manifestFiles, err = RenderHelmChart(true, consts.DirectPath_ToSubchartYaml, opt) + _, err = RenderHelmChart(true, consts.DirectPath_ToMainChartYaml, opt) assert.Nil(t, err) // Given path to a sub-Chart.yaml with a dependency on another subchart, should render both subcharts, but not the main chart @@ -130,8 +130,12 @@ func TestInvalidChartAndValues(t *testing.T) { _, err = RenderHelmChart(false, consts.InvalidValuesChart, opt) assert.NotNil(t, err) + + _, err = RenderHelmChart(false, consts.DirectPath_ToInvalidChart, opt) + assert.NotNil(t, err) } +// Testing with malformed Deployment.yaml func TestInvalidDeployments(t *testing.T) { var opt chartutil.ReleaseOptions diff --git a/pkg/safeguards/preprocessing/preprocessing_test_helpers.go b/pkg/safeguards/preprocessing/preprocessing_test_helpers.go index ad81425c..5078e7aa 100644 --- a/pkg/safeguards/preprocessing/preprocessing_test_helpers.go +++ b/pkg/safeguards/preprocessing/preprocessing_test_helpers.go @@ -7,8 +7,6 @@ import ( "testing" ) -const () - // Returns the content of a manifest file as bytes func getManifestAsBytes(t *testing.T, filePath string) []byte { yamlFileContent, err := os.ReadFile(filePath) diff --git a/pkg/safeguards/types/constants.go b/pkg/safeguards/types/constants.go index c9f35398..a2a7d0bb 100644 --- a/pkg/safeguards/types/constants.go +++ b/pkg/safeguards/types/constants.go @@ -16,34 +16,30 @@ const ( Constraint_all = "all" KustomizationPath = "../tests/kustomize/overlays/production" - KustomizationFilePath = "../tests/kustomize/overlays/production/kustomization.yaml" DirectPath_ToValidChart = "../tests/testmanifests/validchart/Chart.yaml" ChartPath = "../tests/testmanifests/validchart" InvalidChartPath = "../tests/testmanifests/invalidchart" InvalidValuesChart = "../tests/testmanifests/invalidvalues" - InvalidDeploymentsChart = "../tests/testmanifests/invaliddeployment" InvalidDeploymentSyntax = "../tests/testmanifests/invaliddeployment-syntax" InvalidDeploymentValues = "../tests/testmanifests/invaliddeployment-values" FolderwithHelpersTmpl = "../tests/testmanifests/different-structure" MultipleTemplateDirs = "../tests/testmanifests/multiple-templates" MultipleValuesFile = "../tests/testmanifests/multiple-values-files" - Subcharts = "../tests/testmanifests/multiple-charts" - SubchartDir = "../tests/testmanifests/multiple-charts/charts/subchart2" - DirectPath_ToSubchartYaml = "../tests/testmanifests/multiple-charts/charts/subchart1/Chart.yaml" - irectPath_ToMainChartYaml = "../tests/testmanifests/multiple-charts/Chart.yaml" - directPath_ToInvalidChart = "../tests/testmanifests/invalidchart/Chart.yaml" + Subcharts = "../tests/testmanifests/multiple-charts" + SubchartDir = "../tests/testmanifests/multiple-charts/charts/subchart2" + DirectPath_ToSubchartYaml = "../tests/testmanifests/multiple-charts/charts/subchart1/Chart.yaml" + DirectPath_ToMainChartYaml = "../tests/testmanifests/multiple-charts/Chart.yaml" + DirectPath_ToInvalidChart = "../tests/testmanifests/invalidchart/Chart.yaml" + + TemplateFileName = "template.yaml" + ConstraintFileName = "constraint.yaml" ) var SelectedVersion = "v1.0.0" var SupportedVersions = []string{SelectedVersion} -const ( - TemplateFileName = "template.yaml" - ConstraintFileName = "constraint.yaml" -) - var Safeguard_CRIP = Safeguard{ Name: Constraint_CRIP, TemplatePath: fmt.Sprintf("lib/%s/%s/%s", SelectedVersion, Constraint_CRIP, TemplateFileName),