Skip to content

Commit 3f68f12

Browse files
authored
Merge pull request #96 from renoki-co/fix/namespace-in-array
[2.x] Include namespace in ->toArray() variant
2 parents 6c7b9db + b90853c commit 3f68f12

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Kinds/K8sResource.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Closure;
66
use Illuminate\Contracts\Support\Arrayable;
77
use Illuminate\Contracts\Support\Jsonable;
8+
use Illuminate\Support\Arr;
89
use Illuminate\Support\Str;
910
use RenokiCo\PhpK8s\Exceptions\KubernetesAPIException;
1011
use RenokiCo\PhpK8s\KubernetesCluster;
@@ -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)