@@ -785,28 +785,55 @@ func isAppAlreadyInstalled(ctx context.Context, cr splcommon.MetaObject, podExec
785785
786786 scopedLog .Info ("check app's installation state" )
787787
788- command := fmt .Sprintf ("/opt/splunk/bin/splunk list app %s -auth admin:`cat /mnt/splunk-secrets/password`| grep ENABLED; echo -n $? " , appTopFolder )
788+ command := fmt .Sprintf ("/opt/splunk/bin/splunk list app %s -auth admin:`cat /mnt/splunk-secrets/password`| grep ENABLED" , appTopFolder )
789789
790790 streamOptions := splutil .NewStreamOptionsObject (command )
791791
792792 stdOut , stdErr , err := podExecClient .RunPodExecCommand (ctx , streamOptions , []string {"/bin/sh" })
793793
794+ // Handle specific stderr cases first
794795 if strings .Contains (stdErr , "Could not find object" ) {
795796 // when app is not installed you will see something like on StdErr:
796797 // "Could not find object id=<app_name>"
797798 // which mean app is not installed (no need to check enabled at this time)
798799 return false , nil
799800 }
800801
801- if stdErr != "" || err != nil {
802- return false , fmt .Errorf ("could not get installed app status stdOut: %s, stdErr: %s, command: %s" , stdOut , stdErr , command )
802+ // Handle FIPS messages in stderr - these are informational, not errors
803+ if stdErr != "" && strings .Contains (stdErr , "FIPS provider enabled" ) {
804+ scopedLog .Info ("FIPS provider informational message detected" , "stderr" , stdErr )
805+ // Continue processing - FIPS messages don't indicate failure
806+ } else if stdErr != "" {
807+ // Log warning for any other stderr content we haven't seen before
808+ scopedLog .Info ("Unexpected stderr content detected - please review" , "stderr" , stdErr , "command" , command )
803809 }
804810
805- appInstallCheck , _ := strconv .Atoi (stdOut )
811+ // Now check the actual command result
812+ if err != nil {
813+ // Kubernetes exec returns different error types for different exit codes
814+ // For grep: exit code 1 = pattern not found, exit code 2+ = actual error
815+ errMsg := err .Error ()
816+
817+ // Check for grep exit code 1 (pattern not found)
818+ if strings .Contains (errMsg , "exit status 1" ) || strings .Contains (errMsg , "command terminated with exit code 1" ) {
819+ // grep exit code 1 means "ENABLED" pattern not found - app is not enabled
820+ scopedLog .Info ("App not enabled - grep pattern not found" , "stdout" , stdOut , "stderr" , stdErr )
821+ return false , nil
822+ }
823+
824+ // Any other exit code indicates a real error (splunk command failed, etc.)
825+ return false , fmt .Errorf ("could not get installed app status stdOut: %s, stdErr: %s, error: %v, command: %s" , stdOut , stdErr , err , command )
826+ }
806827
807- scopedLog .Info ("Apps installation state" , stdOut , stdOut )
828+ // If we reach here, grep found "ENABLED" (exit code 0)
829+ // stdOut should contain the app status line with "ENABLED"
830+ if stdOut == "" {
831+ // This shouldn't happen if grep succeeded, but let's be safe
832+ return false , fmt .Errorf ("command succeeded but no output received, command: %s" , command )
833+ }
808834
809- return appInstallCheck == 0 , nil
835+ scopedLog .Info ("App installation state check successful - app is enabled" , "appStatus" , strings .TrimSpace (stdOut ))
836+ return true , nil
810837}
811838
812839// get the name of top folder from the package.
0 commit comments