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

Vtop: Refactor Conditions to List for Kubectl Wait #136

Merged
merged 7 commits into from Sep 16, 2020

Conversation

PrismaPhonic
Copy link
Contributor

This PR refactors conditions to be a list rather than map so they can be used with kubectl wait command.

…ess.

Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>
Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>
Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>
pkg/apis/planetscale/v2/vitesskeyspace_methods.go Outdated Show resolved Hide resolved

// GetCondition provides map style access to retrieve a condition from the conditions list by it's type
// If the condition doesn't exist, we return nil, false.
func (s *VitessKeyspaceStatus) GetCondition(ty VitessKeyspaceConditionType) (value *VitessKeyspaceCondition, exists bool) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it may be bug-prone to have an exported method that returns a pointer into the underlying array. Callers may think it's ok to retain the pointer, but that's not safe in general. Either the caller's value might get unintentionally mutated underneath them, or the caller might intend to mutate the value in the array and fail.

Consider this scenario:

ptr := GetCondition(condType)
SetConditionStatus(otherCondType, ...)

// This may or may not update the value in the array,
// depending on whether SetConditionStatus() above
// allocated a new array while appending to the slice.
ptr.Status = corev1.ConditionTrue

I think it'll be useful to have an exported GetCondition() method, but it should return a deep copy to be safe. We could convert this version to an unexported method getCondition() that's used by both SetConditionStatus() and GetCondition().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh, I see what you're saying. Ok, will adjust.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adjusted.

pkg/apis/planetscale/v2/vitesskeyspace_types.go Outdated Show resolved Hide resolved
pkg/apis/planetscale/v2/vitessshard_types.go Outdated Show resolved Hide resolved
Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>
…tion.

Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>
Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>
…feedback.

Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>
Copy link
Contributor

@enisoc enisoc left a comment

Choose a reason for hiding this comment

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

LGTM

@PrismaPhonic PrismaPhonic merged commit 764be92 into feature/resharding Sep 16, 2020
@PrismaPhonic PrismaPhonic deleted the pf-refactor-conditions branch September 16, 2020 23:56
PrismaPhonic added a commit that referenced this pull request Sep 17, 2020
* Refactored conditions to be a list, and have methods for map like access.

Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>

* Oops.

Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>

* Update shard conditions per new list design for Wait support.

Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>

* List size needs to be 0 to use append.

Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>

* Refactored so public GetCondition returns deep copy per review suggestion.

Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>

* Remove left over fragment I missed.

Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>

* Reverted changes to VitessShardStatus and related methods per review feedback.

Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>
enisoc pushed a commit that referenced this pull request Sep 17, 2020
* Refactored conditions to be a list, and have methods for map like access.

Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>

* Oops.

Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>

* Update shard conditions per new list design for Wait support.

Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>

* List size needs to be 0 to use append.

Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>

* Refactored so public GetCondition returns deep copy per review suggestion.

Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>

* Remove left over fragment I missed.

Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>

* Reverted changes to VitessShardStatus and related methods per review feedback.

Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>
enisoc pushed a commit that referenced this pull request Sep 17, 2020
* Refactored conditions to be a list, and have methods for map like access.

Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>

* Oops.

Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>

* Update shard conditions per new list design for Wait support.

Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>

* List size needs to be 0 to use append.

Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>

* Refactored so public GetCondition returns deep copy per review suggestion.

Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>

* Remove left over fragment I missed.

Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>

* Reverted changes to VitessShardStatus and related methods per review feedback.

Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>
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.

None yet

2 participants