diff --git a/providers/k8s/resources/k8s.lr b/providers/k8s/resources/k8s.lr index ed78102f7e..863b7fe0ed 100644 --- a/providers/k8s/resources/k8s.lr +++ b/providers/k8s/resources/k8s.lr @@ -114,6 +114,8 @@ private k8s.node @defaults("name labels['kubernetes.io/arch'] labels['kubernetes name string // Kubernetes object type kind string + // Kubernetes object creation timestamp + created time } // Kubernetes Pod diff --git a/providers/k8s/resources/k8s.lr.go b/providers/k8s/resources/k8s.lr.go index 667689571a..f5d0f3e873 100644 --- a/providers/k8s/resources/k8s.lr.go +++ b/providers/k8s/resources/k8s.lr.go @@ -364,6 +364,9 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "k8s.node.kind": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlK8sNode).GetKind()).ToDataRes(types.String) }, + "k8s.node.created": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlK8sNode).GetCreated()).ToDataRes(types.Time) + }, "k8s.pod.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlK8sPod).GetId()).ToDataRes(types.String) }, @@ -1500,6 +1503,10 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlK8sNode).Kind, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, + "k8s.node.created": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlK8sNode).Created, ok = plugin.RawToTValue[*time.Time](v.Value, v.Error) + return + }, "k8s.pod.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlK8sPod).__id, ok = v.Value.(string) return @@ -3486,6 +3493,7 @@ type mqlK8sNode struct { ResourceVersion plugin.TValue[string] Name plugin.TValue[string] Kind plugin.TValue[string] + Created plugin.TValue[*time.Time] } // createK8sNode creates a new instance of this resource @@ -3557,6 +3565,10 @@ func (c *mqlK8sNode) GetKind() *plugin.TValue[string] { return &c.Kind } +func (c *mqlK8sNode) GetCreated() *plugin.TValue[*time.Time] { + return &c.Created +} + // mqlK8sPod for the k8s.pod resource type mqlK8sPod struct { MqlRuntime *plugin.Runtime diff --git a/providers/k8s/resources/k8s.lr.manifest.yaml b/providers/k8s/resources/k8s.lr.manifest.yaml index 94dfb58bc3..44e4c9e885 100755 --- a/providers/k8s/resources/k8s.lr.manifest.yaml +++ b/providers/k8s/resources/k8s.lr.manifest.yaml @@ -488,6 +488,8 @@ resources: fields: annotations: min_mondoo_version: 5.29.2 + created: + min_mondoo_version: 9.0.0 id: min_mondoo_version: 6.10.0 kind: {} diff --git a/providers/k8s/resources/node.go b/providers/k8s/resources/node.go index dae0153e07..08aea6d1b0 100644 --- a/providers/k8s/resources/node.go +++ b/providers/k8s/resources/node.go @@ -54,12 +54,15 @@ 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() + 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), }) if err != nil { return nil, err