Skip to content

Commit 0ef64c4

Browse files
authored
Merge pull request #146 from renoki-co/fix/resource-version
[3.x] Fixed bug with metadata.resourceVersion was not updated
2 parents 6ed13bd + 1d31a8a commit 0ef64c4

File tree

5 files changed

+85
-0
lines changed

5 files changed

+85
-0
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ jobs:
8080
echo "some-namespace" | sudo tee /var/run/secrets/kubernetes.io/serviceaccount/namespace
8181
sudo chmod -R 777 /var/run/secrets/kubernetes.io/serviceaccount/
8282
83+
- name: Setting CRDs for testing
84+
run: |
85+
kubectl apply -f https://raw.githubusercontent.com/bitnami-labs/sealed-secrets/main/helm/sealed-secrets/crds/sealedsecret-crd.yaml
86+
8387
- name: Run tests
8488
run: |
8589
vendor/bin/phpunit --coverage-text --coverage-clover=coverage.xml

src/Traits/RunsClusterOperations.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,21 @@ public function refreshOriginal(array $query = ['pretty' => 1])
9595
return $this->syncOriginalWith($this->get($query)->toArray());
9696
}
9797

98+
/**
99+
* Make sure to sync the resource version with the original.
100+
*
101+
* @return $this
102+
*/
103+
public function refreshResourceVersion()
104+
{
105+
$this->setAttribute(
106+
'metadata.resourceVersion',
107+
$this->original['metadata']['resourceVersion']
108+
);
109+
110+
return $this;
111+
}
112+
98113
/**
99114
* Create or update the resource, wether the resource exists
100115
* or not within the cluster.
@@ -219,6 +234,7 @@ public function create(array $query = ['pretty' => 1])
219234
public function update(array $query = ['pretty' => 1]): bool
220235
{
221236
$this->refreshOriginal();
237+
$this->refreshResourceVersion();
222238

223239
// If it didn't change, no way to trigger the change.
224240
if (! $this->hasChanged()) {

tests/Kinds/SealedSecret.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace RenokiCo\PhpK8s\Test\Kinds;
4+
5+
use RenokiCo\PhpK8s\Contracts\InteractsWithK8sCluster;
6+
use RenokiCo\PhpK8s\Kinds\K8sResource;
7+
use RenokiCo\PhpK8s\Traits\Resource\HasSelector;
8+
use RenokiCo\PhpK8s\Traits\Resource\HasSpec;
9+
use RenokiCo\PhpK8s\Traits\Resource\HasStatus;
10+
use RenokiCo\PhpK8s\Traits\Resource\HasStatusConditions;
11+
use RenokiCo\PhpK8s\Traits\Resource\HasTemplate;
12+
13+
class SealedSecret extends K8sResource implements InteractsWithK8sCluster
14+
{
15+
use HasSelector;
16+
use HasSpec;
17+
use HasStatus;
18+
use HasStatusConditions;
19+
use HasTemplate;
20+
21+
/**
22+
* The resource Kind parameter.
23+
*
24+
* @var string|null
25+
*/
26+
protected static $kind = 'SealedSecret';
27+
28+
/**
29+
* The default version for the resource.
30+
*
31+
* @var string
32+
*/
33+
protected static $defaultVersion = 'bitnami.com/v1alpha1';
34+
35+
/**
36+
* Wether the resource has a namespace.
37+
*
38+
* @var bool
39+
*/
40+
protected static $namespaceable = true;
41+
}

tests/YamlTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use RenokiCo\PhpK8s\Test\Kinds\IstioGateway;
66
use RenokiCo\PhpK8s\Test\Kinds\IstioGatewayNoNamespacedVersion;
7+
use RenokiCo\PhpK8s\Test\Kinds\SealedSecret;
78

89
class YamlTest extends TestCase
910
{
@@ -119,4 +120,20 @@ public function test_yaml_import_for_crds_without_namespace()
119120

120121
$this->assertInstanceOf(IstioGatewayNoNamespacedVersion::class, $gateway);
121122
}
123+
124+
public function test_creation_and_update_from_yaml_file()
125+
{
126+
SealedSecret::register('sealedSecret');
127+
128+
$ss = $this->cluster->fromYamlFile(__DIR__.'/yaml/sealedsecret.yaml');
129+
$ss->createOrUpdate();
130+
131+
$ss = $this->cluster->fromYamlFile(__DIR__.'/yaml/sealedsecret.yaml');
132+
$ss->createOrUpdate();
133+
134+
$this->assertInstanceOf(SealedSecret::class, $ss);
135+
$this->assertTrue($ss->exists());
136+
137+
$ss->delete();
138+
}
122139
}

tests/yaml/sealedsecret.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: bitnami.com/v1alpha1
2+
kind: SealedSecret
3+
metadata:
4+
name: mysecret
5+
spec:
6+
encryptedData:
7+
foo: AgBy3i4OJSWK+PiTySYZZA9rO43cGDEq

0 commit comments

Comments
 (0)