github.com/verrazzano/verrazzano-monitoring-operator@v0.0.30/pkg/vmo/suboperator.go (about)

     1  // Copyright (C) 2020, 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 vmo
     5  
     6  import (
     7  	vmcontrollerv1 "github.com/verrazzano/verrazzano-monitoring-operator/pkg/apis/vmcontroller/v1"
     8  	"github.com/verrazzano/verrazzano-monitoring-operator/pkg/constants"
     9  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    10  	"k8s.io/apimachinery/pkg/labels"
    11  	"k8s.io/apimachinery/pkg/runtime/schema"
    12  )
    13  
    14  // Returns OwnerReferences to the running deployment of the hyper operator, if it exists, or nil otherwise.
    15  func getHyperOperatorOwnerReferences(controller *Controller) []metav1.OwnerReference {
    16  	selector := labels.SelectorFromSet(map[string]string{constants.K8SAppLabel: "verrazzano-monitoring-operator", constants.HyperOperatorModeLabel: "true"})
    17  	hyperOperatorDeploymentsList, _ := controller.deploymentLister.Deployments(controller.namespace).List(selector)
    18  	if len(hyperOperatorDeploymentsList) == 0 {
    19  		return nil
    20  	}
    21  	// If we find more than 1 Hyper Operator, just use the first
    22  	return []metav1.OwnerReference{
    23  		*metav1.NewControllerRef(hyperOperatorDeploymentsList[0], schema.GroupVersionKind{
    24  			Group:   vmcontrollerv1.SchemeGroupVersion.Group,
    25  			Version: vmcontrollerv1.SchemeGroupVersion.Version,
    26  			Kind:    "Deployment",
    27  		}),
    28  	}
    29  }