-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd: Introduce
HUBBLE_COMPAT=legacy-json-output
[ upstream commit 221b8ea ] This commit introduces a new environment variable, `HUBBLE_COMPAT`, which can be used to restore old behavior in the presence of breaking changes. It's inspired by Golang's GODEBUG variable documented here: https://pkg.go.dev/runtime The intent of this flag is to allow us introduce breaking changes in the CLI, while still preserving backwards-compatibility with older versions where needed. As an example, this commit also bring back the legacy `-o json` flow schema if `HUBBLE_COMPAT` is set to `legacy-json-output`. This allows older Cilium stable versions to pull in a newer version of the Hubble CLI as part of security updates, while preserving the behavior of the Hubble CLI that originally shipped with that Cilium version. HUBBLE_COMPAT options are _not_ intended to be supported indefinitely. Rather, compat options may be removed once the ecosystem (such as downstream users like the Cilium-Agent image) has caught up. We use an environment variable instead of a viper flag to ensure that we could also use it to modify the behavior of viper or pflags if needed in the future. Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
- Loading branch information
Showing
5 changed files
with
76 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of Hubble | ||
|
||
package config | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
) | ||
|
||
const ( | ||
// HUBBLE_COMPAT is an environment variable similar to GODEBUG. | ||
// | ||
// It allows us to preserve old CLI behavior in the presence of | ||
// breaking changes. | ||
compatEnvKey = "HUBBLE_COMPAT" | ||
|
||
// legacy-json-output uses the old "-o json" format present | ||
// in Hubble CLI v0.10 and older | ||
compatLegacyJSONOutput = "legacy-json-output" | ||
) | ||
|
||
// CompatOptions defines the available compatibility options | ||
type CompatOptions struct { | ||
LegacyJSONOutput bool | ||
} | ||
|
||
// Compat contains the parsed HUBBLE_COMPAT options | ||
var Compat = compatFromEnv() | ||
|
||
func compatFromEnv() CompatOptions { | ||
c := CompatOptions{} | ||
|
||
for _, opt := range strings.Split(os.Getenv(compatEnvKey), ",") { | ||
switch strings.ToLower(opt) { | ||
case compatLegacyJSONOutput: | ||
c.LegacyJSONOutput = true | ||
default: | ||
// silently ignore unknown options for forward-compatibility | ||
} | ||
} | ||
|
||
return c | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters