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

[release-2.13] Fix mapping file marshalling #1251

Open
wants to merge 3 commits into
base: release-2.13
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/kind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
go-version: 'stable'

- name: Download Coverage Results
uses: actions/download-artifact@v4
Expand Down
4 changes: 2 additions & 2 deletions pkg/dryrun/dryrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,13 +490,13 @@ func (d *DryRunner) setupReconciler(
}

if d.mappingsPath != "" {
reader, err := os.Open(d.mappingsPath)
mFile, err := os.ReadFile(d.mappingsPath)
if err != nil {
return nil, err
}

apiMappings := []mappings.APIMapping{}
if err := yaml.NewDecoder(reader).Decode(&apiMappings); err != nil {
if err := k8syaml.Unmarshal(mFile, &apiMappings); err != nil {
return nil, err
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/dryrun/dryrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ func cliTest(scenarioPath string) func(t *testing.T) {
}
}

mappingsPath := path.Join(scenarioPath, "mappings.yaml")
if PathExists(mappingsPath) {
err = cmd.Flags().Set("mappings-file", mappingsPath)
if err != nil {
t.Fatal(err)
}
}

err = cmd.Execute()
if err != nil && !errors.Is(err, ErrNonCompliant) {
t.Fatal(err)
Expand Down
11 changes: 11 additions & 0 deletions pkg/dryrun/testdata/test_mappings/input_resource.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: LimitRange # limit memory usage
metadata:
name: mem-limit-range
spec:
limits:
- default:
memory: 512Mi
defaultRequest:
memory: 256Mi
type: Container
12 changes: 12 additions & 0 deletions pkg/dryrun/testdata/test_mappings/mappings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- Group: ""
Kind: LimitRange
Plural: limitranges
Scope: namespace
Singular: limitrange
Version: v1
- Group: ""
Kind: Fake
Plural: fakes
Scope: root
Singular: fake
Version: beta1
5 changes: 5 additions & 0 deletions pkg/dryrun/testdata/test_mappings/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Diffs:
v1 LimitRange default/mem-limit-range:

# Compliance messages:
Compliant; notification - limitranges [mem-limit-range] found as specified in namespace default
23 changes: 23 additions & 0 deletions pkg/dryrun/testdata/test_mappings/policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: hello
namespace: default
spec:
remediationAction: enforce
namespaceSelector:
include: ["default"]
object-templates:
- complianceType: musthave
objectDefinition:
apiVersion: v1
kind: LimitRange # limit memory usage
metadata:
name: mem-limit-range
spec:
limits:
- default:
memory: 512Mi
defaultRequest:
memory: 256Mi
type: Container
Loading
Loading