iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🐙

Implementing Kubernetes Operators is Painful

に公開

This article is a late entry for day 24 of the Rook and Friends, Cloud Native Storage Advent Calendar 2020.

First of all, while this article uses Rook as an example, it's not specifically about Rook. Rather, it's about the general difficulties of implementing Kubernetes operators, using Rook as a case study[1].

First, there's the issue of often having to perform messy hacks depending on the architecture of the software managed by the operator (hereafter referred to as the "managed target"). As an example, let's talk about managing RGW, a service that provides S3-compatible object storage in Ceph. This service is operated via the radosgw-admin command.

When retrieving information such as object storage users, this command outputs JSON to standard output and returns 0. If it fails, it outputs an error log to standard error and returns 1. Because of this, the operator's implementation used to look like this:

  1. Execute the command and capture both standard output and standard error into a single buffer.
  2. If the command terminates abnormally (i.e., returns 1), output the buffer contents and fail the process.
  3. If the command terminates normally, interpret the buffer contents as JSON.

However, this command sometimes output logs to standard error even when it succeeded, such as when the system load was high. While there are various ways to solve this, for this particular case, step 3 above was changed to "if the command terminates normally, skip to the beginning of the JSON-like string in the buffer before parsing it."

Let's look at another example with radosgw-admin. When this command fails, there are times when you want to handle the error differently depending on the cause. It would be easy if the error messages were structured or if the command's return values changed depending on the cause, but unfortunately, that's not the case. For this reason, in Rook, we perform the messy task of searching for specific strings in the error output to determine the cause.

Furthermore, if the error message changes in the future, we will need to add more conditional statements. This type of change isn't usually mentioned in release notes, so the cost of handling it is high, especially when testing is insufficient.

The examples above are just the tip of the iceberg, and there are many instances where these kinds of minor hacks must be included. It takes a lot of effort, and if you don't leave proper comments, it often happens that you can't tell what the code is for later on.

You might think, "Why not just fix Ceph to make it more operator-friendly?" That is true, and in fact, there are many such movements within Ceph. However, even if a problem is fixed later, the operator must still support older versions, which leads to messy code everywhere that branches logic based on the version.

In Rook, for example, there is something like this. This is for determining feature support, so it's slightly different from the previous point, but you can get the idea. The code of an operator that has been used for many years is quite difficult to read in a sense that is different from technical complexity. I remember being confused by a mountain of code whose intentions I didn't understand when I first looked at Rook's source code.

It's also tough when you realize there might be an issue with the managed target while using the operator. In such cases, the operator developers have to work with the developers of the managed target to find a compromise—often by fixing it themselves—which is quite a demanding task. I have summarized my experience with this in a blog post, so please refer to it if you're interested. At that time, I was going back and forth between the Rook and Ceph communities for several months.

I've written quite critically so far, but I like operators and I like implementing them. Of course, the implementation is hard work, but I think it's a huge step forward that vast operational manuals are now encoded in code and comments, even if the person facing the difficulties has just shifted from the user to the operator developer. I will continue to work hard to grow Rook into an even better operator.

脚注
  1. More broadly, this might apply to any orchestrator, not just Kubernetes operators. ↩︎

Discussion