@@ -42,6 +42,15 @@ import (
4242 apiv1 "github.com/fluxcd/notification-controller/api/v1beta2"
4343)
4444
45+ // defaultFluxAPIVersions is a map of Flux API kinds to their API versions.
46+ var defaultFluxAPIVersions = map [string ]string {
47+ "Bucket" : "source.toolkit.fluxcd.io/v1beta2" ,
48+ "HelmRepository" : "source.toolkit.fluxcd.io/v1beta2" ,
49+ "GitRepository" : "source.toolkit.fluxcd.io/v1beta2" ,
50+ "OCIRepository" : "source.toolkit.fluxcd.io/v1beta2" ,
51+ "ImageRepository" : "image.toolkit.fluxcd.io/v1beta2" ,
52+ }
53+
4554func (s * ReceiverServer ) handlePayload () func (w http.ResponseWriter , r * http.Request ) {
4655 return func (w http.ResponseWriter , r * http.Request ) {
4756 ctx := context .Background ()
@@ -348,20 +357,12 @@ func (s *ReceiverServer) annotate(ctx context.Context, resource apiv1.CrossNames
348357 Name : resource .Name ,
349358 }
350359
351- apiVersionMap := map [string ]string {
352- "Bucket" : "source.toolkit.fluxcd.io/v1beta2" ,
353- "HelmRepository" : "source.toolkit.fluxcd.io/v1beta2" ,
354- "GitRepository" : "source.toolkit.fluxcd.io/v1beta2" ,
355- "OCIRepository" : "source.toolkit.fluxcd.io/v1beta2" ,
356- "ImageRepository" : "image.toolkit.fluxcd.io/v1beta1" ,
357- }
358-
359360 apiVersion := resource .APIVersion
360361 if apiVersion == "" {
361- if apiVersionMap [resource .Kind ] == "" {
362+ if defaultFluxAPIVersions [resource .Kind ] == "" {
362363 return fmt .Errorf ("apiVersion must be specified for kind '%s'" , resource .Kind )
363364 }
364- apiVersion = apiVersionMap [resource .Kind ]
365+ apiVersion = defaultFluxAPIVersions [resource .Kind ]
365366 }
366367
367368 group , version := getGroupVersion (apiVersion )
0 commit comments