-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bpf: Migrate cilium-migrate-map From C to Go
Currently initializing bpf programs and migrating maps is done with a bash script. This creates a Go version of the "cilium-migrate-map" program and refactors it to be useful by a, similarly, migrated init program. Specifically, giving feedback as to whether any maps even need migrating (often they don't) thus allowing the init program to skip the expensive loading and processing of ELF files. Additionally, a Go version of the C command line program is also added to the cilium container cli program to be used, temporarily, by the init.sh program to ensure that the logic of the new Go migrate program is sound. Signed-off-by: Nate Sweet <nathanjsweet@pm.me>
- Loading branch information
1 parent
fc6ef4d
commit 21ffe74
Showing
4 changed files
with
410 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
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,29 @@ | ||
// Copyright 2021 Authors of Cilium | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// bpfMigrateCmd represents the map command | ||
var bpfMapCmd = &cobra.Command{ | ||
Use: "map", | ||
Short: "BPF map commands", | ||
} | ||
|
||
func init() { | ||
bpfCmd.AddCommand(bpfMapCmd) | ||
} |
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,71 @@ | ||
// Copyright 2021 Authors of Cilium | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cmd | ||
|
||
import ( | ||
"log/syslog" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/cilium/cilium/pkg/bpf/migrate" | ||
) | ||
|
||
// bpfMigrateCmd represents the migrate command | ||
var ( | ||
bpfMigrateCmd = &cobra.Command{ | ||
Use: "migrate", | ||
Short: "Migrate map", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if len(s) > 0 && len(e) > 0 { | ||
log.Fatalf("s (%q) and e (%q) cannot be both set", s, e) | ||
} | ||
var ( | ||
pathName string | ||
finalize bool | ||
) | ||
if len(s) > 0 { | ||
pathName = s | ||
} else if len(e) > 0 { | ||
pathName = e | ||
finalize = true | ||
} else { | ||
log.Fatalf("either s or e must be a valid filepath") | ||
} | ||
sysLogger, err := syslog.New(syslog.LOG_WARNING, "cilium-map-migrate") | ||
if err != nil { | ||
log.Fatalf("Could not open syslog: %v", err) | ||
} | ||
defer sysLogger.Close() | ||
if finalize { | ||
_, err = migrate.Start(pathName, sysLogger) | ||
} else { | ||
err = migrate.Finish(pathName, r, sysLogger) | ||
} | ||
if err != nil { | ||
log.Fatalf("error migrating state for %q: %v", pathName, err) | ||
} | ||
}, | ||
} | ||
s string | ||
e string | ||
r int | ||
) | ||
|
||
func init() { | ||
bpfMapCmd.AddCommand(bpfMigrateCmd) | ||
bpfMigrateCmd.Flags().StringVarP(&s, "start", "s", "", "start file") | ||
bpfMigrateCmd.Flags().StringVarP(&e, "end", "e", "", "end file") | ||
bpfMigrateCmd.Flags().IntVarP(&r, "return", "r", 0, "return code") | ||
} |
Oops, something went wrong.