-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 FieldRef support #8126
Add FieldRef support #8126
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ limitations under the License. | |
package config | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
|
@@ -57,21 +58,57 @@ func TestFeaturesConfiguration(t *testing.T) { | |
}, { | ||
name: "multi-container Allowed", | ||
wantErr: false, | ||
wantFeatures: &Features{ | ||
wantFeatures: defaultWith(&Features{ | ||
MultiContainer: Allowed, | ||
}, | ||
}), | ||
data: map[string]string{ | ||
"multi-container": "Allowed", | ||
}, | ||
}, { | ||
name: "multi-container Enabled", | ||
wantErr: false, | ||
wantFeatures: &Features{ | ||
wantFeatures: defaultWith(&Features{ | ||
MultiContainer: Enabled, | ||
}, | ||
}), | ||
data: map[string]string{ | ||
"multi-container": "Enabled", | ||
}, | ||
}, { | ||
name: "multi-container Disabled", | ||
wantErr: false, | ||
wantFeatures: defaultWith(&Features{ | ||
MultiContainer: Disabled, | ||
}), | ||
data: map[string]string{ | ||
"multi-container": "Disabled", | ||
}, | ||
}, { | ||
name: "kubernetes/field-ref Allowed", | ||
wantErr: false, | ||
wantFeatures: defaultWith(&Features{ | ||
KubernetesFieldRef: Allowed, | ||
}), | ||
data: map[string]string{ | ||
"kubernetes/field-ref": "Allowed", | ||
}, | ||
}, { | ||
name: "kubernetes/field-ref Enabled", | ||
wantErr: false, | ||
wantFeatures: defaultWith(&Features{ | ||
KubernetesFieldRef: Enabled, | ||
}), | ||
data: map[string]string{ | ||
"kubernetes/field-ref": "Enabled", | ||
}, | ||
}, { | ||
name: "kubernetes/field-ref Disabled", | ||
wantErr: false, | ||
wantFeatures: defaultWith(&Features{ | ||
KubernetesFieldRef: Disabled, | ||
}), | ||
data: map[string]string{ | ||
"kubernetes/field-ref": "Disabled", | ||
}, | ||
}} | ||
|
||
for _, tt := range configTests { | ||
|
@@ -91,3 +128,16 @@ func TestFeaturesConfiguration(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
// defaultWith returns the default *Feature patched with the provided *Features. | ||
func defaultWith(p *Features) *Features { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is pure evil |
||
f := defaultFeaturesConfig() | ||
pType := reflect.ValueOf(p).Elem() | ||
fType := reflect.ValueOf(f).Elem() | ||
for i := 0; i < pType.NumField(); i++ { | ||
if pType.Field(i).Interface().(Flag) != "" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we sure no other types of values will be added? This is test, so 🤷 , but stil. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can check the type assertion and fail but that doesn't help much compared to failing directly with a panic. It is for test only, I don't think we care. |
||
fType.Field(i).Set(pType.Field(i)) | ||
} | ||
} | ||
return f | ||
} |
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.
note: there's a discussion about the format of these fields
https://knative.slack.com/archives/CU9DGL4FM/p1591710914146300