Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type ContainerInfo struct {
Root string `json:"root"`
Sandbox string `json:"sandbox"`
IPs []string `json:"ip_addresses"`
HostNetwork *bool `json:"host_network"`
}

// IDMappings specifies the ID mappings used for containers.
Expand Down
2 changes: 2 additions & 0 deletions server/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/go-chi/chi/v5"
json "github.com/json-iterator/go"
"github.com/sirupsen/logrus"
"k8s.io/utils/ptr"

"github.com/cri-o/cri-o/internal/lib/sandbox"
"github.com/cri-o/cri-o/internal/log"
Expand Down Expand Up @@ -130,6 +131,7 @@ func (s *Server) getContainerInfo(ctx context.Context, id string, getContainerFu
LogPath: ctr.LogPath(),
Sandbox: ctr.Sandbox(),
IPs: sb.IPs(),
HostNetwork: ptr.To(sb.HostNetwork()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could potentially seg fault.

Should you use deref?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how would it segfault? HostNetwork() returns a bool, and ptr.To() just creates a pointer out of that returned bool

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HostNetwork is a pointer to a bool though.

couldn't that be nil?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sb.HostNetwork() returns a bool, the HostNetwork we nest in the ContainerInfo field is a pointer. They're different

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the use of a bool pointer here?

In kube we would use it for marshaling non default fields but I don't see a reason to have this here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sb.HostNetwork() returns a bool, the HostNetwork we nest in the ContainerInfo field is a pointer. They're different

I see. Yea I got confused.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's already a nil check for sb at lines 88-93

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In kube we would use it for marshaling non default fields but I don't see a reason to have this here.

exactly this reason. Eventually cadvisor will consume this field, and we need to be able to differentiate between cri-o not supporting the field and the field being false.

}, nil
}

Expand Down
Loading