...

Source file src/sigs.k8s.io/cli-utils/pkg/kstatus/polling/aggregator/aggregator.go

Documentation: sigs.k8s.io/cli-utils/pkg/kstatus/polling/aggregator

     1  // Copyright 2020 The Kubernetes Authors.
     2  // SPDX-License-Identifier: Apache-2.0
     3  
     4  package aggregator
     5  
     6  import (
     7  	"sigs.k8s.io/cli-utils/pkg/kstatus/polling/event"
     8  	"sigs.k8s.io/cli-utils/pkg/kstatus/status"
     9  )
    10  
    11  // AggregateStatus computes the aggregate status for all the resources.
    12  // The rules are the following:
    13  //   - If any of the resources has the FailedStatus, the aggregate status is also
    14  //     FailedStatus
    15  //   - If none of the resources have the FailedStatus and at least one is
    16  //     UnknownStatus, the aggregate status is UnknownStatus
    17  //   - If all the resources have the desired status, the aggregate status is the
    18  //     desired status.
    19  //   - If none of the first three rules apply, the aggregate status is
    20  //     InProgressStatus
    21  func AggregateStatus(rss []*event.ResourceStatus, desired status.Status) status.Status {
    22  	if len(rss) == 0 {
    23  		return desired
    24  	}
    25  
    26  	allDesired := true
    27  	anyUnknown := false
    28  	for _, rs := range rss {
    29  		s := rs.Status
    30  		if s == status.FailedStatus {
    31  			return status.FailedStatus
    32  		}
    33  		if s == status.UnknownStatus {
    34  			anyUnknown = true
    35  		}
    36  		if s != desired {
    37  			allDesired = false
    38  		}
    39  	}
    40  	if anyUnknown {
    41  		return status.UnknownStatus
    42  	}
    43  	if allDesired {
    44  		return desired
    45  	}
    46  	return status.InProgressStatus
    47  }
    48  

View as plain text