github.com/kubewharf/katalyst-core@v0.5.3/pkg/util/general.go (about) 1 /* 2 Copyright 2022 The Katalyst Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 // util package will be arranged as follows 18 // - utils for extended crd will be put in top-level dir 19 // - for each crd, put functions in individual file(s) 20 // - for general utils, put functions in this file 21 // - utils for specific utils, put them in individual dir(s) 22 // - e.g. cgroup/native-objects ... 23 24 package util 25 26 import ( 27 "sync" 28 29 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 30 31 apiconsts "github.com/kubewharf/katalyst-api/pkg/consts" 32 ) 33 34 // WorkloadSPDEnabledFunc checks if the given workload is enabled with service profiling. 35 type WorkloadSPDEnabledFunc func(metav1.Object) bool 36 37 var ( 38 workloadSPDEnabledLock sync.RWMutex 39 workloadSPDEnabled WorkloadSPDEnabledFunc = func(workload metav1.Object) bool { 40 return workload.GetAnnotations()[apiconsts.WorkloadAnnotationSPDEnableKey] == apiconsts.WorkloadAnnotationSPDEnabled 41 } 42 ) 43 44 // SetWorkloadEnableFunc provides a way to set the 45 func SetWorkloadEnableFunc(f WorkloadSPDEnabledFunc) { 46 workloadSPDEnabledLock.Lock() 47 defer workloadSPDEnabledLock.Unlock() 48 workloadSPDEnabled = f 49 } 50 51 func WorkloadSPDEnabled(workload metav1.Object) bool { 52 workloadSPDEnabledLock.RLock() 53 defer workloadSPDEnabledLock.RUnlock() 54 return workloadSPDEnabled(workload) 55 }