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
32 changes: 20 additions & 12 deletions pkg/dyntracker/dynamic_absence_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ type DynamicAbsenceTracker struct {
dynamicClient dynamic.Interface
mapper meta.ResettableRESTMapper

timeout time.Duration
pollPeriod time.Duration
timeout time.Duration
pollPeriod time.Duration
caseInsensitiveGVKMatching bool
}

func NewDynamicAbsenceTracker(
Expand All @@ -44,18 +45,20 @@ func NewDynamicAbsenceTracker(
}

return &DynamicAbsenceTracker{
taskState: taskState,
informerFactory: informerFactory,
dynamicClient: dynamicClient,
mapper: mapper,
timeout: timeout,
pollPeriod: pollPeriod,
taskState: taskState,
informerFactory: informerFactory,
dynamicClient: dynamicClient,
mapper: mapper,
timeout: timeout,
pollPeriod: pollPeriod,
caseInsensitiveGVKMatching: opts.CaseInsensitiveGVKMatching,
}
}

type DynamicAbsenceTrackerOptions struct {
Timeout time.Duration
PollPeriod time.Duration
Timeout time.Duration
PollPeriod time.Duration
CaseInsensitiveGVKMatching bool
}

func (t *DynamicAbsenceTracker) Track(ctx context.Context) error {
Expand All @@ -70,12 +73,17 @@ func (t *DynamicAbsenceTracker) Track(ctx context.Context) error {
groupVersionKind = ts.GroupVersionKind()
})

namespaced, err := util.IsNamespaced(groupVersionKind, t.mapper)
lookupGVK := groupVersionKind
if t.caseInsensitiveGVKMatching {
lookupGVK = util.LowercaseGVK(groupVersionKind)
}

namespaced, err := util.IsNamespaced(lookupGVK, t.mapper)
if err != nil {
return fmt.Errorf("check if namespaced: %w", err)
}

gvr, err := util.GVRFromGVK(groupVersionKind, t.mapper)
gvr, err := util.GVRFromGVK(lookupGVK, t.mapper)
if err != nil {
return fmt.Errorf("get GroupVersionResource: %w", err)
}
Expand Down
32 changes: 20 additions & 12 deletions pkg/dyntracker/dynamic_presence_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ type DynamicPresenceTracker struct {
dynamicClient dynamic.Interface
mapper meta.ResettableRESTMapper

timeout time.Duration
pollPeriod time.Duration
timeout time.Duration
pollPeriod time.Duration
caseInsensitiveGVKMatching bool
}

func NewDynamicPresenceTracker(
Expand All @@ -50,18 +51,20 @@ func NewDynamicPresenceTracker(
}

return &DynamicPresenceTracker{
taskState: taskState,
informerFactory: informerFactory,
dynamicClient: dynamicClient,
mapper: mapper,
timeout: timeout,
pollPeriod: pollPeriod,
taskState: taskState,
informerFactory: informerFactory,
dynamicClient: dynamicClient,
mapper: mapper,
timeout: timeout,
pollPeriod: pollPeriod,
caseInsensitiveGVKMatching: opts.CaseInsensitiveGVKMatching,
}
}

type DynamicPresenceTrackerOptions struct {
Timeout time.Duration
PollPeriod time.Duration
Timeout time.Duration
PollPeriod time.Duration
CaseInsensitiveGVKMatching bool
}

func (t *DynamicPresenceTracker) Track(ctx context.Context) error {
Expand All @@ -76,12 +79,17 @@ func (t *DynamicPresenceTracker) Track(ctx context.Context) error {
groupVersionKind = ts.GroupVersionKind()
})

namespaced, err := util.IsNamespaced(groupVersionKind, t.mapper)
lookupGVK := groupVersionKind
if t.caseInsensitiveGVKMatching {
lookupGVK = util.LowercaseGVK(groupVersionKind)
}

namespaced, err := util.IsNamespaced(lookupGVK, t.mapper)
if err != nil {
return fmt.Errorf("check if namespaced: %w", err)
}

gvr, err := util.GVRFromGVK(groupVersionKind, t.mapper)
gvr, err := util.GVRFromGVK(lookupGVK, t.mapper)
if err != nil {
return fmt.Errorf("get GroupVersionResource: %w", err)
}
Expand Down
24 changes: 15 additions & 9 deletions pkg/dyntracker/dynamic_readiness_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,20 @@ func NewDynamicReadinessTracker(
resourceGVK = ts.GroupVersionKind()
})

if namespaced, err := util.IsNamespaced(resourceGVK, mapper); err != nil {
lookupGVK := resourceGVK
if opts.CaseInsensitiveGVKMatching {
lookupGVK = util.LowercaseGVK(resourceGVK)
}

if namespaced, err := util.IsNamespaced(lookupGVK, mapper); err != nil {
return nil, fmt.Errorf("check if namespaced: %w", err)
} else if !namespaced {
resourceNamespace = ""
}

var tracker any
switch resourceGVK.GroupKind() {
case schema.GroupKind{Group: "apps", Kind: "Deployment"}, schema.GroupKind{Group: "extensions", Kind: "Deployment"}:
switch lookupGVK.GroupKind() {
case schema.GroupKind{Group: "apps", Kind: "deployment"}, schema.GroupKind{Group: "extensions", Kind: "deployment"}:
tracker = deployment.NewTracker(resourceName, resourceNamespace, staticClient, informerFactory, commontracker.Options{
ParentContext: ctx,
Timeout: timeout,
Expand All @@ -117,7 +122,7 @@ func NewDynamicReadinessTracker(
IgnoreLogs: opts.IgnoreLogs,
IgnoreReadinessProbeFailsByContainerName: ignoreReadinessProbeFailsByContainerName,
})
case schema.GroupKind{Group: "apps", Kind: "DaemonSet"}, schema.GroupKind{Group: "extensions", Kind: "DaemonSet"}:
case schema.GroupKind{Group: "apps", Kind: "daemonset"}, schema.GroupKind{Group: "extensions", Kind: "daemonset"}:
tracker = daemonset.NewTracker(resourceName, resourceNamespace, staticClient, informerFactory, commontracker.Options{
ParentContext: ctx,
Timeout: timeout,
Expand All @@ -126,14 +131,14 @@ func NewDynamicReadinessTracker(
IgnoreLogs: opts.IgnoreLogs,
IgnoreReadinessProbeFailsByContainerName: ignoreReadinessProbeFailsByContainerName,
})
case schema.GroupKind{Group: "flagger.app", Kind: "Canary"}:
case schema.GroupKind{Group: "flagger.app", Kind: "canary"}:
tracker = canary.NewTracker(resourceName, resourceNamespace, staticClient, dynamicClient, informerFactory, commontracker.Options{
ParentContext: ctx,
Timeout: timeout,
LogsFromTime: captureLogsFromTime,
IgnoreReadinessProbeFailsByContainerName: ignoreReadinessProbeFailsByContainerName,
})
case schema.GroupKind{Group: "apps", Kind: "StatefulSet"}:
case schema.GroupKind{Group: "apps", Kind: "statefulset"}:
tracker = statefulset.NewTracker(resourceName, resourceNamespace, staticClient, informerFactory, commontracker.Options{
ParentContext: ctx,
Timeout: timeout,
Expand All @@ -142,7 +147,7 @@ func NewDynamicReadinessTracker(
IgnoreLogs: opts.IgnoreLogs,
IgnoreReadinessProbeFailsByContainerName: ignoreReadinessProbeFailsByContainerName,
})
case schema.GroupKind{Group: "batch", Kind: "Job"}:
case schema.GroupKind{Group: "batch", Kind: "job"}:
tracker = job.NewTracker(resourceName, resourceNamespace, staticClient, informerFactory, commontracker.Options{
ParentContext: ctx,
Timeout: timeout,
Expand All @@ -151,13 +156,13 @@ func NewDynamicReadinessTracker(
IgnoreLogs: opts.IgnoreLogs,
IgnoreReadinessProbeFailsByContainerName: ignoreReadinessProbeFailsByContainerName,
})
case schema.GroupKind{Group: "", Kind: "Pod"}:
case schema.GroupKind{Group: "", Kind: "pod"}:
tracker = pod.NewTracker(resourceName, resourceNamespace, staticClient, informerFactory, pod.Options{
IgnoreReadinessProbeFailsByContainerName: ignoreReadinessProbeFailsByContainerName,
IgnoreLogs: opts.IgnoreLogs,
})
default:
resid := resid.NewResourceID(resourceName, resourceGVK, resid.NewResourceIDOptions{
resid := resid.NewResourceID(resourceName, lookupGVK, resid.NewResourceIDOptions{
Namespace: resourceNamespace,
})

Expand Down Expand Up @@ -191,6 +196,7 @@ type DynamicReadinessTrackerOptions struct {
NoActivityTimeout time.Duration
IgnoreReadinessProbeFailsByContainerName map[string]time.Duration
CaptureLogsFromTime time.Time
CaseInsensitiveGVKMatching bool
SaveLogsOnlyForNumberOfReplicas int
SaveLogsOnlyForContainers []string
SaveLogsByRegex *regexp.Regexp
Expand Down
9 changes: 9 additions & 0 deletions pkg/dyntracker/util/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package util

import (
"fmt"
"strings"

"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down Expand Up @@ -29,6 +30,14 @@ func GVRFromGVK(groupVersionKind schema.GroupVersionKind, mapper meta.Resettable
return mapping.Resource, nil
}

func LowercaseGVK(gvk schema.GroupVersionKind) schema.GroupVersionKind {
return schema.GroupVersionKind{
Group: strings.ToLower(gvk.Group),
Version: strings.ToLower(gvk.Version),
Kind: strings.ToLower(gvk.Kind),
}
}

func ResourceHumanID(name, namespace string, groupVersionKind schema.GroupVersionKind, mapper meta.ResettableRESTMapper) string {
namespaced := true
if mapper != nil {
Expand Down
1 change: 0 additions & 1 deletion pkg/tracker/daemonset/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,3 @@ processingPodsStatuses:

return res
}

1 change: 0 additions & 1 deletion pkg/tracker/indicators/indicators.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,3 @@ func (indicator *Int64GreaterOrEqualConditionIndicator) FormatTableElem(prevIndi

return res
}

1 change: 0 additions & 1 deletion pkg/tracker/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,3 @@ type Options struct {
IgnoreLogs bool
IgnoreReadinessProbeFailsByContainerName map[string]time.Duration
}

Loading