Skip to content

Support for optional field in configmap / secret ref#181

Open
GuyCarmy wants to merge 2 commits intorundeck-plugins:masterfrom
GuyCarmy:envfrom-optional
Open

Support for optional field in configmap / secret ref#181
GuyCarmy wants to merge 2 commits intorundeck-plugins:masterfrom
GuyCarmy:envfrom-optional

Conversation

@GuyCarmy
Copy link
Copy Markdown
Contributor

No description provided.

@GuyCarmy
Copy link
Copy Markdown
Contributor Author

Hi @ltamaster, are you still maintaining this repo?
a very small PR to enable "optional" for envFrom for jobs, tested on my side, please review.
Thanks

@GuyCarmy
Copy link
Copy Markdown
Contributor Author

GuyCarmy commented Sep 3, 2025

Hi @fdevans, I see you were active in this repo last week, any chance you can take a look at this small PR?

@fdevans fdevans requested a review from Copilot October 1, 2025 23:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for the optional field in configmap and secret references in Kubernetes job creation. The changes enable users to specify whether a configmap or secret reference should be treated as optional during job execution.

  • Extracts configmap and secret references to separate variables for cleaner code
  • Adds support for the optional field in both V1ConfigMapEnvSource and V1SecretEnvSource
  • Fixes parameter passing by using named parameters instead of positional ones

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread contents/job-create.py
Comment on lines 98 to 101
config_map_ref=client.V1ConfigMapEnvSource(
env_from_data['configMapRef']['name']
name=config_map_ref['name'],
optional=config_map_ref.get('optional')
)
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original code was passing the name as a positional argument, but V1ConfigMapEnvSource expects named parameters. However, the API typically expects the optional parameter to be a boolean. Using .get('optional') could return None, which may not be handled correctly by the Kubernetes client. Consider using .get('optional', False) to provide a default boolean value.

Copilot uses AI. Check for mistakes.
Comment thread contents/job-create.py
Comment on lines 108 to 111
secret_ref=client.V1SecretEnvSource(
env_from_data['secretRef']['name']
name=secret_ref['name'],
optional=secret_ref.get('optional')
)
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the configmap reference, the optional parameter should have a boolean default value. Using .get('optional') could return None, which may cause issues with the Kubernetes client. Consider using .get('optional', False) to ensure a proper boolean value is always passed.

Copilot uses AI. Check for mistakes.
@GuyCarmy
Copy link
Copy Markdown
Contributor Author

@fdevans fixed according to the copilot suggestions

@fdevans
Copy link
Copy Markdown
Contributor

fdevans commented Mar 6, 2026

@GuyCarmy Thanks for the contribution! This is a useful feature addition.

Code Review

The implementation looks good:

  • ✅ Clean refactoring by extracting refs to variables
  • ✅ Proper use of named parameters instead of positional
  • ✅ Correct handling of the optional field with .get('optional', False) defaults
  • ✅ Follows Kubernetes API conventions

Requests Before Merge

1. Rebase on Latest Master

Your branch is behind master by several commits, including important security updates (urllib3 and kubernetes client upgrades for CVE fixes). Please rebase on the latest master:

git fetch upstream
git rebase upstream/master
# Resolve any conflicts if needed
git push --force-with-lease

2. Add Documentation

Please add an example to the README showing how to use the new optional field. Something like:

In the "Create / Delete / Re-run Jobs" section, add an example showing:

  • How to specify optional: true in a configMapRef
  • How to specify optional: true in a secretRef
  • What the behavior difference is (job starts even if resource is missing vs fails)

This will help users understand when and how to use this feature.

Example Documentation Format

envFrom:
  - configMapRef:
      name: my-config
      optional: true  # Job will start even if my-config doesn't exist
  - secretRef:
      name: my-secret
      optional: false  # Job will fail if my-secret doesn't exist (default)

Once you've rebased and added the documentation, we'll be ready to merge. Thanks again for the contribution!

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.

3 participants