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

Cleanup for kustomize/helm feature #357

Merged
merged 3 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
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
11 changes: 0 additions & 11 deletions pkg/safeguards/preprocessing/preprocessing.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package preprocessing

import (
"fmt"
"os"
"path/filepath"

sgTypes "github.com/Azure/draft/pkg/safeguards/types"
Expand Down Expand Up @@ -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...")
Expand Down
1 change: 1 addition & 0 deletions pkg/safeguards/preprocessing/preprocessing_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion pkg/safeguards/preprocessing/preprocessing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions pkg/safeguards/preprocessing/preprocessing_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 8 additions & 12 deletions pkg/safeguards/types/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Loading