Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.

Add default storage class name #52

Merged
merged 3 commits into from
Jul 19, 2022
Merged

Add default storage class name #52

merged 3 commits into from
Jul 19, 2022

Conversation

nolancon
Copy link
Collaborator

Changes

Discover and set default storage class name if not set

Verification

@nolancon nolancon requested a review from a team as a code owner July 18, 2022 16:04
if err != nil {
if apierrors.IsNotFound(err) {
// No storageclass found
return nil, nil
Copy link

Choose a reason for hiding this comment

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

I think based on this comment An error is returned if no default storage class is found we have to return an error.

Choose a reason for hiding this comment

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

Here it looks like it's when no storageclass is found at all, not that we didn't find a default one. That happens below at the end of this function

Copy link

Choose a reason for hiding this comment

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

@Ricardo-Osorio I see, but the comment tells something different. /that's why i never trust in comments and usually try to avoid/. apierrors.IsNotFound(err) == no default storage class is found, so i expect An error is returned. We have to:
a) change the comment
b) change the behavior

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

After looking at the ticket again: the etcdcluster CR requires an explicit storageClassName for the volume.
Therefore if it has not been set and we cannot find a storage class to use, then returning an error makes sense here imo.

// storage class is found.
func (r *EtcdClusterReconciler) getDefaultStorageClass(ctx context.Context) (*kstoragev1.StorageClass, error) {
storageClasses := &kstoragev1.StorageClassList{}
err := r.List(ctx, storageClasses)
Copy link

Choose a reason for hiding this comment

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

Suggested change
err := r.List(ctx, storageClasses)
if err := r.List(ctx, storageClasses); err != nil {

// getDefaultStorageClassName returns the name of the default storage class in the cluster, if more
// than one storage class is set to default, the first one discovered is returned. An error is returned
// if no default storage class is found.
func (r *EtcdClusterReconciler) getDefaultStorageClassName(ctx context.Context) (string, error) {
Copy link

Choose a reason for hiding this comment

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

Do we really need a separated function for defaultSC.Name?

Copy link
Collaborator Author

@nolancon nolancon Jul 19, 2022

Choose a reason for hiding this comment

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

I guess not right now, but I like having the option to get the SC in case we need it in future (seeing as we need to pull it from the API here anyway).

Edit: On second thought, if we are now returning an error (as above) a single function with the sole task of acquiring the name makes more sense.

Ricardo-Osorio
Ricardo-Osorio previously approved these changes Jul 19, 2022
mhmxs
mhmxs previously approved these changes Jul 19, 2022
Ricardo-Osorio
Ricardo-Osorio previously approved these changes Jul 19, 2022
@nolancon nolancon dismissed stale reviews from Ricardo-Osorio and mhmxs via e694314 July 19, 2022 11:57
@nolancon nolancon merged commit 89c08d4 into main Jul 19, 2022
@nolancon nolancon deleted the ctrl-265-default-sc branch July 19, 2022 12:32
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.

3 participants