Skip to content

Commit

Permalink
Merge pull request #31 from xentra-ai/fix/labels
Browse files Browse the repository at this point in the history
fix: add more logging and support jobs
  • Loading branch information
xunholy authored Nov 2, 2023
2 parents f5912a9 + 37263ff commit 25f61a8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
with:
build-args: |
APPLICATION_NAME=advisor
VERSION=0.0.1
VERSION=0.0.2
SHA=${{ github.sha }}
context: ./advisor
file: Dockerfile
Expand Down
11 changes: 9 additions & 2 deletions advisor/pkg/k8s/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func detectSelectorLabels(clientset *kubernetes.Clientset, origin interface{}) (
func GetOwnerRef(clientset *kubernetes.Clientset, pod *v1.Pod) (map[string]string, error) {
ctx := context.TODO()

// Check if the& Pod has an owner
// Check if the Pod has an owner
if len(pod.OwnerReferences) > 0 {
owner := pod.OwnerReferences[0]

Expand Down Expand Up @@ -61,10 +61,17 @@ func GetOwnerRef(clientset *kubernetes.Clientset, pod *v1.Pod) (map[string]strin
}
return daemonSet.Spec.Selector.MatchLabels, nil

case "Job":
job, err := clientset.BatchV1().Jobs(pod.Namespace).Get(ctx, owner.Name, metav1.GetOptions{})
if err != nil {
return nil, err
}
return job.Spec.Selector.MatchLabels, nil

// Add more controller kinds here if needed

default:
return nil, fmt.Errorf("unknown or unsupported owner kind: %s", owner.Kind)
return nil, fmt.Errorf("unknown or unsupported ownerReference: %s", owner.String())
}
}
return pod.Labels, nil
Expand Down
2 changes: 1 addition & 1 deletion advisor/pkg/k8s/networkpolicies.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func transformToNetworkPolicy(podTraffic []api.PodTraffic, podDetail *api.PodDet
Namespace: podDetail.Namespace,
Labels: map[string]string{
"advisor.xentra.ai/managed-by": "xentra",
"advisor.xentra.ai/version": "0.0.1",
"advisor.xentra.ai/version": "0.0.2",
},
},
Spec: networkingv1.NetworkPolicySpec{
Expand Down

0 comments on commit 25f61a8

Please sign in to comment.