Skip to content

Commit

Permalink
Remove deprecated field ContainerState.NetworkStatusOld
Browse files Browse the repository at this point in the history
This field drags in a dependency on CNI and thereby blocks us from disabling CNI
support via a build tag

[NO NEW TESTS NEEDED]

Signed-off-by: Dan Čermák <[email protected]>
  • Loading branch information
dcermak committed Dec 12, 2023
1 parent d8c6ca6 commit 5c7f745
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 44 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
github.com/buger/goterm v1.0.4
github.com/checkpoint-restore/checkpointctl v1.1.0
github.com/checkpoint-restore/go-criu/v7 v7.0.0
github.com/containernetworking/cni v1.1.2
github.com/containernetworking/plugins v1.4.0
github.com/containers/buildah v1.33.2-0.20231121195905-d1a1c53c8e1c
github.com/containers/common v0.57.1-0.20231206135104-b647eb3a5eea
Expand Down Expand Up @@ -97,6 +96,7 @@ require (
github.com/containerd/log v0.1.0 // indirect
github.com/containerd/stargz-snapshotter/estargz v0.15.1 // indirect
github.com/containerd/typeurl/v2 v2.1.1 // indirect
github.com/containernetworking/cni v1.1.2 // indirect
github.com/containers/libtrust v0.0.0-20230121012942-c1716e8a8d01 // indirect
github.com/containers/luksy v0.0.0-20231030195837-b5a7f79da98b // indirect
github.com/coreos/go-oidc/v3 v3.7.0 // indirect
Expand Down
42 changes: 2 additions & 40 deletions libpod/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
"strings"
"time"

types040 "github.com/containernetworking/cni/pkg/types/040"
"github.com/containers/common/libnetwork/cni"
"github.com/containers/common/libnetwork/types"
"github.com/containers/common/pkg/config"
"github.com/containers/common/pkg/secrets"
Expand Down Expand Up @@ -176,13 +174,6 @@ type ContainerState struct {
LegacyExecSessions map[string]*legacyExecSession `json:"execSessions,omitempty"`
// NetNS is the path or name of the NetNS
NetNS string `json:"netns,omitempty"`
// NetworkStatusOld contains the configuration results for all networks
// the pod is attached to. Only populated if we created a network
// namespace for the container, and the network namespace is currently
// active.
// These are DEPRECATED and will be removed in a future release.
// This field is only used for backwarts compatibility.
NetworkStatusOld []*types040.Result `json:"networkResults,omitempty"`
// NetworkStatus contains the network Status for all networks
// the container is attached to. Only populated if we created a network
// namespace for the container, and the network namespace is currently
Expand Down Expand Up @@ -1374,39 +1365,10 @@ func (c *Container) GetNetworkStatus() (map[string]types.StatusBlock, error) {
return c.getNetworkStatus(), nil
}

// getNetworkStatus get the current network status from the state. If the container
// still uses the old network status it is converted to the new format. This function
// getNetworkStatus get the current network status from the state. This function
// should be used instead of reading c.state.NetworkStatus directly.
func (c *Container) getNetworkStatus() map[string]types.StatusBlock {
if c.state.NetworkStatus != nil {
return c.state.NetworkStatus
}
if c.state.NetworkStatusOld != nil {
networks, err := c.networks()
if err != nil {
return nil
}
if len(networks) != len(c.state.NetworkStatusOld) {
return nil
}
result := make(map[string]types.StatusBlock, len(c.state.NetworkStatusOld))
i := 0
// Note: NetworkStatusOld does not contain the network names so we get them extra
// We cannot guarantee the same order but after a state refresh it should work
for netName := range networks {
status, err := cni.CNIResultToStatus(c.state.NetworkStatusOld[i])
if err != nil {
return nil
}
result[netName] = status
i++
}
c.state.NetworkStatus = result
_ = c.save()

return result
}
return nil
return c.state.NetworkStatus
}

func (c *Container) NamespaceMode(ns spec.LinuxNamespaceType, ctrSpec *spec.Spec) string {
Expand Down
2 changes: 0 additions & 2 deletions libpod/container_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,6 @@ func resetContainerState(state *ContainerState) {
state.StartupHCFailureCount = 0
state.NetNS = ""
state.NetworkStatus = nil
state.NetworkStatusOld = nil
}

// Refresh refreshes the container's state after a restart.
Expand Down Expand Up @@ -694,7 +693,6 @@ func (c *Container) refresh() error {
c.lock = lock

c.state.NetworkStatus = nil
c.state.NetworkStatusOld = nil

// Rewrite the config if necessary.
// Podman 4.0 uses a new port format in the config.
Expand Down
1 change: 0 additions & 1 deletion libpod/container_internal_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ func (c *Container) cleanupNetwork() error {

c.state.NetNS = ""
c.state.NetworkStatus = nil
c.state.NetworkStatusOld = nil

if c.valid {
return c.save()
Expand Down

0 comments on commit 5c7f745

Please sign in to comment.