Skip to content

Commit

Permalink
cloud: Check for podNetworkConfig
Browse files Browse the repository at this point in the history
Bail out early if podNetworkConfig is nil.
This is important as we set the ExternalNetViaPodVM via
podNetworkConfig.

Also fix the test case.

Signed-off-by: Pradipta Banerjee <[email protected]>
  • Loading branch information
bpradipt committed Feb 4, 2025
1 parent 9585fb1 commit 3069500
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/cloud-api-adaptor/pkg/adaptor/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ func (s *cloudService) CreateVM(ctx context.Context, req *pb.CreateVMRequest) (r
return nil, fmt.Errorf("failed to inspect netns %s: %w", netNSPath, err)
}

if podNetworkConfig == nil {
return nil, fmt.Errorf("pod network config is nil")
}

// Pod VM spec
vmSpec := provider.InstanceTypeSpec{
InstanceType: instanceType,
Expand Down
7 changes: 6 additions & 1 deletion src/cloud-api-adaptor/pkg/adaptor/cloud/cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/pkg/adaptor/proxy"
"github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/pkg/forwarder"
"github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/pkg/podnetwork"
"github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/pkg/podnetwork/tunneler"
"github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/pkg/securecomms/kubemgr"
"github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/pkg/securecomms/ppssh"
Expand Down Expand Up @@ -97,7 +98,11 @@ func (f *mockProxyFactory) New(serverName, socketPath string) proxy.AgentProxy {
type mockWorkerNode struct{}

func (n mockWorkerNode) Inspect(nsPath string) (*tunneler.Config, error) {
return nil, nil
return &tunneler.Config{
TunnelType: podnetwork.DefaultTunnelType,
Index: 0,
ExternalNetViaPodVM: false,
}, nil
}

func (n *mockWorkerNode) Setup(nsPath string, podNodeIPs []netip.Addr, config *tunneler.Config) error {
Expand Down

0 comments on commit 3069500

Please sign in to comment.