@@ -77,6 +77,11 @@ public function deployExApp(ExApp $exApp, DaemonConfig $daemonConfig, array $par
7777 $ harpUrl = $ this ->buildHarpK8sUrl ($ daemonConfig );
7878 $ this ->initGuzzleClient ($ daemonConfig );
7979
80+ $ pingError = $ this ->ping ($ daemonConfig );
81+ if ($ pingError !== '' ) {
82+ return $ pingError ;
83+ }
84+
8085 $ roles = $ params ['k8s_service_roles ' ] ?? [];
8186
8287 if (empty ($ roles )) {
@@ -703,6 +708,42 @@ public function resolveExAppUrl(
703708 return sprintf ('%s/exapps/%s ' , $ url , $ appId );
704709 }
705710
711+ /**
712+ * Pre-flight check: verify HaRP has a working Kubernetes backend.
713+ *
714+ * Calls GET /info and inspects the kubernetes status fields.
715+ * Returns empty string on success, actionable error message on failure.
716+ */
717+ public function ping (DaemonConfig $ daemonConfig ): string {
718+ $ url = rtrim ($ daemonConfig ->getProtocol () . ':// ' . $ daemonConfig ->getHost (), '/ ' )
719+ . '/exapps/app_api/info ' ;
720+ try {
721+ $ response = $ this ->guzzleClient ->get ($ url , ['timeout ' => 5 ]);
722+ $ data = json_decode ((string )$ response ->getBody (), true );
723+
724+ $ k8s = $ data ['kubernetes ' ] ?? null ;
725+ if ($ k8s === null ) {
726+ return 'HaRP version is too old and does not report Kubernetes support. Please update HaRP. ' ;
727+ }
728+ if (!($ k8s ['enabled ' ] ?? false )) {
729+ return 'Kubernetes backend is disabled in HaRP. Set HP_K8S_ENABLED=true in HaRP configuration. ' ;
730+ }
731+ if (!($ k8s ['reachable ' ] ?? false )) {
732+ return sprintf (
733+ 'HaRP cannot reach the Kubernetes API server (%s). Check HP_K8S_API_SERVER, token, and network connectivity. ' ,
734+ $ k8s ['api_server ' ] ?? 'unknown '
735+ );
736+ }
737+ return '' ;
738+ } catch (GuzzleException $ e ) {
739+ $ this ->logger ->error (sprintf ('K8s pre-flight check failed: %s ' , $ e ->getMessage ()), ['exception ' => $ e ]);
740+ return sprintf ('Cannot reach HaRP: %s ' , $ e ->getMessage ());
741+ } catch (Exception $ e ) {
742+ $ this ->logger ->error (sprintf ('K8s pre-flight check failed: %s ' , $ e ->getMessage ()), ['exception ' => $ e ]);
743+ return sprintf ('K8s pre-flight check failed: %s ' , $ e ->getMessage ());
744+ }
745+ }
746+
706747 public function buildHarpK8sUrl (DaemonConfig $ daemonConfig ): string {
707748 $ url = $ daemonConfig ->getProtocol () . ':// ' . $ daemonConfig ->getHost ();
708749 return rtrim ($ url , '/ ' ) . '/exapps/app_api/k8s ' ;
0 commit comments