Skip to content
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

Unbreak the cilium-dbg preflight migrate-identity command #36089

Merged
merged 3 commits into from
Nov 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions cilium-dbg/cmd/preflight_identity_crd_migrate.go
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@ import (
"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/identity"
@@ -53,11 +52,10 @@ func migrateIdentityCmd() *cobra.Command {

hive := hive.New(
k8sClient.Cell,
agentK8s.LocalNodeCell,
cell.Invoke(func(lc cell.Lifecycle, clientset k8sClient.Clientset, resources agentK8s.LocalNodeResources, shutdowner hive.Shutdowner) {
cell.Invoke(func(lc cell.Lifecycle, clientset k8sClient.Clientset, shutdowner hive.Shutdowner) {
lc.Append(cell.Hook{
OnStart: func(ctx cell.HookContext) error {
return migrateIdentities(ctx, clientset, resources, shutdowner)
return migrateIdentities(ctx, clientset, shutdowner)
},
})
}),
@@ -96,8 +94,8 @@ func migrateIdentityCmd() *cobra.Command {
//
// NOTE: It is assumed that the migration is from k8s to k8s installations. The
// key labels different when running in non-k8s mode.
func migrateIdentities(ctx cell.HookContext, clientset k8sClient.Clientset, resources agentK8s.LocalNodeResources, shutdowner hive.Shutdowner) error {
defer shutdowner.Shutdown(nil)
func migrateIdentities(ctx cell.HookContext, clientset k8sClient.Clientset, shutdowner hive.Shutdowner) error {
defer shutdowner.Shutdown()

// Setup global configuration
// These are defined in cilium/cmd/kvstore.go
@@ -109,9 +107,9 @@ func migrateIdentities(ctx cell.HookContext, clientset k8sClient.Clientset, reso

// Init Identity backends
initCtx, initCancel := context.WithTimeout(ctx, opTimeout)
kvstoreBackend := initKVStore(initCtx)
kvstoreBackend := initKVStore(ctx, initCtx)

crdBackend, crdAllocator := initK8s(initCtx, clientset, resources)
crdBackend, crdAllocator := initK8s(initCtx, clientset)
initCancel()

log.Info("Listing identities in kvstore")
@@ -205,13 +203,9 @@ func migrateIdentities(ctx cell.HookContext, clientset k8sClient.Clientset, reso

// initK8s connects to k8s with a allocator.Backend and an initialized
// allocator.Allocator, using the k8s config passed into the command.
func initK8s(ctx context.Context, clientset k8sClient.Clientset, resources agentK8s.LocalNodeResources) (crdBackend allocator.Backend, crdAllocator *allocator.Allocator) {
func initK8s(ctx context.Context, clientset k8sClient.Clientset) (crdBackend allocator.Backend, crdAllocator *allocator.Allocator) {
log.Info("Setting up kubernetes client")

if err := agentK8s.WaitForNodeInformation(ctx, log, resources.LocalNode, resources.LocalCiliumNode); err != nil {
log.WithError(err).Fatal("Unable to connect to get node spec from apiserver")
}

// Update CRDs to ensure ciliumIdentity is present
ciliumClient.RegisterCRDs(clientset)

@@ -248,10 +242,14 @@ func initK8s(ctx context.Context, clientset k8sClient.Clientset, resources agent

// initKVStore connects to the kvstore with a allocator.Backend, initialised to
// find identities at the default cilium paths.
func initKVStore(ctx context.Context) (kvstoreBackend allocator.Backend) {
func initKVStore(ctx, wctx context.Context) (kvstoreBackend allocator.Backend) {
log.Info("Setting up kvstore client")
setupKvstore(ctx)

if err := <-kvstore.Client().Connected(wctx); err != nil {
log.WithError(err).Fatal("Cannot connect to the kvstore")
}

idPath := path.Join(cache.IdentitiesPath, "id")
kvstoreBackend, err := kvstoreallocator.NewKVStoreBackend(kvstoreallocator.KVStoreBackendConfiguration{BasePath: cache.IdentitiesPath, Suffix: idPath, Typ: &cacheKey.GlobalIdentity{}, Backend: kvstore.Client()})
if err != nil {
Loading