Skip to content

Commit

Permalink
Fix the bug where obj-temp is abead of raw
Browse files Browse the repository at this point in the history
Signed-off-by: yiraeChristineKim <[email protected]>
  • Loading branch information
yiraeChristineKim committed Aug 7, 2024
1 parent dd1f91f commit 9e0d6f6
Show file tree
Hide file tree
Showing 5 changed files with 358 additions and 111 deletions.
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

0 comments on commit 9e0d6f6

Please sign in to comment.