github.com/banzaicloud/operator-tools@v0.28.10/pkg/reconciler/checks.go (about) 1 // Copyright © 2020 Banzai Cloud 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 reconciler 16 17 import ( 18 "context" 19 20 "emperror.dev/errors" 21 corev1 "k8s.io/api/core/v1" 22 "sigs.k8s.io/controller-runtime/pkg/client" 23 24 "github.com/banzaicloud/operator-tools/pkg/wait" 25 ) 26 27 func IstioSidecarInjectorExistsCheck(c client.Client, namespace string) wait.CustomResourceConditionCheck { 28 return func() (bool, error) { 29 var pods corev1.PodList 30 err := c.List(context.Background(), &pods, client.InNamespace(namespace), client.MatchingLabels(map[string]string{ 31 "istio": "sidecar-injector", 32 })) 33 if err != nil { 34 return false, errors.WrapIf(err, "could not list pods") 35 } 36 if len(pods.Items) == 0 { 37 err = c.List(context.Background(), &pods, client.InNamespace(namespace), client.MatchingLabels(map[string]string{ 38 "istio": "pilot", 39 })) 40 if err != nil { 41 return false, errors.WrapIf(err, "could not list pods") 42 } 43 } 44 45 for _, pod := range pods.Items { 46 if pod.Status.Phase == corev1.PodRunning { 47 for _, cs := range pod.Status.ContainerStatuses { 48 if !cs.Ready { 49 return false, nil 50 } 51 } 52 return true, nil 53 } 54 } 55 56 return false, nil 57 } 58 }