istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pkg/test/framework/components/echo/kube/util.go (about) 1 // Copyright Istio Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package kube 16 17 import ( 18 "strings" 19 20 corev1 "k8s.io/api/core/v1" 21 22 "istio.io/api/annotation" 23 "istio.io/istio/pkg/config/constants" 24 "istio.io/istio/pkg/test/framework/components/echo" 25 ) 26 27 type podSelector struct { 28 Label string 29 Value string 30 } 31 32 func (s podSelector) String() string { 33 return s.Label + "=" + s.Value 34 } 35 36 func (s podSelector) MatchesPod(pod *corev1.Pod) bool { 37 return pod.ObjectMeta.Labels[s.Label] == s.Value 38 } 39 40 func newPodSelector(cfg echo.Config) podSelector { 41 label := "app" 42 if cfg.DeployAsVM { 43 label = constants.TestVMLabel 44 } 45 return podSelector{ 46 Label: label, 47 Value: cfg.Service, 48 } 49 } 50 51 func serviceAccount(cfg echo.Config) string { 52 if cfg.ServiceAccount { 53 return cfg.Service 54 } 55 if cfg.DeployAsVM { 56 return "default" 57 } 58 return "" 59 } 60 61 // workloadHasSidecar returns true if the input endpoint is deployed with sidecar injected based on the config. 62 func workloadHasSidecar(pod *corev1.Pod) bool { 63 if strings.HasPrefix(pod.Annotations[annotation.InjectTemplates.Name], "grpc-") { 64 return false 65 } 66 for _, c := range pod.Spec.Containers { 67 if c.Name == "istio-proxy" { 68 return true 69 } 70 } 71 for _, c := range pod.Spec.InitContainers { 72 if c.Name == "istio-proxy" { 73 return true 74 } 75 } 76 return false 77 }