Skip to content

Commit ed1db7b

Browse files
ecordellnjhale
authored andcommitted
feat(bundleimage): resolve bundle images
1 parent 05e1615 commit ed1db7b

File tree

10 files changed

+84
-108
lines changed

10 files changed

+84
-108
lines changed

pkg/api/apis/operators/installplan_types.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"fmt"
66

7+
batchv1 "k8s.io/api/batch/v1"
78
corev1 "k8s.io/api/core/v1"
89
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
910
)
@@ -83,6 +84,7 @@ type InstallPlanStatus struct {
8384
CatalogSources []string
8485
Plan []*Step
8586
AttenuatedServiceAccountRef *corev1.ObjectReference
87+
BundleLookups []*BundleLookup
8688
}
8789

8890
// InstallPlanCondition represents the overall status of the execution of
@@ -157,6 +159,24 @@ type Step struct {
157159
Status StepStatus
158160
}
159161

162+
// BundleJob tracks the job status for a given bundle
163+
type BundleJob struct {
164+
Name string `json:"name,omitempty"`
165+
Namespace string `json:"namespace,omitempty"`
166+
Condition batchv1.JobConditionType `json:"condition,omitempty"`
167+
CompletionTime *metav1.Time `json:"completionTime,omitempty"`
168+
}
169+
170+
// BundleLookup serves as accounting for tracking a bundle data lookup
171+
type BundleLookup struct {
172+
BundleJob *BundleJob `json:"bundleJob"`
173+
ConfigMapRef *ConfigMapResourceReference `json:"configMapRef"`
174+
Image string `json:"image"`
175+
CatalogName string `json:"catalogName"`
176+
CatalogNamespace string `json:"catalogNamespace"`
177+
Replaces string `json:"replaces"`
178+
}
179+
160180
// ManifestsMatch returns true if the CSV manifests in the StepResources of the given list of steps
161181
// matches those in the InstallPlanStatus.
162182
func (s *InstallPlanStatus) CSVManifestsMatch(steps []*Step) bool {

pkg/api/apis/operators/v1alpha1/installplan_types.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import (
77
batchv1 "k8s.io/api/batch/v1"
88
corev1 "k8s.io/api/core/v1"
99
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10-
11-
"github.com/operator-framework/operator-registry/pkg/api"
1210
)
1311

1412
const (
@@ -176,12 +174,12 @@ type BundleJob struct {
176174

177175
// BundleLookup serves as accounting for tracking a bundle data lookup
178176
type BundleLookup struct {
179-
BundleJob *BundleJob `json:"bundleJob"`
180-
ConfigMapRef *ConfigMapResourceReference `json:"configMapRef"`
181-
Image string `json:"image"`
182-
BundleFromRegistry *api.Bundle `json:"bundleFromRegistry"`
183-
CatalogName string `json:"catalogName"`
184-
CatalogNamespace string `json:"catalogNamespace"`
177+
BundleJob *BundleJob `json:"bundleJob"`
178+
ConfigMapRef *ConfigMapResourceReference `json:"configMapRef"`
179+
Image string `json:"image"`
180+
CatalogName string `json:"catalogName"`
181+
CatalogNamespace string `json:"catalogNamespace"`
182+
Replaces string `json:"replaces"`
185183
}
186184

187185
// ManifestsMatch returns true if the CSV manifests in the StepResources of the given list of steps

pkg/controller/operators/catalog/operator.go

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,10 @@ func NewOperator(ctx context.Context, kubeconfigPath string, clock utilclock.Clo
137137
client: crClient,
138138
lister: lister,
139139
namespace: operatorNamespace,
140-
resolver: resolver.NewOperatorsV1alpha1Resolver(lister, crClient),
140+
resolver: resolver.NewOperatorsV1alpha1Resolver(lister, crClient, opClient.KubernetesInterface()),
141141
catsrcQueueSet: queueinformer.NewEmptyResourceQueueSet(),
142142
subQueueSet: queueinformer.NewEmptyResourceQueueSet(),
143+
ipQueueSet: queueinformer.NewEmptyResourceQueueSet(),
143144
csvProvidedAPIsIndexer: map[string]cache.Indexer{},
144145
catalogSubscriberIndexer: map[string]cache.Indexer{},
145146
serviceAccountQuerier: scoped.NewUserDefinedServiceAccountQuerier(logger, crClient),
@@ -1097,45 +1098,21 @@ func (o *Operator) checkBundleLookups(plan *v1alpha1.InstallPlan) (bool, error)
10971098
}
10981099

10991100
// extract data from configmap and write to install plan
1100-
manifest, err := o.bundleLoader.Load(configmap)
1101+
bundle, err := o.bundleLoader.Load(configmap)
11011102
if err != nil {
11021103
return false, err
11031104
}
11041105

1105-
// combine data from the bundle image into what's already known from the registry
1106-
bundleLookup.BundleFromRegistry.CsvName = manifest.Bundle.Name
1107-
bundleLookup.BundleFromRegistry.PackageName = manifest.Bundle.Package
1108-
bundleLookup.BundleFromRegistry.ChannelName = manifest.Bundle.Channel
1109-
_, jsonCSV, _, err := manifest.Bundle.Serialize()
1110-
if err != nil {
1111-
return false, fmt.Errorf("serialize failed: %s", err.Error())
1112-
}
1113-
bundleLookup.BundleFromRegistry.CsvJson = string(jsonCSV)
1114-
bundleLookup.BundleFromRegistry.Object = []string{string(jsonCSV)}
1115-
for _, item := range manifest.Bundle.Objects {
1116-
bytes, err := item.MarshalJSON()
1117-
if err != nil {
1118-
return false, fmt.Errorf("marshall failed: %v", err)
1119-
}
1120-
bundleLookup.BundleFromRegistry.Object = append(bundleLookup.BundleFromRegistry.Object, string(bytes))
1121-
}
1122-
1123-
var olmCSV v1alpha1.ClusterServiceVersion
1124-
err = json.Unmarshal(jsonCSV, &olmCSV)
1125-
if err != nil {
1126-
return false, fmt.Errorf("csv retrieval failed: %s", err.Error())
1127-
}
1128-
11291106
// TODO: refactor with resolver code (and call the subscription stuff too)
1130-
bundleSteps, err := resolver.NewStepResourceFromBundle(bundleLookup.BundleFromRegistry, plan.GetNamespace(), olmCSV.Spec.Replaces, bundleLookup.CatalogName, bundleLookup.CatalogNamespace)
1107+
bundleSteps, err := resolver.NewStepResourceFromBundle(bundle, plan.GetNamespace(), bundleLookup.Replaces, bundleLookup.CatalogName, bundleLookup.CatalogNamespace)
11311108
if err != nil {
11321109
return false, fmt.Errorf("failed to turn bundle into steps: %s", err.Error())
11331110
}
11341111

11351112
// TODO: could this add duplicate steps?
11361113
for _, s := range bundleSteps {
11371114
plan.Status.Plan = append(plan.Status.Plan, &v1alpha1.Step{
1138-
Resolving: olmCSV.GetName(),
1115+
Resolving: bundle.CsvName,
11391116
Resource: s,
11401117
Status: v1alpha1.StepStatusUnknown,
11411118
})

pkg/controller/operators/catalog/subscriptions_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -819,8 +819,8 @@ func TestSyncSubscriptions(t *testing.T) {
819819

820820
o.sourcesLastUpdate.Set(tt.fields.sourcesLastUpdate.Time)
821821
o.resolver = &fakes.FakeResolver{
822-
ResolveStepsStub: func(string, resolver.SourceQuerier) ([]*v1alpha1.Step, []*v1alpha1.Subscription, error) {
823-
return tt.fields.resolveSteps, tt.fields.resolveSubs, tt.fields.resolveErr
822+
ResolveStepsStub: func(string, resolver.SourceQuerier) ([]*v1alpha1.Step, []*v1alpha1.BundleLookup, []*v1alpha1.Subscription, error) {
823+
return tt.fields.resolveSteps, nil, tt.fields.resolveSubs, tt.fields.resolveErr
824824
},
825825
}
826826

@@ -951,7 +951,7 @@ func BenchmarkSyncResolvingNamespace(b *testing.B) {
951951
},
952952
},
953953
resolver: &fakes.FakeResolver{
954-
ResolveStepsStub: func(string, resolver.SourceQuerier) ([]*v1alpha1.Step, []*v1alpha1.Subscription, error) {
954+
ResolveStepsStub: func(string, resolver.SourceQuerier) ([]*v1alpha1.Step, []*v1alpha1.BundleLookup, []*v1alpha1.Subscription, error) {
955955
steps := []*v1alpha1.Step{
956956
{
957957
Resolving: "csv.v.2",
@@ -987,7 +987,7 @@ func BenchmarkSyncResolvingNamespace(b *testing.B) {
987987
},
988988
}
989989

990-
return steps, subs, nil
990+
return steps, nil, subs, nil
991991
},
992992
},
993993
},

pkg/controller/registry/resolver/evolver.go

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ func (e *NamespaceGenerationEvolver) checkForUpdates() error {
6666
e.gen.AddPendingOperator(LaunchBundleImageInfo{
6767
operatorSourceInfo: op.SourceInfo(),
6868
image: bundle.BundlePath,
69-
bundle: bundle,
69+
replaces: op.Identifier(),
7070
})
71+
return nil
7172
}
7273

7374
o, err := NewOperatorFromBundle(bundle, op.SourceInfo().StartingCSV, *key)
@@ -97,22 +98,13 @@ func (e *NamespaceGenerationEvolver) addNewOperators(add map[OperatorSourceInfo]
9798
// TODO: log or collect warnings
9899
return errors.Wrapf(err, "%s not found", s)
99100
}
100-
if bundle.BundlePath != "" {
101-
e.gen.AddPendingOperator(LaunchBundleImageInfo{
102-
operatorSourceInfo: &s,
103-
image: bundle.BundlePath,
104-
bundle: bundle,
105-
})
106-
}
107101

108102
o, err := NewOperatorFromBundle(bundle, s.StartingCSV, *key)
109103
if err != nil {
110104
return errors.Wrap(err, "error parsing bundle")
111105
}
112106
if err := e.gen.AddOperator(o); err != nil {
113-
if err != nil {
114-
return errors.Wrap(err, "error calculating generation changes due to new bundle")
115-
}
107+
return errors.Wrap(err, "error calculating generation changes due to new bundle")
116108
}
117109
}
118110
return nil
@@ -137,15 +129,6 @@ func (e *NamespaceGenerationEvolver) queryForRequiredAPIs() error {
137129

138130
// attempt to find a bundle that provides that api
139131
if bundle, key, err := e.querier.FindProvider(*api, initialSource.Catalog); err == nil {
140-
if bundle.BundlePath != "" {
141-
e.gen.AddPendingOperator(LaunchBundleImageInfo{
142-
operatorSourceInfo: initialSource,
143-
image: bundle.BundlePath,
144-
bundle: bundle,
145-
})
146-
return nil
147-
}
148-
149132
// add a bundle that provides the api to the generation
150133
o, err := NewOperatorFromBundle(bundle, "", *key)
151134
if err != nil {

pkg/controller/registry/resolver/generation.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55

66
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
7-
"github.com/operator-framework/operator-registry/pkg/api"
87
"github.com/operator-framework/operator-registry/pkg/registry"
98
)
109

@@ -24,7 +23,7 @@ type Generation interface {
2423
type LaunchBundleImageInfo struct {
2524
operatorSourceInfo *OperatorSourceInfo
2625
image string
27-
bundle *api.Bundle
26+
replaces string
2827
}
2928

3029
type BundleImageSet map[LaunchBundleImageInfo]struct{}

pkg/controller/registry/resolver/generation_test.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ func TestNewGenerationFromCSVs(t *testing.T) {
3737
},
3838
},
3939
want: &NamespaceGeneration{
40-
providedAPIs: EmptyAPIOwnerSet(),
41-
requiredAPIs: EmptyAPIMultiOwnerSet(),
42-
uncheckedAPIs: EmptyAPISet(),
43-
missingAPIs: EmptyAPIMultiOwnerSet(),
40+
pendingOperators: BundleImageSet{},
41+
providedAPIs: EmptyAPIOwnerSet(),
42+
requiredAPIs: EmptyAPIMultiOwnerSet(),
43+
uncheckedAPIs: EmptyAPISet(),
44+
missingAPIs: EmptyAPIMultiOwnerSet(),
4445
},
4546
},
4647
{
@@ -76,6 +77,7 @@ func TestNewGenerationFromCSVs(t *testing.T) {
7677
},
7778
},
7879
want: &NamespaceGeneration{
80+
pendingOperators: BundleImageSet{},
7981
providedAPIs: map[opregistry.APIKey]OperatorSurface{
8082
{Group: "g", Version: "v1", Kind: "APIKind", Plural: "apikinds"}: &Operator{
8183
name: "operator.v1",
@@ -136,7 +138,8 @@ func TestNewGenerationFromCSVs(t *testing.T) {
136138
},
137139
},
138140
want: &NamespaceGeneration{
139-
providedAPIs: EmptyAPIOwnerSet(),
141+
pendingOperators: BundleImageSet{},
142+
providedAPIs: EmptyAPIOwnerSet(),
140143
requiredAPIs: map[opregistry.APIKey]OperatorSet{
141144
{Group: "g", Version: "v1", Kind: "APIKind", Plural: "apikinds"}: map[string]OperatorSurface{
142145
"operator.v1": &Operator{
@@ -243,6 +246,7 @@ func TestNewGenerationFromCSVs(t *testing.T) {
243246
},
244247
},
245248
want: &NamespaceGeneration{
249+
pendingOperators: BundleImageSet{},
246250
providedAPIs: map[opregistry.APIKey]OperatorSurface{
247251
{Group: "g", Version: "v1", Kind: "APIOwnedKind", Plural: "apiownedkinds"}: &Operator{
248252
name: "operator.v1",

pkg/controller/registry/resolver/resolver.go

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,22 @@ type Resolver interface {
2424
}
2525

2626
type OperatorsV1alpha1Resolver struct {
27-
subLister v1alpha1listers.SubscriptionLister
28-
csvLister v1alpha1listers.ClusterServiceVersionLister
29-
ipLister v1alpha1listers.InstallPlanLister
30-
client versioned.Interface
31-
kubeclient kubernetes.Interface
32-
operatorNamespace string
27+
subLister v1alpha1listers.SubscriptionLister
28+
csvLister v1alpha1listers.ClusterServiceVersionLister
29+
ipLister v1alpha1listers.InstallPlanLister
30+
client versioned.Interface
31+
kubeclient kubernetes.Interface
3332
}
3433

3534
var _ Resolver = &OperatorsV1alpha1Resolver{}
3635

37-
func NewOperatorsV1alpha1Resolver(lister operatorlister.OperatorLister, client versioned.Interface, kubeclient kubernetes.Interface, operatorNamespace string) *OperatorsV1alpha1Resolver {
36+
func NewOperatorsV1alpha1Resolver(lister operatorlister.OperatorLister, client versioned.Interface, kubeclient kubernetes.Interface) *OperatorsV1alpha1Resolver {
3837
return &OperatorsV1alpha1Resolver{
39-
subLister: lister.OperatorsV1alpha1().SubscriptionLister(),
40-
csvLister: lister.OperatorsV1alpha1().ClusterServiceVersionLister(),
41-
ipLister: lister.OperatorsV1alpha1().InstallPlanLister(),
42-
client: client,
43-
kubeclient: kubeclient,
44-
operatorNamespace: operatorNamespace,
38+
subLister: lister.OperatorsV1alpha1().SubscriptionLister(),
39+
csvLister: lister.OperatorsV1alpha1().ClusterServiceVersionLister(),
40+
ipLister: lister.OperatorsV1alpha1().InstallPlanLister(),
41+
client: client,
42+
kubeclient: kubeclient,
4543
}
4644
}
4745

@@ -90,6 +88,7 @@ func (r *OperatorsV1alpha1Resolver) ResolveSteps(namespace string, sourceQuerier
9088
// changes to persist to the cluster and write them out as `steps`
9189
steps := []*v1alpha1.Step{}
9290
updatedSubs := []*v1alpha1.Subscription{}
91+
bundleLookups := []*v1alpha1.BundleLookup{}
9392
for name, op := range gen.Operators() {
9493
_, isAdded := add[*op.SourceInfo()]
9594
existingSubscription, subExists := subMap[*op.SourceInfo()]
@@ -100,7 +99,7 @@ func (r *OperatorsV1alpha1Resolver) ResolveSteps(namespace string, sourceQuerier
10099
}
101100

102101
// add steps for any new bundle
103-
if op.Bundle() != nil {
102+
if op.Bundle().BundlePath == "" {
104103
bundleSteps, err := NewStepResourceFromBundle(op.Bundle(), namespace, op.Replaces(), op.SourceInfo().Catalog.Name, op.SourceInfo().Catalog.Namespace)
105104
if err != nil {
106105
return nil, nil, nil, fmt.Errorf("failed to turn bundle into steps: %s", err.Error())
@@ -129,29 +128,22 @@ func (r *OperatorsV1alpha1Resolver) ResolveSteps(namespace string, sourceQuerier
129128
}
130129
}
131130

131+
if op.Bundle().BundlePath != "" {
132+
bundleLookups = append(bundleLookups, &v1alpha1.BundleLookup{
133+
Image: op.Bundle().BundlePath,
134+
CatalogName: op.SourceInfo().Catalog.Name,
135+
CatalogNamespace: op.SourceInfo().Catalog.Namespace,
136+
Replaces: op.Replaces(),
137+
})
138+
}
139+
132140
// update existing subscriptions status
133141
if subExists && existingSubscription.Status.CurrentCSV != op.Identifier() {
134142
existingSubscription.Status.CurrentCSV = op.Identifier()
135143
updatedSubs = append(updatedSubs, existingSubscription)
136144
}
137145
}
138146

139-
// allow other operators to be processed first, then process ones that require copying data out of image
140-
bundleLookups := []*v1alpha1.BundleLookup{}
141-
142-
for bundleImageInfo := range gen.PendingOperators() {
143-
// TODO: switch image to standalone image, but this image can be used upstream as well
144-
// change to use configmapRegistryImage
145-
//configmap, job, err := configmap.LaunchBundleImage(r.kubeclient, bundleImageInfo.image, "quay.io/openshift/origin-operator-registry:latest", r.operatorNamespace)
146-
147-
bundleLookups = append(bundleLookups, &v1alpha1.BundleLookup{
148-
Image: bundleImageInfo.image,
149-
BundleFromRegistry: bundleImageInfo.bundle,
150-
CatalogName: bundleImageInfo.operatorSourceInfo.Catalog.Name,
151-
CatalogNamespace: bundleImageInfo.operatorSourceInfo.Catalog.Namespace,
152-
})
153-
}
154-
155147
return steps, bundleLookups, updatedSubs, nil
156148
}
157149

0 commit comments

Comments
 (0)