-
Notifications
You must be signed in to change notification settings - Fork 104
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
Dirty-fix for known bug #307: Ignore keys containing '$'. #481
base: master
Are you sure you want to change the base?
Dirty-fix for known bug #307: Ignore keys containing '$'. #481
Conversation
As already stated in #482 - gonna check this in the next weeks to make sure it doesn't have a side-effect |
Refers to #307. I can't say I fully understand the use of these But to generate valid jsonnet, a couple of spec: {
'#flagSpec':: d.obj(help='"FlagSpec is the structured representation of the feature flag specification"'),
flagSpec: {
'#withEvaluators':: d.fn(help='', args=[d.arg(name='evaluators', type=d.T.object)]),
withEvaluators(evaluators): { spec+: { flagSpec+: { evaluators: evaluators } } },
'#withEvaluatorsMixin':: d.fn(help='\n\n**Note:** This function appends passed data to existing values', args=[d.arg(name='evaluators', type=d.T.object)]),
withEvaluatorsMixin(evaluators): { spec+: { flagSpec+: { evaluators+: evaluators } } },
'#withFlags':: d.fn(help='', args=[d.arg(name='flags', type=d.T.object)]),
withFlags(flags): { spec+: { flagSpec+: { flags: flags } } },
'#withFlagsMixin':: d.fn(help='\n\n**Note:** This function appends passed data to existing values', args=[d.arg(name='flags', type=d.T.object)]),
withFlagsMixin(flags): { spec+: { flagSpec+: { flags+: flags } } },
},
}, Here's what I hacked really quicky to try it: diff --git a/pkg/model/modifiers.go b/pkg/model/modifiers.go
index 5833521..754188d 100644
--- a/pkg/model/modifiers.go
+++ b/pkg/model/modifiers.go
@@ -94,6 +94,8 @@ func newModifier(name string, p *swagger.Schema, ctx string, inArray bool,
defArray bool) (string, interface{}) {
name = CamelLower(name)
+ name = strings.TrimPrefix(name, "$")
+
switch p.Type {
case swagger.TypeArray:
// when defArray is true, create modifier directly
@@ -147,15 +149,15 @@ func fnArg(name string) string {
"then", "self", "super", "true":
return normalizedTitle(name)
default:
- return name
+ return strings.TrimPrefix(name, "$")
}
}
// normalizedTitle normalizes a name and applied strings.Title()
func normalizedTitle(name string) string {
- if strings.HasPrefix(name, "-") {
- name = strings.TrimPrefix(name, "-")
- }
+ name = strings.TrimPrefix(name, "-")
+
+ name = strings.TrimPrefix(name, "$")
name = strings.Replace(name, ".", "_", -1)
|
I encountered the issue first when generating the jsonnet-libs for the CRDs of the Open-Feature-Operator. The problematic field in question was FeatureFlag.spec.flagSpec.$evaluators I have tested how k8s reacts to "$evaluators" being referenced to as "evaluators":
I would suggest ignoring the "$foo" fields (for now, until it is properly fixed). This makes the libraries potentially incomplete, but at least the generated yaml will work 100% of the time. I mean if the CRD calls for a "$foo" field, it would not do anything with a "foo" field anyways. |
Here is the URL of the known bug i am referring to: Bug-307
I encountered the same issue when attempting to create a lib for the OpenFeatureOperators CRDs.
This is only a quick and dirty "fix". It basically just ignores the field containing the $ sign. This allows at least the rest of the libsonnet to be generated.
Additionally a message is written to the Log, informing, that certain fields have been ommited.