Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use cronjob labels #156

Merged
merged 3 commits into from
Dec 4, 2023
Merged

use cronjob labels #156

merged 3 commits into from
Dec 4, 2023

Conversation

Daniel-GrunbergerCA
Copy link
Contributor

@Daniel-GrunbergerCA Daniel-GrunbergerCA commented Dec 4, 2023

type:

bug_fix


description:

This PR addresses an issue with the labels of NetworkNeighbors generated for CronJobs. Previously, the labels of the CronJob were used as the labels of the NetworkNeighbors, which could lead to incorrect policy enforcement, as the labels of the Pod generated by the Job may differ. The PR modifies this behavior to use the labels from the podTemplate inside the jobSpec, which will be present in the Pods generated by the Job.


main_files_walkthrough:

files:
  • pkg/networkmanager/network_manager.go: The changes in this file include a new condition to check if the parent workload is a CronJob. If it is, the labels from the podTemplate inside the jobSpec are used to create a new LabelSelector. If the parent workload is not a CronJob, the previous behavior is maintained. This change ensures that the correct labels are used for NetworkNeighbors in the case of CronJobs.

User Description:

Overview

This PR fixes the labels of NetworkNeighbors generated for CronJobs. Previously we were using the labels of the CronJob as the labels of the NetworkNeighbors, which will cause the policy to be not always correct, since the labels of the Pod generated by the Job may differ. Instead, we will take the labels from the podTemplate inside the jobSpec, which will be present at the Pods generated by the Job.

Signed-off-by: DanielGrunbergerCA <[email protected]>
Copy link

PR Description updated to latest commit (097e6aa)

Copy link

PR Analysis

  • 🎯 Main theme: Fixing label issue in NetworkNeighbors for CronJobs
  • 📝 PR summary: This PR addresses an issue with the labels of NetworkNeighbors generated for CronJobs. Previously, the labels of the CronJob were used as the labels of the NetworkNeighbors, which could lead to incorrect policy enforcement. The PR modifies this behavior to use the labels from the podTemplate inside the jobSpec.
  • 📌 Type of PR: Bug fix
  • 🧪 Relevant tests added: No
  • ⏱️ Estimated effort to review [1-5]: 2, because the PR is relatively small and the changes are straightforward, but it requires knowledge of Kubernetes CronJobs and how labels are used in policy enforcement.
  • 🔒 Security concerns: No

PR Feedback

  • 💡 General suggestions: The PR is well-structured and the changes are clear. However, it would be beneficial to include tests that verify the new behavior, especially given that this is a bug fix. Additionally, it would be helpful to include more context in the PR description about how this issue was discovered and the impact of the bug.

  • 🤖 Code feedback:
    • relevant file: pkg/networkmanager/network_manager.go
      suggestion: Consider handling the error when marshalling and unmarshalling the CronJob object in a separate function to reduce the complexity of the handleContainerStarted function. [medium]
      relevant line: jsonBytes, err := json.Marshal(obj)

    • relevant file: pkg/networkmanager/network_manager.go
      suggestion: It would be better to use a type assertion to convert the parentWL.GetObject() to a CronJob instead of marshalling and unmarshalling the object. This would be more efficient and avoid potential errors with the marshalling process. [important]
      relevant line: var cronjob k8sv1beta1.CronJob

How to use

Instructions

To invoke the PR-Agent, add a comment using one of the following commands:
/review: Request a review of your Pull Request.
/describe: Update the PR title and description based on the contents of the PR.
/improve [--extended]: Suggest code improvements. Extended mode provides a higher quality feedback.
/ask <QUESTION>: Ask a question about the PR.
/update_changelog: Update the changelog based on the PR's contents.
/add_docs: Generate docstring for new components introduced in the PR.
/generate_labels: Generate labels for the PR based on the PR's contents.
see the tools guide for more details.

To edit any configuration parameter from the configuration.toml, add --config_path=new_value.
For example: /review --pr_reviewer.extra_instructions="focus on the file: ..."
To list the possible configuration parameters, add a /config comment.

Copy link

github-actions bot commented Dec 4, 2023

Summary:

  • License scan: success
  • Credentials scan: success
  • Vulnerabilities scan: success
  • Unit test: success
  • Go linting: success

Signed-off-by: DanielGrunbergerCA <[email protected]>
Signed-off-by: DanielGrunbergerCA <[email protected]>
Copy link

github-actions bot commented Dec 4, 2023

Summary:

  • License scan: success
  • Credentials scan: success
  • Vulnerabilities scan: success
  • Unit test: success
  • Go linting: success

@matthyx matthyx merged commit cb087ad into main Dec 4, 2023
6 checks passed
@matthyx matthyx deleted the fix-cj branch December 4, 2023 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants