Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KO-293] - Adding support for dynamic config change. #262

Merged
merged 27 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
495db95
Adding support for dynamic config change.
tanmayja Dec 11, 2023
3751956
Code structure change
tanmayja Dec 14, 2023
7de7c95
Supporting logging dynamic changes.
tanmayja Dec 20, 2023
f62c38f
Moving dynamic field validation in management lib.
tanmayja Dec 22, 2023
4a31423
version 2, handing diff in more detailed way
tanmayja Dec 27, 2023
8422b3b
Merge branch 'master' into dynamicConfig
tanmayja Jan 3, 2024
0eac6fa
Disallow DC and Namespace addition/removal dynamically from xdr.
tanmayja Jan 9, 2024
7ec3d63
storing status in annotation of pod for error handling
tanmayja Jan 30, 2024
a18475d
Giving pod update permission in cluster role and adding testcases.
tanmayja Feb 2, 2024
d5feeef
Merge branch 'master' into dynamicConfig
tanmayja Feb 5, 2024
c064dfe
Merge branch 'master' into dynamicConfig
tanmayja Feb 6, 2024
05ffaef
adressing comments
tanmayja Feb 12, 2024
5ebb6f2
fixing lint
tanmayja Feb 12, 2024
b73f541
addressing comments
tanmayja Feb 14, 2024
2573a38
addressing comments
tanmayja Feb 15, 2024
ea10a6f
fixing tests
tanmayja Feb 17, 2024
afe0e13
fixing failed pod handling
tanmayja Feb 23, 2024
22a4781
Merge branch 'master' into dynamicConfig
tanmayja Mar 4, 2024
4f28102
Merge branch 'master' into dynamicConfig
tanmayja Mar 22, 2024
c52d173
Merge branch 'master' into dynamicConfig
tanmayja Mar 26, 2024
dd8412f
Using latest lib and disallowing dynamic config change in xdr
tanmayja Mar 26, 2024
5fdde7c
Modifying test case
tanmayja Mar 26, 2024
46ce1ae
address comments
tanmayja Mar 28, 2024
53aa9ca
Merge branch 'master' into dynamicConfig
tanmayja Apr 3, 2024
ce05234
fixing testcases
tanmayja Apr 3, 2024
d612203
addressing comments and adding testcases
tanmayja Apr 10, 2024
3ee87e1
Updating init tag
tanmayja Apr 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
48 changes: 14 additions & 34 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 @@ -30,6 +30,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"

"github.com/aerospike/aerospike-kubernetes-operator/pkg/merge"
lib "github.com/aerospike/aerospike-management-lib"
)

//nolint:lll // for readability
Expand Down Expand Up @@ -88,9 +89,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, DefaultRackID); err != nil {
return err
}

Expand Down Expand Up @@ -254,18 +253,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 = lib.DeepCopy(c.Spec.AerospikeConfig.Value).(map[string]interface{})
}

asLog.V(1).Info(
Expand All @@ -275,9 +274,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 @@ -287,15 +284,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 @@ -362,10 +356,7 @@ 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 @@ -399,21 +390,10 @@ 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,
)
}
nsMap["rack-id"] = rackID
sud82 marked this conversation as resolved.
Show resolved Hide resolved
} 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
Expand Down
147 changes: 66 additions & 81 deletions api/v1/aerospikecluster_types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021.
Copyright 2023.

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 @@ -827,6 +827,9 @@ type AerospikePodStatus struct { //nolint:govet // for readability

// PodSpecHash is ripemd160 hash of PodSpec used by this pod
PodSpecHash string `json:"podSpecHash"`

// DynamicConfigFailed is true if aerospike config change failed to apply dynamically.
DynamicConfigFailed bool `json:"dynamicConfigFailed,omitempty"`
abhishekdwivedi3060 marked this conversation as resolved.
Show resolved Hide resolved
}

// +kubebuilder:object:root=true
Expand Down Expand Up @@ -864,87 +867,78 @@ func init() {
}

// CopySpecToStatus copy spec in status. Spec to Status DeepCopy doesn't work. It fails in reflect lib.
func CopySpecToStatus(spec *AerospikeClusterSpec) (*AerospikeClusterStatusSpec, error) { //nolint:dupl // not duplicate
func CopySpecToStatus(spec *AerospikeClusterSpec) (*AerospikeClusterStatusSpec, error) {
status := AerospikeClusterStatusSpec{}

status.Size = spec.Size
status.Image = spec.Image

// Storage
statusStorage := AerospikeStorageSpec{}
lib.DeepCopy(&statusStorage, &spec.Storage)
statusStorage := lib.DeepCopy(spec.Storage).(AerospikeStorageSpec)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we modify the DeepCopy to take pointer as an input param and return same type.
We can also check the feasibility of keeping the src and dst params just like before


status.Storage = statusStorage

if spec.AerospikeAccessControl != nil {
// AerospikeAccessControl
statusAerospikeAccessControl := &AerospikeAccessControlSpec{}
lib.DeepCopy(
statusAerospikeAccessControl, spec.AerospikeAccessControl,
)
statusAerospikeAccessControl := lib.DeepCopy(
*spec.AerospikeAccessControl,
).(AerospikeAccessControlSpec)

status.AerospikeAccessControl = statusAerospikeAccessControl
status.AerospikeAccessControl = &statusAerospikeAccessControl
}

// AerospikeConfig
statusAerospikeConfig := &AerospikeConfigSpec{}
lib.DeepCopy(
statusAerospikeConfig, spec.AerospikeConfig,
)
if spec.AerospikeConfig != nil {
// AerospikeConfig
statusAerospikeConfig := lib.DeepCopy(
*spec.AerospikeConfig,
).(AerospikeConfigSpec)

status.AerospikeConfig = statusAerospikeConfig
status.AerospikeConfig = &statusAerospikeConfig
}

if spec.ValidationPolicy != nil {
// ValidationPolicy
statusValidationPolicy := &ValidationPolicySpec{}
lib.DeepCopy(
statusValidationPolicy, spec.ValidationPolicy,
)
statusValidationPolicy := lib.DeepCopy(
*spec.ValidationPolicy,
).(ValidationPolicySpec)

status.ValidationPolicy = statusValidationPolicy
status.ValidationPolicy = &statusValidationPolicy
}

// RackConfig
statusRackConfig := RackConfig{}
lib.DeepCopy(&statusRackConfig, &spec.RackConfig)
statusRackConfig := lib.DeepCopy(spec.RackConfig).(RackConfig)
status.RackConfig = statusRackConfig

// AerospikeNetworkPolicy
statusAerospikeNetworkPolicy := AerospikeNetworkPolicy{}
lib.DeepCopy(
&statusAerospikeNetworkPolicy, &spec.AerospikeNetworkPolicy,
)
statusAerospikeNetworkPolicy := lib.DeepCopy(
spec.AerospikeNetworkPolicy,
).(AerospikeNetworkPolicy)

status.AerospikeNetworkPolicy = statusAerospikeNetworkPolicy

if spec.OperatorClientCertSpec != nil {
clientCertSpec := &AerospikeOperatorClientCertSpec{}
lib.DeepCopy(
clientCertSpec, spec.OperatorClientCertSpec,
)
clientCertSpec := lib.DeepCopy(
*spec.OperatorClientCertSpec,
).(AerospikeOperatorClientCertSpec)

status.OperatorClientCertSpec = clientCertSpec
status.OperatorClientCertSpec = &clientCertSpec
}

// Storage
statusPodSpec := AerospikePodSpec{}
lib.DeepCopy(&statusPodSpec, &spec.PodSpec)
statusPodSpec := lib.DeepCopy(spec.PodSpec).(AerospikePodSpec)
status.PodSpec = statusPodSpec

seedsFinderServices := SeedsFinderServices{}
lib.DeepCopy(
&seedsFinderServices, &spec.SeedsFinderServices,
)
seedsFinderServices := lib.DeepCopy(
spec.SeedsFinderServices,
).(SeedsFinderServices)

status.SeedsFinderServices = seedsFinderServices

// RosterNodeBlockList
if len(spec.RosterNodeBlockList) != 0 {
var rosterNodeBlockList []string

lib.DeepCopy(
&rosterNodeBlockList, &spec.RosterNodeBlockList,
)
rosterNodeBlockList := lib.DeepCopy(
spec.RosterNodeBlockList,
).([]string)

status.RosterNodeBlockList = rosterNodeBlockList
}
Expand All @@ -953,88 +947,79 @@ func CopySpecToStatus(spec *AerospikeClusterSpec) (*AerospikeClusterStatusSpec,
}

// CopyStatusToSpec copy status in spec. Status to Spec DeepCopy doesn't work. It fails in reflect lib.
func CopyStatusToSpec(status *AerospikeClusterStatusSpec) (*AerospikeClusterSpec, error) { //nolint:dupl // no need
func CopyStatusToSpec(status *AerospikeClusterStatusSpec) (*AerospikeClusterSpec, error) {
spec := AerospikeClusterSpec{}

spec.Size = status.Size
spec.Image = status.Image

// Storage
specStorage := AerospikeStorageSpec{}
lib.DeepCopy(&specStorage, &status.Storage)
specStorage := lib.DeepCopy(status.Storage).(AerospikeStorageSpec)
spec.Storage = specStorage

if status.AerospikeAccessControl != nil {
// AerospikeAccessControl
specAerospikeAccessControl := &AerospikeAccessControlSpec{}
lib.DeepCopy(
specAerospikeAccessControl, status.AerospikeAccessControl,
)
specAerospikeAccessControl := lib.DeepCopy(
status.AerospikeAccessControl,
).(*AerospikeAccessControlSpec)

spec.AerospikeAccessControl = specAerospikeAccessControl
}

// AerospikeConfig
specAerospikeConfig := &AerospikeConfigSpec{}
lib.DeepCopy(
specAerospikeConfig, status.AerospikeConfig,
)
if status.AerospikeConfig != nil {
specAerospikeConfig := lib.DeepCopy(
status.AerospikeConfig,
).(*AerospikeConfigSpec)

spec.AerospikeConfig = specAerospikeConfig
spec.AerospikeConfig = specAerospikeConfig
}

if status.ValidationPolicy != nil {
// ValidationPolicy
specValidationPolicy := &ValidationPolicySpec{}
lib.DeepCopy(
specValidationPolicy, status.ValidationPolicy,
)
specValidationPolicy := lib.DeepCopy(
*status.ValidationPolicy,
).(ValidationPolicySpec)

spec.ValidationPolicy = specValidationPolicy
spec.ValidationPolicy = &specValidationPolicy
}

// RackConfig
specRackConfig := RackConfig{}
lib.DeepCopy(&specRackConfig, &status.RackConfig)
specRackConfig := lib.DeepCopy(status.RackConfig).(RackConfig)

spec.RackConfig = specRackConfig

// AerospikeNetworkPolicy
specAerospikeNetworkPolicy := AerospikeNetworkPolicy{}
lib.DeepCopy(
&specAerospikeNetworkPolicy, &status.AerospikeNetworkPolicy,
)
specAerospikeNetworkPolicy := lib.DeepCopy(
status.AerospikeNetworkPolicy,
).(AerospikeNetworkPolicy)

spec.AerospikeNetworkPolicy = specAerospikeNetworkPolicy

if status.OperatorClientCertSpec != nil {
clientCertSpec := &AerospikeOperatorClientCertSpec{}
lib.DeepCopy(
clientCertSpec, status.OperatorClientCertSpec,
)
clientCertSpec := lib.DeepCopy(
*status.OperatorClientCertSpec,
).(AerospikeOperatorClientCertSpec)

spec.OperatorClientCertSpec = clientCertSpec
spec.OperatorClientCertSpec = &clientCertSpec
}

// Storage
specPodSpec := AerospikePodSpec{}
lib.DeepCopy(&specPodSpec, &status.PodSpec)
specPodSpec := lib.DeepCopy(status.PodSpec).(AerospikePodSpec)

spec.PodSpec = specPodSpec

seedsFinderServices := SeedsFinderServices{}
lib.DeepCopy(
&seedsFinderServices, &status.SeedsFinderServices,
)
seedsFinderServices := lib.DeepCopy(
status.SeedsFinderServices,
).(SeedsFinderServices)

spec.SeedsFinderServices = seedsFinderServices

// RosterNodeBlockList
if len(status.RosterNodeBlockList) != 0 {
var rosterNodeBlockList []string

lib.DeepCopy(
&rosterNodeBlockList, &status.RosterNodeBlockList,
)
rosterNodeBlockList := lib.DeepCopy(
status.RosterNodeBlockList,
).([]string)

spec.RosterNodeBlockList = rosterNodeBlockList
}
Expand Down
Loading
Loading