Skip to content

Commit 50c0001

Browse files
committed
Include namespace in ->toArray() variant
1 parent 6c7b9db commit 50c0001

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/Kinds/K8sResource.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33
namespace RenokiCo\PhpK8s\Kinds;
44

55
use Closure;
6-
use Illuminate\Contracts\Support\Arrayable;
7-
use Illuminate\Contracts\Support\Jsonable;
6+
use Illuminate\Support\Arr;
87
use Illuminate\Support\Str;
9-
use RenokiCo\PhpK8s\Exceptions\KubernetesAPIException;
10-
use RenokiCo\PhpK8s\KubernetesCluster;
11-
use RenokiCo\PhpK8s\Traits\HasAnnotations;
12-
use RenokiCo\PhpK8s\Traits\HasAttributes;
138
use RenokiCo\PhpK8s\Traits\HasKind;
14-
use RenokiCo\PhpK8s\Traits\HasLabels;
159
use RenokiCo\PhpK8s\Traits\HasName;
16-
use RenokiCo\PhpK8s\Traits\HasNamespace;
10+
use RenokiCo\PhpK8s\Traits\HasLabels;
11+
use RenokiCo\PhpK8s\KubernetesCluster;
1712
use RenokiCo\PhpK8s\Traits\HasVersion;
13+
use RenokiCo\PhpK8s\Traits\HasNamespace;
14+
use RenokiCo\PhpK8s\Traits\HasAttributes;
15+
use Illuminate\Contracts\Support\Jsonable;
16+
use RenokiCo\PhpK8s\Traits\HasAnnotations;
17+
use Illuminate\Contracts\Support\Arrayable;
1818
use RenokiCo\PhpK8s\Traits\RunsClusterOperations;
19+
use RenokiCo\PhpK8s\Exceptions\KubernetesAPIException;
1920

2021
class K8sResource implements Arrayable, Jsonable
2122
{
@@ -93,7 +94,14 @@ public function getByName(string $name, array $query = ['pretty' => 1])
9394
*/
9495
public function toArray(string $kind = null)
9596
{
96-
return array_merge($this->attributes, [
97+
$attributes = $this->attributes;
98+
99+
// Make sure to also include the namespace.
100+
if (static::$namespaceable) {
101+
Arr::set($attributes, 'metadata.namespace', $this->getNamespace());
102+
}
103+
104+
return array_merge($attributes, [
97105
'kind' => $kind ?: $this::getKind(),
98106
'apiVersion' => $this->getApiVersion(),
99107
]);

0 commit comments

Comments
 (0)