Skip to content
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

Merged
merged 6 commits into from
Oct 27, 2020

Conversation

rubenvp8510
Copy link
Collaborator

Signed-off-by: Ruben Vargas Palma ruben.vp8510@gmail.com

Fixes #1242

@codecov
Copy link

codecov bot commented Oct 14, 2020

Codecov Report

Merging #1253 into master will decrease coverage by 0.10%.
The diff coverage is 46.66%.

Impacted file tree graph

@@            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              
Impacted Files Coverage Δ
pkg/upgrade/upgrade.go 55.68% <38.46%> (-2.22%) ⬇️
pkg/controller/jaeger/jaeger_controller.go 35.63% <100.00%> (+0.37%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8b07b3f...ef5d183. Read the comment docs.

Copy link
Contributor

@jpkrohling jpkrohling left a 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
Copy link
Contributor

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.

Copy link
Collaborator Author

@rubenvp8510 rubenvp8510 Oct 14, 2020

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.

@@ -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 {
Copy link
Contributor

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.

Copy link
Collaborator Author

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.

@rubenvp8510 rubenvp8510 force-pushed the fix-upgrade branch 6 times, most recently from a8475a4 to 1eeb75d Compare October 15, 2020 22:26
Copy link
Contributor

@jpkrohling jpkrohling left a 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?

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Update/Patch/ ?

Copy link
Collaborator Author

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?

Copy link
Collaborator Author

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.

"testing"
)

const EnvUpdateVersionKey = "UPDATE_TEST_VERSION"
Copy link
Contributor

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.

func TestOperatorUpgrade(t *testing.T) {

upgradeTestVersion := os.Getenv(EnvUpdateVersionKey)
t.Log(upgradeTestVersion)
Copy link
Contributor

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 ...

Copy link
Collaborator Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Update/Patch/?


func TestOperatorUpgrade(t *testing.T) {

upgradeTestVersion := os.Getenv(EnvUpdateVersionKey)
Copy link
Contributor

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It fails :)

Copy link
Contributor

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?

Copy link
Collaborator Author

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()}
Copy link
Contributor

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

Copy link
Contributor

@jpkrohling jpkrohling left a 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 Show resolved Hide resolved
log.WithFields(log.Fields{
"instance": jaeger.Name,
"namespace": jaeger.Namespace,
}).WithError(err).Error("failed update status of the upgraded instance")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}).WithError(err).Error("failed update status of the upgraded instance")
}).WithError(err).Error("failed to update the status of the upgraded instance")

require.Regexp(t, versionRegexp, upgradeTestVersion,
"Invalid upgrade version, need to specify a version to upgrade in format X.Y.Z")

ctx, err := prepare(t)
Copy link
Contributor

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.

  1. 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.
  2. 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()

@rubenvp8510
Copy link
Collaborator Author

I've already done all requested changes :=)

Thanks for the review!

Signed-off-by: Ruben Vargas Palma <ruben.vp8510@gmail.com>
Signed-off-by: Ruben Vargas Palma <ruben.vp8510@gmail.com>
Signed-off-by: Ruben Vargas Palma <ruben.vp8510@gmail.com>
Signed-off-by: Ruben Vargas Palma <ruben.vp8510@gmail.com>
Signed-off-by: Ruben Vargas Palma <ruben.vp8510@gmail.com>
Signed-off-by: Ruben Vargas Palma <ruben.vp8510@gmail.com>
@rubenvp8510
Copy link
Collaborator Author

Any other comments on this PR? :)

@jpkrohling jpkrohling merged commit e5f2540 into jaegertracing:master Oct 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Jaeger instance is not getting upgraded automatically
3 participants