-
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
configmap & utime sync: provide via hive cell #24830
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of Cilium | ||
|
||
package bpf | ||
|
||
// BpfMap defines the base interface every BPF map needs to implement. | ||
// | ||
// Its main purpose is to register a BPF map via value group `bpf-maps`. | ||
// | ||
// Example: | ||
// | ||
// type MapOut struct { | ||
// cell.Out | ||
// | ||
// BpfMap bpf.BpfMap `group:"bpf-maps"` | ||
// } | ||
type BpfMap interface{} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of Cilium | ||
|
||
package utime | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/cilium/cilium/pkg/controller" | ||
"github.com/cilium/cilium/pkg/hive" | ||
"github.com/cilium/cilium/pkg/hive/cell" | ||
"github.com/cilium/cilium/pkg/maps/configmap" | ||
) | ||
|
||
const ( | ||
syncControllerName = "sync-utime" | ||
syncControllerInterval = 1 * time.Minute | ||
) | ||
|
||
// Cell initializes and manages the utime offset synchronization. | ||
var Cell = cell.Module( | ||
"utime", | ||
"Synchronizes utime offset between userspace and datapath", | ||
|
||
cell.Invoke(initUtimeSync), | ||
) | ||
|
||
func initUtimeSync(lifecycle hive.Lifecycle, configMap configmap.Map) { | ||
controllerManager := controller.NewManager() | ||
|
||
lifecycle.Append(hive.Hook{ | ||
OnStart: func(startCtx hive.HookContext) error { | ||
ctrl := &utimeController{configMap: configMap} | ||
|
||
// Add controller for keeping clock in sync for NTP time jumps and any difference | ||
// between monotonic and boottime clocks. | ||
controllerManager.UpdateController(syncControllerName, | ||
controller.ControllerParams{ | ||
DoFunc: func(ctx context.Context) error { | ||
return ctrl.sync() | ||
}, | ||
RunInterval: syncControllerInterval, | ||
}, | ||
) | ||
return nil | ||
}, | ||
OnStop: func(stopCtx hive.HookContext) error { | ||
if err := controllerManager.RemoveController(syncControllerName); err != nil { | ||
return fmt.Errorf("failed to remove controller: %w", err) | ||
} | ||
return nil | ||
}, | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of Cilium | ||
|
||
package maps | ||
|
||
import ( | ||
"github.com/cilium/cilium/pkg/hive/cell" | ||
"github.com/cilium/cilium/pkg/maps/authmap" | ||
"github.com/cilium/cilium/pkg/maps/configmap" | ||
) | ||
|
||
// Cell contains all cells which are providing BPF Maps. | ||
var Cell = cell.Module( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When should I add something here vs. to the datapath cell as done for the configmap? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah nvm utime.Cell is not a map. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exactly - utime just syncs the utime and uses the configmap to write from user- to kernelspace. the cell of the configmap itself is part of the maps cell. |
||
"maps", | ||
"BPF Maps", | ||
|
||
// Provides the auth.Map which contains the authentication state between Cilium security identities. | ||
authmap.Cell, | ||
|
||
// ConfigMap stores runtime configuration state for the Cilium datapath. | ||
configmap.Cell, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of Cilium | ||
|
||
package configmap | ||
|
||
import ( | ||
"github.com/cilium/cilium/pkg/bpf" | ||
"github.com/cilium/cilium/pkg/hive" | ||
"github.com/cilium/cilium/pkg/hive/cell" | ||
) | ||
|
||
// Cell initializes and manages the config map. | ||
var Cell = cell.Module( | ||
"config-map", | ||
"eBPF map config contains runtime configuration state for the Cilium datapath", | ||
|
||
cell.Provide(newMap), | ||
) | ||
|
||
func newMap(lifecycle hive.Lifecycle) MapOut { | ||
configmap := newConfigMap() | ||
|
||
lifecycle.Append(hive.Hook{ | ||
OnStart: func(startCtx hive.HookContext) error { | ||
return configmap.init() | ||
}, | ||
OnStop: func(stopCtx hive.HookContext) error { | ||
return configmap.close() | ||
}, | ||
}) | ||
|
||
return MapOut{ | ||
ConfigMap: configmap, | ||
BpfMap: configmap, | ||
} | ||
} | ||
|
||
type MapOut struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I usually try to avoid writing |
||
cell.Out | ||
|
||
ConfigMap Map | ||
BpfMap bpf.BpfMap `group:"bpf-maps"` | ||
} |
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.
@joamaki would it be worth to have a provider for the controller manager?
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.
What do you think of #24558?
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.
interesting - will take a look.
i think something like this could help in this case - and could be refactored in the future (once its merged)