Skip to content

Commit 1feacb9

Browse files
author
Mikalai Radchuk
committed
Fixes replace based upgrades
Signed-off-by: Mikalai Radchuk <[email protected]>
1 parent 0ddf9ad commit 1feacb9

File tree

4 files changed

+10
-20
lines changed

4 files changed

+10
-20
lines changed

internal/resolution/entities/bundle_entity.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ import (
1111
)
1212

1313
const PropertyBundlePath = "olm.bundle.path"
14-
15-
// TODO: Is this the right place for these?
16-
// ----
14+
const PropertyBundleReplaces = "olm.replaces"
1715
const PropertyBundleMediaType = "olm.bundle.mediatype"
1816

1917
type MediaType string
@@ -140,7 +138,7 @@ func (b *BundleEntity) loadReplaces() error {
140138
b.mu.Lock()
141139
defer b.mu.Unlock()
142140
if b.replaces == nil {
143-
replaces, err := loadFromEntity[Replaces](b.Entity, "olm.replaces", optional)
141+
replaces, err := loadFromEntity[Replaces](b.Entity, PropertyBundleReplaces, optional)
144142
if err != nil {
145143
return fmt.Errorf("error determining replaces for entity '%s': %w", b.ID, err)
146144
}

internal/resolution/entitysources/catalogdsource.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,10 @@ func getEntities(ctx context.Context, client client.Client) (input.EntityList, e
110110
if catalogScopedEntryName == bundle.Name {
111111
channelValue, _ := json.Marshal(property.Channel{ChannelName: ch.Name, Priority: 0})
112112
props[property.TypeChannel] = string(channelValue)
113-
// TODO(jmprusi): Add the proper PropertyType for this
114-
replacesValue, _ := json.Marshal(replacesProperty{Replaces: b.Replaces})
115-
props["olm.replaces"] = string(replacesValue)
113+
replacesValue, _ := json.Marshal(replacesProperty{
114+
Replaces: fmt.Sprintf("%s-%s%s%s", bundle.Spec.Catalog.Name, b.Replaces, bundle.Spec.Package, ch.Name),
115+
})
116+
props[entities.PropertyBundleReplaces] = string(replacesValue)
116117
entity := input.Entity{
117118
ID: deppy.IdentifierFromString(fmt.Sprintf("%s%s%s", bundle.Name, bundle.Spec.Package, ch.Name)),
118119
Properties: props,

internal/resolution/variablesources/installed_package.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,7 @@ func (r *InstalledPackageVariableSource) GetVariables(ctx context.Context, entit
4646
// now find the bundles that replace the installed bundle
4747
// TODO: this algorithm does not yet consider skips and skipRange
4848
// we simplify the process here by just searching for the bundle that replaces the installed bundle
49-
packageName, err := installedBundle.PackageName()
50-
if err != nil {
51-
return nil, err
52-
}
53-
version, err := installedBundle.Version()
54-
if err != nil {
55-
return nil, err
56-
}
57-
bundleID := fmt.Sprintf("%s.v%s", packageName, version.String())
58-
resultSet, err = entitySource.Filter(ctx, predicates.Replaces(bundleID))
49+
resultSet, err = entitySource.Filter(ctx, predicates.Replaces(installedBundle.ID.String()))
5950
if err != nil {
6051
return nil, err
6152
}
@@ -68,7 +59,7 @@ func (r *InstalledPackageVariableSource) GetVariables(ctx context.Context, entit
6859
// you can always upgrade to yourself, i.e. not upgrade
6960
upgradeEdges = append(upgradeEdges, installedBundle)
7061
return []deppy.Variable{
71-
variables.NewInstalledPackageVariable(bundleID, upgradeEdges),
62+
variables.NewInstalledPackageVariable(installedBundle.ID.String(), upgradeEdges),
7263
}, nil
7364
}
7465

testdata/catalogs/test-catalog/catalog.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ package: prometheus
99
entries:
1010
- name: prometheus-operator.0.37.0
1111
- name: prometheus-operator.0.47.0
12-
replaces: "prometheus.v0.37.0"
12+
replaces: prometheus-operator.0.37.0
1313
- name: prometheus-operator.0.65.1
14-
replaces: prometheus.v0.47.0
14+
replaces: prometheus-operator.0.47.0
1515
---
1616
schema: olm.bundle
1717
name: prometheus-operator.0.37.0

0 commit comments

Comments
 (0)