• Fix an Internal Server Error while creating K8s CloudServerTemplate when specified invalid API server endpoint hostname and/or invalid token

Drupal\k8s\Service\K8sServiceException: cURL error 7: Failed to connect to 192.168.0.1 port 6443: Connection timed out (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) in Drupal\k8s\Service\K8sClientExtension\K8sClient->sendRequest() (line 147 of /var/www/html/web/modules/contrib/cloud/modules/cloud_service_providers/k8s/src/Service/K8sClientExtension/K8sClient.php).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

yas created an issue. See original summary.

yas’s picture

Status: Needs work » Needs review
FileSize
8.53 KB
yas’s picture

@all

Please review the patch.

Thanks

yas’s picture

baldwinlouie’s picture

Status: Needs review » Needs work

@yas, I have the following comment about this patch.

+++ b/modules/cloud_service_providers/k8s/src/Form/K8sCreateForm.php
@@ -36,11 +40,54 @@ class K8sCreateForm extends K8sContentForm {
+      $cloud_service_providers = $this->entityTypeManager
+        ->getStorage('cloud_config')
+        ->loadByProperties([
+          'type' => 'k8s',
+          'cloud_context' => $cloud_context,
+        ]);
+
+      if (!empty($cloud_service_providers)) {
+
+        $cloud_service_provider = array_shift($cloud_service_providers);
+        $name = $cloud_service_provider->getName();
+
+        $page_link = Link::fromTextAndUrl(
+          $name, Url::fromRoute(
+            'entity.cloud_config.edit_form',
+            ['cloud_config' => $cloud_service_provider->id()]
+          )
+        )->toString();
+
+        \Drupal::messenger()->addError(
+          t('The endpoint is unreachable. Please check the API server and token: @page_link', [
+            '@page_link' => $page_link,
+          ])
+        );
+      }
+
+      $this->messenger->addError($e->getMessage());
+
+      $url = Url::fromRoute("entity.{$this->entity->getEntityTypeId()}.collection", [
+        'cloud_context' => $cloud_context,
+      ]);
+
+      $redirect_response = new RedirectResponse($url->toString());
+      $redirect_response->send();
+      $this->messenger->addError($e->getMessage());

Can some of this be abstracted into a common method in K8sContentForm?

I ask because the same logic appears in K8sNamespaceCreateForm as well.

yas’s picture

Status: Needs work » Needs review
FileSize
11.7 KB
786.42 KB

@baldwinlouie

Thank you for your review. I updated the patch. Could you please review the patch again?

screenshot-2019-12-31a.png

yas’s picture

Updated.

yas’s picture

Updated.

baldwinlouie’s picture

Status: Needs review » Needs work

@yas, thank you for the updated patch. I have two more comments below.

  1. +++ b/modules/cloud_service_providers/k8s/src/Service/K8sService.php
    @@ -1725,12 +1731,72 @@ class K8sService implements K8sServiceInterface {
    +    \Drupal::messenger()->addError(
    +      t('The endpoint is unreachable.')
    +    );
    

    Can you use $this->messenger instead of \Drupal::messenger()?

  2. +++ b/modules/cloud_service_providers/k8s/src/Service/K8sService.php
    @@ -1725,12 +1731,72 @@ class K8sService implements K8sServiceInterface {
    +      \Drupal::messenger()->addError(
    +        t('Please check the API server and token: @page_link', [
    +          '@page_link' => $page_link,
    +        ])
    +      );
    

    Can you use $this->messenger instead of \Drupal::messenger()

yas’s picture

Status: Needs work » Needs review
FileSize
19.5 KB
757 bytes

@baldwinlouie

Thank you for your review. I've updated the patch; so could you please review it again?

yas’s picture

Fixing coding violations

baldwinlouie’s picture

Status: Needs review » Reviewed & tested by the community

@yas,. Looks good!

yas’s picture

@baldwinlouie

Thank you for your review. I'll merge the patch to 8.x-2.x and close this issue as Fixed.

  • yas committed e3b085e on 8.x-2.x
    Issue #3102906 by yas, baldwinlouie: Fix an Internal Server Error while...
yas’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.