Skip to content

Commit 1b92ad5

Browse files
vivekr-splunkclaude
andcommitted
Fix unit test failures in Platform SDK integration
This commit fixes 4 failing unit tests after the Platform SDK integration: 1. Fixed 3 SecretAdapter tests (TestSecretAdapter_SDKMode, TestSecretAdapter_SDKMode_SecretNotReady, TestSecretAdapter_SDKMode_SecretVersioning) by adding PlatformConfig CRD scheme registration. The tests were failing with: "no kind is registered for the type v4.PlatformConfig in scheme" 2. Fixed TestApplyStandalone panic by adding nil check for sdkRuntime in getStandaloneStatefulSet. When sdkRuntime is nil (legacy tests), the function now falls back to getStandaloneStatefulSetLegacy which uses the pre-SDK implementation. Changes: - pkg/splunk/enterprise/secret_adapter_test.go: Import platformv4 and register PlatformConfig scheme in all SDK-mode tests - pkg/splunk/enterprise/standalone.go: Add nil check and legacy fallback path in getStandaloneStatefulSet, add getStandaloneStatefulSetLegacy function for backward compatibility All enterprise package tests now pass successfully. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 0cfff27 commit 1b92ad5

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

pkg/splunk/enterprise/secret_adapter_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"sigs.k8s.io/controller-runtime/pkg/client/fake"
1616

1717
"github.com/go-logr/logr"
18+
platformv4 "github.com/splunk/splunk-operator/api/platform/v4"
1819
sdk "github.com/splunk/splunk-operator/pkg/platform-sdk"
1920
"github.com/splunk/splunk-operator/pkg/platform-sdk/api/config"
2021
splcommon "github.com/splunk/splunk-operator/pkg/splunk/common"
@@ -104,6 +105,7 @@ func TestSecretAdapter_SDKMode(t *testing.T) {
104105
scheme := runtime.NewScheme()
105106
_ = corev1.AddToScheme(scheme)
106107
_ = config.AddToScheme(scheme)
108+
_ = platformv4.AddToScheme(scheme)
107109

108110
// Create source secret (what admins create manually or via ESO)
109111
sourceSecret := &corev1.Secret{
@@ -217,6 +219,7 @@ func TestSecretAdapter_SDKMode_SecretNotReady(t *testing.T) {
217219
scheme := runtime.NewScheme()
218220
_ = corev1.AddToScheme(scheme)
219221
_ = config.AddToScheme(scheme)
222+
_ = platformv4.AddToScheme(scheme)
220223

221224
// Create fake client WITHOUT source secret (simulating ExternalSecret not yet synced)
222225
fakeClient := fake.NewClientBuilder().
@@ -292,6 +295,7 @@ func TestSecretAdapter_SDKMode_SecretVersioning(t *testing.T) {
292295
scheme := runtime.NewScheme()
293296
_ = corev1.AddToScheme(scheme)
294297
_ = config.AddToScheme(scheme)
298+
_ = platformv4.AddToScheme(scheme)
295299

296300
// Create source secret
297301
sourceSecret := &corev1.Secret{

pkg/splunk/enterprise/standalone.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,12 @@ func getStandaloneStatefulSet(ctx context.Context, client splcommon.ControllerCl
294294
reqLogger := log.FromContext(ctx)
295295
scopedLog := reqLogger.WithName("getStandaloneStatefulSet").WithValues("name", cr.GetName(), "namespace", cr.GetNamespace())
296296

297+
// Legacy mode: fall back to old implementation if SDK runtime is nil
298+
if sdkRuntime == nil {
299+
scopedLog.Info("Using legacy StatefulSet creation (SDK runtime not available)")
300+
return getStandaloneStatefulSetLegacy(ctx, client, cr)
301+
}
302+
297303
// Create SDK reconcile context
298304
rctx := sdkRuntime.NewReconcileContext(ctx, cr.Namespace, cr.Name)
299305

@@ -432,6 +438,27 @@ func getStandaloneStatefulSet(ctx context.Context, client splcommon.ControllerCl
432438
return ss, nil
433439
}
434440

441+
// getStandaloneStatefulSetLegacy returns a StatefulSet using the legacy (pre-SDK) implementation.
442+
// This is used for backward compatibility when SDK runtime is not available (e.g., in old tests).
443+
func getStandaloneStatefulSetLegacy(ctx context.Context, client splcommon.ControllerClient, cr *enterpriseApi.Standalone) (*appsv1.StatefulSet, error) {
444+
// get generic statefulset for Splunk Enterprise objects
445+
ss, err := getSplunkStatefulSet(ctx, client, cr, &cr.Spec.CommonSplunkSpec, SplunkStandalone, cr.Spec.Replicas, []corev1.EnvVar{})
446+
if err != nil {
447+
return nil, err
448+
}
449+
450+
smartStoreConfigMap := getSmartstoreConfigMap(ctx, client, cr, SplunkStandalone)
451+
452+
if smartStoreConfigMap != nil {
453+
setupInitContainer(&ss.Spec.Template, cr.Spec.Image, cr.Spec.ImagePullPolicy, commandForStandaloneSmartstore, cr.Spec.CommonSplunkSpec.EtcVolumeStorageConfig.EphemeralStorage)
454+
}
455+
456+
// Setup App framework staging volume for apps
457+
setupAppsStagingVolume(ctx, client, cr, &ss.Spec.Template, &cr.Spec.AppFrameworkConfig)
458+
459+
return ss, nil
460+
}
461+
435462
// validateStandaloneSpec checks validity and makes default updates to a StandaloneSpec, and returns error if something is wrong.
436463
func validateStandaloneSpec(ctx context.Context, c splcommon.ControllerClient, cr *enterpriseApi.Standalone) error {
437464
if cr.Spec.Replicas < 0 {

0 commit comments

Comments
 (0)