@@ -20,15 +20,22 @@ import (
20
20
"context"
21
21
22
22
"github.com/operator-framework/operator-registry/alpha/action"
23
+ "github.com/operator-framework/operator-registry/alpha/declcfg"
23
24
24
25
"github.com/operator-framework/operator-controller/internal/catalogmetadata"
26
+ "github.com/operator-framework/operator-controller/internal/catalogmetadata/client"
27
+ "github.com/operator-framework/operator-controller/internal/controllers"
25
28
)
26
29
27
30
type indexRefClient struct {
28
- renderer action.Render
29
- bundlesCache []* catalogmetadata.Bundle
31
+ renderer action.Render
32
+ bundlesCache []* catalogmetadata.Bundle
33
+ channelsCache []* catalogmetadata.Channel
34
+ packagesCache []* catalogmetadata.Package
30
35
}
31
36
37
+ var _ controllers.CatalogProvider = & indexRefClient {}
38
+
32
39
func newIndexRefClient (indexRef string ) * indexRefClient {
33
40
return & indexRefClient {
34
41
renderer : action.Render {
@@ -38,47 +45,81 @@ func newIndexRefClient(indexRef string) *indexRefClient {
38
45
}
39
46
}
40
47
41
- func (c * indexRefClient ) Bundles (ctx context.Context ) ([] * catalogmetadata. Bundle , error ) {
42
- if c .bundlesCache == nil {
48
+ func (c * indexRefClient ) CatalogContents (ctx context.Context ) (* client. Contents , error ) {
49
+ if c .bundlesCache == nil || c . channelsCache == nil || c . packagesCache == nil {
43
50
cfg , err := c .renderer .Run (ctx )
44
51
if err != nil {
45
52
return nil , err
46
53
}
47
54
48
55
var (
49
- channels []* catalogmetadata.Channel
50
- bundles []* catalogmetadata.Bundle
51
- deprecations []* catalogmetadata.Deprecation
56
+ channels []* catalogmetadata.Channel
57
+ bundles []* catalogmetadata.Bundle
58
+ packages []* catalogmetadata.Package
52
59
)
53
60
61
+ // TODO: update fake catalog name string to be catalog name once we support multiple catalogs in CLI
62
+ catalogName := "offline-catalog"
63
+
64
+ for i := range cfg .Packages {
65
+ packages = append (packages , & catalogmetadata.Package {
66
+ Package : cfg .Packages [i ],
67
+ Catalog : catalogName ,
68
+ })
69
+ }
70
+
54
71
for i := range cfg .Channels {
55
72
channels = append (channels , & catalogmetadata.Channel {
56
73
Channel : cfg .Channels [i ],
74
+ Catalog : catalogName ,
57
75
})
58
76
}
59
77
60
78
for i := range cfg .Bundles {
61
79
bundles = append (bundles , & catalogmetadata.Bundle {
62
- Bundle : cfg .Bundles [i ],
80
+ Bundle : cfg .Bundles [i ],
81
+ Catalog : catalogName ,
63
82
})
64
83
}
65
84
66
- for i := range cfg .Deprecations {
67
- deprecations = append (deprecations , & catalogmetadata.Deprecation {
68
- Deprecation : cfg .Deprecations [i ],
69
- })
85
+ for _ , deprecation := range cfg .Deprecations {
86
+ for _ , entry := range deprecation .Entries {
87
+ switch entry .Reference .Schema {
88
+ case declcfg .SchemaPackage :
89
+ for _ , pkg := range packages {
90
+ if pkg .Name == deprecation .Package {
91
+ pkg .Deprecation = & declcfg.DeprecationEntry {
92
+ Reference : entry .Reference ,
93
+ Message : entry .Message ,
94
+ }
95
+ }
96
+ }
97
+ case declcfg .SchemaChannel :
98
+ for _ , channel := range channels {
99
+ if channel .Package == deprecation .Package && channel .Name == entry .Reference .Name {
100
+ channel .Deprecation = & declcfg.DeprecationEntry {
101
+ Reference : entry .Reference ,
102
+ Message : entry .Message ,
103
+ }
104
+ }
105
+ }
106
+ case declcfg .SchemaBundle :
107
+ for _ , bundle := range bundles {
108
+ if bundle .Package == deprecation .Package && bundle .Name == entry .Reference .Name {
109
+ bundle .Deprecation = & declcfg.DeprecationEntry {
110
+ Reference : entry .Reference ,
111
+ Message : entry .Message ,
112
+ }
113
+ }
114
+ }
115
+ }
116
+ }
70
117
}
71
118
72
- // TODO: update fake catalog name string to be catalog name once we support multiple catalogs in CLI
73
- // catalogName := "offline-catalog"
74
-
75
- // bundles, err = client.PopulateExtraFields(catalogName, channels, bundles, deprecations)
76
- // if err != nil {
77
- // return nil, err
78
- // }
79
-
80
119
c .bundlesCache = bundles
120
+ c .channelsCache = channels
121
+ c .packagesCache = packages
81
122
}
82
123
83
- return c . bundlesCache , nil
124
+ return & client. Contents {} , nil
84
125
}
0 commit comments