github.com/stakater/IngressMonitorController@v1.0.103/pkg/callbacks/resourceActionFuncs.go (about) 1 package callbacks 2 3 import ( 4 routev1 "github.com/openshift/api/route/v1" 5 "k8s.io/api/extensions/v1beta1" 6 "time" 7 ) 8 9 // AnnotationFunc is a generic function to return annotations for resource 10 type AnnotationFunc func(interface{}) map[string]string 11 12 // NameFunc is a generic function to return name of resource 13 type NameFunc func(interface{}) string 14 15 // NamespaceFunc is a generic function to return namespace of resource 16 type NamespaceFunc func(interface{}) string 17 18 // NamespaceFunc is a generic function to return namespace of resource 19 type CreationTimestampFunc func(interface{}) time.Time 20 21 // ResourceActionFuncs provides generic functions to return name, namespace and annotations etc. 22 type ResourceActionFuncs struct { 23 AnnotationFunc AnnotationFunc 24 NameFunc NameFunc 25 NamespaceFunc NamespaceFunc 26 CreationTimestampFunc CreationTimestampFunc 27 } 28 29 // GetIngressAnnotation returns the ingress annotations 30 func GetIngressAnnotation(resource interface{}) map[string]string { 31 return resource.(*v1beta1.Ingress).GetAnnotations() 32 } 33 34 // GetIngressName returns the ingress name 35 func GetIngressName(resource interface{}) string { 36 return resource.(*v1beta1.Ingress).GetName() 37 } 38 39 // GetIngressNamespace returns the ingress namespace 40 func GetIngressNamespace(resource interface{}) string { 41 return resource.(*v1beta1.Ingress).GetNamespace() 42 } 43 44 // GetIngressCreationTimestamp returns the ingress CreationTimestamp 45 func GetIngressCreationTimestamp(resource interface{}) time.Time { 46 return resource.(*v1beta1.Ingress).CreationTimestamp.Time 47 } 48 49 // GetRouteAnnotation returns the route annotations 50 func GetRouteAnnotation(resource interface{}) map[string]string { 51 return resource.(*routev1.Route).GetAnnotations() 52 } 53 54 // GetRouteName returns the route name 55 func GetRouteName(resource interface{}) string { 56 return resource.(*routev1.Route).GetName() 57 } 58 59 // GetRouteNamespace returns the route namespace 60 func GetRouteNamespace(resource interface{}) string { 61 return resource.(*routev1.Route).GetNamespace() 62 } 63 64 // GetRouteCreationTimestamp returns the route CreationTimestamp 65 func GetRouteCreationTimestamp(resource interface{}) time.Time { 66 return resource.(*routev1.Route).CreationTimestamp.Time 67 }