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

Add method for deduping images #1266

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Add dedupe to all providers
  • Loading branch information
IamTheFij committed Dec 19, 2024
commit 45a228462c2f8905d1381db47aa1ffdb623cd0c2
4 changes: 2 additions & 2 deletions internal/provider/docker/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (c *Client) listContainerImage() []model.Image {
return []model.Image{}
}

var list []model.Image
var list model.ImageList
for _, ctn := range ctns {
imageName := ctn.Image
imageRaw, err := cli.ImageInspectWithRaw(imageName)
Expand Down Expand Up @@ -112,7 +112,7 @@ func (c *Client) listContainerImage() []model.Image {
list = append(list, image)
}

return list
return list.Dedupe()
}

func metadata(ctn types.Container) map[string]string {
Expand Down
4 changes: 3 additions & 1 deletion internal/provider/dockerfile/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/crazy-max/diun/v4/pkg/utl"
)

func (c *Client) listExtImage() (list []model.Image) {
func (c *Client) listExtImage() (list model.ImageList) {
for _, filename := range c.listDockerfiles(c.config.Patterns) {
dfile, err := dockerfile.New(dockerfile.Options{
Filename: filename,
Expand Down Expand Up @@ -50,7 +50,9 @@ func (c *Client) listExtImage() (list []model.Image) {
Msg("Watch disabled")
continue
}

list = append(list, image)
list = list.Dedupe()
}
}
return
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/file/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func (c *Client) listFileImage() []model.Image {
var images []model.Image
var images model.ImageList

files := c.getFiles()
if len(files) == 0 {
Expand Down Expand Up @@ -99,7 +99,7 @@ func (c *Client) listFileImage() []model.Image {
}
}

return images
return images.Dedupe()
}

func (c *Client) getFiles() []string {
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/kubernetes/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (c *Client) listPodImage() []model.Image {
return []model.Image{}
}

var list []model.Image
var list model.ImageList
for _, pod := range pods {
for _, ctn := range pod.Spec.Containers {
c.logger.Debug().
Expand Down Expand Up @@ -64,7 +64,7 @@ func (c *Client) listPodImage() []model.Image {
}
}

return list
return list.Dedupe()
}

func metadata(pod v1.Pod, ctn v1.Container) map[string]string {
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/swarm/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (c *Client) listServiceImage() []model.Image {
return []model.Image{}
}

var list []model.Image
var list model.ImageList
for _, svc := range svcs {
c.logger.Debug().
Str("svc_name", svc.Spec.Name).
Expand Down Expand Up @@ -57,7 +57,7 @@ func (c *Client) listServiceImage() []model.Image {
list = append(list, image)
}

return list
return list.Dedupe()
}

func metadata(svc swarm.Service) map[string]string {
Expand Down
Loading