Skip to content

Bring Cluster Resources into ConfigHub

Configuration reaches a cluster from ConfigHub through Releases. This guide covers the other direction: tracing a live resource back to the Unit it came from, keeping a change someone made in the cluster, and recording facts about the cluster on its Target. The cub k8s source, refresh and collect commands do these. They read the cluster with your kubeconfig, as kubectl does, from $KUBECONFIG or ~/.kube/config, or from --kubeconfig and --kube-context. ConfigHub itself never connects to the cluster.

Finding where a resource came from

Every resource a Release deploys carries a confighub.com/origin annotation naming the Space, Unit and Revision it came from. cub k8s source reads it from the live resource and opens the Unit in the UI:

cub k8s source deployment backend --namespace app
cub k8s source clusterrole app-reader

A resource without the annotation wasn't deployed by a ConfigHub Release. From there, cub unit blame says who set each field of the Unit, in which Revision, and under which ChangeOrder.

Keeping a change made in the cluster

During an incident, someone may change a resource in the cluster directly, with kubectl or a controller's UI. The next Release overwrites that change, because a Release deploys what the Unit holds. To keep it, bring it back into the Unit with cub k8s refresh, previewing it first:

cub k8s refresh deployment backend --namespace app --dry-run
cub k8s refresh deployment backend --namespace app --change-desc "Keep the memory limit raised during the incident"

Refresh finds the Unit by the resource's confighub.com/origin annotation, so it takes no --space. It reads the live resource and strips what is cluster state rather than configuration: status, managedFields, cluster-internal metadata, and every field only a controller owns, such as the replica count an HPA sets. It diffs what is left against the Revision last released to the cluster, the Unit's LastReleasedRevisionNum, so that changes made in ConfigHub since the Release aren't mistaken for drift, and patches the difference onto the Unit's head. Only that resource and the paths that changed are written. k8s-mf cleanup shows the stripping on its own, for a field refresh brings back that you didn't expect.

A path with a guard, such as the Override guard on a variant's own value, is not overwritten unless --clearance covers the guard, and is reported as a conflict instead. --guard records a guard on the paths refresh writes, so the next merge from upstream doesn't undo the change either. A Unit that has never been released has nothing to diff against, and refresh refuses it.

The cluster already runs the change, so publishing a Release afterwards changes nothing there; it makes what ConfigHub released match what is running. Live resources describes refresh in more detail, including a caveat about Argo CD's default resource tracking label.

Recording facts about a cluster

A Target's Facts are properties of the cluster it represents. Two things record them: cub k8s collect, run by you, and k8sbot, each time it starts in a cluster connected with cub cluster attach. To collect them yourself:

cub k8s collect --kube-context prod-eu --dry-run
cub k8s collect --space platform --kube-context prod-eu prod-eu-target

Each fact is a string, and a list is comma-separated. The facts of an EKS cluster look like this, with the long lists shortened:

Cluster.Name: prod
Cluster.Distribution: eks
Cluster.KubernetesVersion: 1.33.1-eks-91f89a9
Cluster.NamespaceScopedResourceTypes: apps/v1/DaemonSet,apps/v1/Deployment,apps/v1/StatefulSet,...
Cluster.ClusterScopedResourceTypes: admissionregistration.k8s.io/v1/ValidatingWebhookConfiguration,...
Cluster.NamespaceScopedCRDs: argoproj.io/v1alpha1/Application,cert-manager.io/v1/Certificate,...
Cluster.ClusterScopedCRDs: cert-manager.io/v1/ClusterIssuer,external-secrets.io/v1/ClusterSecretStore,...
Cluster.StorageClasses: gp2,gp3
Cluster.DefaultStorageClass: gp3
Cluster.IngressClasses: traefik
Cluster.NetworkPolicyEnforcer: aws-vpc-cni

cub k8s collect also records Cluster.Zones and Cluster.NodeLabelKeys, the zones and label keys of the cluster's nodes, when it may list Nodes. Collected facts are kept under the reserved prefix Cluster., which collection owns: a later collection rewrites them and removes the ones the cluster no longer has. Cluster.Name can't be read from the cluster, so it is set from --cluster-name, or from --kube-context.

Facts outside the prefix are yours, and collection leaves them alone:

cub target update --patch --space platform prod-eu-target --fact Region=eu-west-1

Facts are used in three places:

  • Selecting Targets, in a where filter: cub target list --space "*" --where "Facts.Cluster.Distribution = 'eks' AND Facts.Cluster.KubernetesVersion LIKE '1.33.%'".
  • Validating against the cluster. vet-schemas checks a Unit against the schemas of its Target's Kubernetes version, from Cluster.KubernetesVersion, rather than a fixed one.
  • Functions, which receive the facts of the Unit's Target as TargetFacts.

Resources ConfigHub doesn't hold yet

These commands work on resources a Release deployed. To bring in resources that were deployed some other way, start from what produced them rather than from the live objects, which hold cluster state, defaulted fields and fields controllers write alongside the configuration: