Skip to content

Commit

Permalink
feat: support metadata and labels on AbstractResource
Browse files Browse the repository at this point in the history
  • Loading branch information
joostfaassen committed Jan 3, 2020
1 parent 945b331 commit edd5b2e
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/Resource/AbstractResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ abstract class AbstractResource implements ResourceInterface
protected $graph;
protected $typeName;
protected $spec = [];
protected $metadata = [];

protected function __construct(Graph $graph)
{
Expand All @@ -30,6 +31,7 @@ public static function fromConfig(Graph $graph, array $config)
if (!isset($metadata['name'])) {
throw new RuntimeException("Name missing on resource");
}
$resource->metadata = $metadata;
$resource->name = $metadata['name'];

if (!isset($config['kind'])) {
Expand Down Expand Up @@ -66,6 +68,11 @@ public function getSpec()
return $this->spec;
}

public function getMetadata()
{
return $this->metadata;
}

public function offsetSet($offset, $value) {
throw new RuntimeException("Read only array access");
}
Expand All @@ -88,11 +95,21 @@ public function serialize()
{
$data = [
'kind' => $this->getTypeName(),
'metadata' => [
'name' => $this->getName()
],
'metadata' => $this->getMetadata(),
'spec' => $this->spec
];
return $data;
}

public function getLabels()
{
$data = [];
foreach ($this->getMetadata()['labels'] as $k=>$v) {
$data[] = [
'key' => $k,
'value' => $v,
];
}
return $data;
}
}

0 comments on commit edd5b2e

Please sign in to comment.