events: make `--for` case insensitive for kinds

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
pull/3628/head
Hidde Beydals 2 years ago
parent 5b8f673baa
commit 34220fd514
No known key found for this signature in database
GPG Key ID: 979F380FC2341744

@ -155,7 +155,7 @@ func getRows(ctx context.Context, kubeclient client.Client, clientListOpts []cli
var rows [][]string var rows [][]string
for _, item := range el.Items { for _, item := range el.Items {
if filterEvent(item) { if ignoreEvent(item) {
continue continue
} }
rows = append(rows, getEventRow(item, showNs)) rows = append(rows, getEventRow(item, showNs))
@ -212,7 +212,7 @@ func eventsCmdWatchRun(ctx context.Context, kubeclient client.WithWatch, listOpt
if !ok { if !ok {
return nil return nil
} }
if filterEvent(*event) { if ignoreEvent(*event) {
return nil return nil
} }
rows := getEventRow(*event, showNs) rows := getEventRow(*event, showNs)
@ -366,52 +366,52 @@ type refInfo struct {
} }
func getGroupVersionAndRef(kind, name, ns string) (refInfo, error) { func getGroupVersionAndRef(kind, name, ns string) (refInfo, error) {
switch kind { switch strings.ToLower(kind) {
case kustomizev1.KustomizationKind: case strings.ToLower(kustomizev1.KustomizationKind):
return refInfo{ return refInfo{
gv: kustomizev1.GroupVersion, gv: kustomizev1.GroupVersion,
crossNamespaced: true, crossNamespaced: true,
field: []string{"spec", "sourceRef"}, field: []string{"spec", "sourceRef"},
}, nil }, nil
case helmv2.HelmReleaseKind: case strings.ToLower(helmv2.HelmReleaseKind):
return refInfo{ return refInfo{
gv: helmv2.GroupVersion, gv: helmv2.GroupVersion,
crossNamespaced: true, crossNamespaced: true,
otherRefs: []string{fmt.Sprintf("HelmChart/%s-%s", ns, name)}, otherRefs: []string{fmt.Sprintf("%s/%s-%s", sourcev1.HelmChartKind, ns, name)},
field: []string{"spec", "chart", "spec", "sourceRef"}, field: []string{"spec", "chart", "spec", "sourceRef"},
}, nil }, nil
case notificationv1.AlertKind: case strings.ToLower(notificationv1.AlertKind):
return refInfo{ return refInfo{
gv: notificationv1.GroupVersion, gv: notificationv1.GroupVersion,
kind: notificationv1.ProviderKind, kind: notificationv1.ProviderKind,
crossNamespaced: false, crossNamespaced: false,
field: []string{"spec", "providerRef"}, field: []string{"spec", "providerRef"},
}, nil }, nil
case notificationv1.ReceiverKind, case strings.ToLower(notificationv1.ReceiverKind),
notificationv1.ProviderKind: strings.ToLower(notificationv1.ProviderKind):
return refInfo{ return refInfo{
gv: notificationv1.GroupVersion, gv: notificationv1.GroupVersion,
}, nil }, nil
case imagev1.ImagePolicyKind: case strings.ToLower(imagev1.ImagePolicyKind):
return refInfo{ return refInfo{
gv: imagev1.GroupVersion, gv: imagev1.GroupVersion,
kind: imagev1.ImageRepositoryKind, kind: imagev1.ImageRepositoryKind,
crossNamespaced: true, crossNamespaced: true,
field: []string{"spec", "imageRepositoryRef"}, field: []string{"spec", "imageRepositoryRef"},
}, nil }, nil
case sourcev1.GitRepositoryKind, sourcev1.HelmChartKind, sourcev1.BucketKind, case strings.ToLower(sourcev1.GitRepositoryKind), strings.ToLower(sourcev1.HelmChartKind), strings.ToLower(sourcev1.BucketKind),
sourcev1.HelmRepositoryKind, sourcev1.OCIRepositoryKind: strings.ToLower(sourcev1.HelmRepositoryKind), strings.ToLower(sourcev1.OCIRepositoryKind):
return refInfo{gv: sourcev1.GroupVersion}, nil return refInfo{gv: sourcev1.GroupVersion}, nil
case autov1.ImageUpdateAutomationKind: case strings.ToLower(autov1.ImageUpdateAutomationKind):
return refInfo{gv: autov1.GroupVersion}, nil return refInfo{gv: autov1.GroupVersion}, nil
case imagev1.ImageRepositoryKind: case strings.ToLower(imagev1.ImageRepositoryKind):
return refInfo{gv: imagev1.GroupVersion}, nil return refInfo{gv: imagev1.GroupVersion}, nil
default: default:
return refInfo{}, fmt.Errorf("'%s' is not a flux kind", kind) return refInfo{}, fmt.Errorf("'%s' is not a recognized Flux kind", kind)
} }
} }
func filterEvent(e corev1.Event) bool { func ignoreEvent(e corev1.Event) bool {
if !utils.ContainsItemString(fluxKinds, e.InvolvedObject.Kind) { if !utils.ContainsItemString(fluxKinds, e.InvolvedObject.Kind) {
return true return true
} }

Loading…
Cancel
Save