-
Notifications
You must be signed in to change notification settings - Fork 139
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
Add optional key to the FieldExport target #100
Conversation
Hi @baijum. Thanks for your PR. I'm waiting for a aws-controllers-k8s member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
FieldExport generates the key name with an output structure like `<namespace>.<FieldExport-resource-name>`. This default naming structure creates non-conflicting names as the keys. However, many applications expect short names as keys. This is important, especially when the Secret/ConfigMap is mounted as files; the file names are nothing but the key names. This PR adds an optional attribute (.spec.to.key) to specify the key name in the FieldExport resource. If this attribute is specified, use this key name instead of the default. Proposal: aws-controllers-k8s/community#1410 Signed-off-by: Baiju Muthukadan <baiju.m.mail@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@baijum cool stuff! couple things for you inline :)
apis/core/v1alpha1/field_export.go
Outdated
@@ -24,6 +24,7 @@ type FieldExportTarget struct { | |||
// Namespace is marked as optional, so we cannot compose `NamespacedName` | |||
Namespace *string `json:"namespace,omitempty"` | |||
Kind FieldExportOutputType `json:"kind"` | |||
Key *string `json:"key,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Go ahead and add a docstring above here so that our API reference docs will include an explanation for the field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added docs. a974e46
@@ -296,6 +296,9 @@ func (r *fieldExportReconciler) writeToConfigMap( | |||
) error { | |||
// Construct the data key | |||
key := fmt.Sprintf("%s.%s", desired.Namespace, desired.Name) | |||
if desired.Spec.To.Key != nil { | |||
key = *desired.Spec.To.Key |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if the user enters an empty string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have changed the logic to consider empty strings. With an empty string value, the key will fall back to <namespace>.<FieldExport-resource-name>
. a974e46
Signed-off-by: Baiju Muthukadan <baiju.m.mail@gmail.com>
/ok-to-test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! left one question
@@ -340,6 +343,9 @@ func (r *fieldExportReconciler) writeToSecret( | |||
) error { | |||
// Construct the data key | |||
key := fmt.Sprintf("%s.%s", desired.Namespace, desired.Name) | |||
if desired.Spec.To.Key != nil && strings.TrimSpace(*desired.Spec.To.Key) != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we handle cases where Spec.To
is nil? to avoid nil panics?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. f6caece
Signed-off-by: Baiju Muthukadan <baiju.m.mail@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat! 👍
Once this PR is merged. I am planning to write a blog. Here is the early draft: https://gist.github.com/baijum/96158408eaf544f692acfad42f2b49df |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an awesome addition. It's something I considered in the original design, but left it out just because I thought it wasn't necessary for an initial release. Thank you!
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: A-Hilaly, baijum, RedbackThomson The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
FieldExport generates the key name with an output structure like
<namespace>.<FieldExport-resource-name>
. This default naming structurecreates non-conflicting names as the keys. However, many applications
expect short names as keys. This is important, especially when the
Secret/ConfigMap is mounted as files; the file names are nothing but
the key names.
This PR adds an optional attribute (.spec.to.key) to specify the key
name in the FieldExport resource. If this attribute is specified,
use this key name instead of the default.
Signed-off-by: Baiju Muthukadan baiju.m.mail@gmail.com
Issue #, if available: aws-controllers-k8s/community#1410
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.