Skip to content

Commit

Permalink
k8s, operator: Move enable-k8s option to clientset config
Browse files Browse the repository at this point in the history
The enable-k8s option has been introduced to avoid some operator code
paths that assumed to run in a k8s environment.  Instead of passing
around the flag, we use it to configure the clientset, so that the check
`clientset.IsEnabled()` will keep that too into account and avoid the
execution of kubernetes-specific code.

The operator api server cell and tests have been updated accordingly.

Related: #21344

Signed-off-by: Fabio Falzoi <fabio.falzoi@isovalent.com>
  • Loading branch information
pippolo84 authored and dylandreimerink committed Apr 13, 2023
1 parent fe4da68 commit d5005bf
Show file tree
Hide file tree
Showing 31 changed files with 63 additions and 73 deletions.
1 change: 1 addition & 0 deletions Documentation/cmdref/cilium-agent.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Documentation/cmdref/cilium-agent_hive.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Documentation/cmdref/cilium-agent_hive_dot-graph.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Documentation/cmdref/cilium-operator-alibabacloud.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Documentation/cmdref/cilium-operator-alibabacloud_hive.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Documentation/cmdref/cilium-operator-aws.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Documentation/cmdref/cilium-operator-aws_hive.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Documentation/cmdref/cilium-operator-aws_hive_dot-graph.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Documentation/cmdref/cilium-operator-azure.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Documentation/cmdref/cilium-operator-azure_hive.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Documentation/cmdref/cilium-operator-generic.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Documentation/cmdref/cilium-operator-generic_hive.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Documentation/cmdref/cilium-operator.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Documentation/cmdref/cilium-operator_hive.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Documentation/cmdref/cilium-operator_hive_dot-graph.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Documentation/cmdref/cilium_build-config.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Documentation/cmdref/cilium_preflight_migrate-identity.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Documentation/cmdref/cilium_preflight_validate-cnp.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions operator/api/cell.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,3 @@ type Config struct {
func (def Config) Flags(flags *pflag.FlagSet) {
flags.String(OperatorAPIServeAddr, OperatorAPIServeAddrDefault, "Address to serve API requests")
}

// SharedConfig contains the configuration that is shared between
// this module and others.
// This is done to avoid polluting this module with a direct dependency
// on global operator configuration.
type SharedConfig struct {
EnableK8s bool
}
3 changes: 1 addition & 2 deletions operator/api/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ func HealthHandlerCell(
cell.Provide(func(
clientset k8sClient.Clientset,
logger logrus.FieldLogger,
cfg SharedConfig,
) operator.GetHealthzHandler {
if !cfg.EnableK8s || !clientset.IsEnabled() {
if !clientset.IsEnabled() {
return &healthHandler{
enabled: false,
}
Expand Down
11 changes: 2 additions & 9 deletions operator/api/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ func TestHealthHandlerK8sDisabled(t *testing.T) {

hive := hive.New(
k8sClient.FakeClientCell,
cell.Provide(func() SharedConfig {
return SharedConfig{
EnableK8s: false,
}
cell.Invoke(func(cs *k8sClient.FakeClientset) {
cs.Disable()
}),

HealthHandlerCell(
Expand Down Expand Up @@ -84,11 +82,6 @@ func TestHealthHandlerK8sEnabled(t *testing.T) {

hive := hive.New(
k8sClient.FakeClientCell,
cell.Provide(func() SharedConfig {
return SharedConfig{
EnableK8s: true,
}
}),

HealthHandlerCell(
func() bool {
Expand Down
7 changes: 1 addition & 6 deletions operator/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ type Server interface {
type params struct {
cell.In

Cfg Config
SharedCfg SharedConfig
Cfg Config

HealthHandler operator.GetHealthzHandler
MetricsHandler metrics.GetMetricsHandler
Expand Down Expand Up @@ -66,10 +65,6 @@ type httpServer struct {
func newServer(
p params,
) (Server, error) {
if !p.SharedCfg.EnableK8s {
return nil, nil
}

server := &server{
logger: p.Logger,
shutdowner: p.Shutdowner,
Expand Down

0 comments on commit d5005bf

Please sign in to comment.