@@ -18,24 +18,36 @@ import (
1818)
1919
2020// ConvertBundleToAPIBundle converts a declcfg.Bundle to an api.Bundle.
21- // The pkg and channels parameters provide context needed for the conversion.
22- func ConvertBundleToAPIBundle (b Bundle , pkg Package , channels []Channel ) (* api.Bundle , error ) {
21+ // The pkg, channels, and deprecations parameters provide context needed for the conversion.
22+ // api.Bundle can only represent one channel, so the first matching channel is used.
23+ func ConvertBundleToAPIBundle (b Bundle , pkg Package , channels []Channel , deprecations []Deprecation ) (* api.Bundle , error ) {
2324 props , err := parseProperties (b .Properties )
2425 if err != nil {
2526 return nil , fmt .Errorf ("parse properties: %v" , err )
2627 }
2728
2829 csvJSON := generateCSVJSON (b , pkg , props )
30+ objects := b .Objects
31+ if len (objects ) == 0 && csvJSON != "" {
32+ objects = []string {csvJSON }
33+ }
2934
30- // Find which channel this bundle belongs to
31- channelName := ""
35+ // Find which channel this bundle belongs to and get its entry data.
36+ // api.Bundle can only represent one channel, so use the first match.
37+ var channelName string
38+ var replaces string
39+ var skips []string
40+ var skipRange string
3241 for _ , ch := range channels {
3342 if ch .Package != b .Package {
3443 continue
3544 }
3645 for _ , entry := range ch .Entries {
3746 if entry .Name == b .Name {
3847 channelName = ch .Name
48+ replaces = entry .Replaces
49+ skips = entry .Skips
50+ skipRange = entry .SkipRange
3951 break
4052 }
4153 }
@@ -44,22 +56,21 @@ func ConvertBundleToAPIBundle(b Bundle, pkg Package, channels []Channel) (*api.B
4456 }
4557 }
4658
47- // Get replaces and skips from channel entry
48- var replaces string
49- var skips []string
50- var skipRange string
51- for _ , ch := range channels {
52- if ch .Package != b .Package {
59+ // Find bundle deprecation
60+ var deprecation * api.Deprecation
61+ for _ , d := range deprecations {
62+ if d .Package != b .Package {
5363 continue
5464 }
55- for _ , entry := range ch .Entries {
56- if entry .Name == b .Name {
57- replaces = entry .Replaces
58- skips = entry .Skips
59- skipRange = entry .SkipRange
65+ for _ , entry := range d .Entries {
66+ if entry .Reference .Schema == SchemaBundle && entry .Reference .Name == b .Name {
67+ deprecation = & api.Deprecation {Message : entry .Message }
6068 break
6169 }
6270 }
71+ if deprecation != nil {
72+ break
73+ }
6374 }
6475
6576 apiDeps , err := convertPropertiesToAPIDependencies (b .Properties )
@@ -81,7 +92,8 @@ func ConvertBundleToAPIBundle(b Bundle, pkg Package, channels []Channel) (*api.B
8192 Replaces : replaces ,
8293 Skips : skips ,
8394 CsvJson : csvJSON ,
84- Object : b .Objects ,
95+ Object : objects ,
96+ Deprecation : deprecation ,
8597 }, nil
8698}
8799
@@ -95,11 +107,7 @@ func generateCSVJSON(b Bundle, pkg Package, props *property.Properties) string {
95107 if err != nil {
96108 return b .CsvJSON
97109 }
98- csvJSON := string (csvData )
99- if len (b .Objects ) == 0 {
100- b .Objects = []string {csvJSON }
101- }
102- return csvJSON
110+ return string (csvData )
103111}
104112
105113func buildCSV (b Bundle , pkg Package , props * property.Properties ) * v1alpha1.ClusterServiceVersion {
0 commit comments