istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pilot/pkg/autoregistration/internal/health/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 health
    16  
    17  import (
    18  	"istio.io/api/meta/v1alpha1"
    19  	"istio.io/istio/pilot/pkg/model/status"
    20  	"istio.io/istio/pkg/config"
    21  )
    22  
    23  // IsEligibleForHealthStatusUpdates returns true if a given WorkloadEntry
    24  // is allowed to receive health status updates sent by an Istio Proxy.
    25  //
    26  // Consider a workload eligible for health status updates as long as the
    27  // WorkloadEntryHealthCheckAnnotation is present (no matter what the value is).
    28  // In case the annotation is present but the value is not "true", the proxy should be allowed
    29  // to send health status updates, config health condition should be updated accordingly,
    30  // however reported health status should not come into effect.
    31  func IsEligibleForHealthStatusUpdates(wle *config.Config) bool {
    32  	if wle == nil {
    33  		return false
    34  	}
    35  	_, annotated := wle.Annotations[status.WorkloadEntryHealthCheckAnnotation]
    36  	return annotated
    37  }
    38  
    39  // HasHealthCondition returns true if a given WorkloadEntry has ConditionHealthy
    40  // condition.
    41  func HasHealthCondition(wle *config.Config) bool {
    42  	if wle == nil {
    43  		return false
    44  	}
    45  	s, ok := wle.Status.(*v1alpha1.IstioStatus)
    46  	if !ok {
    47  		return false
    48  	}
    49  	return status.GetCondition(s.Conditions, status.ConditionHealthy) != nil
    50  }