kusion icon indicating copy to clipboard operation
kusion copied to clipboard

Bugfix: Kusion may throw resource dependency errors in a valid change

Open ffforest opened this issue 2 years ago • 0 comments

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, 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

$ kusion version
# paste output here

OS version

# 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

ffforest avatar Sep 06 '23 08:09 ffforest