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

Fix the bug where raw is abead of obj-temp #175

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
64 changes: 53 additions & 11 deletions internal/ordering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,12 @@ policies:
remediationAction: inform
name: bird
extraDependencies:
- name: tiger2
kind: ConfigurationPolicy
compliance: "Compliant"
- name: lion2
kind: ConfigurationPolicy
compliance: "Compliant"
- name: tiger2
kind: ConfigurationPolicy
compliance: "Compliant"
- name: lion2
kind: ConfigurationPolicy
compliance: "Compliant"
`,
wantFile: "testdata/ordering/manifest-level-name.yaml",
wantErr: "",
Expand All @@ -283,7 +283,7 @@ policies:
wantFile: "testdata/ordering/manifest-level-name-raw-consolidate-false.yaml",
wantErr: "",
},
"complicated raw policies with consolidateManifests true": {
"consolidateManifests true and objTemplate with raw": {
tmpDir: tmpDir,
generator: `
apiVersion: policy.open-cluster-management.io/v1
Expand All @@ -297,16 +297,58 @@ policyDefaults:
policies:
- name: one
manifests:
- path: {{printf "%v/%v" .Dir "object-templates-raw.yaml"}}
name: bird
- path: {{printf "%v/%v" .Dir "configmap.yaml"}}
name: tiger
- path: {{printf "%v/%v" .Dir "configmap.yaml"}}
name: rabbit
`,
wantFile: "testdata/ordering/manifest-level-name-raw-consolidate-true.yaml",
wantErr: "",
},
"consolidateManifests true and objTemplate with empty name": {
tmpDir: tmpDir,
generator: `
apiVersion: policy.open-cluster-management.io/v1
kind: PolicyGenerator
metadata:
name: test
policyDefaults:
orderPolicies: true
namespace: my-policies
consolidateManifests: true
policies:
- name: one
manifests:
- path: {{printf "%v/%v" .Dir "object-templates-raw.yaml"}}
name: bird
- path: {{printf "%v/%v" .Dir "object-templates-raw.yaml"}}
name: bird
- path: {{printf "%v/%v" .Dir "configmap.yaml"}}
- path: {{printf "%v/%v" .Dir "configmap.yaml"}}
`,
wantFile: "testdata/ordering/manifest-level-name-raw-consolidate-true-empty-name.yaml",
wantErr: "",
},
"consolidateManifests true and objTemplate with name": {
tmpDir: tmpDir,
generator: `
apiVersion: policy.open-cluster-management.io/v1
kind: PolicyGenerator
metadata:
name: test
policyDefaults:
orderPolicies: true
namespace: my-policies
consolidateManifests: true
policies:
- name: one
manifests:
- path: {{printf "%v/%v" .Dir "object-templates-raw.yaml"}}
name: bird
- path: {{printf "%v/%v" .Dir "configmap.yaml"}}
- path: {{printf "%v/%v" .Dir "configmap.yaml"}}
name: tiger
`,
wantFile: "testdata/ordering/manifest-level-name-raw-consolidate-true.yaml",
wantFile: "testdata/ordering/manifest-level-name-raw-consolidate-true-with-name.yaml",
wantErr: "",
},
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
---
apiVersion: policy.open-cluster-management.io/v1
kind: Policy
metadata:
annotations:
policy.open-cluster-management.io/categories: CM Configuration Management
policy.open-cluster-management.io/controls: CM-2 Baseline Configuration
policy.open-cluster-management.io/description: ""
policy.open-cluster-management.io/standards: NIST SP 800-53
name: one
namespace: my-policies
spec:
disabled: false
policy-templates:
- objectDefinition:
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: one
spec:
object-templates-raw: |-
- complianceType: musthave
objectDefinition:
apiVersion: v1
kind: ConfigMap
metadata:
name: example
namespace: default
data:
extraData: data
remediationAction: inform
severity: low
- objectDefinition:
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: one2
spec:
object-templates-raw: |-
- complianceType: musthave
objectDefinition:
apiVersion: v1
kind: ConfigMap
metadata:
name: example
namespace: default
data:
extraData: data
remediationAction: inform
severity: low
- objectDefinition:
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: bird
spec:
object-templates-raw: |-
- complianceType: musthave
objectDefinition:
apiVersion: v1
kind: ConfigMap
metadata:
name: example
namespace: default
data:
extraData: data
remediationAction: inform
severity: low
- objectDefinition:
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: bird2
spec:
object-templates-raw: |-
- complianceType: musthave
objectDefinition:
apiVersion: v1
kind: ConfigMap
metadata:
name: example
namespace: default
data:
extraData: data
remediationAction: inform
severity: low
- objectDefinition:
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: one3
spec:
object-templates:
- complianceType: musthave
objectDefinition:
apiVersion: v1
data:
game.properties: enemies=potato
kind: ConfigMap
metadata:
name: my-configmap
- complianceType: musthave
objectDefinition:
apiVersion: v1
data:
game.properties: enemies=cabbage
kind: ConfigMap
metadata:
name: config-2
- complianceType: musthave
objectDefinition:
apiVersion: v1
data:
game.properties: enemies=potato
kind: ConfigMap
metadata:
name: my-configmap
- complianceType: musthave
objectDefinition:
apiVersion: v1
data:
game.properties: enemies=cabbage
kind: ConfigMap
metadata:
name: config-2
remediationAction: inform
severity: low
remediationAction: inform
---
apiVersion: cluster.open-cluster-management.io/v1beta1
kind: Placement
metadata:
name: placement-one
namespace: my-policies
spec:
predicates:
- requiredClusterSelector:
labelSelector:
matchExpressions: []
tolerations:
- key: cluster.open-cluster-management.io/unavailable
operator: Exists
- key: cluster.open-cluster-management.io/unreachable
operator: Exists
---
apiVersion: policy.open-cluster-management.io/v1
kind: PlacementBinding
metadata:
name: binding-one
namespace: my-policies
placementRef:
apiGroup: cluster.open-cluster-management.io
kind: Placement
name: placement-one
subjects:
- apiGroup: policy.open-cluster-management.io
kind: Policy
name: one
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
---
apiVersion: policy.open-cluster-management.io/v1
kind: Policy
metadata:
annotations:
policy.open-cluster-management.io/categories: CM Configuration Management
policy.open-cluster-management.io/controls: CM-2 Baseline Configuration
policy.open-cluster-management.io/description: ""
policy.open-cluster-management.io/standards: NIST SP 800-53
name: one
namespace: my-policies
spec:
disabled: false
policy-templates:
- objectDefinition:
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: bird
spec:
object-templates-raw: |-
- complianceType: musthave
objectDefinition:
apiVersion: v1
kind: ConfigMap
metadata:
name: example
namespace: default
data:
extraData: data
remediationAction: inform
severity: low
- objectDefinition:
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: bird2
spec:
object-templates-raw: |-
- complianceType: musthave
objectDefinition:
apiVersion: v1
kind: ConfigMap
metadata:
name: example
namespace: default
data:
extraData: data
remediationAction: inform
severity: low
- objectDefinition:
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: tiger
spec:
object-templates:
- complianceType: musthave
objectDefinition:
apiVersion: v1
data:
game.properties: enemies=potato
kind: ConfigMap
metadata:
name: my-configmap
- complianceType: musthave
objectDefinition:
apiVersion: v1
data:
game.properties: enemies=cabbage
kind: ConfigMap
metadata:
name: config-2
- complianceType: musthave
objectDefinition:
apiVersion: v1
data:
game.properties: enemies=potato
kind: ConfigMap
metadata:
name: my-configmap
- complianceType: musthave
objectDefinition:
apiVersion: v1
data:
game.properties: enemies=cabbage
kind: ConfigMap
metadata:
name: config-2
remediationAction: inform
severity: low
remediationAction: inform
---
apiVersion: cluster.open-cluster-management.io/v1beta1
kind: Placement
metadata:
name: placement-one
namespace: my-policies
spec:
predicates:
- requiredClusterSelector:
labelSelector:
matchExpressions: []
tolerations:
- key: cluster.open-cluster-management.io/unavailable
operator: Exists
- key: cluster.open-cluster-management.io/unreachable
operator: Exists
---
apiVersion: policy.open-cluster-management.io/v1
kind: PlacementBinding
metadata:
name: binding-one
namespace: my-policies
placementRef:
apiGroup: cluster.open-cluster-management.io
kind: Placement
name: placement-one
subjects:
- apiGroup: policy.open-cluster-management.io
kind: Policy
name: one
Loading