KusionStack / KusionStack/kusion
Bugfix: Kusion may throw resource dependency errors in a valid change
- Dominant language
- Go
- Stars
- 1.3k
- Forks
- 108
- Avg merge
- 11m
- Merged PRs (30d)
- 1
Description
### What happened?
If two `Services` are created alongside a workload, and later on I tried to remove one of them, `kusion` throws an dependency error where it cannot delete the service because the workload "depends on it", where as deleting one of the two services without having to delete the workload first is a perfectly valid use case.
See below:
```
~/playground/code-city/my-app/dev/single-stack-sample/dev$ kusion apply
✔︎ Generating Spec in the Stack dev...
❌ preview failed.
Kind: ERROR, Code: INTERNAL, Message: apps/v1:Deployment:helloworld:helloworld-dev-nginx dependson v1:Service:helloworld:helloworld-dev-nginx-public, cannot delete resource v1:Service:helloworld:helloworld-dev-nginx-public
```
### What did you expect to happen?
I can delete `Service` without having to delete `Deployment`
### How can we reproduce it (as minimally and precisely as possible)?
```
import catalog.models.schema.v1 as ac
import catalog.models.schema.v1.workload as wl
import catalog.models.schema.v1.workload.network as n
import catalog.models.schema.v1.workload.container as c
nginx: ac.AppConfiguration {
workload: wl.Service {
containers: {
"nginx": c.Container {
image = "nginx"
resources: {
"cpu": "500m"
"memory": "512Mi"
}
}
}
replicas: 1
ports: [
n.Port {
port: 80
}
n.Port {
port: 443
public: True
}
]
}
}
```
Apply the above first, then remove the `443` port and apply again.
### Anything else we need to know?
Currently the resource dependency is calculated using [this static list](https://github.com/KusionStack/kusion/blob/main/pkg/generator/appconfiguration/generator/ordered_resources_generator.go#L11-L36), based on the resource Kind, which means a resource Kind that appears first in the list are the dependencies for one that appear later. e.g. All deployments depends on all services, which means you cannot delete a service without deleting the deployment first, which seems unreasonable.
### Kusion version
```console
$ kusion version
# paste output here
```
### OS version
```console
# On Linux:
$ cat /etc/os-release
# paste output here
$ uname -a
# paste output here
# On Windows:
C:\> wmic os get Caption, Version, BuildNumber, OSArchitecture
# paste output here
```
### Install tools
Contributor guide
Assessment
This issue has not been assessed yet.