From 457bbca0cb099eaa84f85cd92ab8a7854f90456e Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 25 Jul 2026 17:11:47 +0200 Subject: [PATCH] remove uses of deprecated grpc.DialContext and grpc.WithInsecure Signed-off-by: Sebastiaan van Stijn --- agent/csi/plugin/plugin.go | 5 +++-- manager/csi/plugin.go | 16 ++++++++-------- .../orchestrator_controlapi_integration_test.go | 14 ++++++++------ 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/agent/csi/plugin/plugin.go b/agent/csi/plugin/plugin.go index a721ac25a8..d77547d490 100644 --- a/agent/csi/plugin/plugin.go +++ b/agent/csi/plugin/plugin.go @@ -8,6 +8,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" + "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/status" "github.com/container-storage-interface/spec/lib/go/csi" @@ -108,9 +109,9 @@ func newNodePlugin(name string, p plugin.AddrPlugin, secrets SecretGetter) *node // client from a grpc client. it exists separately so that testing code can // substitute in fake clients without a grpc connection func (np *nodePlugin) connect(ctx context.Context) error { - // even though this is a unix socket, we must set WithInsecure or the + // even though this is a unix socket, we must set insecure.NewCredential or the // connection will not be allowed. - cc, err := grpc.DialContext(ctx, np.socket, grpc.WithInsecure()) + cc, err := grpc.NewClient(np.socket, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { return err } diff --git a/manager/csi/plugin.go b/manager/csi/plugin.go index 0aacdb33cd..8b8e82793c 100644 --- a/manager/csi/plugin.go +++ b/manager/csi/plugin.go @@ -8,6 +8,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" + "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/status" "github.com/container-storage-interface/spec/lib/go/csi" @@ -93,7 +94,7 @@ func NewPlugin(p mobyplugin.AddrPlugin, provider SecretProvider) Plugin { // connect is a private method that initializes a gRPC ClientConn and creates // the IdentityClient and ControllerClient. func (p *plugin) connect(ctx context.Context) error { - cc, err := grpc.DialContext(ctx, p.socket, grpc.WithInsecure()) + cc, err := grpc.NewClient(p.socket, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { return err } @@ -231,8 +232,8 @@ func (p *plugin) PublishVolume(ctx context.Context, v *api.Volume, nodeID string } // UnpublishVolume calls ControllerUnpublishVolume to unpublish the given -// Volume from the Node with the given swarmkit ID. It returns an error if the -// unpublish does not succeed +// Volume from the Node with the given swarmkit ID. It returns an error if +// unpublish does not succeed. func (p *plugin) UnpublishVolume(ctx context.Context, v *api.Volume, nodeID string) error { if !p.publisher { return nil @@ -319,16 +320,15 @@ func (p *plugin) makeControllerPublishVolumeRequest(v *api.Volume, nodeID string return nil } - secrets := p.makeSecrets(v) - capability := capability.MakeCapability(v.Spec.AccessMode) - capability.AccessType = &csi.VolumeCapability_Mount{ + volumeCapability := capability.MakeCapability(v.Spec.AccessMode) + volumeCapability.AccessType = &csi.VolumeCapability_Mount{ Mount: &csi.VolumeCapability_MountVolume{}, } return &csi.ControllerPublishVolumeRequest{ VolumeId: v.VolumeInfo.VolumeID, NodeId: p.swarmToCSI[nodeID], - Secrets: secrets, - VolumeCapability: capability, + Secrets: p.makeSecrets(v), + VolumeCapability: volumeCapability, VolumeContext: v.VolumeInfo.VolumeContext, } } diff --git a/manager/orchestrator/jobs/orchestrator_controlapi_integration_test.go b/manager/orchestrator/jobs/orchestrator_controlapi_integration_test.go index 396deac830..9fd0404713 100644 --- a/manager/orchestrator/jobs/orchestrator_controlapi_integration_test.go +++ b/manager/orchestrator/jobs/orchestrator_controlapi_integration_test.go @@ -3,6 +3,7 @@ package jobs import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "google.golang.org/grpc/credentials/insecure" "context" "net" @@ -82,12 +83,13 @@ var _ = Describe("Integration between the controlapi and jobs orchestrator", fun // cancel after dial has completed is a no-op, but if we don't cancel, // linters will (probably) complain about a leaked context. defer cancel() - conn, err = grpc.DialContext( - ctx, "unix:"+tempUnixSocket, + //nolint:staticcheck // NewClient does not support WithBlock. + conn, err = grpc.DialContext(ctx, + "unix:"+tempUnixSocket, // block on making this connection, to avoid the tests failing for // funny reasons related to this connection being established async grpc.WithBlock(), - grpc.WithInsecure(), + grpc.WithTransportCredentials(insecure.NewCredentials()), ) Expect(err).ToNot(HaveOccurred()) @@ -101,12 +103,12 @@ var _ = Describe("Integration between the controlapi and jobs orchestrator", fun }) AfterEach(func() { - conn.Close() + _ = conn.Close() grpcServer.Stop() // wait for the server to stop <-serverDone - s.Close() - os.RemoveAll(tempUnixSocket) + _ = s.Close() + _ = os.RemoveAll(tempUnixSocket) o.Stop() <-orchestratorDone