Skip to content

Commit 5a0389d

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

File tree

9 files changed

+29
-25
lines changed

9 files changed

+29
-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 {
@@ -141,6 +143,8 @@ func ApplyClusterManager(ctx context.Context, client splcommon.ControllerClient,
141143
}
142144
}
143145

146+
DeleteOwnerReferencesForResources(ctx, client, cr, SplunkClusterManager)
147+
144148
// If this is the last of its kind getting deleted,
145149
// remove the entry for this CR type from configMap or else
146150
// just decrement the refCount for this CR type.

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 {
@@ -138,6 +140,8 @@ func ApplyClusterMaster(ctx context.Context, client splcommon.ControllerClient,
138140
}
139141
}
140142

143+
DeleteOwnerReferencesForResources(ctx, client, cr, SplunkClusterMaster)
144+
141145
// If this is the last of its kind getting deleted,
142146
// remove the entry for this CR type from configMap or else
143147
// just decrement the refCount for this CR type.
@@ -147,7 +151,7 @@ func ApplyClusterMaster(ctx context.Context, client splcommon.ControllerClient,
147151
return result, err
148152
}
149153
}
150-
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: 2 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,8 @@ func ApplyLicenseManager(ctx context.Context, client splcommon.ControllerClient,
10198
return result, err
10299
}
103100
}
101+
DeleteOwnerReferencesForResources(ctx, client, cr, SplunkLicenseManager)
102+
104103
// If this is the last of its kind getting deleted,
105104
// remove the entry for this CR type from configMap or else
106105
// just decrement the refCount for this CR type.

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,9 @@ func ApplyLicenseMaster(ctx context.Context, client splcommon.ControllerClient,
10198
return result, err
10299
}
103100
}
101+
102+
DeleteOwnerReferencesForResources(ctx, client, cr, SplunkLicenseMaster)
103+
104104
// If this is the last of its kind getting deleted,
105105
// remove the entry for this CR type from configMap or else
106106
// just decrement the refCount for this CR type.

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 != "" {
@@ -124,6 +121,8 @@ func ApplySearchHeadCluster(ctx context.Context, client splcommon.ControllerClie
124121
}
125122
}
126123

124+
DeleteOwnerReferencesForResources(ctx, client, cr, SplunkSearchHead)
125+
127126
// If this is the last of its kind getting deleted,
128127
// remove the entry for this CR type from configMap or else
129128
// just decrement the refCount for this CR type.

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,9 @@ func ApplyStandalone(ctx context.Context, client splcommon.ControllerClient, cr
126128
return result, err
127129
}
128130
}
131+
132+
DeleteOwnerReferencesForResources(ctx, client, cr, SplunkStandalone)
133+
129134
// If this is the last of its kind getting deleted,
130135
// remove the entry for this CR type from configMap or else
131136
// just decrement the refCount for this CR type.

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)