github.com/operator-framework/operator-lifecycle-manager@v0.30.0/pkg/controller/install/resolver.go (about)

     1  //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -o ../../fakes/fake_strategy.go resolver.go Strategy
     2  //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -o ../../fakes/fake_strategy_installer.go resolver.go StrategyInstaller
     3  //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -o ../../fakes/fake_strategy_resolver.go resolver.go StrategyResolverInterface
     4  package install
     5  
     6  import (
     7  	"fmt"
     8  	"time"
     9  
    10  	"github.com/operator-framework/api/pkg/operators/v1alpha1"
    11  	"github.com/operator-framework/operator-lifecycle-manager/pkg/api/wrappers"
    12  	"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
    13  	"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorlister"
    14  	"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/ownerutil"
    15  )
    16  
    17  type Strategy interface {
    18  	GetStrategyName() string
    19  }
    20  
    21  type StrategyInstaller interface {
    22  	Install(strategy Strategy) error
    23  	CheckInstalled(strategy Strategy) (bool, error)
    24  	ShouldRotateCerts(strategy Strategy) (bool, error)
    25  	CertsRotateAt() time.Time
    26  	CertsRotated() bool
    27  }
    28  
    29  type StrategyResolverInterface interface {
    30  	UnmarshalStrategy(s v1alpha1.NamedInstallStrategy) (strategy Strategy, err error)
    31  	InstallerForStrategy(strategyName string, opClient operatorclient.ClientInterface, opLister operatorlister.OperatorLister, owner ownerutil.Owner, annotations map[string]string, apiServiceDescriptions []v1alpha1.APIServiceDescription, webhookDescriptions []v1alpha1.WebhookDescription, previousStrategy Strategy) StrategyInstaller
    32  }
    33  
    34  type StrategyResolver struct {
    35  	OverridesBuilderFunc DeploymentInitializerBuilderFunc
    36  }
    37  
    38  func (r *StrategyResolver) UnmarshalStrategy(s v1alpha1.NamedInstallStrategy) (strategy Strategy, err error) {
    39  	switch s.StrategyName {
    40  	case v1alpha1.InstallStrategyNameDeployment:
    41  		return &s.StrategySpec, nil
    42  	}
    43  	err = fmt.Errorf("unrecognized install strategy")
    44  	return
    45  }
    46  
    47  func (r *StrategyResolver) InstallerForStrategy(strategyName string, opClient operatorclient.ClientInterface, opLister operatorlister.OperatorLister, owner ownerutil.Owner, annotations map[string]string, apiServiceDescriptions []v1alpha1.APIServiceDescription, webhookDescriptions []v1alpha1.WebhookDescription, previousStrategy Strategy) StrategyInstaller {
    48  	switch strategyName {
    49  	case v1alpha1.InstallStrategyNameDeployment:
    50  		strategyClient := wrappers.NewInstallStrategyDeploymentClient(opClient, opLister, owner.GetNamespace())
    51  
    52  		initializers := []DeploymentInitializerFunc{}
    53  		if r.OverridesBuilderFunc != nil {
    54  			initializers = append(initializers, r.OverridesBuilderFunc(owner))
    55  		}
    56  
    57  		return NewStrategyDeploymentInstaller(strategyClient, annotations, owner, previousStrategy, initializers, apiServiceDescriptions, webhookDescriptions)
    58  	}
    59  
    60  	// Insurance against these functions being called incorrectly (unmarshal strategy will return a valid strategy name)
    61  	return &NullStrategyInstaller{}
    62  }
    63  
    64  type NullStrategyInstaller struct{}
    65  
    66  var _ StrategyInstaller = &NullStrategyInstaller{}
    67  
    68  func (i *NullStrategyInstaller) Install(s Strategy) error {
    69  	return fmt.Errorf("null InstallStrategy used")
    70  }
    71  
    72  func (i *NullStrategyInstaller) CheckInstalled(s Strategy) (bool, error) {
    73  	return true, nil
    74  }
    75  
    76  func (i *NullStrategyInstaller) CertsRotateAt() time.Time {
    77  	return time.Time{}
    78  }
    79  
    80  func (i *NullStrategyInstaller) CertsRotated() bool {
    81  	return false
    82  }
    83  
    84  func (i *NullStrategyInstaller) ShouldRotateCerts(s Strategy) (bool, error) {
    85  	return false, nil
    86  }