github.com/operator-framework/operator-lifecycle-manager@v0.30.0/pkg/controller/operators/olm/operatorconditions.go (about)

     1  package olm
     2  
     3  import (
     4  	"fmt"
     5  
     6  	apierrors "k8s.io/apimachinery/pkg/api/errors"
     7  	meta "k8s.io/apimachinery/pkg/api/meta"
     8  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
     9  
    10  	"github.com/operator-framework/api/pkg/operators/v1alpha1"
    11  	operatorsv2 "github.com/operator-framework/api/pkg/operators/v2"
    12  	"github.com/sirupsen/logrus"
    13  )
    14  
    15  func (a *Operator) isOperatorUpgradeable(csv *v1alpha1.ClusterServiceVersion) (bool, error) {
    16  	if csv == nil {
    17  		return false, fmt.Errorf("CSV is invalid")
    18  	}
    19  
    20  	cond, err := a.lister.OperatorsV2().OperatorConditionLister().OperatorConditions(csv.GetNamespace()).Get(csv.GetName())
    21  	if err != nil {
    22  		if apierrors.IsNotFound(err) {
    23  			return true, nil
    24  		}
    25  		return false, err
    26  	}
    27  
    28  	logger := a.logger.WithFields(logrus.Fields{
    29  		"name":      csv.GetName(),
    30  		"namespace": csv.GetNamespace(),
    31  	})
    32  
    33  	// Check condition overrides
    34  	if o := meta.FindStatusCondition(cond.Spec.Overrides, operatorsv2.Upgradeable); o != nil {
    35  		if o.Status == metav1.ConditionTrue {
    36  			logger.Infof("Upgradeable condition is overridden to true: %s", o.Message)
    37  			return true, nil
    38  		}
    39  		logger.Infof("Upgradeable condition is overridden to false: %s", o.Message)
    40  		return false, fmt.Errorf("the operator is not upgradeable: %s", o.Message)
    41  	}
    42  
    43  	// Check for OperatorUpgradeable condition status
    44  	if c := meta.FindStatusCondition(cond.Status.Conditions, operatorsv2.Upgradeable); c != nil {
    45  		if c.ObservedGeneration != cond.ObjectMeta.Generation {
    46  			logger.Debugf("Upgradeable condition's generation doesn't match: %d/%d", c.ObservedGeneration, cond.ObjectMeta.Generation)
    47  			return false, fmt.Errorf("the operatorcondition status %q=%q is outdated", c.Type, c.Status)
    48  		}
    49  		if c.Status == metav1.ConditionFalse {
    50  			return false, fmt.Errorf("the operator is not upgradeable: %s", c.Message)
    51  		}
    52  	}
    53  
    54  	return true, nil
    55  }