Skip to content

Commit

Permalink
Adding support for dynamic config change. (#262)
Browse files Browse the repository at this point in the history
* Adding support for dynamic config change.

* Restrict DC and Namespace addition/removal dynamically from XDR.

* Storing config status in the annotation of the Pod for error handling

* Giving pod update permission in cluster role.
  • Loading branch information
tanmayja authored Apr 10, 2024
1 parent db15cd9 commit 27f19b6
Show file tree
Hide file tree
Showing 30 changed files with 1,064 additions and 397 deletions.
5 changes: 4 additions & 1 deletion api/v1/access_control_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const (

// DefaultAdminPassword si default admin user password.
DefaultAdminPassword = "admin"

// Version6 server version 6 tag
Version6 = "6.0.0.0"
)

// roleNameForbiddenChars are characters forbidden in role name.
Expand Down Expand Up @@ -319,7 +322,7 @@ func isPrivilegeValid(
}

// Check if new privileges are used in an older version.
cmp, err := lib.CompareVersions(version, "6.0.0.0")
cmp, err := lib.CompareVersions(version, Version6)
if err != nil {
return false, err
}
Expand Down
64 changes: 28 additions & 36 deletions api/v1/aerospikecluster_mutating_webhook.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021.
Copyright 2024.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -95,9 +95,7 @@ func (c *AerospikeCluster) setDefaults(asLog logr.Logger) error {

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

Expand Down Expand Up @@ -261,18 +259,18 @@ func (c *AerospikeCluster) updateRacksAerospikeConfigFromGlobal(asLog logr.Logge
c.Spec.AerospikeConfig.Value, rack.InputAerospikeConfig.Value,
)

if err != nil {
return err
}

asLog.V(1).Info(
"Merged rack config from global aerospikeConfig", "rack id",
rack.ID, "rackAerospikeConfig", m, "globalAerospikeConfig",
c.Spec.AerospikeConfig,
)

if err != nil {
return err
}
} else {
// Use the global config.
m = c.Spec.AerospikeConfig.Value
m = c.Spec.AerospikeConfig.DeepCopy().Value
}

asLog.V(1).Info(
Expand All @@ -282,9 +280,7 @@ func (c *AerospikeCluster) updateRacksAerospikeConfigFromGlobal(asLog logr.Logge

// Set defaults in updated rack config
// Above merge function may have overwritten defaults.
if err := c.setDefaultAerospikeConfigs(
asLog, AerospikeConfigSpec{Value: m},
); err != nil {
if err := c.setDefaultAerospikeConfigs(asLog, AerospikeConfigSpec{Value: m}, &rack.ID); err != nil {
return err
}

Expand All @@ -294,15 +290,12 @@ func (c *AerospikeCluster) updateRacksAerospikeConfigFromGlobal(asLog logr.Logge
return nil
}

func (c *AerospikeCluster) setDefaultAerospikeConfigs(
asLog logr.Logger, configSpec AerospikeConfigSpec,
) error {
func (c *AerospikeCluster) setDefaultAerospikeConfigs(asLog logr.Logger,
configSpec AerospikeConfigSpec, rackID *int) error {
config := configSpec.Value

// namespace conf
if err := setDefaultNsConf(
asLog, configSpec, c.Spec.RackConfig.Namespaces,
); err != nil {
if err := setDefaultNsConf(asLog, configSpec, c.Spec.RackConfig.Namespaces, rackID); err != nil {
return err
}

Expand Down Expand Up @@ -369,10 +362,8 @@ func (n *AerospikeNetworkPolicy) setNetworkNamespace(namespace string) {
// Helper
// *****************************************************************************

func setDefaultNsConf(
asLog logr.Logger, configSpec AerospikeConfigSpec,
rackEnabledNsList []string,
) error {
func setDefaultNsConf(asLog logr.Logger, configSpec AerospikeConfigSpec,
rackEnabledNsList []string, rackID *int) error {
config := configSpec.Value
// namespace conf
nsConf, ok := config["namespaces"]
Expand Down Expand Up @@ -406,28 +397,29 @@ func setDefaultNsConf(
)
}

// Add dummy rack-id only for rackEnabled namespaces
defaultConfs := map[string]interface{}{"rack-id": DefaultRackID}

if nsName, ok := nsMap["name"]; ok {
if _, ok := nsName.(string); ok {
if isNameExist(rackEnabledNsList, nsName.(string)) {
// Add dummy rack-id, should be replaced with actual rack-id by init-container script
if err := setDefaultsInConfigMap(
asLog, nsMap, defaultConfs,
); err != nil {
return fmt.Errorf(
"failed to set default aerospikeConfig.namespaces rack config: %v",
err,
)
if name, ok := nsName.(string); ok {
if isNameExist(rackEnabledNsList, name) {
// Add rack-id only for rackEnabled namespaces
if rackID != nil {
// Add rack-id only in rack specific config, not in global config
defaultConfs := map[string]interface{}{"rack-id": *rackID}
if err := setDefaultsInConfigMap(
asLog, nsMap, defaultConfs,
); err != nil {
return fmt.Errorf(
"failed to set default aerospikeConfig.namespaces rack config: %v",
err,
)
}
}
} else {
// User may have added this key or may have patched object with new smaller rackEnabledNamespace list
// but left namespace defaults. This key should be removed then only controller will detect
// that some namespace is removed from rackEnabledNamespace list and cluster needs rolling restart
asLog.Info(
"Name aerospikeConfig.namespaces.name not found in rackEnabled namespace list. "+
"Namespace will not have defaultRackID",
"Namespace will not have any rackID",
"nsName", nsName, "rackEnabledNamespaces",
rackEnabledNsList,
)
Expand Down
Loading

0 comments on commit 27f19b6

Please sign in to comment.