Skip to content

Commit 47ec1f1

Browse files
committed
events: add support for artifact events
- cmd/podman/common/completion.go: Added shell auto-completion for the `artifact=` and `type=artifact` event filters. - libpod/events/events.go: Added `Artifact` to `ToHumanReadable` formatting, mirroring the `Image` output formatting. - libpod/events/filters.go: Implemented event filtering logic for the `ARTIFACT` type by name and ID. - libpod/events/journal_linux.go: Updated journald reader and writer functions to accurately parse and log artifact events. - libpod/events/logfile.go: Allowed the `Artifact` event type to pass through the file logger reader without throwing an unknown type error. Signed-off-by: Byounguk Lee <nimdrak@gmail.com>
1 parent 44a5293 commit 47ec1f1

5 files changed

Lines changed: 17 additions & 5 deletions

File tree

cmd/podman/common/completion.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1577,7 +1577,7 @@ func getMethodNames(f reflect.Value, prefix string) []formatSuggestion {
15771577
}
15781578

15791579
// AutocompleteEventFilter - Autocomplete event filter flag options.
1580-
// -> "container=", "event=", "image=", "pod=", "volume=", "type="
1580+
// -> "container=", "event=", "image=", "pod=", "volume=", "type=", "artifact="
15811581
func AutocompleteEventFilter(cmd *cobra.Command, _ []string, toComplete string) ([]string, cobra.ShellCompDirective) {
15821582
event := func(_ string) ([]string, cobra.ShellCompDirective) {
15831583
return []string{
@@ -1596,11 +1596,13 @@ func AutocompleteEventFilter(cmd *cobra.Command, _ []string, toComplete string)
15961596
return []string{
15971597
events.Container.String(), events.Image.String(), events.Network.String(),
15981598
events.Pod.String(), events.System.String(), events.Volume.String(), events.Secret.String(),
1599+
events.Artifact.String(),
15991600
}, cobra.ShellCompDirectiveNoFileComp
16001601
}
16011602
kv := keyValueCompletion{
16021603
"container=": func(s string) ([]string, cobra.ShellCompDirective) { return getContainers(cmd, s, completeDefault) },
16031604
"image=": func(s string) ([]string, cobra.ShellCompDirective) { return getImages(cmd, s) },
1605+
"artifact=": func(s string) ([]string, cobra.ShellCompDirective) { return getArtifacts(cmd, s) },
16041606
"pod=": func(s string) ([]string, cobra.ShellCompDirective) { return getPods(cmd, s, completeDefault) },
16051607
"volume=": func(s string) ([]string, cobra.ShellCompDirective) { return getVolumes(cmd, s) },
16061608
"event=": event,

libpod/events/events.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (e *Event) ToHumanReadable(truncate bool) string {
7979
} else {
8080
humanFormat = fmt.Sprintf("%s %s %s %s (container=%s, name=%s)", e.Time, e.Type, e.Status, id, id, e.Network)
8181
}
82-
case Image:
82+
case Image, Artifact:
8383
humanFormat = fmt.Sprintf("%s %s %s %s %s", e.Time, e.Type, e.Status, id, e.Name)
8484
if e.Error != "" {
8585
humanFormat += " " + e.Error

libpod/events/filters.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ func generateEventFilter(filter, filterValue string) (func(e *Event) bool, error
3939
}
4040
return strings.HasPrefix(e.ID, filterValue)
4141
}, nil
42+
case "ARTIFACT":
43+
return func(e *Event) bool {
44+
if e.Type != Artifact {
45+
return false
46+
}
47+
if e.Name == filterValue {
48+
return true
49+
}
50+
return strings.HasPrefix(e.ID, filterValue)
51+
}, nil
4252
case "POD":
4353
return func(e *Event) bool {
4454
if e.Type != Pod {

libpod/events/journal_linux.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (e EventJournalD) Write(ee Event) error {
3737

3838
// Add specialized information based on the podman type
3939
switch ee.Type {
40-
case Image:
40+
case Image, Artifact:
4141
m["PODMAN_NAME"] = ee.Name
4242
m["PODMAN_ID"] = ee.ID
4343
if ee.Error != "" {
@@ -281,7 +281,7 @@ func newEventFromJournalEntry(entry *sdjournal.JournalEntry) (*Event, error) {
281281
if err := getLabelsFromJournal(entry, &newEvent); err != nil {
282282
return nil, err
283283
}
284-
case Image:
284+
case Image, Artifact:
285285
newEvent.ID = entry.Fields["PODMAN_ID"]
286286
if val, ok := entry.Fields["ERROR"]; ok {
287287
newEvent.Error = val

libpod/events/logfile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func (e EventLogFile) Read(ctx context.Context, options ReadOptions) error {
174174
continue
175175
}
176176
switch event.Type {
177-
case Image, Volume, Pod, Container, Network, Secret:
177+
case Image, Volume, Pod, Container, Network, Secret, Artifact:
178178
// no-op
179179
case System:
180180
begin, end, err := e.readRotateEvent(event)

0 commit comments

Comments
 (0)