Skip to content

Commit

Permalink
Merge pull request #2142 from openshift-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…2138-to-release-4.13

Bug 2218863:[release-4.13] fix provAPIServer when NodePort svc is stuck waiting for lb endpoint
  • Loading branch information
openshift-merge-robot authored Aug 16, 2023
2 parents bcb4663 + 55fd12d commit 9815dde
Showing 1 changed file with 65 additions and 12 deletions.
77 changes: 65 additions & 12 deletions controllers/storagecluster/provider_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"math/rand"
"os"
"sort"
"time"

"go.uber.org/multierr"
Expand Down Expand Up @@ -185,27 +186,79 @@ func (o *ocsProviderServer) createService(r *StorageClusterReconciler, instance

r.Log.Info("Service create/update succeeded")

if instance.Spec.ProviderAPIServerServiceType == corev1.ServiceTypeLoadBalancer {
endpoint := o.getLoadBalancerServiceEndpoint(actualService)

if endpoint == "" {
r.recorder.ReportIfNotPresent(instance, corev1.EventTypeNormal, "Waiting", "Waiting for Ingress on service "+actualService.Name)
r.Log.Info("Waiting for Ingress on service", "Service", actualService.Name, "Status", actualService.Status)
return reconcile.Result{RequeueAfter: time.Second * 5}, nil
}

instance.Status.StorageProviderEndpoint = fmt.Sprintf("%s:%d", endpoint, ocsProviderServicePort)
} else {
nodeAddresses, err := o.getWorkerNodesInternalIPAddresses(r)
if err != nil {
return reconcile.Result{}, err
}

if len(nodeAddresses) == 0 {
err = fmt.Errorf("Could not find any worker nodes")
r.Log.Error(err, "Worker nodes count is zero")
return reconcile.Result{}, err
}

instance.Status.StorageProviderEndpoint = fmt.Sprintf("%s:%d", nodeAddresses[0], ocsProviderServiceNodePort)

}

r.Log.Info("status.storageProviderEndpoint is updated", "Endpoint", instance.Status.StorageProviderEndpoint)

return reconcile.Result{}, nil
}

func (o *ocsProviderServer) getLoadBalancerServiceEndpoint(service *corev1.Service) string {
endpoint := ""

if len(actualService.Status.LoadBalancer.Ingress) != 0 {
if actualService.Status.LoadBalancer.Ingress[0].IP != "" {
endpoint = actualService.Status.LoadBalancer.Ingress[0].IP
} else if actualService.Status.LoadBalancer.Ingress[0].Hostname != "" {
endpoint = actualService.Status.LoadBalancer.Ingress[0].Hostname
if len(service.Status.LoadBalancer.Ingress) != 0 {
if service.Status.LoadBalancer.Ingress[0].IP != "" {
endpoint = service.Status.LoadBalancer.Ingress[0].IP
} else if service.Status.LoadBalancer.Ingress[0].Hostname != "" {
endpoint = service.Status.LoadBalancer.Ingress[0].Hostname
}
}

if endpoint == "" {
r.recorder.ReportIfNotPresent(instance, corev1.EventTypeNormal, "Waiting", "Waiting for Ingress on service "+actualService.Name)
r.Log.Info("Waiting for Ingress on service", "Service", actualService.Name, "Status", actualService.Status)
return reconcile.Result{RequeueAfter: time.Second * 5}, nil
return endpoint
}

// getWorkerNodesInternalIPAddresses return slice of Internal IPAddress of worker nodes
func (o *ocsProviderServer) getWorkerNodesInternalIPAddresses(r *StorageClusterReconciler) ([]string, error) {

nodes := &corev1.NodeList{}

err := r.Client.List(context.TODO(), nodes)
if err != nil {
r.Log.Error(err, "Failed to list nodes")
return nil, err
}

instance.Status.StorageProviderEndpoint = fmt.Sprintf("%s:%d", endpoint, ocsProviderServicePort)
nodeAddresses := []string{}

r.Log.Info("status.storageProviderEndpoint is updated", "Endpoint", instance.Status.StorageProviderEndpoint)
for i := range nodes.Items {
node := &nodes.Items[i]
if _, ok := node.ObjectMeta.Labels["node-role.kubernetes.io/worker"]; ok {
for _, address := range node.Status.Addresses {
if address.Type == corev1.NodeInternalIP {
nodeAddresses = append(nodeAddresses, address.Address)
break
}
}
}
}

return reconcile.Result{}, nil
sort.Strings(nodeAddresses)

return nodeAddresses, nil
}

func (o *ocsProviderServer) createSecret(r *StorageClusterReconciler, instance *ocsv1.StorageCluster) error {
Expand Down

0 comments on commit 9815dde

Please sign in to comment.