Skip to content

fix(kafka update): broken preview#1311

Merged
rkpattnaik780 merged 4 commits intomainfrom
broken_update
Nov 12, 2021
Merged

fix(kafka update): broken preview#1311
rkpattnaik780 merged 4 commits intomainfrom
broken_update

Conversation

@rkpattnaik780
Copy link
Contributor

@rkpattnaik780 rkpattnaik780 commented Nov 11, 2021

Closes #1302, #1224

Verification Steps

  1. Run rhoas kafka update --owner foo_user
  2. This should display the existing user and the new user to be set

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation change
  • Other (please specify)

Checklist

  • Documentation added for the feature
  • CI and all relevant tests are passing
  • Code Review completed
  • Verified independently by reviewer

@rkpattnaik780
Copy link
Contributor Author

Added a few todos for when cli will work with ReauthenticationEnabled. Currently handles only string values, needs modification to support other types later.

// creates a summary of what values will be changed in this update
// returns a formatted string. Example:
// owner: foo_user ➡️ bar_user
// to do: Needs update once reauthentication_enabled is incorporated
Copy link
Collaborator

Choose a reason for hiding this comment

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

How reauthentication_enabled affects this preview?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The methods generating preview iterate through the entire update struct, the broken preview did display reauthentication_enabled too.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes. That iteration thru all elements of struct is core issue IMHO

Copy link
Contributor

Choose a reason for hiding this comment

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

We need to filter out the nil properties of the update object.

newT := new.Type()

for i := 0; i < new.NumField(); i++ {
for i := 0; i < 1; i++ {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm just curious what this does, how it fixes it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is to hide the reauthentication_nabled from preview.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I understand why it was done, I just did not yet understand how. I've debugged locally to understand it now.

This is a "quick fix" but once reauth update is possible we won't be able to just revert this change. If the update does not include and change to reauthentication_enabled, reverting this will still include it in the update summary.

I see that the value of ReauthenticationEnabled is nil, so perhaps we can check for nil before including it in the update summary?

This also assumes that the owner field will always be the first property of the update object, we should not rely on this.

@craicoverflow craicoverflow self-requested a review November 11, 2021 13:56
craicoverflow
craicoverflow previously approved these changes Nov 11, 2021
newT := new.Type()

for i := 0; i < new.NumField(); i++ {
for i := 0; i < 1; i++ {
Copy link
Collaborator

Choose a reason for hiding this comment

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

[Question] Why this change?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like in is not stable/subject to break when api return new data

// to do: Needs update once reauthentication_enabled is incorporated
func getUpdateObjValue(v reflect.Value) reflect.Value {
if v.Kind() == reflect.Struct {
vstruct := v.Field(0)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A better waywould be to get the value field instead of index. Do we need to iterate through this struct as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

This should work:

Suggested change
vstruct := v.Field(0)
vstruct := v.FieldByName("value")

This should suffice, no need to iterate.

Though I'm starting to think going forward with reflection on this is a bad idea, as we are making assumptions that are tightly coupled with the SDK, which could introduce breaking changes in the future by changing the name from "value" and since this is not strongly typed, we would not catch it..

For now, once you update with the suggestion above, we can merge as it is blocking any releases. Could you create a follow up issue to address this? We can simplify it by operating directly on the SDK model properties instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!
Ready for review.

@rkpattnaik780 rkpattnaik780 requested review from craicoverflow and removed request for craicoverflow November 12, 2021 10:24
@rkpattnaik780 rkpattnaik780 merged commit 102ecda into main Nov 12, 2021
@rkpattnaik780 rkpattnaik780 deleted the broken_update branch November 12, 2021 10:41
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.

Broken update summary for Kafka update operation Error message should make it clear --topic-prefix or --topic can be used

3 participants