func()

in pkg/cloud_provider/lustre/lustre.go [238:272]


func (sm *lustreServiceManager) GetCreateInstanceOp(ctx context.Context, instance *ServiceInstance) (*longrunningpb.Operation, error) {
	req := &longrunningpb.ListOperationsRequest{
		Name: fmt.Sprintf("projects/%s/locations/%s", instance.Project, instance.Location),
	}
	it := sm.lustreClient.ListOperations(ctx, req)
	for {
		resp, err := it.Next()
		if errors.Is(err, iterator.Done) {
			return nil, nil
		}
		if err != nil {
			return nil, fmt.Errorf("ListOperations failed for request %v: %w", req, err)
		}

		if resp.GetMetadata().MessageName() != v1alphaMessageType {
			klog.V(4).Infof("Skipping operation %q due to invalid message type: got %q, expected %q", resp.GetName(), resp.GetMetadata().MessageName(), v1alphaMessageType)

			continue
		}

		var metaData lustrepb.OperationMetadata
		err = anypb.UnmarshalTo(resp.GetMetadata(), &metaData, proto.UnmarshalOptions{})
		if err != nil {
			return nil, fmt.Errorf("failed to unmarshal %+v: %w", resp, err)
		}

		// Return the response since a single instance creation call generates only one operation.
		// The CSI driver will never initiate more than one instance creation call for the same volume.
		if strings.ToLower(metaData.GetVerb()) == "create" && metaData.GetTarget() == instanceFullName(instance) {
			klog.V(4).Infof("Existing operation found for instance %q: %+v ", instanceFullName(instance), resp)

			return resp, nil
		}
	}
}