Skip to content

Commit

Permalink
Add new values to the k8s.node resource
Browse files Browse the repository at this point in the history
- Fetch the creation date, the port, and the overall OS config.

Signed-off-by: Tim Smith <[email protected]>
  • Loading branch information
tas50 committed Dec 22, 2024
1 parent 916c468 commit ea13220
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 4 deletions.
6 changes: 6 additions & 0 deletions providers/k8s/resources/k8s.lr
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ private k8s.node @defaults("name labels['kubernetes.io/arch'] labels['kubernetes
name string
// Kubernetes object type
kind string
// Kubernetes object creation timestamp
created time
// Node configuration information
nodeInfo dict
// Kubelet port
kubeletPort int
}

// Kubernetes Pod
Expand Down
36 changes: 36 additions & 0 deletions providers/k8s/resources/k8s.lr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions providers/k8s/resources/k8s.lr.manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -488,12 +488,18 @@ resources:
fields:
annotations:
min_mondoo_version: 5.29.2
created:
min_mondoo_version: 9.0.0
id:
min_mondoo_version: 6.10.0
kind: {}
kubeletPort:
min_mondoo_version: 9.0.0
labels:
min_mondoo_version: 5.29.2
name: {}
nodeInfo:
min_mondoo_version: 9.0.0
resourceVersion:
min_mondoo_version: 5.29.2
uid: {}
Expand Down
19 changes: 15 additions & 4 deletions providers/k8s/resources/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,32 @@ func initK8sNode(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[str
func (k *mqlK8s) nodes() ([]interface{}, error) {
k.mqlK8sInternal.nodesByName = make(map[string]*mqlK8sNode)
return k8sResourceToMql(k.MqlRuntime, gvkString(corev1.SchemeGroupVersion.WithKind("nodes")), func(kind string, resource runtime.Object, obj metav1.Object, objT metav1.Type) (interface{}, error) {
ts := obj.GetCreationTimestamp()

n, ok := obj.(*corev1.Node)
if !ok {
return nil, errors.New("not a k8s node")
}

nodeInfo, err := convert.JsonToDict(n.Status.NodeInfo)
if err != nil {
return nil, err
}

r, err := CreateResource(k.MqlRuntime, "k8s.node", map[string]*llx.RawData{
"id": llx.StringData(objIdFromK8sObj(obj, objT)),
"uid": llx.StringData(string(obj.GetUID())),
"resourceVersion": llx.StringData(obj.GetResourceVersion()),
"name": llx.StringData(obj.GetName()),
"kind": llx.StringData(objT.GetKind()),
"created": llx.TimeData(ts.Time),
"nodeInfo": llx.DictData(nodeInfo),
"kubeletPort": llx.IntData(n.Status.DaemonEndpoints.KubeletEndpoint.Port),
})
if err != nil {
return nil, err
}

n, ok := resource.(*corev1.Node)
if !ok {
return nil, errors.New("not a k8s node")
}
r.(*mqlK8sNode).obj = n
k.mqlK8sInternal.nodesByName[obj.GetName()] = r.(*mqlK8sNode)

Expand Down

0 comments on commit ea13220

Please sign in to comment.