Added container labels to ContainerReport interface

This commit is contained in:
Stefan Zwanenburg 2023-06-06 23:37:14 +02:00
parent 36391b0ae7
commit ee49fb953e
7 changed files with 816 additions and 3 deletions

799
go.sum

File diff suppressed because it is too large Load diff

View file

@ -32,7 +32,7 @@ func Update(client container.Client, params types.UpdateParams) (types.Report, e
staleCheckFailed := 0 staleCheckFailed := 0
for i, targetContainer := range containers { for _, targetContainer := range containers {
stale, newestImage, err := client.IsContainerStale(targetContainer) stale, newestImage, err := client.IsContainerStale(targetContainer)
shouldUpdate := stale && !params.NoRestart && !params.MonitorOnly && !targetContainer.IsMonitorOnly() shouldUpdate := stale && !params.NoRestart && !params.MonitorOnly && !targetContainer.IsMonitorOnly()
if err == nil && shouldUpdate { if err == nil && shouldUpdate {
@ -57,7 +57,7 @@ func Update(client container.Client, params types.UpdateParams) (types.Report, e
} else { } else {
progress.AddScanned(targetContainer, newestImage) progress.AddScanned(targetContainer, newestImage)
} }
containers[i].SetStale(stale) targetContainer.SetStale(stale)
if stale { if stale {
staleCount++ staleCount++

View file

@ -76,6 +76,11 @@ func (c Container) IsRestarting() bool {
return c.containerInfo.State.Restarting return c.containerInfo.State.Restarting
} }
// Labels returns a map of all the labels present on the container
func (c Container) Labels() map[string]string {
return c.containerInfo.Config.Labels
}
// Name returns the Docker container name. // Name returns the Docker container name.
func (c Container) Name() string { func (c Container) Name() string {
return c.containerInfo.Name return c.containerInfo.Name

View file

@ -25,7 +25,8 @@ type ContainerStatus struct {
containerName string containerName string
imageName string imageName string
error error
state State state State
labels map[string]string
} }
// ID returns the container ID // ID returns the container ID
@ -61,6 +62,11 @@ func (u *ContainerStatus) Error() string {
return u.error.Error() return u.error.Error()
} }
// Labels returns a map of all labels present on the container
func (u *ContainerStatus) Labels() map[string]string {
return u.labels
}
// State returns the current State that the container is in // State returns the current State that the container is in
func (u *ContainerStatus) State() string { func (u *ContainerStatus) State() string {
switch u.state { switch u.state {

View file

@ -13,6 +13,7 @@ func UpdateFromContainer(cont types.Container, newImage types.ImageID, state Sta
containerID: cont.ID(), containerID: cont.ID(),
containerName: cont.Name(), containerName: cont.Name(),
imageName: cont.ImageName(), imageName: cont.ImageName(),
labels: cont.Labels(),
oldImage: cont.SafeImageID(), oldImage: cont.SafeImageID(),
newImage: newImage, newImage: newImage,
state: state, state: state,

View file

@ -66,6 +66,7 @@ type Container interface {
GetLifecyclePostUpdateCommand() string GetLifecyclePostUpdateCommand() string
VerifyConfiguration() error VerifyConfiguration() error
SetStale(bool) SetStale(bool)
Labels() map[string]string
IsStale() bool IsStale() bool
IsNoPull() bool IsNoPull() bool
SetLinkedToRestarting(bool) SetLinkedToRestarting(bool)

View file

@ -20,4 +20,5 @@ type ContainerReport interface {
ImageName() string ImageName() string
Error() string Error() string
State() string State() string
Labels() map[string]string
} }