Skip to content

Add supports patching Jobs and CronJobs - #17

Open
sportlotto wants to merge 2 commits into
maxtacu:masterfrom
sportlotto:add-cronjobs-support
Open

Add supports patching Jobs and CronJobs#17
sportlotto wants to merge 2 commits into
maxtacu:masterfrom
sportlotto:add-cronjobs-support

Conversation

@sportlotto

@sportlotto sportlotto commented Sep 26, 2025

Copy link
Copy Markdown

The Go program now supports patching Jobs and CronJobs in addition to Pods. I've made the following changes:

  1. Added proper imports for batchv1 and batchv1beta1 to handle Job and CronJob resources

  2. Modified the resource detection logic to handle three resource types:

  • Pod: Direct pod spec access with path /spec
  • Job: Access pod template via job.Spec.Template.Spec with path /spec/template/spec
  • CronJob: Access pod template via cronJob.Spec.JobTemplate.Spec.Template.Spec with path /spec/jobTemplate/spec/template/spec
  1. Updated all container processing (containers, initContainers, ephemeralContainers) to use dynamic path prefixes and resource information

  2. Enhanced logging to show the correct resource type and names for all supported resources

The Go program now supports patching Jobs and CronJobs in addition to Pods. I've made the following changes:

1) Added proper imports for batchv1 and batchv1beta1 to handle Job and CronJob resources

2) Modified the resource detection logic to handle three resource types:

- Pod: Direct pod spec access with path /spec
- Job: Access pod template via job.Spec.Template.Spec with path /spec/template/spec
- CronJob: Access pod template via cronJob.Spec.JobTemplate.Spec.Template.Spec with path /spec/jobTemplate/spec/template/spec
3) Updated all container processing (containers, initContainers, ephemeralContainers) to use dynamic path prefixes and resource information

4) Enhanced logging to show the correct resource type and names for all supported resources
FIx the SonarCube security warning by:

1) Added the missing regexp import that was needed for the sanitizeForLog function

2) Applied the sanitizeForLog function to all user-controlled data in log statements

The sanitizeForLog function addresses the security concern by:

- Removing control characters ([\x00-\x1F\x7F]) that could be used for log injection attacks
- Preventing log flooding by limiting string length to 100 characters
- Preserving observability by keeping the essential information (namespace, resource name, etc.)
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
B Security Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@sportlotto sportlotto changed the title Update main.go Add supports patching Jobs and CronJobs Sep 26, 2025
@maxtacu

maxtacu commented Oct 3, 2025

Copy link
Copy Markdown
Owner

Thanks for the contribution. please check failed docker build and fix the PR. It seems that batchv1beta1 is imported but never used

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants