-
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
Update instances status using client.Status().update interface #1253
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1253 +/- ##
==========================================
- Coverage 87.43% 87.32% -0.11%
==========================================
Files 90 90
Lines 4933 4946 +13
==========================================
+ Hits 4313 4319 +6
- Misses 457 464 +7
Partials 163 163
Continue to review full report at Codecov.
|
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 missing a test. If you can reproduce the problem with a simple unit test, that's optimal, otherwise, an e2e test is required.
} | ||
|
||
// set the status version to the updated instance version | ||
instance.Status.Version = updated.Status.Version |
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 don't think this is the right place to do this... We either do this during the instance creation, or after an upgrade.
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 missing a test. If you can reproduce the problem with a simple unit test, that's optimal, otherwise, an e2e test is required.
I'll add an e2e test, we have unit tests in place for the upgrade process, even with those tests we didn't detect the issue before.
pkg/upgrade/upgrade.go
Outdated
@@ -72,6 +72,15 @@ func ManagedInstances(ctx context.Context, c client.Client, reader client.Reader | |||
"namespace": jaeger.Namespace, | |||
}).WithError(err).Error("failed to store the upgraded instance") | |||
tracing.HandleError(err, span) | |||
} else { |
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 more readable if you invert the situation: "if err == nil { success } else { failure }". We use "if err != nil" only when that's the only code branch.
Also, you might want to change from Update to Patch.
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.
ok, that make sense, about changing Update to Patch I would prefer to do it in a separate PR if it's required.
a8475a4
to
1eeb75d
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.
@kevinearls, could you review this one as well?
pkg/upgrade/upgrade.go
Outdated
if err := c.Update(ctx, &jaeger); err != nil { | ||
if err := c.Update(ctx, &jaeger); err == nil { | ||
jaeger.Status.Version = version | ||
if err := c.Status().Update(ctx, &jaeger); err != 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.
s/Update/Patch/ ?
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 can do the change but What would be the benefit of doing patch for this case?
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.
Nevermind, I did the change.
test/e2e/upgrade_test.go
Outdated
"testing" | ||
) | ||
|
||
const EnvUpdateVersionKey = "UPDATE_TEST_VERSION" |
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.
Those two consts can be part of a single const ()
declaration.
test/e2e/upgrade_test.go
Outdated
func TestOperatorUpgrade(t *testing.T) { | ||
|
||
upgradeTestVersion := os.Getenv(EnvUpdateVersionKey) | ||
t.Log(upgradeTestVersion) |
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.
Add some context to this log entry. Like, Attempting to upgrade to version ...
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 log should not be here, was part of my debugging, but yeah a log message could be useful.
image := deployment.Spec.Template.Spec.Containers[0].Image | ||
image = strings.Replace(image, "latest", upgradeTestTag, 1) | ||
deployment.Spec.Template.Spec.Containers[0].Image = image | ||
fw.Client.Update(context.Background(), deployment) |
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.
s/Update/Patch/?
test/e2e/upgrade_test.go
Outdated
|
||
func TestOperatorUpgrade(t *testing.T) { | ||
|
||
upgradeTestVersion := os.Getenv(EnvUpdateVersionKey) |
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 when the env var is empty?
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 fails :)
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.
When? With which message? Is it easy to understand what's going on?
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.
is not, I'll add a validation here to make it more clear.
} | ||
fw = framework.Global | ||
createdJaeger := &v1.Jaeger{} | ||
key := types.NamespacedName{Name: "my-jaeger", Namespace: ctx.GetID()} |
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.
@rubenvp8510 I realize this is a short test, but I'd prefer if you followed the example of the other tests, used stretchr suites, and put all of this setup code in a SetupSuite(). That would make it consist with all of the other E2E tests
cd4dd1e
to
0a2e476
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 good to me, but the final review is on @kevinearls :-)
pkg/upgrade/upgrade.go
Outdated
log.WithFields(log.Fields{ | ||
"instance": jaeger.Name, | ||
"namespace": jaeger.Namespace, | ||
}).WithError(err).Error("failed update status of the upgraded instance") |
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.
}).WithError(err).Error("failed update status of the upgraded instance") | |
}).WithError(err).Error("failed to update the status of the upgraded instance") |
test/e2e/upgrade_test.go
Outdated
require.Regexp(t, versionRegexp, upgradeTestVersion, | ||
"Invalid upgrade version, need to specify a version to upgrade in format X.Y.Z") | ||
|
||
ctx, err := prepare(t) |
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.
@rubenvp8510 A couple of more small things, which are more for consistently with other tests than correctness.
- Can you move everything from the ""ctx, err := prepare()" down to "fw = framework.Global" into a SetupSuite() method, making sure to remove the "defer ctx.Cleanup() call.
- Then add a TearDownSuite() which should look like this one: https://github.com/jaegertracing/jaeger-operator/blob/master/test/e2e/elasticsearch_test.go#L56-L58 handleSuiteTearDown will take care of the ctx.Cleanup()
I've already done all requested changes :=) Thanks for the review! |
f42f014
to
9c977e6
Compare
Signed-off-by: Ruben Vargas Palma <[email protected]>
Signed-off-by: Ruben Vargas Palma <[email protected]>
Signed-off-by: Ruben Vargas Palma <[email protected]>
Signed-off-by: Ruben Vargas Palma <[email protected]>
Signed-off-by: Ruben Vargas Palma <[email protected]>
Signed-off-by: Ruben Vargas Palma <[email protected]>
9c977e6
to
ef5d183
Compare
Any other comments on this PR? :) |
Signed-off-by: Ruben Vargas Palma [email protected]
Fixes #1242