@@ -142,9 +142,10 @@ func (p *Plugin) Generate() ([]byte, error) {
142142 plcNameToPolicyAndSetIdxs := map [string ]map [string ][]int {}
143143
144144 for i := range p .Policies {
145- // only generate placement when GeneratePlacementWhenInSet equals to true or policy is not
146- // part of any policy sets
147- if p .Policies [i ].GeneratePlacementWhenInSet || len (p .Policies [i ].PolicySets ) == 0 {
145+ // only generate placement when GeneratePlacementWhenInSet equals to true, GeneratePlacement is true,
146+ // or policy is not part of any policy sets
147+ if p .Policies [i ].GeneratePlacementWhenInSet ||
148+ (p .Policies [i ].GeneratePolicyPlacement && len (p .Policies [i ].PolicySets ) == 0 ) {
148149 plcName , err := p .createPlacement (& p .Policies [i ].Placement , p .Policies [i ].Name )
149150 if err != nil {
150151 return nil , err
@@ -429,6 +430,14 @@ func (p *Plugin) applyDefaults(unmarshaledConfig map[string]interface{}) {
429430 p .PolicyDefaults .Standards = defaults .Standards
430431 }
431432
433+ // GeneratePolicyPlacement defaults to true unless explicitly set in the config.
434+ gppValue , setGpp := getDefaultBool (unmarshaledConfig , "generatePolicyPlacement" )
435+ if setGpp {
436+ p .PolicyDefaults .GeneratePolicyPlacement = gppValue
437+ } else {
438+ p .PolicyDefaults .GeneratePolicyPlacement = true
439+ }
440+
432441 // Generate temporary sets to later merge the policy sets declared in p.Policies[*] and p.PolicySets
433442 plcsetToPlc := make (map [string ]map [string ]bool )
434443 plcToPlcset := make (map [string ]map [string ]bool )
@@ -516,10 +525,18 @@ func (p *Plugin) applyDefaults(unmarshaledConfig map[string]interface{}) {
516525 policy .PolicySets = p .PolicyDefaults .PolicySets
517526 }
518527
519- // GeneratePlacementWhenInSet default to false unless explicitly set in the config.
520- gpValue , setGp := getPolicyBool (unmarshaledConfig , i , "generatePlacementWhenInSet" )
521- if setGp {
522- policy .GeneratePlacementWhenInSet = gpValue
528+ // GeneratePolicyPlacement defaults to true unless explicitly set in the config.
529+ gppValue , setGpp := getPolicyBool (unmarshaledConfig , i , "generatePolicyPlacement" )
530+ if setGpp {
531+ policy .GeneratePolicyPlacement = gppValue
532+ } else {
533+ policy .GeneratePolicyPlacement = p .PolicyDefaults .GeneratePolicyPlacement
534+ }
535+
536+ // GeneratePlacementWhenInSet defaults to false unless explicitly set in the config.
537+ gpsetValue , setGpset := getPolicyBool (unmarshaledConfig , i , "generatePlacementWhenInSet" )
538+ if setGpset {
539+ policy .GeneratePlacementWhenInSet = gpsetValue
523540 } else {
524541 policy .GeneratePlacementWhenInSet = p .PolicyDefaults .GeneratePlacementWhenInSet
525542 }
@@ -824,6 +841,12 @@ func (p *Plugin) assertValidConfig() error {
824841 defaultPlacementOptions ++
825842 }
826843
844+ if defaultPlacementOptions > 0 && ! p .PolicyDefaults .GeneratePolicyPlacement {
845+ return errors .New (
846+ "policyDefaults must not specify a placement when generatePlacement is set to false" ,
847+ )
848+ }
849+
827850 if defaultPlacementOptions > 1 {
828851 return errors .New (
829852 "policyDefaults must specify only one of placement selector, placement path, or placement name" ,
@@ -1106,6 +1129,12 @@ func (p *Plugin) assertValidConfig() error {
11061129 policyPlacementOptions ++
11071130 }
11081131
1132+ if policyPlacementOptions > 0 && ! policy .GeneratePolicyPlacement {
1133+ return fmt .Errorf (
1134+ "policy %s must not specify a placement when generatePlacement is set to false" , policy .Name ,
1135+ )
1136+ }
1137+
11091138 if policyPlacementOptions > 1 {
11101139 return fmt .Errorf (
11111140 "policy %s must specify only one of placement selector, placement path, or placement name" , policy .Name ,
0 commit comments