-
Notifications
You must be signed in to change notification settings - Fork 124
bugfix/CSPL-466: If in IndexerCluster spec, replicas < RF(which is configured on ClusterMaster), then set replicas=RF. #166
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
fb617ad
bugfix/CSPL-466: If in IndexerCluster spec, replicas < RF(which is co…
gaurav-splunk 5e4fd3f
Removed a commented line
gaurav-splunk 7e3cf91
Addressed review comments
gaurav-splunk 251d01f
Added Unit test and removed check for speck.Mock in code
gaurav-splunk 0cd2de3
Merge branch 'develop' into bugfix/CSPL-466
gaurav-splunk f43189b
minor typo correction
gaurav-splunk 925b904
Merge branch 'develop' into bugfix/CSPL-466
gaurav-splunk 5fdb933
Only create idxc statefulset and secrets if CM is ready
gaurav-splunk 2a2ddab
Merge branch 'develop' into bugfix/CSPL-466
gaurav-splunk dc8b909
Merge branch 'bugfix/CSPL-466' of github.com:splunk/splunk-operator i…
gaurav-splunk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,8 @@ import ( | |
"context" | ||
"errors" | ||
"fmt" | ||
"regexp" | ||
"strconv" | ||
"time" | ||
|
||
appsv1 "k8s.io/api/apps/v1" | ||
|
@@ -73,6 +75,26 @@ func ApplyIndexerCluster(client splcommon.ControllerClient, cr *enterprisev1.Ind | |
return result, err | ||
} | ||
|
||
namespacedName := types.NamespacedName{ | ||
Namespace: cr.GetNamespace(), | ||
Name: cr.Spec.ClusterMasterRef.Name, | ||
} | ||
masterIdxCluster := &enterprisev1.ClusterMaster{} | ||
err = client.Get(context.TODO(), namespacedName, masterIdxCluster) | ||
if err == nil { | ||
cr.Status.ClusterMasterPhase = masterIdxCluster.Status.Phase | ||
} else { | ||
cr.Status.ClusterMasterPhase = splcommon.PhaseError | ||
} | ||
mgr := indexerClusterPodManager{log: scopedLog, cr: cr, secrets: namespaceScopedSecret, newSplunkClient: splclient.NewSplunkClient} | ||
// Check if we have configured enough number(<= RF) of replicas | ||
if mgr.cr.Status.ClusterMasterPhase == splcommon.PhaseReady { | ||
err = mgr.verifyRFPeers(client) | ||
if err != nil { | ||
return result, err | ||
} | ||
} | ||
|
||
// check if deletion has been requested | ||
if cr.ObjectMeta.DeletionTimestamp != nil { | ||
DeleteOwnerReferencesForResources(client, cr, nil) | ||
|
@@ -97,24 +119,12 @@ func ApplyIndexerCluster(client splcommon.ControllerClient, cr *enterprisev1.Ind | |
return result, err | ||
} | ||
|
||
namespacedName := types.NamespacedName{ | ||
Namespace: cr.GetNamespace(), | ||
Name: cr.Spec.ClusterMasterRef.Name, | ||
} | ||
masterIdxCluster := &enterprisev1.ClusterMaster{} | ||
err = client.Get(context.TODO(), namespacedName, masterIdxCluster) | ||
if err == nil { | ||
cr.Status.ClusterMasterPhase = masterIdxCluster.Status.Phase | ||
} else { | ||
cr.Status.ClusterMasterPhase = splcommon.PhaseError | ||
} | ||
|
||
// create or update statefulset for the indexers | ||
statefulSet, err := getIndexerStatefulSet(client, cr) | ||
if err != nil { | ||
return result, err | ||
} | ||
mgr := indexerClusterPodManager{log: scopedLog, cr: cr, secrets: namespaceScopedSecret, newSplunkClient: splclient.NewSplunkClient} | ||
|
||
akondur marked this conversation as resolved.
Show resolved
Hide resolved
|
||
phase, err := mgr.Update(client, statefulSet, cr.Spec.Replicas) | ||
if err != nil { | ||
return result, err | ||
|
@@ -278,12 +288,20 @@ func ApplyIdxcSecret(mgr *indexerClusterPodManager, replicas int32, mock bool) e | |
|
||
// Update for indexerClusterPodManager handles all updates for a statefulset of indexers | ||
func (mgr *indexerClusterPodManager) Update(c splcommon.ControllerClient, statefulSet *appsv1.StatefulSet, desiredReplicas int32) (splcommon.Phase, error) { | ||
|
||
var err error | ||
//Don't even try to create a statefulset and secret if CM is not ready yet. | ||
if mgr.cr.Status.ClusterMasterPhase != splcommon.PhaseReady { | ||
mgr.log.Error(err, "Cluster Master is not ready yet") | ||
return splcommon.PhaseError, err | ||
} | ||
|
||
// Assign client | ||
if mgr.c == nil { | ||
mgr.c = c | ||
} | ||
// update statefulset, if necessary | ||
_, err := splctrl.ApplyStatefulSet(mgr.c, statefulSet) | ||
_, err = splctrl.ApplyStatefulSet(mgr.c, statefulSet) | ||
if err != nil { | ||
return splcommon.PhaseError, err | ||
} | ||
|
@@ -414,6 +432,40 @@ func (mgr *indexerClusterPodManager) getClusterMasterClient() *splclient.SplunkC | |
return mgr.newSplunkClient(fmt.Sprintf("https://%s:8089", fqdnName), "admin", adminPwd) | ||
} | ||
|
||
gaurav-splunk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// getSiteRepFactorOriginCount gets the origin count of the site_replication_factor | ||
func getSiteRepFactorOriginCount(siteRepFactor string) int32 { | ||
re := regexp.MustCompile(".*origin:(?P<rf>.*),.*") | ||
gaurav-splunk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
match := re.FindStringSubmatch(siteRepFactor) | ||
siteRF, _ := strconv.Atoi(match[1]) | ||
return int32(siteRF) | ||
} | ||
|
||
// verifyRFPeers verifies the number of peers specified in the replicas section | ||
// of IndexerClsuster CR. If it is less than RF, than we set it to RF. | ||
func (mgr *indexerClusterPodManager) verifyRFPeers(c splcommon.ControllerClient) error { | ||
gaurav-splunk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if mgr.c == nil { | ||
akondur marked this conversation as resolved.
Show resolved
Hide resolved
|
||
mgr.c = c | ||
} | ||
cm := mgr.getClusterMasterClient() | ||
gaurav-splunk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
clusterInfo, err := cm.GetClusterInfo(false) | ||
if err != nil { | ||
return fmt.Errorf("Could not get cluster info from cluster master") | ||
} | ||
var replicationFactor int32 | ||
// if it is a multisite indexer cluster, check site_replication_factor | ||
if clusterInfo.MultiSite == "true" { | ||
replicationFactor = getSiteRepFactorOriginCount(clusterInfo.SiteReplicationFactor) | ||
} else { // for single site, check replication factor | ||
replicationFactor = clusterInfo.ReplicationFactor | ||
} | ||
|
||
smohan-splunk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if mgr.cr.Spec.Replicas < replicationFactor { | ||
mgr.log.Info("Changing number of replicas as it is less than RF number of peers", "replicas", mgr.cr.Spec.Replicas) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. super nit: Maybe can change the logging to something like "Increasing number of indexer replicas to match RF number of peers" or something similar |
||
mgr.cr.Spec.Replicas = replicationFactor | ||
} | ||
return nil | ||
} | ||
|
||
// updateStatus for indexerClusterPodManager uses the REST API to update the status for an IndexerCluster custom resource | ||
func (mgr *indexerClusterPodManager) updateStatus(statefulSet *appsv1.StatefulSet) error { | ||
mgr.cr.Status.ReadyReplicas = statefulSet.Status.ReadyReplicas | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.