Skip to content

Commit eefc8bd

Browse files
committed
CSPL-3704 Fix failing tests
1 parent cc0350b commit eefc8bd

File tree

9 files changed

+30
-25
lines changed

9 files changed

+30
-25
lines changed

pkg/splunk/enterprise/clustermanager.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ func ApplyClusterManager(ctx context.Context, client splcommon.ControllerClient,
129129
}
130130

131131
// Smart Store secrets get created manually and should not be managed by the Operator
132-
DeleteOwnerReferencesForResources(ctx, client, cr, &cr.Spec.SmartStore, SplunkClusterManager)
132+
if &cr.Spec.SmartStore != nil {
133+
_ = DeleteOwnerReferencesForS3SecretObjects(ctx, client, cr, &cr.Spec.SmartStore)
134+
}
133135

134136
// check if deletion has been requested
135137
if cr.ObjectMeta.DeletionTimestamp != nil {
@@ -157,6 +159,8 @@ func ApplyClusterManager(ctx context.Context, client splcommon.ControllerClient,
157159
return result, err
158160
}
159161

162+
DeleteOwnerReferencesForResources(ctx, client, cr, SplunkClusterManager)
163+
160164
terminating, err := splctrl.CheckForDeletion(ctx, cr, client)
161165

162166
if terminating && err != nil { // don't bother if no error, since it will just be removed immmediately after

pkg/splunk/enterprise/clustermaster.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ func ApplyClusterMaster(ctx context.Context, client splcommon.ControllerClient,
126126
}
127127

128128
// Smart Store secrets get created manually and should not be managed by the Operator
129-
DeleteOwnerReferencesForResources(ctx, client, cr, &cr.Spec.SmartStore, SplunkClusterMaster)
129+
if &cr.Spec.SmartStore != nil {
130+
_ = DeleteOwnerReferencesForS3SecretObjects(ctx, client, cr, &cr.Spec.SmartStore)
131+
}
130132

131133
// check if deletion has been requested
132134
if cr.ObjectMeta.DeletionTimestamp != nil {
@@ -147,7 +149,9 @@ func ApplyClusterMaster(ctx context.Context, client splcommon.ControllerClient,
147149
return result, err
148150
}
149151
}
150-
152+
153+
DeleteOwnerReferencesForResources(ctx, client, cr, SplunkClusterMaster)
154+
151155
terminating, err := splctrl.CheckForDeletion(ctx, cr, client)
152156
if terminating && err != nil { // don't bother if no error, since it will just be removed immmediately after
153157
cr.Status.Phase = enterpriseApi.PhaseTerminating

pkg/splunk/enterprise/indexercluster.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,9 @@ func ApplyIndexerClusterManager(ctx context.Context, client splcommon.Controller
125125
}
126126
}
127127

128-
// Smart Store secrets get created manually and should not be managed by the Operator
129-
DeleteOwnerReferencesForResources(ctx, client, cr, nil, SplunkIndexer)
130-
131128
// check if deletion has been requested
132129
if cr.ObjectMeta.DeletionTimestamp != nil {
130+
DeleteOwnerReferencesForResources(ctx, client, cr, SplunkIndexer)
133131

134132
terminating, err := splctrl.CheckForDeletion(ctx, cr, client)
135133
if terminating && err != nil { // don't bother if no error, since it will just be removed immmediately after
@@ -382,11 +380,10 @@ func ApplyIndexerCluster(ctx context.Context, client splcommon.ControllerClient,
382380
}
383381
}
384382

385-
// Smart Store secrets get created manually and should not be managed by the Operator
386-
DeleteOwnerReferencesForResources(ctx, client, cr, nil, SplunkIndexer)
387-
388383
// check if deletion has been requested
389384
if cr.ObjectMeta.DeletionTimestamp != nil {
385+
DeleteOwnerReferencesForResources(ctx, client, cr, SplunkIndexer)
386+
390387
terminating, err := splctrl.CheckForDeletion(ctx, cr, client)
391388
if terminating && err != nil { // don't bother if no error, since it will just be removed immmediately after
392389
cr.Status.Phase = enterpriseApi.PhaseTerminating

pkg/splunk/enterprise/licensemanager.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@ func ApplyLicenseManager(ctx context.Context, client splcommon.ControllerClient,
9090
return result, err
9191
}
9292

93-
// Smart Store secrets get created manually and should not be managed by the Operator
94-
DeleteOwnerReferencesForResources(ctx, client, cr, nil, SplunkLicenseManager)
95-
9693
// check if deletion has been requested
9794
if cr.ObjectMeta.DeletionTimestamp != nil {
9895
if cr.Spec.MonitoringConsoleRef.Name != "" {
@@ -101,6 +98,7 @@ func ApplyLicenseManager(ctx context.Context, client splcommon.ControllerClient,
10198
return result, err
10299
}
103100
}
101+
104102
// If this is the last of its kind getting deleted,
105103
// remove the entry for this CR type from configMap or else
106104
// just decrement the refCount for this CR type.
@@ -111,6 +109,8 @@ func ApplyLicenseManager(ctx context.Context, client splcommon.ControllerClient,
111109
}
112110
}
113111

112+
DeleteOwnerReferencesForResources(ctx, client, cr, SplunkLicenseManager)
113+
114114
terminating, err := splctrl.CheckForDeletion(ctx, cr, client)
115115
if terminating && err != nil { // don't bother if no error, since it will just be removed immmediately after
116116
cr.Status.Phase = enterpriseApi.PhaseTerminating

pkg/splunk/enterprise/licensemaster.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@ func ApplyLicenseMaster(ctx context.Context, client splcommon.ControllerClient,
9090
return result, err
9191
}
9292

93-
// Smart Store secrets get created manually and should not be managed by the Operator
94-
DeleteOwnerReferencesForResources(ctx, client, cr, nil, SplunkLicenseMaster)
95-
9693
// check if deletion has been requested
9794
if cr.ObjectMeta.DeletionTimestamp != nil {
9895
if cr.Spec.MonitoringConsoleRef.Name != "" {
@@ -101,6 +98,7 @@ func ApplyLicenseMaster(ctx context.Context, client splcommon.ControllerClient,
10198
return result, err
10299
}
103100
}
101+
104102
// If this is the last of its kind getting deleted,
105103
// remove the entry for this CR type from configMap or else
106104
// just decrement the refCount for this CR type.
@@ -111,6 +109,8 @@ func ApplyLicenseMaster(ctx context.Context, client splcommon.ControllerClient,
111109
}
112110
}
113111

112+
DeleteOwnerReferencesForResources(ctx, client, cr, SplunkLicenseMaster)
113+
114114
terminating, err := splctrl.CheckForDeletion(ctx, cr, client)
115115
if terminating && err != nil { // don't bother if no error, since it will just be removed immmediately after
116116
cr.Status.Phase = enterpriseApi.PhaseTerminating

pkg/splunk/enterprise/searchheadcluster.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,6 @@ func ApplySearchHeadCluster(ctx context.Context, client splcommon.ControllerClie
112112
cr.Status.AdminPasswordChangedSecrets = make(map[string]bool)
113113
}
114114

115-
// Smart Store secrets get created manually and should not be managed by the Operator
116-
DeleteOwnerReferencesForResources(ctx, client, cr, nil, SplunkSearchHead)
117-
118115
// check if deletion has been requested
119116
if cr.ObjectMeta.DeletionTimestamp != nil {
120117
if cr.Spec.MonitoringConsoleRef.Name != "" {
@@ -134,6 +131,8 @@ func ApplySearchHeadCluster(ctx context.Context, client splcommon.ControllerClie
134131
}
135132
}
136133

134+
DeleteOwnerReferencesForResources(ctx, client, cr, SplunkSearchHead)
135+
137136
terminating, err := splctrl.CheckForDeletion(ctx, cr, client)
138137
if terminating && err != nil { // don't bother if no error, since it will just be removed immmediately after
139138
cr.Status.Phase = enterpriseApi.PhaseTerminating

pkg/splunk/enterprise/standalone.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ func ApplyStandalone(ctx context.Context, client splcommon.ControllerClient, cr
115115
}
116116

117117
// Smart Store secrets get created manually and should not be managed by the Operator
118-
DeleteOwnerReferencesForResources(ctx, client, cr, &cr.Spec.SmartStore, SplunkStandalone)
118+
if &cr.Spec.SmartStore != nil {
119+
_ = DeleteOwnerReferencesForS3SecretObjects(ctx, client, cr, &cr.Spec.SmartStore)
120+
}
119121

120122
// check if deletion has been requested
121123
if cr.ObjectMeta.DeletionTimestamp != nil {
@@ -126,6 +128,7 @@ func ApplyStandalone(ctx context.Context, client splcommon.ControllerClient, cr
126128
return result, err
127129
}
128130
}
131+
129132
// If this is the last of its kind getting deleted,
130133
// remove the entry for this CR type from configMap or else
131134
// just decrement the refCount for this CR type.
@@ -136,6 +139,8 @@ func ApplyStandalone(ctx context.Context, client splcommon.ControllerClient, cr
136139
}
137140
}
138141

142+
DeleteOwnerReferencesForResources(ctx, client, cr, SplunkStandalone)
143+
139144
terminating, err := splctrl.CheckForDeletion(ctx, cr, client)
140145

141146
if terminating && err != nil { // don't bother if no error, since it will just be removed immmediately after

pkg/splunk/enterprise/util.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -786,15 +786,11 @@ func setupInitContainer(podTemplateSpec *corev1.PodTemplateSpec, Image string, i
786786

787787
// DeleteOwnerReferencesForResources used to delete any outstanding owner references
788788
// Ideally we should be removing the owner reference wherever the CR is not controller for the resource
789-
func DeleteOwnerReferencesForResources(ctx context.Context, client splcommon.ControllerClient, cr splcommon.MetaObject, smartstore *enterpriseApi.SmartStoreSpec, instanceType InstanceType) error {
789+
func DeleteOwnerReferencesForResources(ctx context.Context, client splcommon.ControllerClient, cr splcommon.MetaObject, instanceType InstanceType) error {
790790
var err error
791791
reqLogger := log.FromContext(ctx)
792792
scopedLog := reqLogger.WithName("DeleteOwnerReferencesForResources").WithValues("kind", cr.GetObjectKind().GroupVersionKind().Kind, "name", cr.GetName(), "namespace", cr.GetNamespace())
793793

794-
if smartstore != nil {
795-
_ = DeleteOwnerReferencesForS3SecretObjects(ctx, client, cr, smartstore)
796-
}
797-
798794
// Delete references to Default secret object
799795
defaultSecretName := splcommon.GetNamespaceScopedSecretName(cr.GetNamespace())
800796
_, err = splutil.RemoveSecretOwnerRef(ctx, client, defaultSecretName, cr)

pkg/splunk/enterprise/util_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ func TestRemoveOwenerReferencesForSecretObjectsReferredBySmartstoreVolumes(t *te
566566
}
567567

568568
// Smartstore volume config with non-existing secret objects
569-
err = DeleteOwnerReferencesForResources(ctx, client, &cr, &cr.Spec.SmartStore, SplunkClusterMaster)
569+
err = DeleteOwnerReferencesForResources(ctx, client, &cr, SplunkClusterMaster)
570570
if err == nil {
571571
t.Errorf("Should report an error, when the secret objects doesn't exist")
572572
}

0 commit comments

Comments
 (0)