-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cli: add "cilium bpf config list" #26105
Merged
tklauser
merged 3 commits into
cilium:main
from
mhofstetter:pr/mhofstetter/cli-bpf-config-map
Jun 15, 2023
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of Cilium | ||
|
||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// bpfConfigCmd represents the bpf command | ||
var bpfConfigCmd = &cobra.Command{ | ||
Use: "config", | ||
Short: "Manage runtime config", | ||
} | ||
|
||
func init() { | ||
bpfCmd.AddCommand(bpfConfigCmd) | ||
} |
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,80 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of Cilium | ||
|
||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"io/fs" | ||
"os" | ||
"text/tabwriter" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/cilium/cilium/pkg/command" | ||
"github.com/cilium/cilium/pkg/common" | ||
"github.com/cilium/cilium/pkg/maps/configmap" | ||
) | ||
|
||
type configEntry struct { | ||
Key string | ||
Value uint64 | ||
} | ||
|
||
var bpfConfigListCmd = &cobra.Command{ | ||
Use: "list", | ||
Short: "List all runtime config entries", | ||
Long: "List all runtime config entries", | ||
Aliases: []string{"ls"}, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
common.RequireRootPrivilege("cilium bpf config list") | ||
|
||
configMap, err := configmap.LoadMap() | ||
if err != nil { | ||
if errors.Is(err, fs.ErrNotExist) { | ||
fmt.Fprintln(os.Stderr, "Cannot find config bpf map") | ||
return | ||
} | ||
|
||
Fatalf("Cannot load config bpf map: %s", err) | ||
} | ||
|
||
var entries []configEntry | ||
|
||
for _, index := range []configmap.Index{ | ||
configmap.AgentLiveness, | ||
configmap.UTimeOffset, | ||
} { | ||
value, err := configMap.Get(index) | ||
if err != nil { | ||
Fatalf("Cannot load value with index %q from config bpf map: %s", index, err) | ||
} | ||
entries = append(entries, configEntry{Key: index.String(), Value: value}) | ||
} | ||
|
||
if command.OutputOption() { | ||
if err := command.PrintOutput(entries); err != nil { | ||
Fatalf("error getting output of map in JSON: %s\n", err) | ||
} | ||
return | ||
} | ||
|
||
printEntries(entries) | ||
}, | ||
} | ||
|
||
func printEntries(entries []configEntry) { | ||
w := tabwriter.NewWriter(os.Stdout, 5, 0, 3, ' ', 0) | ||
|
||
fmt.Fprintln(w, "KEY\tVALUE") | ||
for _, e := range entries { | ||
fmt.Fprintf(w, "%s\t%d\n", e.Key, e.Value) | ||
} | ||
w.Flush() | ||
} | ||
|
||
func init() { | ||
bpfConfigCmd.AddCommand(bpfConfigListCmd) | ||
command.AddOutputOption(bpfConfigListCmd) | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dylandreimerink @jrajahalme it looks like the "marker" entry
UsedEntries
is unused and lost its meaning. When L2 Announcement has been introduced, a new entry has been added to the end (whereas the intention of the marker entry was to be the last entry).should we delete the entry and move
AgentLiveness
to second position?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving
AgentLiveness
is alright with me, as long as we do it before the feature freeze. Moving after that could pose upgrade issues if the map is not recreated. I also have no idea whatUsedEntries
was supposed to be used for.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dylandreimerink thanks - removed the constant (in agent &
common.h
)