Skip to content
Install the CLI

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.

Make the cluster module accept ref, then point the imported instance at the managed prerequisite:

how-to/adoption/cluster.nix
legacy.legacy-api = {
package = kix.mkImport {
kind = "Service";
apiVersion = "v1";
out = {
name = "legacy-api";
fqdn = "legacy-api.legacy.svc.${config.clusterDomain}";
port = 8080;
};
};
aliases = [ "legacyApi" ];
extraDeps = [ ref.apps.legacy-api-contract ];
};
apps.legacy-api-contract.package = contractPackage;

View source on GitHub ↗

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.

Evaluate the complete cluster:

kix-examples/
❱ 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.

Print the dependency tree:

kix-examples/ output excerpt offline capture
❱ 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:

  1. ConfigMap/legacy-api-contract@apps is deployed.
  2. PackageInstance.kix.run/legacy-api-contract@apps records the managed instance.
  3. PackageInstance.kix.run/legacy-api@legacy records 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.