github.com/verrazzano/verrazzano-monitoring-operator@v0.0.30/pkg/resources/services/service.go (about) 1 // Copyright (C) 2020, 2022, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 package services 5 6 import ( 7 vmcontrollerv1 "github.com/verrazzano/verrazzano-monitoring-operator/pkg/apis/vmcontroller/v1" 8 "github.com/verrazzano/verrazzano-monitoring-operator/pkg/config" 9 "github.com/verrazzano/verrazzano-monitoring-operator/pkg/constants" 10 "github.com/verrazzano/verrazzano-monitoring-operator/pkg/resources" 11 corev1 "k8s.io/api/core/v1" 12 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 13 ) 14 15 // New creates a new Service for a VMO resource. It also sets 16 // the appropriate OwnerReferences on the resource so handleObject can discover 17 // the VMO resource that 'owns' it. 18 func New(vmo *vmcontrollerv1.VerrazzanoMonitoringInstance, useNodeRoleSelectors bool) ([]*corev1.Service, error) { 19 var services []*corev1.Service 20 21 if vmo.Spec.Grafana.Enabled { 22 service := createServiceElement(vmo, config.Grafana) 23 services = append(services, service) 24 } 25 if vmo.Spec.Elasticsearch.Enabled { 26 services = append(services, createOpenSearchServiceElements(vmo, useNodeRoleSelectors)...) 27 } 28 if vmo.Spec.Kibana.Enabled { 29 service := createServiceElement(vmo, config.OpenSearchDashboards) 30 services = append(services, service) 31 } 32 if !config.API.Disabled { 33 services = append(services, createServiceElement(vmo, config.API)) 34 } 35 36 return services, nil 37 } 38 func createServiceElement(vmo *vmcontrollerv1.VerrazzanoMonitoringInstance, componentDetails config.ComponentDetails) *corev1.Service { 39 resourceLabel := resources.GetMetaLabels(vmo) 40 resourceLabel[constants.ComponentLabel] = resources.GetCompLabel(componentDetails.Name) 41 return &corev1.Service{ 42 ObjectMeta: metav1.ObjectMeta{ 43 Labels: resourceLabel, 44 Name: resources.GetMetaName(vmo.Name, componentDetails.Name), 45 Namespace: vmo.Namespace, 46 OwnerReferences: resources.GetOwnerReferences(vmo), 47 }, 48 Spec: corev1.ServiceSpec{ 49 Type: vmo.Spec.ServiceType, 50 Selector: resources.GetSpecID(vmo.Name, componentDetails.Name), 51 Ports: []corev1.ServicePort{resources.GetServicePort(componentDetails)}, 52 }, 53 } 54 }