Skip to content

Commit

Permalink
remove unused function
Browse files Browse the repository at this point in the history
Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
  • Loading branch information
somtochiama committed Nov 16, 2023
1 parent 3ec8f31 commit be885a7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 31 deletions.
49 changes: 19 additions & 30 deletions cmd/flux/events.go
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -426,43 +415,43 @@ 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)}
},
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 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/events_test.go
Expand Up @@ -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()))
Expand Down

0 comments on commit be885a7

Please sign in to comment.