github.com/cilium/cilium@v1.16.2/operator/pkg/gateway-api/helpers/serviceimport.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package helpers 5 6 import ( 7 "fmt" 8 9 "k8s.io/apimachinery/pkg/runtime" 10 mcsapiv1alpha1 "sigs.k8s.io/mcs-api/pkg/apis/v1alpha1" 11 mcsapicontrollers "sigs.k8s.io/mcs-api/pkg/controllers" 12 ) 13 14 // HasServiceImportSupport return if the ServiceImport CRD is supported. 15 // This checks if the MCS API group is registered in the client scheme 16 // and it is expected that it is registered only if the ServiceImport 17 // CRD has been installed prior to the client setup. 18 func HasServiceImportSupport(scheme *runtime.Scheme) bool { 19 return scheme.IsGroupRegistered(mcsapiv1alpha1.GroupVersion.Group) 20 } 21 22 func GetServiceName(svcImport *mcsapiv1alpha1.ServiceImport) (string, error) { 23 // ServiceImport gateway api support is conditioned by the fact 24 // that an actual Service backs it. Other implementations of MCS API 25 // are not supported. 26 backendServiceName, ok := svcImport.Annotations[mcsapicontrollers.DerivedServiceAnnotation] 27 if !ok { 28 return "", fmt.Errorf("%s %s/%s does not have annotation %s", svcImport.Kind, svcImport.Namespace, svcImport.Name, mcsapicontrollers.DerivedServiceAnnotation) 29 } 30 31 return backendServiceName, nil 32 }