Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Fixed the panic for uninitialized docker daemon #1958

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion KubeArmor/core/dockerHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,14 @@ func (dm *KubeArmorDaemon) SetContainerVisibility(containerID string) {
}

// GetAlreadyDeployedDockerContainers Function
func (dm *KubeArmorDaemon) GetAlreadyDeployedDockerContainers() {
func (dm *KubeArmorDaemon) GetAlreadyDeployedDockerContainers() error {
// check if Docker exists else instantiate
if Docker == nil {
var err error
Docker, err = NewDockerHandler()
if err != nil {
dm.Logger.Errf("Failed to create new Docker client: %s", err)
return err
}
}

Expand Down Expand Up @@ -455,6 +456,7 @@ func (dm *KubeArmorDaemon) GetAlreadyDeployedDockerContainers() {
} else {
dm.Logger.Warnf("Error while listing containers: %s", err)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do this need to terminate KubeArmorDaemon also?

}
return nil
}

// UpdateDockerContainer Function
Expand Down
16 changes: 12 additions & 4 deletions KubeArmor/core/kubeArmor.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,10 @@ func KubeArmor() {
// monitor containers
if strings.Contains(cfg.GlobalCfg.CRISocket, "docker") {
// update already deployed containers
dm.GetAlreadyDeployedDockerContainers()
err := dm.GetAlreadyDeployedDockerContainers()
if err != nil {
dm.DestroyKubeArmorDaemon()
}
// monitor docker events
go dm.MonitorDockerEvents()
} else if strings.Contains(cfg.GlobalCfg.CRISocket, "containerd") {
Expand Down Expand Up @@ -663,7 +666,10 @@ func KubeArmor() {
// monitor containers
if strings.Contains(dm.Node.ContainerRuntimeVersion, "docker") || strings.Contains(cfg.GlobalCfg.CRISocket, "docker") {
// update already deployed containers
dm.GetAlreadyDeployedDockerContainers()
err := dm.GetAlreadyDeployedDockerContainers()
if err != nil {
dm.DestroyKubeArmorDaemon()
}
// monitor docker events
go dm.MonitorDockerEvents()
} else if strings.Contains(dm.Node.ContainerRuntimeVersion, "containerd") || strings.Contains(cfg.GlobalCfg.CRISocket, "containerd") {
Expand Down Expand Up @@ -691,8 +697,10 @@ func KubeArmor() {
cfg.GlobalCfg.CRISocket = "unix://" + socketFile

// update already deployed containers
dm.GetAlreadyDeployedDockerContainers()

err := dm.GetAlreadyDeployedDockerContainers()
if err != nil {
dm.DestroyKubeArmorDaemon()
}
// monitor docker events
go dm.MonitorDockerEvents()
} else {
Expand Down