Skip to content

Commit

Permalink
Testing all with no idx update code
Browse files Browse the repository at this point in the history
  • Loading branch information
tgarg-splunk committed Aug 3, 2023
1 parent 2bc3bfd commit 33534d3
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 96 deletions.
176 changes: 89 additions & 87 deletions pkg/splunk/enterprise/indexercluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1116,93 +1116,95 @@ func getSiteName(ctx context.Context, c splcommon.ControllerClient, cr *enterpri
// isIndexerClusterReadyForUpgrade checks if IndexerCluster can be upgraded if a version upgrade is in-progress
// No-operation otherwise; returns bool, err accordingly
func (mgr *indexerClusterPodManager) isIndexerClusterReadyForUpgrade(ctx context.Context, c splcommon.ControllerClient, cr *enterpriseApi.IndexerCluster) (bool, error) {
reqLogger := log.FromContext(ctx)
scopedLog := reqLogger.WithName("isIndexerClusterReadyForUpgrade").WithValues("name", cr.GetName(), "namespace", cr.GetNamespace())
eventPublisher, _ := newK8EventPublisher(c, cr)

// get the clusterManagerRef attached to the instance
clusterManagerRef := cr.Spec.ClusterManagerRef

cm := mgr.getClusterManagerClient(ctx)
clusterInfo, err := cm.GetClusterInfo(false)
if err != nil {
return false, fmt.Errorf("could not get cluster info from cluster manager")
}
if clusterInfo.MultiSite == "true" {
opts := []rclient.ListOption{
rclient.InNamespace(cr.GetNamespace()),
}
indexerList, err := getIndexerClusterList(ctx, c, cr, opts)
if err != nil {
return false, err
}
sortedList, err := getIndexerClusterSortedSiteList(ctx, c, cr.Spec.ClusterManagerRef, indexerList)

preIdx := enterpriseApi.IndexerCluster{}

for i, v := range sortedList.Items {
if &v == cr {
if i > 0 {
preIdx = sortedList.Items[i-1]
}
break

}
}
if len(preIdx.Name) != 0 {
image, _ := getCurrentImage(ctx, c, &preIdx, SplunkIndexer)
if preIdx.Status.Phase != enterpriseApi.PhaseReady || image != cr.Spec.Image {
return false, nil
}
}

}

// check if a search head cluster exists with the same ClusterManager instance attached
searchHeadClusterInstance := enterpriseApi.SearchHeadCluster{}
opts := []rclient.ListOption{
rclient.InNamespace(cr.GetNamespace()),
}
searchHeadList, err := getSearchHeadClusterList(ctx, c, cr, opts)
if err != nil {
if err.Error() == "NotFound" {
return true, nil
}
return false, err
}
if len(searchHeadList.Items) == 0 {
return true, nil
}

// check if instance has the required ClusterManagerRef
for _, shc := range searchHeadList.Items {
if shc.Spec.ClusterManagerRef.Name == clusterManagerRef.Name {
searchHeadClusterInstance = shc
break
}
}
if len(searchHeadClusterInstance.GetName()) == 0 {
return true, nil
}

shcImage, err := getCurrentImage(ctx, c, &searchHeadClusterInstance, SplunkSearchHead)
if err != nil {
eventPublisher.Warning(ctx, "isIndexerClusterReadyForUpgrade", fmt.Sprintf("Could not get the Search Head Cluster Image. Reason %v", err))
scopedLog.Error(err, "Unable to get SearchHeadCluster current image")
return false, err
}

idxImage, err := getCurrentImage(ctx, c, cr, SplunkIndexer)
if err != nil {
eventPublisher.Warning(ctx, "isIndexerClusterReadyForUpgrade", fmt.Sprintf("Could not get the Indexer Cluster Image. Reason %v", err))
scopedLog.Error(err, "Unable to get IndexerCluster current image")
return false, err
}

// check if an image upgrade is happening and whether SHC has finished updating yet, return false to stop
// further reconcile operations on IDX until SHC is ready
if (cr.Spec.Image != idxImage) && (searchHeadClusterInstance.Status.Phase != enterpriseApi.PhaseReady || shcImage != cr.Spec.Image) {
return false, nil
}
return true, nil
// reqLogger := log.FromContext(ctx)
// scopedLog := reqLogger.WithName("isIndexerClusterReadyForUpgrade").WithValues("name", cr.GetName(), "namespace", cr.GetNamespace())
// eventPublisher, _ := newK8EventPublisher(c, cr)

// get the clusterManagerRef attached to the instance
// clusterManagerRef := cr.Spec.ClusterManagerRef

// cm := mgr.getClusterManagerClient(ctx)
// clusterInfo, err := cm.GetClusterInfo(false)
// if err != nil {
// return false, fmt.Errorf("could not get cluster info from cluster manager")
// }
// if clusterInfo.MultiSite == "true" {
// opts := []rclient.ListOption{
// rclient.InNamespace(cr.GetNamespace()),
// }
// indexerList, err := getIndexerClusterList(ctx, c, cr, opts)
// if err != nil {
// return false, err
// }
// sortedList, err := getIndexerClusterSortedSiteList(ctx, c, cr.Spec.ClusterManagerRef, indexerList)

// preIdx := enterpriseApi.IndexerCluster{}

// for i, v := range sortedList.Items {
// if &v == cr {
// if i > 0 {
// preIdx = sortedList.Items[i-1]
// }
// break

// }
// }
// if len(preIdx.Name) != 0 {
// image, _ := getCurrentImage(ctx, c, &preIdx, SplunkIndexer)
// if preIdx.Status.Phase != enterpriseApi.PhaseReady || image != cr.Spec.Image {
// return false, nil
// }
// }

// }

// // check if a search head cluster exists with the same ClusterManager instance attached
// searchHeadClusterInstance := enterpriseApi.SearchHeadCluster{}
// opts := []rclient.ListOption{
// rclient.InNamespace(cr.GetNamespace()),
// }
// searchHeadList, err := getSearchHeadClusterList(ctx, c, cr, opts)
// if err != nil {
// if err.Error() == "NotFound" {
// return true, nil
// }
// return false, err
// }
// if len(searchHeadList.Items) == 0 {
// return true, nil
// }

// // check if instance has the required ClusterManagerRef
// for _, shc := range searchHeadList.Items {
// if shc.Spec.ClusterManagerRef.Name == clusterManagerRef.Name {
// searchHeadClusterInstance = shc
// break
// }
// }
// if len(searchHeadClusterInstance.GetName()) == 0 {
// return true, nil
// }

// shcImage, err := getCurrentImage(ctx, c, &searchHeadClusterInstance, SplunkSearchHead)
// if err != nil {
// eventPublisher.Warning(ctx, "isIndexerClusterReadyForUpgrade", fmt.Sprintf("Could not get the Search Head Cluster Image. Reason %v", err))
// scopedLog.Error(err, "Unable to get SearchHeadCluster current image")
// return false, err
// }

// idxImage, err := getCurrentImage(ctx, c, cr, SplunkIndexer)
// if err != nil {
// eventPublisher.Warning(ctx, "isIndexerClusterReadyForUpgrade", fmt.Sprintf("Could not get the Indexer Cluster Image. Reason %v", err))
// scopedLog.Error(err, "Unable to get IndexerCluster current image")
// return false, err
// }

// // check if an image upgrade is happening and whether SHC has finished updating yet, return false to stop
// // further reconcile operations on IDX until SHC is ready
// if (cr.Spec.Image != idxImage) && (searchHeadClusterInstance.Status.Phase != enterpriseApi.PhaseReady || shcImage != cr.Spec.Image) {
// return false, nil
// }
// return true, nil
}
18 changes: 9 additions & 9 deletions test/appframework_aws/c3/manager_appframework_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,9 @@ var _ = Describe("c3appfw test", func() {
mc, err := deployment.DeployMonitoringConsoleWithGivenSpec(ctx, testcaseEnvInst.GetName(), mcName, mcSpec)
Expect(err).To(Succeed(), "Unable to deploy Monitoring Console")

// shcName := fmt.Sprintf("%s-shc", deployment.GetName())
shcName := fmt.Sprintf("%s-shc", deployment.GetName())
idxName := fmt.Sprintf("%s-idxc", deployment.GetName())
// shc, err := deployment.DeploySearchHeadCluster(ctx, shcName, cm.GetName(), lm.GetName(), "", mcName)
shc, err := deployment.DeploySearchHeadCluster(ctx, shcName, cm.GetName(), lm.GetName(), "", mcName)
idxc, err := deployment.DeployIndexerCluster(ctx, idxName, lm.GetName(), 3, cm.GetName(), "")
// Expect(err).To(Succeed(), "Unable to deploy Single Site Indexer Cluster with Search Head Cluster")

Expand All @@ -418,7 +418,7 @@ var _ = Describe("c3appfw test", func() {
testenv.VerifyMonitoringConsoleReady(ctx, deployment, deployment.GetName(), mc, testcaseEnvInst)

// // Ensure Search Head Cluster go to Ready phase
// testenv.SearchHeadClusterReady(ctx, deployment, testcaseEnvInst)
testenv.SearchHeadClusterReady(ctx, deployment, testcaseEnvInst)

// Ensure Indexers go to Ready phase
testenv.SingleSiteIndexersReady(ctx, deployment, testcaseEnvInst)
Expand Down Expand Up @@ -486,12 +486,12 @@ var _ = Describe("c3appfw test", func() {
err = deployment.UpdateCR(ctx, mc)
Expect(err).To(Succeed(), "Failed upgrade Monitoring Console image")

// // Update SHC image
// Update SHC image

// testcaseEnvInst.Log.Info("Upgrading the Search Head Cluster Image", "Current Image", oldImage, "New Image", newImage)
// shc.Spec.Image = newImage
// err = deployment.UpdateCR(ctx, shc)
// Expect(err).To(Succeed(), "Failed upgrade Search Head Cluster image")
testcaseEnvInst.Log.Info("Upgrading the Search Head Cluster Image", "Current Image", oldImage, "New Image", newImage)
shc.Spec.Image = newImage
err = deployment.UpdateCR(ctx, shc)
Expect(err).To(Succeed(), "Failed upgrade Search Head Cluster image")

// // Update IDXC image

Expand All @@ -510,7 +510,7 @@ var _ = Describe("c3appfw test", func() {
testenv.VerifyMonitoringConsoleReady(ctx, deployment, deployment.GetName(), mc, testcaseEnvInst)

// // Ensure Search Head Cluster go to Ready phase
// testenv.SearchHeadClusterReady(ctx, deployment, testcaseEnvInst)
testenv.SearchHeadClusterReady(ctx, deployment, testcaseEnvInst)

// // Ensure Indexers go to Ready phase
testenv.SingleSiteIndexersReady(ctx, deployment, testcaseEnvInst)
Expand Down

0 comments on commit 33534d3

Please sign in to comment.