Skip to content

Commit d8a6540

Browse files
mprahlopenshift-merge-bot[bot]
authored andcommitted
Add the recreateOption field
Signed-off-by: mprahl <[email protected]>
1 parent 692c3e1 commit d8a6540

File tree

5 files changed

+27
-0
lines changed

5 files changed

+27
-0
lines changed

docs/policygenerator-reference.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ policyDefaults:
160160
# the responsibility of the administrator to ensure the placement rule exists. Use of this setting will prevent a
161161
# placement rule from being generated, but the placement binding will still be created.
162162
placementRuleName: ""
163+
# Optional. recreateOption describes whether to delete and recreate an object when an update is required. `IfRequired`
164+
# will recreate the object when updating an immutable field. `Always` will always recreate the object if a mismatch
165+
# is detected. `RecreateOption` has no effect when the `remediationAction` is `inform`. `IfRequired` has no effect
166+
# on clusters without dry run update support. The default value is `None`.
167+
recreateOption: ""
163168
# Optional. Whether (and where) to record the diff between the policy and objects on the cluster. Defaults to an empty
164169
# string, which is equivalent to "None".
165170
recordDiff: ""
@@ -244,6 +249,8 @@ policies:
244249
# Optional. (See policyDefaults.remediationAction for description.)
245250
# Cannot be specified when policyDefaults.consolidateManifests is set to true.
246251
remediationAction: ""
252+
# Optional. (See policyDefaults.recreateOption for description.)
253+
recreateOption: ""
247254
# Optional. (See policyDefaults.recordDiff for description.)
248255
recordDiff: ""
249256
# Optional. (See policyDefaults.severity for description.)
@@ -316,6 +323,8 @@ policies:
316323
placement: {}
317324
# Optional. (See policyDefaults.remediationAction for description.)
318325
remediationAction: ""
326+
# Optional. (See policyDefaults.recreateOption for description.)
327+
recreateOption: ""
319328
# Optional. (See policyDefaults.recordDiff for description.)
320329
recordDiff: ""
321330
# Optional. (See policyDefaults.severity for description.)

internal/plugin.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,10 @@ func (p *Plugin) applyDefaults(unmarshaledConfig map[string]interface{}) {
563563
policy.Description = p.PolicyDefaults.Description
564564
}
565565

566+
if policy.RecreateOption == "" {
567+
policy.RecreateOption = p.PolicyDefaults.RecreateOption
568+
}
569+
566570
if policy.RecordDiff == "" {
567571
policy.RecordDiff = p.PolicyDefaults.RecordDiff
568572
}
@@ -733,6 +737,10 @@ func (p *Plugin) applyDefaults(unmarshaledConfig map[string]interface{}) {
733737
manifest.Severity = policy.Severity
734738
}
735739

740+
if manifest.RecreateOption == "" {
741+
manifest.RecreateOption = policy.RecreateOption
742+
}
743+
736744
if manifest.RecordDiff == "" {
737745
manifest.RecordDiff = policy.RecordDiff
738746
}

internal/plugin_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func TestGenerate(t *testing.T) {
4343
p.PolicyDefaults.Namespace = "my-policies"
4444
p.PolicyDefaults.MetadataComplianceType = "musthave"
4545
p.PolicyDefaults.RecordDiff = "Log"
46+
p.PolicyDefaults.RecreateOption = "IfRequired"
4647
p.PolicyDefaults.PruneObjectBehavior = "DeleteAll"
4748
patch := map[string]interface{}{
4849
"metadata": map[string]interface{}{
@@ -70,6 +71,7 @@ func TestGenerate(t *testing.T) {
7071
ConfigurationPolicyOptions: types.ConfigurationPolicyOptions{
7172
MetadataComplianceType: "mustonlyhave",
7273
RecordDiff: "None",
74+
RecreateOption: "None",
7375
},
7476
Path: path.Join(tmpDir, "configmap.yaml"),
7577
},
@@ -120,6 +122,7 @@ spec:
120122
chandler: bing
121123
name: my-configmap
122124
recordDiff: Log
125+
recreateOption: IfRequired
123126
pruneObjectBehavior: None
124127
remediationAction: inform
125128
severity: low
@@ -155,6 +158,7 @@ spec:
155158
metadata:
156159
name: my-configmap
157160
recordDiff: None
161+
recreateOption: None
158162
pruneObjectBehavior: DeleteAll
159163
remediationAction: inform
160164
severity: low

internal/types/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type ConfigurationPolicyOptions struct {
4444
NamespaceSelector NamespaceSelector `json:"namespaceSelector,omitempty" yaml:"namespaceSelector,omitempty"`
4545
PruneObjectBehavior string `json:"pruneObjectBehavior,omitempty" yaml:"pruneObjectBehavior,omitempty"`
4646
RecordDiff string `json:"recordDiff,omitempty" yaml:"recordDiff,omitempty"`
47+
RecreateOption string `json:"recreateOption,omitempty" yaml:"recreateOption,omitempty"`
4748
}
4849

4950
type Manifest struct {

internal/utils.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ func getPolicyTemplates(policyConf *types.PolicyConfig) ([]map[string]interface{
171171
for i, manifestGroup := range manifestGroups {
172172
complianceType := policyConf.Manifests[i].ComplianceType
173173
metadataComplianceType := policyConf.Manifests[i].MetadataComplianceType
174+
recreateOption := policyConf.Manifests[i].RecreateOption
174175
recordDiff := policyConf.Manifests[i].RecordDiff
175176
ignorePending := policyConf.Manifests[i].IgnorePending
176177
extraDeps := policyConf.Manifests[i].ExtraDependencies
@@ -231,6 +232,10 @@ func getPolicyTemplates(policyConf *types.PolicyConfig) ([]map[string]interface{
231232
objTemplate["metadataComplianceType"] = metadataComplianceType
232233
}
233234

235+
if recreateOption != "" {
236+
objTemplate["recreateOption"] = recreateOption
237+
}
238+
234239
if recordDiff != "" {
235240
objTemplate["recordDiff"] = recordDiff
236241
}

0 commit comments

Comments
 (0)