@@ -140,6 +140,54 @@ func (meta *BundleMetaData) GenerateMetadata() error {
140
140
return nil
141
141
}
142
142
143
+ // GenerateAnnotations generates the annotations.yaml file using the provided
144
+ // annotation values for the Operator Bundle.
145
+ func (meta * BundleMetaData ) GenerateAnnotations () error {
146
+ // Ensure the output directory exists
147
+ metadataDir := filepath .Join (meta .BundleDir , defaultMetadataDir )
148
+ if err := os .MkdirAll (metadataDir , projutil .DirMode ); err != nil {
149
+ return err
150
+ }
151
+
152
+ // Prepare annotation values
153
+ values := annotationsValues {
154
+ BundleDir : meta .BundleDir ,
155
+ PackageName : meta .PackageName ,
156
+ Channels : meta .Channels ,
157
+ DefaultChannel : meta .DefaultChannel ,
158
+ IsScorecardConfigPresent : meta .IsScoreConfigPresent ,
159
+ }
160
+
161
+ // Add any other labels to the values
162
+ for k , v := range meta .OtherLabels {
163
+ values .OtherLabels = append (values .OtherLabels , fmt .Sprintf ("%s=%s" , k , v ))
164
+ }
165
+ sort .Strings (values .OtherLabels )
166
+
167
+ // Define the path to annotations.yaml
168
+ annotationsPath := filepath .Join (metadataDir , "annotations.yaml" )
169
+
170
+ // Open (or create) the annotations.yaml file
171
+ f , err := os .OpenFile (annotationsPath , os .O_WRONLY | os .O_CREATE | os .O_TRUNC , 0666 )
172
+ if err != nil {
173
+ return err
174
+ }
175
+ defer func () {
176
+ if err := f .Close (); err != nil {
177
+ log .Error (err )
178
+ }
179
+ }()
180
+
181
+ // Create and execute the annotations template
182
+ err = annotationsTemplate .Execute (f , values )
183
+ if err != nil {
184
+ return err
185
+ }
186
+
187
+ log .Infof ("Annotations generated successfully at %s" , annotationsPath )
188
+ return nil
189
+ }
190
+
143
191
// CopyOperatorManifests copies packagemanifestsDir/manifests to bundleDir/manifests.
144
192
func (meta * BundleMetaData ) CopyOperatorManifests () error {
145
193
return copyOperatorManifests (meta .PkgmanifestPath , filepath .Join (meta .BundleDir , defaultManifestDir ))
0 commit comments