diff --git a/cmd/flux/events.go b/cmd/flux/events.go index 3c003c84fd..7ae3abee90 100644 --- a/cmd/flux/events.go +++ b/cmd/flux/events.go @@ -125,7 +125,7 @@ func eventsCmdRun(cmd *cobra.Command, args []string) error { if err != nil { return err } - clientListOpts = append(clientListOpts, getListOpt(refInfoKind.gv.Kind, name)) + clientListOpts = append(clientListOpts, getListOpt(refInfoKind.gvk.Kind, name)) refs, err := getObjectRef(ctx, kubeclient, refInfoKind, name, *kubeconfigArgs.Namespace) if err != nil { return err @@ -313,9 +313,9 @@ func getObjectRef(ctx context.Context, kubeclient client.Client, ref refInfo, na obj := &unstructured.Unstructured{} obj.SetGroupVersionKind(schema.GroupVersionKind{ - Kind: ref.gv.Kind, - Version: ref.gv.Version, - Group: ref.gv.Group, + Kind: ref.gvk.Kind, + Version: ref.gvk.Version, + Group: ref.gvk.Group, }) objName := types.NamespacedName{ Namespace: ns, @@ -382,17 +382,6 @@ func (r refMap) getRefInfo(kind string) (refInfo, error) { return refInfo{}, fmt.Errorf("'%s' is not a recognized Flux kind", kind) } -// getKind returns the kind from the refMap. -// this returns the correct kind even if the kind arg is lowercased. -func (r refMap) getKind(kind string) (string, error) { - for key, _ := range r { - if strings.EqualFold(key, kind) { - return key, nil - } - } - return "", fmt.Errorf("'%s' is not a recognized Flux kind", kind) -} - func (r refMap) hasKind(kind string) bool { _, err := r.getRefInfo(kind) return err == nil @@ -412,8 +401,8 @@ func validateEventTypes(eventTypes []string) error { } type refInfo struct { - // gv is the group version kind of the resource - gv schema.GroupVersionKind + // gvk is the group version kind of the resource + gvk schema.GroupVersionKind // kind is the kind that the resource references if it's not static kind string // crossNamespaced indicates if this resource uses cross namespaced references @@ -426,12 +415,12 @@ type refInfo struct { var fluxKindMap = refMap{ kustomizev1.KustomizationKind: { - gv: kustomizev1.GroupVersion.WithKind(kustomizev1.KustomizationKind), + gvk: kustomizev1.GroupVersion.WithKind(kustomizev1.KustomizationKind), crossNamespaced: true, field: []string{"spec", "sourceRef"}, }, helmv2.HelmReleaseKind: { - gv: helmv2.GroupVersion.WithKind(helmv2.HelmReleaseKind), + gvk: helmv2.GroupVersion.WithKind(helmv2.HelmReleaseKind), crossNamespaced: true, otherRefs: func(namespace, name string) []string { return []string{fmt.Sprintf("%s/%s-%s", sourcev1b2.HelmChartKind, namespace, name)} @@ -439,30 +428,30 @@ var fluxKindMap = refMap{ field: []string{"spec", "chart", "spec", "sourceRef"}, }, notificationv1b2.AlertKind: { - gv: notificationv1b2.GroupVersion.WithKind(notificationv1b2.AlertKind), + gvk: notificationv1b2.GroupVersion.WithKind(notificationv1b2.AlertKind), kind: notificationv1b2.ProviderKind, crossNamespaced: false, field: []string{"spec", "providerRef"}, }, - notificationv1.ReceiverKind: {gv: notificationv1.GroupVersion.WithKind(notificationv1.ReceiverKind)}, - notificationv1b2.ProviderKind: {gv: notificationv1b2.GroupVersion.WithKind(notificationv1b2.ProviderKind)}, + notificationv1.ReceiverKind: {gvk: notificationv1.GroupVersion.WithKind(notificationv1.ReceiverKind)}, + notificationv1b2.ProviderKind: {gvk: notificationv1b2.GroupVersion.WithKind(notificationv1b2.ProviderKind)}, imagev1.ImagePolicyKind: { - gv: imagev1.GroupVersion.WithKind(imagev1.ImagePolicyKind), + gvk: imagev1.GroupVersion.WithKind(imagev1.ImagePolicyKind), kind: imagev1.ImageRepositoryKind, crossNamespaced: true, field: []string{"spec", "imageRepositoryRef"}, }, sourcev1b2.HelmChartKind: { - gv: sourcev1b2.GroupVersion.WithKind(sourcev1b2.HelmChartKind), + gvk: sourcev1b2.GroupVersion.WithKind(sourcev1b2.HelmChartKind), crossNamespaced: true, field: []string{"spec", "sourceRef"}, }, - sourcev1.GitRepositoryKind: {gv: sourcev1.GroupVersion.WithKind(sourcev1.GitRepositoryKind)}, - sourcev1b2.OCIRepositoryKind: {gv: sourcev1b2.GroupVersion.WithKind(sourcev1b2.OCIRepositoryKind)}, - sourcev1b2.BucketKind: {gv: sourcev1b2.GroupVersion.WithKind(sourcev1b2.BucketKind)}, - sourcev1b2.HelmRepositoryKind: {gv: sourcev1b2.GroupVersion.WithKind(sourcev1b2.HelmRepositoryKind)}, - autov1.ImageUpdateAutomationKind: {gv: autov1.GroupVersion.WithKind(autov1.ImageUpdateAutomationKind)}, - imagev1.ImageRepositoryKind: {gv: imagev1.GroupVersion.WithKind(imagev1.ImageRepositoryKind)}, + sourcev1.GitRepositoryKind: {gvk: sourcev1.GroupVersion.WithKind(sourcev1.GitRepositoryKind)}, + sourcev1b2.OCIRepositoryKind: {gvk: sourcev1b2.GroupVersion.WithKind(sourcev1b2.OCIRepositoryKind)}, + sourcev1b2.BucketKind: {gvk: sourcev1b2.GroupVersion.WithKind(sourcev1b2.BucketKind)}, + sourcev1b2.HelmRepositoryKind: {gvk: sourcev1b2.GroupVersion.WithKind(sourcev1b2.HelmRepositoryKind)}, + autov1.ImageUpdateAutomationKind: {gvk: autov1.GroupVersion.WithKind(autov1.ImageUpdateAutomationKind)}, + imagev1.ImageRepositoryKind: {gvk: imagev1.GroupVersion.WithKind(imagev1.ImageRepositoryKind)}, } func ignoreEvent(e corev1.Event) bool { diff --git a/cmd/flux/events_test.go b/cmd/flux/events_test.go index d98fca5b9f..63cbeaff3f 100644 --- a/cmd/flux/events_test.go +++ b/cmd/flux/events_test.go @@ -365,7 +365,7 @@ func Test_getRows(t *testing.T) { if tt.selector != "" { kind, name := utils.ParseObjectKindName(tt.selector) infoRef, err := fluxKindMap.getRefInfo(kind) - clientOpts = append(clientOpts, getTestListOpt(infoRef.gv.Kind, name)) + clientOpts = append(clientOpts, getTestListOpt(infoRef.gvk.Kind, name)) g.Expect(err).To(Not(HaveOccurred())) refs, err = getObjectRef(context.Background(), c, infoRef, name, tt.namespace) g.Expect(err).To(Not(HaveOccurred()))