How-to guide / Adopt existing resources
Add explicit ordering with extraDeps
These docs describe Kix's main branch, which can include changes not yet released. Read the docs for the latest release.
Use an instance-level extraDeps edge when an imported instance’s marker must
follow a managed prerequisite, but no manifest field carries a reference
between them.
The example below imports an existing legacy-api Service. Its
PackageInstance marker should be recorded only after Kix deploys a managed
compatibility contract.
Add the explicit edge
Section titled “Add the explicit edge”Make the cluster module accept ref, then point the imported instance at the
managed prerequisite:
25 legacy.legacy-api = {26 package = kix.mkImport {27 kind = "Service";28 apiVersion = "v1";29 out = {30 name = "legacy-api";31 fqdn = "legacy-api.legacy.svc.${config.clusterDomain}";32 port = 8080;33 };34 };35 aliases = [ "legacyApi" ];36
37 extraDeps = [ ref.apps.legacy-api-contract ];38 };39
40 apps.legacy-api-contract.package = contractPackage;The reference has the form ref.<namespace>.<instance>. In extraDeps it
stands for that instance’s PackageInstance marker, which is itself ordered
after the instance’s resources. The reference does not activate an optional
instance; something else must, such as a required dependency.
extraDeps adds an ordering edge to the imported instance’s marker. It does
not modify, deploy, or check the imported Kubernetes resource.
Check the cluster
Section titled “Check the cluster”Evaluate the complete cluster:
❱ kix check how-to-adoption
TOOL RESULT DETAILS
eval pass 19 manifests evaluated
scorecard pass 0 errors, 14 warnings, 2 info
architecture.annotationDomainOwnership (warning), 1:
apps/client: 'client' uses annotations under domain 'example.com' (ConfigMap/legacy-api-client) but no package in this cluster declares that it handles them. Add the operator package that handles these annotations. If something outside Kix consumes this domain, declare it in `scorecard.knownAnnotationDomains`.
governance.hasOwner (warning), 4:
apps/client: package 'client' has no meta.owner
apps/helm-web: package 'helm-web' has no meta.owner
apps/legacy-api-contract: package 'legacy-api-contract' has no meta.owner
apps/legacy-web: package 'legacy-web' has no meta.owner
reliability.boundedResources (warning), 2:
apps/helm-web/helm-web: container 'nginx' is missing resource settings: limits.cpu. Set CPU and memory requests and limits.
apps/legacy-web/legacy-web: container 'nginx' is missing resource settings: limits.cpu. Set CPU and memory requests and limits.
reliability.hasProbes (warning), 2:
apps/helm-web/helm-web: container 'nginx' has no livenessProbe
apps/legacy-web/legacy-web: container 'nginx' has no livenessProbe
security.hasNetworkPolicy (warning), 1:
apps: namespace 'apps' has workloads but no network policy
security.nonRoot (warning), 2:
apps/helm-web/helm-web: container 'nginx' may run as root: neither it nor the pod sets securityContext.runAsNonRoot, and no non-zero runAsUser resolves for it
apps/legacy-web/legacy-web: container 'nginx' may run as root: neither it nor the pod sets securityContext.runAsNonRoot, and no non-zero runAsUser resolves for it
security.readOnlyRootfs (warning), 2:
apps/helm-web/helm-web: container 'nginx' does not set readOnlyRootFilesystem
apps/legacy-web/legacy-web: container 'nginx' does not set readOnlyRootFilesystem
2 info finding(s) not listed; run with -v to list them. Evaluation fails for a missing namespace or instance in the ref path, for
an entry that is neither a resource nor a ref, and for a ref to the
import itself, even when the import is optional and inactive. It also fails
for a ref to an optional instance that is not active. Fix the
entry before inspecting the graph.
Verify the order
Section titled “Verify the order”Print the dependency tree:
❱ kix graph how-to-adoption -o tree Show outputHide output · 7 lines
├── ConfigMap/legacy-api-contract@apps
│ └── PackageInstance.kix.run/legacy-api-contract@apps
│ ├── PackageInstance.kix.run/legacy-api@legacy (import)
├── PackageInstance.kix.run/legacy-api-contract@apps
│ ├── PackageInstance.kix.run/legacy-api@legacy (import)
└── PackageInstance.kix.run/legacy-api@legacy (import)
19 resources, 31 dependencies The relevant chain is:
ConfigMap/legacy-api-contract@appsis deployed.PackageInstance.kix.run/legacy-api-contract@appsrecords the managed instance.PackageInstance.kix.run/legacy-api@legacyrecords the import.
Use extraDeps only when the ordering relationship has no corresponding
manifest value. Reading a dependency’s tracked out value already creates an
edge, so adding another one is unnecessary.
At the cluster instance level, extraDeps applies only to kix.mkImport
instances. A managed instance with extraDeps fails evaluation. Package
authors set requires or extraDeps on the individual resource that needs
the ordering constraint instead.
This edge does not automatically order packages that consume manually declared import outputs. If a consumer must wait for the same prerequisite, declare that dependency in the consumer as well.