Skip to content

Commit

Permalink
Adding warning while mutating maxUnavailable.
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmayja committed Jan 17, 2025
1 parent 6bac453 commit afa3e81
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions api/v1/aerospikecluster_mutating_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ func (c *AerospikeCluster) Default(operation v1.Operation) admission.Response {
c.Spec,
)

if err := c.setDefaults(asLog); err != nil {
var (
warn admission.Warnings
err error
)

if warn, err = c.setDefaults(asLog); err != nil {
asLog.Error(err, "Mutate AerospikeCluster create failed")
return webhook.Denied(err.Error())
}
Expand All @@ -67,13 +72,17 @@ func (c *AerospikeCluster) Default(operation v1.Operation) admission.Response {
return webhook.Patched(
"Patched aerospike spec with defaults",
patches...,
)
).WithWarnings(warn...)
}

func (c *AerospikeCluster) setDefaults(asLog logr.Logger) error {
func (c *AerospikeCluster) setDefaults(asLog logr.Logger) (admission.Warnings, error) {
var warn admission.Warnings
// If PDB is disabled, set maxUnavailable to nil
if GetBool(c.Spec.DisablePDB) {
c.Spec.MaxUnavailable = nil

warn = append(warn, fmt.Sprintf("Spec field 'spec.maxUnavailable' will be omitted from Custom Resource (CR) "+
"because 'spec.disablePDB' is true."))
} else if c.Spec.MaxUnavailable == nil {
// Set default maxUnavailable if not set
maxUnavailable := intstr.FromInt32(1)
Expand All @@ -90,27 +99,27 @@ func (c *AerospikeCluster) setDefaults(asLog logr.Logger) error {
// Need to set before setting defaults in aerospikeConfig.
// aerospikeConfig.namespace checks for racks
if err := c.setDefaultRackConf(asLog); err != nil {
return err
return warn, err
}

if c.Spec.AerospikeConfig == nil {
return fmt.Errorf("spec.aerospikeConfig cannot be nil")
return warn, fmt.Errorf("spec.aerospikeConfig cannot be nil")
}

// Set common aerospikeConfig defaults
// Update configMap
if err := c.setDefaultAerospikeConfigs(asLog, *c.Spec.AerospikeConfig, nil); err != nil {
return err
return warn, err
}

// Update racks configuration using global values where required.
if err := c.updateRacks(asLog); err != nil {
return err
return warn, err
}

// Set defaults for pod spec
if err := c.Spec.PodSpec.SetDefaults(); err != nil {
return err
return warn, err
}

// Validation policy
Expand Down Expand Up @@ -138,7 +147,7 @@ func (c *AerospikeCluster) setDefaults(asLog logr.Logger) error {
c.Labels[AerospikeAPIVersionLabel] = AerospikeAPIVersion
}

return nil
return warn, nil
}

// SetDefaults applies defaults to the pod spec.
Expand Down

0 comments on commit afa3e81

Please sign in to comment.