Skip to content

Commit

Permalink
treewide: rebase on cilium/hive
Browse files Browse the repository at this point in the history
The general idea is to have `pkg/hive` contain the cilium-specific
adaptations of `cilium/hive`. Specifically, that's providing certain
cells like statedb and jobs directly, and having module decorators
creating the right health and logging components.

It's one big commit as it has proven difficult to get intermediate
commits to compile (which our CI mandates). The health part needs a bit
of love after this, we can probably move `healthv2` into `hive/health`
as it's strongly tied to cilium's hive.

The bulk of the changes are mechanical. The categories are:

1. import path change from cilium/cilium/pkg/hive/{cell,job} to
cilium/hive/{cell,job}
2. giving hive.{Start,Stop,Run} an slog.Logger to provide to the hive,
3. changes to the health interfaces - Scope and HealthReporter are
unified under just Health
4. modules are provided with a job group scoped to their module id
directly, instead of having to create a group from a registry

In addition, a broken test is fixed in api_limits_test. The test was
inadvertently using global state of pflag, and reading the config did
_not_ actually work, but just inherited the existing state from a
previous test.

Finally, in pkg endpoint, due to the removal of cell.GetSubScope, a bit
of health logic is exposed - cell.GetSubScope used to allocate a new
shim scope if the passed parent is `nil`, which it is for EP tests.
Instead of fixing up all the tests which don't pass a health, put that
logic into pkg/endpoint where it's at least visible, and can be cleaned
up if so desired.

Signed-off-by: Jussi Maki <jussi@isovalent.com>
Signed-off-by: David Bimmler <david.bimmler@isovalent.com>
  • Loading branch information
joamaki authored and aanm committed Apr 29, 2024
1 parent 8a2a958 commit 2311f3d
Show file tree
Hide file tree
Showing 424 changed files with 4,117 additions and 6,238 deletions.
1 change: 0 additions & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,6 @@ Makefile* @cilium/build
/pkg/healthv2/ @cilium/sig-foundations
/pkg/health/ @cilium/sig-agent
/pkg/hive/ @cilium/sig-foundations
/pkg/hive/job/metrics.go @cilium/sig-foundations @cilium/metrics
/pkg/hubble/ @cilium/sig-hubble
/pkg/hubble/metrics @cilium/sig-hubble @cilium/sig-hubble-api
/pkg/iana/ @cilium/sig-agent
Expand Down
2 changes: 1 addition & 1 deletion Documentation/contributing/development/hive.rst
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ See also the runnable example in `pkg/k8s/resource/example <https://github.com/c
Job groups
^^^^^^^^^^

The `job package <https://pkg.go.dev/github.com/cilium/cilium/pkg/hive/job>`_ contains logic that
The `job package <https://pkg.go.dev/github.com/cilium/hive/job>`_ contains logic that
makes it easy to manage units of work that the package refers to as "jobs". These jobs are
scheduled as part of a job group.

Expand Down
2 changes: 1 addition & 1 deletion api/v1/health/server/server.go

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

2 changes: 1 addition & 1 deletion api/v1/operator/server/server.go

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

2 changes: 1 addition & 1 deletion api/v1/server.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import (

{{ imports .DefaultImports }}
{{ imports .Imports }}
"github.com/cilium/hive/cell"

"github.com/cilium/cilium/pkg/hive"
"github.com/cilium/cilium/pkg/hive/cell"
)

// Cell implements the {{ humanize .Name }} REST API server when provided
Expand Down
2 changes: 1 addition & 1 deletion api/v1/server/server.go

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

4 changes: 2 additions & 2 deletions cilium-dbg/cmd/bpf_nodeid_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
"os"
"text/tabwriter"

"github.com/spf13/cobra"

"github.com/cilium/cilium/pkg/bpf"
"github.com/cilium/cilium/pkg/command"
"github.com/cilium/cilium/pkg/common"
"github.com/cilium/cilium/pkg/maps/nodemap"

"github.com/spf13/cobra"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions cilium-dbg/cmd/bpf_srv6_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
"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/srv6map"

"github.com/spf13/cobra"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions cilium-dbg/cmd/bpf_srv6_sid.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
"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/srv6map"

"github.com/spf13/cobra"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions cilium-dbg/cmd/bpf_srv6_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
"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/srv6map"

"github.com/spf13/cobra"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions cilium-dbg/cmd/bpf_srv6_vrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
"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/srv6map"

"github.com/spf13/cobra"
)

const (
Expand Down
5 changes: 3 additions & 2 deletions cilium-dbg/cmd/build-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ package cmd

import (
"fmt"
"log/slog"
"os"
"strings"

"github.com/cilium/hive/cell"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"

"github.com/cilium/cilium/pkg/hive"
"github.com/cilium/cilium/pkg/hive/cell"
k8sClient "github.com/cilium/cilium/pkg/k8s/client"
k8sConsts "github.com/cilium/cilium/pkg/k8s/constants"
"github.com/cilium/cilium/pkg/option/resolver"
Expand All @@ -38,7 +39,7 @@ var buildConfigCmd = &cobra.Command{
Short: "Resolve all of the configuration sources that apply to this node",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Running")
if err := buildConfigHive.Run(); err != nil {
if err := buildConfigHive.Run(slog.Default()); err != nil {
Fatalf("Build config failed: %v\n", err)
}
},
Expand Down
3 changes: 1 addition & 2 deletions cilium-dbg/cmd/post_uninstall_cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import (
"path/filepath"
"strings"

"github.com/cilium/ebpf"
"github.com/spf13/cobra"
"github.com/vishvananda/netlink"
"golang.org/x/sys/unix"

"github.com/cilium/ebpf"

"github.com/cilium/cilium/pkg/bpf"
"github.com/cilium/cilium/pkg/common"
"github.com/cilium/cilium/pkg/datapath/loader"
Expand Down
6 changes: 3 additions & 3 deletions cilium-dbg/cmd/preflight_identity_crd_migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ package cmd
import (
"context"
"errors"
"log/slog"
"path"
"time"

"github.com/cilium/hive/cell"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
k8serrors "k8s.io/apimachinery/pkg/api/errors"

agentK8s "github.com/cilium/cilium/daemon/k8s"
"github.com/cilium/cilium/pkg/allocator"
"github.com/cilium/cilium/pkg/hive"
"github.com/cilium/cilium/pkg/hive/cell"
"github.com/cilium/cilium/pkg/identity"
"github.com/cilium/cilium/pkg/identity/cache"
cacheKey "github.com/cilium/cilium/pkg/identity/key"
Expand Down Expand Up @@ -61,15 +62,14 @@ func migrateIdentityCmd() *cobra.Command {
})
}),
)
hive.SetTimeouts(opTimeout, opTimeout)
hive.RegisterFlags(cmd.Flags())

cmd.Run = func(cmd *cobra.Command, args []string) {
// The internal packages log things. Make sure they follow the setup of
// the CLI tool.
logging.DefaultLogger.SetFormatter(log.Formatter)

if err := hive.Run(); err != nil {
if err := hive.Run(slog.Default()); err != nil {
log.Fatal(err)
}
}
Expand Down
6 changes: 3 additions & 3 deletions cilium-dbg/cmd/preflight_k8s_valid_cnp.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ package cmd
import (
"context"
"fmt"
"log/slog"
"time"

"github.com/cilium/hive/cell"
"github.com/spf13/cobra"
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"

"github.com/cilium/cilium/pkg/hive"
"github.com/cilium/cilium/pkg/hive/cell"
v2_validation "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2/validator"
k8sClient "github.com/cilium/cilium/pkg/k8s/client"
"github.com/cilium/cilium/pkg/k8s/client/clientset/versioned/scheme"
Expand All @@ -41,15 +42,14 @@ has an exit code 1 is returned.`,
})
}),
)
hive.SetTimeouts(validateK8sPoliciesTimeout, validateK8sPoliciesTimeout)
hive.RegisterFlags(cmd.Flags())

cmd.Run = func(cmd *cobra.Command, args []string) {
// The internal packages log things. Make sure they follow the setup of of
// the CLI tool.
logging.DefaultLogger.SetFormatter(log.Formatter)

if err := hive.Run(); err != nil {
if err := hive.Run(slog.Default()); err != nil {
log.Fatal(err)
}
}
Expand Down
3 changes: 2 additions & 1 deletion clustermesh-apiserver/clustermesh/cells.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package clustermesh

import (
"github.com/cilium/hive/cell"

cmk8s "github.com/cilium/cilium/clustermesh-apiserver/clustermesh/k8s"
"github.com/cilium/cilium/clustermesh-apiserver/health"
cmmetrics "github.com/cilium/cilium/clustermesh-apiserver/metrics"
Expand All @@ -13,7 +15,6 @@ import (
"github.com/cilium/cilium/pkg/controller"
"github.com/cilium/cilium/pkg/defaults"
"github.com/cilium/cilium/pkg/gops"
"github.com/cilium/cilium/pkg/hive/cell"
k8sClient "github.com/cilium/cilium/pkg/k8s/client"
"github.com/cilium/cilium/pkg/kvstore"
"github.com/cilium/cilium/pkg/kvstore/heartbeat"
Expand Down
2 changes: 1 addition & 1 deletion clustermesh-apiserver/clustermesh/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ package clustermesh
import (
"net/http"

"github.com/cilium/hive/cell"
"github.com/sirupsen/logrus"

"github.com/cilium/cilium/clustermesh-apiserver/health"
"github.com/cilium/cilium/clustermesh-apiserver/syncstate"
"github.com/cilium/cilium/pkg/hive/cell"
k8sClient "github.com/cilium/cilium/pkg/k8s/client"
)

Expand Down
2 changes: 1 addition & 1 deletion clustermesh-apiserver/clustermesh/k8s/resource_ctors.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
package k8s

import (
"github.com/cilium/hive/cell"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"

"github.com/cilium/cilium/pkg/hive/cell"
"github.com/cilium/cilium/pkg/k8s"
cilium_api_v2 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2"
"github.com/cilium/cilium/pkg/k8s/client"
Expand Down
3 changes: 2 additions & 1 deletion clustermesh-apiserver/clustermesh/k8s/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
package k8s

import (
"github.com/cilium/cilium/pkg/hive/cell"
"github.com/cilium/hive/cell"

"github.com/cilium/cilium/pkg/k8s"
cilium_api_v2 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2"
"github.com/cilium/cilium/pkg/k8s/resource"
Expand Down
5 changes: 3 additions & 2 deletions clustermesh-apiserver/clustermesh/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ package clustermesh
import (
"context"
"errors"
"log/slog"
"net"
"path"
"sync"

"github.com/cilium/hive/cell"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -20,7 +22,6 @@ import (
cmtypes "github.com/cilium/cilium/pkg/clustermesh/types"
cmutils "github.com/cilium/cilium/pkg/clustermesh/utils"
"github.com/cilium/cilium/pkg/hive"
"github.com/cilium/cilium/pkg/hive/cell"
"github.com/cilium/cilium/pkg/identity"
identityCache "github.com/cilium/cilium/pkg/identity/cache"
"github.com/cilium/cilium/pkg/ipcache"
Expand Down Expand Up @@ -51,7 +52,7 @@ func NewCmd(h *hive.Hive) *cobra.Command {
Use: "clustermesh",
Short: "Run ClusterMesh",
Run: func(cmd *cobra.Command, args []string) {
if err := h.Run(); err != nil {
if err := h.Run(slog.Default()); err != nil {
log.Fatal(err)
}
},
Expand Down
2 changes: 1 addition & 1 deletion clustermesh-apiserver/clustermesh/users_mgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (
"os"
"sync"

"github.com/cilium/hive/cell"
"github.com/spf13/pflag"
"gopkg.in/yaml.v3"

cmtypes "github.com/cilium/cilium/pkg/clustermesh/types"
"github.com/cilium/cilium/pkg/controller"
"github.com/cilium/cilium/pkg/fswatcher"
"github.com/cilium/cilium/pkg/hive/cell"
"github.com/cilium/cilium/pkg/kvstore"
"github.com/cilium/cilium/pkg/logging/logfields"
"github.com/cilium/cilium/pkg/promise"
Expand Down
8 changes: 5 additions & 3 deletions clustermesh-apiserver/clustermesh/users_mgmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import (
"testing"
"time"

"github.com/cilium/hive/cell"
"github.com/cilium/hive/hivetest"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"

"github.com/cilium/cilium/operator/watchers"
cmtypes "github.com/cilium/cilium/pkg/clustermesh/types"
"github.com/cilium/cilium/pkg/hive"
"github.com/cilium/cilium/pkg/hive/cell"
"github.com/cilium/cilium/pkg/kvstore"
"github.com/cilium/cilium/pkg/promise"
)
Expand Down Expand Up @@ -102,12 +103,13 @@ func TestUsersManagement(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

if err := hive.Start(ctx); err != nil {
tlog := hivetest.Logger(t)
if err := hive.Start(tlog, ctx); err != nil {
t.Fatalf("failed to start: %s", err)
}

defer func() {
if err := hive.Stop(ctx); err != nil {
if err := hive.Stop(tlog, ctx); err != nil {
t.Fatalf("failed to stop: %s", err)
}
}()
Expand Down
2 changes: 1 addition & 1 deletion clustermesh-apiserver/clustermesh/vmmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"path"
"sort"

"github.com/cilium/hive/cell"
"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -20,7 +21,6 @@ import (
"github.com/cilium/cilium/pkg/cidr"
cmtypes "github.com/cilium/cilium/pkg/clustermesh/types"
"github.com/cilium/cilium/pkg/defaults"
"github.com/cilium/cilium/pkg/hive/cell"
"github.com/cilium/cilium/pkg/identity"
identityCache "github.com/cilium/cilium/pkg/identity/cache"
identitymodel "github.com/cilium/cilium/pkg/identity/model"
Expand Down
Loading

0 comments on commit 2311f3d

Please sign in to comment.