Skip to content

Commit 3a56591

Browse files
authored
Move operator caching from resolver into a new package. (#2316)
Signed-off-by: Ben Luddy <[email protected]>
1 parent 31350db commit 3a56591

21 files changed

+837
-833
lines changed

pkg/controller/operators/olm/operator.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/internal/pruning"
3939
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/olm/overrides"
4040
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver"
41+
resolvercache "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/cache"
4142
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/clients"
4243
csvutility "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/csv"
4344
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/event"
@@ -1364,7 +1365,7 @@ func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v
13641365
out = in.DeepCopy()
13651366
now := a.now()
13661367

1367-
operatorSurface, err := resolver.NewOperatorFromV1Alpha1CSV(out)
1368+
operatorSurface, err := resolvercache.NewOperatorFromV1Alpha1CSV(out)
13681369
if err != nil {
13691370
// If the resolver is unable to retrieve the operator info from the CSV the CSV requires changes, a syncError should not be returned.
13701371
logger.WithError(err).Warn("Unable to retrieve operator information from CSV")
@@ -1428,7 +1429,7 @@ func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v
14281429

14291430
groupSurface := resolver.NewOperatorGroup(operatorGroup)
14301431
otherGroupSurfaces := resolver.NewOperatorGroupSurfaces(otherGroups...)
1431-
providedAPIs := operatorSurface.ProvidedAPIs().StripPlural()
1432+
providedAPIs := operatorSurface.GetProvidedAPIs().StripPlural()
14321433

14331434
switch result := a.apiReconciler.Reconcile(providedAPIs, groupSurface, otherGroupSurfaces...); {
14341435
case operatorGroup.Spec.StaticProvidedAPIs && (result == resolver.AddAPIs || result == resolver.RemoveAPIs):

pkg/controller/operators/olm/operator_test.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import (
5555
olmerrors "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/errors"
5656
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
5757
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver"
58+
resolvercache "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/cache"
5859
"github.com/operator-framework/operator-lifecycle-manager/pkg/fakes"
5960
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/clientfake"
6061
csvutility "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/csv"
@@ -872,7 +873,7 @@ func TestTransitionCSV(t *testing.T) {
872873
logrus.SetLevel(logrus.DebugLevel)
873874
namespace := "ns"
874875

875-
apiHash, err := resolver.APIKeyToGVKHash(opregistry.APIKey{Group: "g1", Version: "v1", Kind: "c1"})
876+
apiHash, err := resolvercache.APIKeyToGVKHash(opregistry.APIKey{Group: "g1", Version: "v1", Kind: "c1"})
876877
require.NoError(t, err)
877878

878879
defaultOperatorGroup := &v1.OperatorGroup{
@@ -3693,7 +3694,7 @@ func TestSyncOperatorGroups(t *testing.T) {
36933694
v1alpha1.CSVPhaseNone,
36943695
), labels.Set{resolver.APILabelKeyPrefix + "9f4c46c37bdff8d0": "provided"})
36953696

3696-
operatorCSV.Spec.InstallStrategy.StrategySpec.DeploymentSpecs[0].Spec.Template.Spec.Containers[0].Env = []corev1.EnvVar{corev1.EnvVar{
3697+
operatorCSV.Spec.InstallStrategy.StrategySpec.DeploymentSpecs[0].Spec.Template.Spec.Containers[0].Env = []corev1.EnvVar{{
36973698
Name: "OPERATOR_CONDITION_NAME",
36983699
Value: operatorCSV.GetName(),
36993700
}}
@@ -4631,7 +4632,7 @@ func TestOperatorGroupConditions(t *testing.T) {
46314632
},
46324633
expectError: true,
46334634
expectedConditions: []metav1.Condition{
4634-
metav1.Condition{
4635+
{
46354636
Type: v1.OperatorGroupServiceAccountCondition,
46364637
Status: metav1.ConditionTrue,
46374638
Reason: v1.OperatorGroupServiceAccountReason,
@@ -4674,7 +4675,7 @@ func TestOperatorGroupConditions(t *testing.T) {
46744675
},
46754676
expectError: true,
46764677
expectedConditions: []metav1.Condition{
4677-
metav1.Condition{
4678+
{
46784679
Type: v1.MutlipleOperatorGroupCondition,
46794680
Status: metav1.ConditionTrue,
46804681
Reason: v1.MultipleOperatorGroupsReason,

pkg/controller/operators/olm/operatorgroup.go

+12-11
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
2323
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/decorators"
2424
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver"
25+
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/cache"
2526
hashutil "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/kubernetes/pkg/util/hash"
2627
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/ownerutil"
2728
opregistry "github.com/operator-framework/operator-registry/pkg/registry"
@@ -46,7 +47,7 @@ var (
4647
)
4748

4849
func aggregationLabelFromAPIKey(k opregistry.APIKey, suffix string) (string, error) {
49-
hash, err := resolver.APIKeyToGVKHash(k)
50+
hash, err := cache.APIKeyToGVKHash(k)
5051
if err != nil {
5152
return "", err
5253
}
@@ -188,7 +189,7 @@ func (a *Operator) syncOperatorGroups(obj interface{}) error {
188189
groupSurface := resolver.NewOperatorGroup(op)
189190
groupProvidedAPIs := groupSurface.ProvidedAPIs()
190191
providedAPIsForCSVs := a.providedAPIsFromCSVs(op, logger)
191-
providedAPIsForGroup := make(resolver.APISet)
192+
providedAPIsForGroup := make(cache.APISet)
192193
for api := range providedAPIsForCSVs {
193194
providedAPIsForGroup[api] = struct{}{}
194195
}
@@ -309,26 +310,26 @@ func (a *Operator) providedAPIsFromCSVs(group *v1.OperatorGroup, logger *logrus.
309310
// TODO: Throw out CSVs that aren't members of the group due to group related failures?
310311

311312
// Union the providedAPIsFromCSVs from existing members of the group
312-
operatorSurface, err := resolver.NewOperatorFromV1Alpha1CSV(csv)
313+
operatorSurface, err := cache.NewOperatorFromV1Alpha1CSV(csv)
313314
if err != nil {
314315
logger.WithError(err).Warn("could not create OperatorSurface from csv")
315316
continue
316317
}
317-
for providedAPI := range operatorSurface.ProvidedAPIs().StripPlural() {
318+
for providedAPI := range operatorSurface.GetProvidedAPIs().StripPlural() {
318319
providedAPIsFromCSVs[providedAPI] = csv
319320
}
320321
}
321322
return providedAPIsFromCSVs
322323
}
323324

324-
func (a *Operator) pruneProvidedAPIs(group *v1.OperatorGroup, groupProvidedAPIs resolver.APISet, providedAPIsFromCSVs map[opregistry.APIKey]*v1alpha1.ClusterServiceVersion, logger *logrus.Entry) {
325+
func (a *Operator) pruneProvidedAPIs(group *v1.OperatorGroup, groupProvidedAPIs cache.APISet, providedAPIsFromCSVs map[opregistry.APIKey]*v1alpha1.ClusterServiceVersion, logger *logrus.Entry) {
325326
// Don't prune providedAPIsFromCSVs if static
326327
if group.Spec.StaticProvidedAPIs {
327328
a.logger.Debug("group has static provided apis. skipping provided api pruning")
328329
return
329330
}
330331

331-
intersection := make(resolver.APISet)
332+
intersection := make(cache.APISet)
332333
for api := range providedAPIsFromCSVs {
333334
if _, ok := groupProvidedAPIs[api]; ok {
334335
intersection[api] = struct{}{}
@@ -978,7 +979,7 @@ func (a *Operator) updateNamespaceList(op *v1.OperatorGroup) ([]string, error) {
978979
return namespaceList, nil
979980
}
980981

981-
func (a *Operator) ensureOpGroupClusterRole(op *v1.OperatorGroup, suffix string, apis resolver.APISet) error {
982+
func (a *Operator) ensureOpGroupClusterRole(op *v1.OperatorGroup, suffix string, apis cache.APISet) error {
982983
clusterRole := &rbacv1.ClusterRole{
983984
ObjectMeta: metav1.ObjectMeta{
984985
Name: strings.Join([]string{op.GetName(), suffix}, "-"),
@@ -1029,7 +1030,7 @@ func (a *Operator) ensureOpGroupClusterRole(op *v1.OperatorGroup, suffix string,
10291030
return nil
10301031
}
10311032

1032-
func (a *Operator) ensureOpGroupClusterRoles(op *v1.OperatorGroup, apis resolver.APISet) error {
1033+
func (a *Operator) ensureOpGroupClusterRoles(op *v1.OperatorGroup, apis cache.APISet) error {
10331034
for _, suffix := range Suffices {
10341035
if err := a.ensureOpGroupClusterRole(op, suffix, apis); err != nil {
10351036
return err
@@ -1038,7 +1039,7 @@ func (a *Operator) ensureOpGroupClusterRoles(op *v1.OperatorGroup, apis resolver
10381039
return nil
10391040
}
10401041

1041-
func (a *Operator) findCSVsThatProvideAnyOf(provide resolver.APISet) ([]*v1alpha1.ClusterServiceVersion, error) {
1042+
func (a *Operator) findCSVsThatProvideAnyOf(provide cache.APISet) ([]*v1alpha1.ClusterServiceVersion, error) {
10421043
csvs, err := a.lister.OperatorsV1alpha1().ClusterServiceVersionLister().ClusterServiceVersions(metav1.NamespaceAll).List(labels.Everything())
10431044
if err != nil {
10441045
return nil, err
@@ -1051,12 +1052,12 @@ func (a *Operator) findCSVsThatProvideAnyOf(provide resolver.APISet) ([]*v1alpha
10511052
continue
10521053
}
10531054

1054-
operatorSurface, err := resolver.NewOperatorFromV1Alpha1CSV(csv)
1055+
operatorSurface, err := cache.NewOperatorFromV1Alpha1CSV(csv)
10551056
if err != nil {
10561057
continue
10571058
}
10581059

1059-
if len(operatorSurface.ProvidedAPIs().StripPlural().Intersection(provide)) > 0 {
1060+
if len(operatorSurface.GetProvidedAPIs().StripPlural().Intersection(provide)) > 0 {
10601061
providers = append(providers, csv)
10611062
}
10621063
}

0 commit comments

Comments
 (0)