Nonlinear parallel transport: preserving level sets of an arbitrary function Motivation: Consider a smooth vector bundle $\pi:E\to M$, a fiber metric $g$, and an affine connection $\nabla$ compatible with $g$. Then the parallel transport $\Pi_{\gamma,t_0,t}$ determined by $\nabla$ is an isometry of the fibers of $E$.
Consider the smooth function $f:E\to \mathbb{R}$ on a vector bundle defined by $f(v):= g(v,v)$. In particular, parallel transport yields a smooth family of smooth maps $\Pi_{\gamma,t_0,t}:E_{\gamma(t_0)}\to E_{\gamma(t)}$ satisfying $$f \circ \Pi_{\gamma,t_0,t} = f,$$
for any path $\gamma:[t_0,t]\to M$.
Question: Suppose that $\pi:E\to M$ is a smooth fiber bundle and $f:E\to \mathbb{R}$ is an arbitrary smooth function. When is it possible to find, for any path $\gamma:[t_0,t]\to M$ a smooth family of smooth maps $\Pi_{\gamma,t_0,t}:E_{\gamma(t_0)}\to E_{\gamma(t)}$ satisfying $$f \circ \Pi_{\gamma,t_0,t} = f?$$
I.e., are there natural conditions that may be imposed on $f$ to ensure that this is possible?
Idea: If the level sets of $f$ are all manifolds and there exists a smooth Ehresmann connection on $E$ such that the corresponding horizontal bundle $\mathcal{H}$ is contained in the distribution $\ker df$, then I think the parallel transport determined by this connection would solve the problem. But it isn't clear to me when such an Ehresmann connection exists. 
Evidently such a (linear) Ehresmann connection exists for the case of $E$ a vector bundle and $f(v) = g(v,v)$ described above.
 A: There are many examples in which such a parallel transport does not exist (for example, take a non-constant function on the base $M$ and pull it back to $E$). However, it does exist in very specific cases, such as your example of a vector bundle with fiber metric. Let us try to generalize your example.
Let $E\to M$ be a fiber bundle with fiber $F$. So $E$ can be represented by a collection of trivializations and transition maps. The transition maps are all of the form $$\varphi_{\alpha,\beta}:U_\alpha\cap U_\beta\to \mathrm{diff}(F).$$ Let $G$ be a Lie subgroup of $\mathrm{diff}(F)$. A $G$-structure on our fiber bundle is a representation in which all the transition maps admit values in $G$. 
Example: A vector bundle is merely a fiber bundle with fiber $\mathbb{R}^k$, equipped with a $GL_k(\mathbb{R})$-structure. Once you give this vector bundle a fiber metric, you actually reduce the structure group to $O_k(\mathbb{R})$. 
We continue with a fiber bundle $E\to M$. To begin with, every fiber $E_p$ can be identified with the fiber model $F$ in many different ways. In fact, the set of diffeomorphisms $E_p\to F$ is diffeomorphic to $\mathrm{diff}(F)$. Once you equip $E$ with a $G$-structure, you distinguish a set of "special" identifications - those that respect the $G$-structure. The set of such identifications is diffeomorphic to $G$. (For example, if $E$ is a vector bundle, then the special identifications are the linear isomorphisms $E_p\to\mathbb{R}^k$. If you have a metric, the special identifications are the isometric linear isomorphisms). 
Assume now that $E\to M$ has a $G$-structure and a compatible connection $\nabla$. That is, all the parallel transport maps of $\nabla$ respect the $G$-structure. Let $h:F\to\mathbb{R}$ be a function which respects the $G$-action on $F$. In other words, $h$ is constant on every $G$-orbit in $F$. Note that in this case, there is a well defined function $\tilde{h}:E\to\mathbb{R}$, which is induced by $h$. Namely, for $q\in E_p\subset E$ we have $$\tilde{h}(q)=h\circ\psi_p(q),$$where $\psi_p:E_p\to F$ is an identification that respects the $G$-structure. (Our assumptions guarantee that this is well defined). The conncection $\nabla$ will then satisfy what you want for the function $\tilde{h}$. 
I leave it you to convince yourself that your example is a particular case of the situation described above.
Edit: Under mild further assumptions,  the above story is in fact the only context in which this phenomenon occurs. Namely, let $E\to M$ be a fiber bundle equipped with a connection $\nabla$, and let $h:E\to\mathbb{R}$ be a function which is preserved by parallel transport of $\nabla$. We only add the assumption that parallel transport exists for every path (this is not always the case in general fiber bundles).
Choose a point $p\in M$, and let $G$ be the group of all diffeomorphisms $E_p\to E_p$ which respect $h|_{E_p}$. Then, construct a collection of trivializations of $E\to M$ using $E_p$ as the model fiber, where all identifications $E_{p'}\to E_p$ are obtained from parallel transport along some path. There are many different ways to do that, but all the transition maps will have values in $G$. This means that the function $h$ is of the sort described above.
Remark: Willie Wong's comment is correct and gives a very simple necessary and sufficient condition. Having said that, all the examples I have encountered of such behavior of a function and a connection originate naturally from a function on the model fiber, as described in this answer (this is definitely the case in your example). In other words, there is usually a bigger picture behind such a function.
A: I'll give a shot at a detailed statement/proof based on Willie Wong's comments.
Theorem: There exists a parallel transport $\Pi$ as in my question iff $\ker df$ is transverse to the tangent spaces of the fibers.
Proof: $(\implies)$ Suppose there exists $e \in E$ with $\ker df_e$ not intersecting $T_e E_{\pi(e)}$ transversely. Then there exists $v \in T_{\pi(e)}M$ with $v \not \in d\pi_e(\ker df_e)$. But then any curve $\gamma$ in $M$ with $\gamma'(0) = v$ cannot lift to a curve contained in a level set of $f$, for such a lift $\tilde{\gamma}$ would satisfy $d\pi_e \tilde\gamma'(0) = v$ and also $\tilde{\gamma}'(0)\in \ker df_e$.
$(\impliedby)$ Assume now that $\ker df$ is transverse to the tangent spaces of the fibers. Suppose that we can find an open cover $(U_a)_{a\in A}$ of $E$ and for each $a \in A$ a vector bundle map $P_a:TU_a\to T U_a$ covering the identity such that $P_a$ is a linear projection on each $T_e U_a \subset T_e E$ with $\ker P_a \subset \ker d f$ and $\text{im }P_a =T_e E_{\pi(e)}$.
Taking a partition of unity $\psi_a$ subordinate to $(U_a)_{a\in A}$, $$P:= \sum_{a\in A}\psi_a P_a$$
is well-defined. $P:T E\to TE$ is a vector bundle map covering the identity, and on each tangent space it is a vertical-valued linear projection since linear projections with common image are closed under convex combinations. We also have $\ker P \subset \ker df$, because the kernel of a convex combination of linear projections is contained in the convex hull of their kernels$^\mathbf{1}$ and $\ker df$ is convex, being a vector space. Defining a horizontal bundle $\mathcal{H}:= \ker P$ yields a smooth (because $P$ is a smooth, constant rank vector bundle map) Ehresmann connection contained in $\ker df$. Parallel transport with respect to this connection does the trick, based on my Idea in the original post.
Thus it suffices to produce $(U_a)_{a\in A}$ and $(P_a)_{a\in A}$. Let $e \in E$. Being a smooth fiber bundle, $e\in E$ is in particular a smooth foliation and thus $e$ has a neighborhood $U$ diffeomorphic to $\mathbb{R}^{n_1}\times \mathbb{R}^{n_2}$, with $n_1 = \dim{M}$ and $n_2$ the dimension of the fibers. Denote a typical element of $\mathbb{R}^{n_1}$ by $x$ and a typical element of $\mathbb{R}^{n_2}$ by $(y,z)$ with $z \in \mathbb{R}$. Since we are assuming $\ker df$ is transverse to the tangent spaces of fibers, by the implicit function theorem (re-ordering the standard coordinates on $\mathbb{R}^{n_2}$ and shrinking $U$ if needed) we obtain a smooth parametrization
$$(x,y,c)\mapsto (x,y, f^c(x,y))$$
of $U$ with each of the level sets $f^{-1}(c)$ obtained by fixing $c \in \mathbb{R}$. Define the smooth vector bundle map $Q:TU\to \ker df \subset TU$ by setting $$Q\left(\sum_i a^i \frac{\partial}{\partial x^i} + \sum_j b^j \frac{\partial}{\partial y^j} + d \frac{\partial}{\partial z}\right):= \sum_i a^i \left(\frac{\partial}{\partial x^i}+ \frac{\partial f^c}{\partial x^i}\right) + \sum_j b^j \left(\frac{\partial}{\partial y^j} + \frac{\partial f^c}{\partial y^j}\right).$$
Then $P:TU \to TU$ defined by $P:= I-Q$ is a vertical-valued projection with $\ker dP \subset \ker df$. 
$\square$
Footnote $^{\mathbf{1}}:$ Given $L = c_1L_1 + c_2 L_2$, note that $\ker L_i = \text{im}(I-L_i)$ and similarly for $L$, and $(I-L) = I-c_1L_1 - c_2L_2 = c_1(I-L_1)+c_2(I-L_2)$ since $c_1 + c_2 = 1$. Now use induction.
