Skip to content

Commit 3d57baa

Browse files
authored
Merge pull request #344 from jumppad-labs/erik/undo-network
Undo default network work until a better implementation is made
2 parents 6d64ed4 + 04ddd1a commit 3d57baa

File tree

6 files changed

+30
-197
lines changed

6 files changed

+30
-197
lines changed

pkg/clients/container/docker_tasks.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -397,24 +397,6 @@ func (d *DockerTasks) CreateContainer(c *dtypes.Container) (string, error) {
397397
}
398398
}
399399

400-
if len(c.Networks) == 0 {
401-
net, err := d.FindNetwork("resource.network.jumppad")
402-
if err != nil {
403-
return "", err
404-
}
405-
406-
err = d.AttachNetwork(net.Name, cont.ID, []string{}, "")
407-
if err != nil {
408-
// if we fail to connect to the network roll back the container
409-
errRemove := d.RemoveContainer(cont.ID, false)
410-
if errRemove != nil {
411-
return "", fmt.Errorf("failed to attach network %s to container %s, unable to roll back container: %w", "jumppad", cont.ID, err)
412-
}
413-
414-
return "", fmt.Errorf("unable to connect container to network %s, successfully rolled back container: %w", "jumppad", err)
415-
}
416-
}
417-
418400
err = d.c.ContainerStart(context.Background(), cont.ID, container.StartOptions{})
419401
if err != nil {
420402
return "", err

pkg/clients/container/docker_tasks_container_create_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ func setupContainerMocks() (*mocks.Docker, *imocks.ImageLog) {
115115
[]network.Summary{
116116
{ID: "abc", Labels: map[string]string{"id": "network.testnet"}, IPAM: network.IPAM{Config: []network.IPAMConfig{{Subnet: "10.0.0.0/24"}}}},
117117
{ID: "123", Labels: map[string]string{"id": "network.wan"}, IPAM: network.IPAM{Config: []network.IPAMConfig{{Subnet: "10.2.0.0/24"}}}},
118-
{ID: "jumppad", Labels: map[string]string{"id": "resource.network.jumppad"}, IPAM: network.IPAM{Config: []network.IPAMConfig{{Subnet: "10.0.10.0/24"}}}},
119118
}, nil)
120119

121120
md.On("VolumeList", mock.Anything, mock.Anything).Return(volume.ListResponse{}, nil)
@@ -269,14 +268,14 @@ func TestContainerRollsbackWhenUnableToConnectToNetwork(t *testing.T) {
269268
md.AssertCalled(t, "ContainerRemove", mock.Anything, mock.Anything, mock.Anything)
270269
}
271270

272-
func TestContainerOnlyAttachesToDefaultNetworkWhenNil(t *testing.T) {
271+
func TestContainerDoesNOTAttachesToUserNetworkWhenNil(t *testing.T) {
273272
cc, md, mic := createContainerConfig()
274273
cc.Networks = []dtypes.NetworkAttachment{}
275274

276275
err := setupContainer(t, cc, md, mic)
277276
assert.NoError(t, err)
278277

279-
md.AssertNumberOfCalls(t, "NetworkConnect", 1)
278+
md.AssertNumberOfCalls(t, "NetworkConnect", 0)
280279
}
281280

282281
func TestContainerAssignsIPToUserNetwork(t *testing.T) {

pkg/clients/container/docker_tasks_copy_to_volume_test.go

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,7 @@ func testSetupCopyLocal(t *testing.T) (*DockerTasks, *mocks.Docker) {
8989
Return(volume.ListResponse{Volumes: []*volume.Volume{{}}})
9090

9191
mk.On("NetworkList", mock.Anything, mock.Anything).
92-
Return([]network.Inspect{{
93-
Name: "jumppad",
94-
ID: "resource.network.jumppad",
95-
Labels: map[string]string{
96-
"id": "resource.network.jumppad",
97-
},
98-
IPAM: network.IPAM{
99-
Driver: "default",
100-
Config: []network.IPAMConfig{
101-
{
102-
Subnet: "10.0.10.0/24",
103-
},
104-
},
105-
},
106-
EnableIPv6: false,
107-
}}, nil)
92+
Return([]network.Inspect{}, nil)
10893

10994
mk.On("NetworkConnect", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil)
11095

pkg/config/resources/network/resource.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ import (
77
// TypeNetwork is the string resource type for Network resources
88
const TypeNetwork string = "network"
99

10-
const (
11-
DefaultNetworkID string = "resource.network.jumppad"
12-
DefaultNetworkName string = "jumppad"
13-
DefaultNetworkSubnet string = "10.0.10.0/24"
14-
)
15-
1610
// Network defines a Docker network
1711
type Network struct {
1812
// embedded type holding name, etc

pkg/jumppad/engine.go

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"github.com/jumppad-labs/jumppad/pkg/clients/logger"
1818
"github.com/jumppad-labs/jumppad/pkg/config"
1919
"github.com/jumppad-labs/jumppad/pkg/config/resources/cache"
20-
"github.com/jumppad-labs/jumppad/pkg/config/resources/container"
2120
"github.com/jumppad-labs/jumppad/pkg/config/resources/network"
2221
"github.com/jumppad-labs/jumppad/pkg/jumppad/constants"
2322
"github.com/jumppad-labs/jumppad/pkg/utils"
@@ -164,11 +163,6 @@ func (e *EngineImpl) Diff(path string, variables map[string]string, variablesFil
164163
continue
165164
}
166165

167-
// if this is the default network continue as this is always added
168-
if r.Metadata().Type == network.TypeNetwork && r.Metadata().ID == network.DefaultNetworkID {
169-
continue
170-
}
171-
172166
found := false
173167
for _, r2 := range res.Resources {
174168
if r.Metadata().ID == r2.Metadata().ID {
@@ -245,49 +239,6 @@ func (e *EngineImpl) ApplyWithVariables(ctx context.Context, path string, vars m
245239

246240
e.config = c
247241

248-
// check if there are any networks defined by the user
249-
_, err = c.FindResourcesByType(network.TypeNetwork)
250-
if err != nil {
251-
// create a new network
252-
n := &network.Network{
253-
ResourceBase: types.ResourceBase{
254-
Meta: types.Meta{
255-
ID: network.DefaultNetworkID,
256-
Name: network.DefaultNetworkName,
257-
Type: network.TypeNetwork,
258-
Properties: map[string]interface{}{},
259-
},
260-
},
261-
Subnet: network.DefaultNetworkSubnet,
262-
}
263-
264-
e.log.Debug("Creating default Network", "id", n.Meta.ID)
265-
266-
p := e.providers.GetProvider(n)
267-
if p == nil {
268-
// this should never happen
269-
panic("Unable to find provider for Network, Nic assured me that you should never see this message. Sorry, the monkey has broken something again")
270-
}
271-
272-
// create the network
273-
err := p.Create(ctx)
274-
if err != nil {
275-
n.Meta.Properties[constants.PropertyStatus] = constants.StatusFailed
276-
} else {
277-
n.Meta.Properties[constants.PropertyStatus] = constants.StatusCreated
278-
}
279-
280-
// add the new network to the config
281-
e.config.AppendResource(n)
282-
283-
// save the state
284-
config.SaveState(e.config)
285-
286-
if err != nil {
287-
return nil, fmt.Errorf("unable to create network %s", err)
288-
}
289-
}
290-
291242
// check to see we already have an image cache
292243
_, err = c.FindResourcesByType(cache.TypeImageCache)
293244
if err != nil {
@@ -303,20 +254,6 @@ func (e *EngineImpl) ApplyWithVariables(ctx context.Context, path string, vars m
303254
},
304255
}
305256

306-
// if the default network was created,
307-
// add the default network as a dependency
308-
_, err = c.FindResource(network.DefaultNetworkID)
309-
if err == nil {
310-
ca.Networks = container.NetworkAttachments{
311-
{
312-
ID: network.DefaultNetworkID,
313-
Name: network.DefaultNetworkName,
314-
},
315-
}
316-
317-
ca.AddDependency(network.DefaultNetworkID)
318-
}
319-
320257
e.log.Debug("Creating new Image Cache", "id", ca.Meta.ID)
321258

322259
p := e.providers.GetProvider(ca)

0 commit comments

Comments
 (0)