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

Commit

Permalink
Review items
Browse files Browse the repository at this point in the history
  • Loading branch information
nolancon committed Jul 19, 2022
1 parent a67eb4c commit 4dcd600
Showing 1 changed file with 6 additions and 23 deletions.
29 changes: 6 additions & 23 deletions controllers/etcdcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,41 +162,24 @@ func (r *EtcdClusterReconciler) getStorageOSClientSecret(ctx context.Context, se
return secret, nil
}

// getDefaultStorage returns the 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) getDefaultStorageClass(ctx context.Context) (*kstoragev1.StorageClass, error) {
// getDefaultStorageName 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) {
storageClasses := &kstoragev1.StorageClassList{}
err := r.List(ctx, storageClasses)
if err != nil {
if apierrors.IsNotFound(err) {
// No storageclass found
return nil, nil
}
// Unexpected error, some other problem?
if err := r.List(ctx, storageClasses); err != nil {
return nil, err
}

for _, storageClass := range storageClasses.Items {
if defaultSC, ok := storageClass.GetObjectMeta().GetAnnotations()["storageclass.kubernetes.io/is-default-class"]; ok && defaultSC == "true" {
return &storageClass, nil
return storageClass.Name, nil
}
}

return nil, fmt.Errorf("no default storage class discovered in cluster")
}

// 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) {
defaultSC, err := r.getDefaultStorageClass(ctx)
if err != nil {
return "", err
}
return defaultSC.Name, nil
}

func storageOSClientSecretName(name, namespace string) types.NamespacedName {
return types.NamespacedName{
Name: name,
Expand Down

0 comments on commit 4dcd600

Please sign in to comment.