Skip to content

Commit 47465d9

Browse files
cuppettclaude
andcommitted
Fix scale subresource operations for ReplicaSet
- Override create() and update() in K8sScale to use REPLACE_OP (PUT) instead of CREATE_OP (POST) since scale subresources only support PUT - Update ReplicaSetTest to use the correct scale() pattern that matches StatefulSetTest implementation - Scale operations now properly update the replica count on the cluster Fixes integration test scaling errors where scale API was returning 404 for POST operations. Scale subresources require PUT to the resource's scale path (e.g., /apis/apps/v1/namespaces/default/replicasets/{name}/scale). Generated with Claude Code Co-Authored-By: Claude <[email protected]>
1 parent 5887173 commit 47465d9

File tree

2 files changed

+56
-12
lines changed

2 files changed

+56
-12
lines changed

src/Kinds/K8sScale.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,55 @@ public function refreshOriginal(array $query = ['pretty' => 1])
8787

8888
return parent::refreshOriginal($query);
8989
}
90+
91+
/**
92+
* Create the scale resource.
93+
* Scale subresources should use replace (PUT) operations, not create (POST).
94+
* Scale subresources don't support POST, so we use PUT to the scale subresource path.
95+
*
96+
* @param array $query
97+
* @return \RenokiCo\PhpK8s\Kinds\K8sResource
98+
*
99+
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesAPIException
100+
*/
101+
public function create(array $query = ['pretty' => 1])
102+
{
103+
return $this->cluster
104+
->setResourceClass(get_class($this))
105+
->runOperation(
106+
\RenokiCo\PhpK8s\KubernetesCluster::REPLACE_OP,
107+
$this->resourcePath(),
108+
$this->toJsonPayload(),
109+
$query
110+
);
111+
}
112+
113+
/**
114+
* Update the scale resource.
115+
* This is the correct operation for scale subresources.
116+
* Scale is updated via PUT to the scale subresource path.
117+
*
118+
* @param array $query
119+
* @return bool
120+
*
121+
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesAPIException
122+
*/
123+
public function update(array $query = ['pretty' => 1]): bool
124+
{
125+
$this->refreshOriginal();
126+
$this->refreshResourceVersion();
127+
128+
$instance = $this->cluster
129+
->setResourceClass(get_class($this))
130+
->runOperation(
131+
\RenokiCo\PhpK8s\KubernetesCluster::REPLACE_OP,
132+
$this->resourcePath(),
133+
$this->toJsonPayload(),
134+
$query
135+
);
136+
137+
$this->syncWith($instance->toArray());
138+
139+
return true;
140+
}
90141
}

tests/ReplicaSetTest.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -183,26 +183,19 @@ public function runScalingTests()
183183

184184
$this->assertTrue($rs->isSynced());
185185

186-
$scaler = $rs->scaler();
187-
$scaler->setReplicas(2);
188-
189-
$this->assertEquals(2, $scaler->getReplicas());
190-
191-
$scaler->create();
192-
193-
sleep(1);
186+
$scaler = $rs->scale(2);
194187

195188
$this->assertTrue($rs->isSynced());
196-
$this->assertEquals(2, $rs->getReplicas());
197189

198-
$rs->refresh();
190+
while ($rs->getReadyReplicasCount() < 2 || $scaler->getReplicas() < 2) {
191+
$scaler->refresh();
192+
$rs->refresh();
199193

200-
while ($rs->getReadyReplicasCount() !== 2) {
201194
sleep(1);
202-
$rs->refresh();
203195
}
204196

205197
$this->assertEquals(2, $rs->getReadyReplicasCount());
198+
$this->assertEquals(2, $scaler->getReplicas());
206199
}
207200

208201
public function runUpdateTests()

0 commit comments

Comments
 (0)