delete() does not remove resources imported from YAML
buzanits opened this issue · 4 comments
I can create and update resources with
$x = $cluster->fromYaml($code);
$x->createOrUpdate();
But when doing
$x = $cluster->fromYaml($code);
$x->delete();
with the same $code
the resources do not get deleted. Deleting works when I do
kubectl delete -f code.yaml
having the content of $code
in the code.yaml
.
btw this is the $code
used in this test:
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-test1
spec:
storageClassName: ""
capacity:
storage: 1Gi
accessModes:
- ReadOnlyMany
persistentVolumeReclaimPolicy:
mountOptions:
- hard
- nfsvers=4.1
nfs:
path: /srv/nfs/test1
server: 10.255.3.203
readOnly: false
Interesting discovery: It works if you do
$x = $cluster->fromYaml($code);
$x->update();
$x->delete();
So updating seems to load the object and then it can be deleted. But this is a quick & dirty workaround, I think.
In the fromYaml
documentation, it's stated clearly that the resources are not synced (https://php-k8s.renoki.org/interacting-with-the-cluster/import-from-yaml?q=fromyaml):
Keep in mind, the resources are not synced, since it's not known if they exist already or not. So everything you have to do is to loop through them and make sure to call ->create() if it's needed or sync them using ->createOrUpdate()
Additionally, syncWithCluster
can be used to avoid updating the state, and instead create it if it does not exist, or fetch it to delete.
For everyone who finds this thread: It also works with
$x = $cluster->fromYaml($code);
$x->refresh();
$x->delete();