-
Notifications
You must be signed in to change notification settings - Fork 344
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
New DeploymentStrategy type for JaegerSpec.Strategy #704
Conversation
ea92767
to
3949e62
Compare
Signed-off-by: volmedo <[email protected]>
Signed-off-by: volmedo <[email protected]>
Signed-off-by: volmedo <[email protected]>
Signed-off-by: volmedo <[email protected]>
3949e62
to
cafa6ce
Compare
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 really good so far! It's missing a couple of things, like:
- make sure all unserialized values are converted to lower case
- possibly a test ensuring that current CRs with a mixed-case strategy are correctly parsed
- the constant in the strategy package, mentioned in Make JaegerSpec.Strategy a type #137
Apart from that, LGTM.
// to Kafka, and the storage options will be used in the Ingester instead | ||
if strings.EqualFold(c.jaeger.Spec.Strategy, "streaming") { | ||
if c.jaeger.Spec.Strategy == v1.DeploymentStrategyStreaming { |
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 would happen if we have a CR with a strategy set to Streaming
?
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 was assuming that the value was being normalized somewhere else. Sorry, my bad.
@@ -49,11 +49,33 @@ const ( | |||
IngressSecurityOAuthProxy IngressSecurityType = "oauth-proxy" | |||
) | |||
|
|||
// DeploymentStrategy represents the possible values for deployment strategies | |||
// +k8s:openapi-gen=true | |||
type DeploymentStrategy 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.
You could implement the UnmarshalJSON method to the type, to ensure the values read from JSON are converted to lowercase.
Where is the unmarshalling being done? I suppose it is done by some library from k8s or the operator framework. If that is the case, is it enough to make the new type implement the
Where should this test live? Are there any other similar tests? |
It's done by the Operator SDK. It's sufficient to have a couple of methods, like these from the jaeger-operator/pkg/apis/jaegertracing/v1/options.go Lines 41 to 62 in d11973f
I think you only need to implement the We have some tests for the same object that could be used as reference: jaeger-operator/pkg/apis/jaegertracing/v1/options_test.go Lines 11 to 16 in d11973f
|
…ned ones Signed-off-by: volmedo <[email protected]>
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.
LGTM. There's only one minor comment about the import renaming for corev1
vs. jv1
. If you don't want to change it in this PR, please create an issue so that we don't lose track of it.
pkg/strategy/strategy.go
Outdated
@@ -9,12 +9,13 @@ import ( | |||
"k8s.io/api/extensions/v1beta1" | |||
rbac "k8s.io/api/rbac/v1" | |||
|
|||
jv1 "github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1" |
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.
We typically use v1
for Jaeger, and corev1
for k8s.io/api/core/v1
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.
Makes a lot of sense!
I saw that v1
was already in use and invented a different alias for Jaeger. Didn't think about the possibility of renaming the existing one :). Will do it now.
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.
Sorry, let me take back my approval :-) Just realized that it's still missing the serialization tests, to ensure backwards compatibility (which is probably why this is still WIP).
Signed-off-by: volmedo <[email protected]>
Yes, it's WIP because of that. I added three items to a todo list for the PR and I began with the last one instead of the first one :). |
Signed-off-by: volmedo <[email protected]>
0da9d6d
to
ae31e2b
Compare
I added the unmarshalling code and the corresponding tests. I implemented Aside from the tests, I also did some manual tests applying several modified yaml files and everything worked as expected. BTW, is there any end to end test that involves applying malformed deployment yaml files? I didn't include code for marshalling. Since the underlying type is I've also removed the |
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.
LGTM. Once the nil pointer check is clarified, this can be merged!
// UnmarshalText implements encoding.TextUnmarshaler to ensure that JSON values in the | ||
// strategy field of JSON jaeger specs are interpreted in a case-insensitive manner | ||
func (ds *DeploymentStrategy) UnmarshalText(text []byte) error { | ||
if ds == nil { |
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 interesting. I'm probably missing something obvious, but how would this be triggered? Wouldn't a nil object fail with a nil reference before reaching this code? Can you come up with a test case for this?
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.
It's not obvious. It is possible for the function to be called on a nil receiver when interfaces are involved (as is the case here).
I was digging into the docs and I had a look at how json.RawMessage.UnmarshalJSON is implemented. The check for nil felt strange, so I did a bit of research and came up with this https://tour.golang.org/methods/12
Wonderful Go! :)
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.
BTW, I guess this kind of check should be implemented in other types implementing interfaces for additional safety. Options
come to my mind, implementing both json.Marshaler
and json.Unmarshaler
interfaces, but I'm sure there are several others.
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.
TIL! I'm merging this one. Would you mind creating an issue to do the same nil check in the other relevant types?
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.
Will do!
Thanks for your contribution! |
This PR adds a new type,
DeploymentStrategy
, to be used inJaegerSpec.Strategy
instead of just astring
. Constants based on the new type are also defined to define valid values.When merged, this PR will close #137.
To do