Skip to content

Commit

Permalink
Merge pull request #19 from armosec/fix_parser_labels
Browse files Browse the repository at this point in the history
feat: Add selector for kubescape app in pod.json
  • Loading branch information
kooomix authored Jul 22, 2024
2 parents 79eb014 + 5320c88 commit cae76ef
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 1 deletion.
2 changes: 1 addition & 1 deletion armometadata/k8sutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func ExtractMetadataFromJsonBytes(input []byte) (Metadata, error) {
m.ResourceVersion = unquote(value)
case strings.HasPrefix(jsonPath, "metadata.annotations."):
m.Annotations[unquote(key)] = unquote(value)
case strings.HasPrefix(jsonPath, "metadata.labels."):
case strings.Contains(jsonPath, "metadata.labels."):
m.Labels[unquote(key)] = unquote(value)
case strings.HasPrefix(jsonPath, "metadata.ownerReferences.."):
m.OwnerReferences[unquote(key)] = unquote(value)
Expand Down
15 changes: 15 additions & 0 deletions armometadata/k8sutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,21 @@ func TestExtractMetadataFromJsonBytes(t *testing.T) {
apiVersion string
podSelectorMatchLabels map[string]string
}{
{
name: "testdeployment",
annotations: map[string]string{
"deployment.kubernetes.io/revision": "1",
},
labels: map[string]string{
"app": "emailservice",
},
ownerReferences: map[string]string{},
creationTs: "2024-07-18T19:58:44Z",
resourceVersion: "6486",
kind: "Deployment",
apiVersion: "apps/v1",
podSelectorMatchLabels: map[string]string{},
},
{
name: "networkpolicy_withoutmatching_labels",
annotations: map[string]string{},
Expand Down
5 changes: 5 additions & 0 deletions armometadata/testdata/pod.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
},
"spec": {
"automountServiceAccountToken": true,
"selector": {
"matchLabels": {
"app": "kubescape"
}
},
"containers": [
{
"command": [
Expand Down
148 changes: 148 additions & 0 deletions armometadata/testdata/testdeployment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"annotations": {
"deployment.kubernetes.io/revision": "1"
},
"creationTimestamp": "2024-07-18T19:58:44Z",
"generation": 1,
"name": "emailservice",
"namespace": "default",
"resourceVersion": "6486",
"uid": "916f902f-619c-4f42-9734-5df3a8e88cb7"
},
"spec": {
"progressDeadlineSeconds": 600,
"replicas": 1,
"revisionHistoryLimit": 10,
"selector": {
"matchLabels": {
"app": "emailservice"
}
},
"strategy": {
"rollingUpdate": {
"maxSurge": "25%",
"maxUnavailable": "25%"
},
"type": "RollingUpdate"
},
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"app": "emailservice"
}
},
"spec": {
"containers": [
{
"env": [
{
"name": "PORT",
"value": "8080"
},
{
"name": "DISABLE_PROFILER",
"value": "1"
}
],
"image": "gcr.io/google-samples/microservices-demo/emailservice:v0.5.1",
"imagePullPolicy": "IfNotPresent",
"livenessProbe": {
"exec": {
"command": [
"/bin/grpc_health_probe",
"-addr=:8080"
]
},
"failureThreshold": 3,
"periodSeconds": 5,
"successThreshold": 1,
"timeoutSeconds": 1
},
"name": "server",
"ports": [
{
"containerPort": 8080,
"protocol": "TCP"
}
],
"readinessProbe": {
"exec": {
"command": [
"/bin/grpc_health_probe",
"-addr=:8080"
]
},
"failureThreshold": 3,
"periodSeconds": 5,
"successThreshold": 1,
"timeoutSeconds": 1
},
"resources": {
"limits": {
"cpu": "200m",
"memory": "128Mi"
},
"requests": {
"cpu": "100m",
"memory": "64Mi"
}
},
"securityContext": {
"allowPrivilegeEscalation": false,
"capabilities": {
"drop": [
"all"
]
},
"privileged": false,
"readOnlyRootFilesystem": true
},
"terminationMessagePath": "/dev/termination-log",
"terminationMessagePolicy": "File"
}
],
"dnsPolicy": "ClusterFirst",
"restartPolicy": "Always",
"schedulerName": "default-scheduler",
"securityContext": {
"fsGroup": 1000,
"runAsGroup": 1000,
"runAsNonRoot": true,
"runAsUser": 1000
},
"serviceAccount": "default",
"serviceAccountName": "default",
"terminationGracePeriodSeconds": 5
}
}
},
"status": {
"availableReplicas": 1,
"conditions": [
{
"lastTransitionTime": "2024-07-18T19:59:08Z",
"lastUpdateTime": "2024-07-18T19:59:08Z",
"message": "Deployment has minimum availability.",
"reason": "MinimumReplicasAvailable",
"status": "True",
"type": "Available"
},
{
"lastTransitionTime": "2024-07-18T19:58:44Z",
"lastUpdateTime": "2024-07-18T19:59:08Z",
"message": "ReplicaSet \"emailservice-d9dbcbd\" has successfully progressed.",
"reason": "NewReplicaSetAvailable",
"status": "True",
"type": "Progressing"
}
],
"observedGeneration": 1,
"readyReplicas": 1,
"replicas": 1,
"updatedReplicas": 1
}
}

0 comments on commit cae76ef

Please sign in to comment.