Skip to content
Snippets Groups Projects
Commit dc80bc7e authored by Masami  Suzuki's avatar Masami Suzuki Committed by Yas Naoi
Browse files

Issue #3215747 by Masami, yas: Fix an issue while launching K8s launch template (1) (Bugfix)

parent f6750822
No related branches found
No related tags found
No related merge requests found
......@@ -2229,13 +2229,38 @@ function k8s_create_resources_message(array &$form, array $resources) {
$entity = \Drupal::entityTypeManager()
->getStorage($type)
->load($id);
if (isset($entity)) {
\Drupal::messenger()->addWarning(t('@type: <a href=":url">%name</a>', [
'@type' => \Drupal::entityTypeManager()->getDefinition($entity->bundle())->getSingularLabel(),
'%name' => $entity->getName(),
':url' => $entity->toUrl('canonical')->toString(),
]));
if (empty($entity)) {
continue;
}
$namespaceable = $entity->getEntityType()->get('namespaceable');
$message = '';
// We can't use empty() here since $namespaceable can be one of two values
// such as FALSE or NULL.
if (!isset($namespaceable) && !($entity instanceof K8sNamespace)) {
$namespaces = \Drupal::entityTypeManager()
->getStorage('k8s_namespace')
->loadByProperties([
'name' => $entity->getNamespace(),
'cloud_context' => $entity->getCloudContext(),
]);
if (!empty($namespaces)) {
$namespace = reset($namespaces);
$message = t('(Namespace: <a href=":url">%name</a>)', [
'%name' => $namespace->getName(),
':url' => $namespace->toUrl('canonical')->toString(),
]);
}
}
\Drupal::messenger()->addWarning(t('@type: <a href=":url">%name</a> @namespace', [
'@type' => $entity->getEntityType()->getSingularLabel(),
'%name' => $entity->getName(),
':url' => $entity->toUrl('canonical')->toString(),
'@namespace' => $message,
]));
}
$messages = \Drupal::messenger()->deleteAll();
......
......@@ -733,13 +733,15 @@ class K8sCloudServerTemplatePlugin extends CloudPluginBase implements CloudServe
'metadata.name' => $result['metadata']['name'],
], FALSE);
$params = [
'cloud_context' => $cloud_server_template->getCloudContext(),
'name' => $result['metadata']['name'],
];
$params += !empty($namespaceable) ? ['namespace' => $result['metadata']['namespace']] : [];
// Update creation_yaml field of entity.
$entities = $this->entityTypeManager->getStorage($entity_type_id)->loadByProperties(
[
'cloud_context' => $cloud_server_template->getCloudContext(),
'name' => $result['metadata']['name'],
]
);
$entities = $this->entityTypeManager->getStorage($entity_type_id)->loadByProperties($params);
if (!empty($entities)) {
$entity = reset($entities);
......
......@@ -558,7 +558,9 @@ class CloudServerTemplateTest extends K8sTestBase {
foreach ($items ?: [] as $item) {
$this->$addMockDataFunction($item);
$entities[] = $this->$createTestEntityFunction($item);
$param = ['name' => $item['name']];
$param += !empty($item['post_data']['namespace']) ? ['namespace' => $item['post_data']['namespace']] : [];
$entities[] = $this->$createTestEntityFunction($param);
$this->$deleteMockDataFunction($item);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment