Rooting has always been a legal grey area, especially when it comes to warranties. Fortunately, if you purchase your shiny new Pixel 2 directly from Google, it appears you can root away without voiding your warranty.
As one user by the handle "Brian706" discovered while conversing with Google's online support, even if you flash new firmware or switch operating systems, Google will happily service it under warranty.
The only condition is that you'll need to "return your device to the latest stable version of Android".
Things get a little murky if you go with a plan instead -- there's no guarantee you'll get the same deal from the likes of say, Telstra. But you can always try your luck.