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