Skip to content

Commit df3295f

Browse files
committed
ApplianceConfig: support 'useDefaultSourceNames' flag
Rename CatalogSource names generated by oc-mirror to the default naming. E.g. 'redhat-operators' instead of 'cs-redhat-operator-index-v4-19'. Default: false [Optional] useDefaultSourceNames: false/true
1 parent ab77faf commit df3295f

File tree

5 files changed

+47
-4
lines changed

5 files changed

+47
-4
lines changed

docs/user-guide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ enableFips: enable-fips
151151
# Default: false
152152
# [Optional]
153153
enableInteractiveFlow: enable-interactive-flow
154+
# Rename CatalogSource names generated by oc-mirror to the default naming.
155+
# E.g. 'redhat-operators' instead of 'cs-redhat-operator-index-v4-19'.
156+
# Default: false
157+
# [Optional]
158+
useDefaultSourceNames: use-default-source-names
154159
# Additional images to be included in the appliance disk image.
155160
# [Optional]
156161
additionalImages:

pkg/asset/config/appliance_config.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,12 @@ stopLocalRegistry: %t
185185
# [Optional]
186186
# enableInteractiveFlow: %t
187187
188+
# Rename CatalogSource names generated by oc-mirror to the default naming.
189+
# E.g. 'redhat-operators' instead of 'cs-redhat-operator-index-v4-19'.
190+
# Default: false
191+
# [Optional]
192+
# useDefaultSourceNames: %t
193+
188194
# Additional images to be included in the appliance disk image.
189195
# [Optional]
190196
# additionalImages:
@@ -207,7 +213,7 @@ stopLocalRegistry: %t
207213
graph.ReleaseChannelStable, CpuArchitectureX86, MinDiskSize,
208214
RegistryMinPort, RegistryMaxPort, consts.RegistryPort,
209215
consts.EnableDefaultSources, consts.StopLocalRegistry, consts.CreatePinnedImageSets,
210-
consts.EnableFips, consts.EnableInteractiveFlow)
216+
consts.EnableFips, consts.EnableInteractiveFlow, consts.UseDefaultSourceNames)
211217

212218
return nil
213219
}

pkg/asset/ignition/bootstrap_ignition.go

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"fmt"
77
"path/filepath"
8+
"regexp"
89
"strings"
910

1011
"github.com/coreos/ignition/v2/config/util"
@@ -41,6 +42,17 @@ const (
4142
extraManifestsPath = "/etc/assisted/extra-manifests"
4243
)
4344

45+
type CatalogSource struct {
46+
metav1.TypeMeta `json:",inline"`
47+
metav1.ObjectMeta `json:"metadata"`
48+
Spec CatalogSourceSpec `json:"spec"`
49+
}
50+
type CatalogSourceSpec struct {
51+
Image string `json:"image,omitempty"`
52+
SourceType SourceType `json:"sourceType"`
53+
}
54+
type SourceType string
55+
4456
var (
4557
bootstrapServices = []string{
4658
"start-local-registry.service",
@@ -200,7 +212,7 @@ func (i *BootstrapIgnition) Generate(_ context.Context, dependencies asset.Paren
200212
}
201213

202214
// Add manifests generated by oc-mirror
203-
if err := i.addGeneratedManifests(envConfig); err != nil {
215+
if err := i.addGeneratedManifests(envConfig.CacheDir, applianceConfig.Config.UseDefaultSourceNames); err != nil {
204216
return err
205217
}
206218

@@ -263,9 +275,9 @@ func (i *BootstrapIgnition) addExtraManifests(config *igntypes.Config, extraMani
263275
return nil
264276
}
265277

266-
func (i *BootstrapIgnition) addGeneratedManifests(envConfig *config.EnvConfig) error {
278+
func (i *BootstrapIgnition) addGeneratedManifests(cacheDir string, useDefaultSourceNames *bool) error {
267279
// Find manifests yaml files
268-
files, err := filepath.Glob(filepath.Join(envConfig.CacheDir, release.OcGeneratedManifestsDir, "*.yaml"))
280+
files, err := filepath.Glob(filepath.Join(cacheDir, release.OcGeneratedManifestsDir, "*.yaml"))
269281
if err != nil {
270282
logrus.Error("Missing manifests files in cache")
271283
return err
@@ -283,6 +295,24 @@ func (i *BootstrapIgnition) addGeneratedManifests(envConfig *config.EnvConfig) e
283295
// Use CatalogSource instead
284296
continue
285297
}
298+
299+
// Convert to default source naming (e.g. redhat-operators)
300+
if swag.BoolValue(useDefaultSourceNames) {
301+
var cs CatalogSource
302+
if err = yaml.Unmarshal(fileBytes, &cs); err != nil {
303+
return err
304+
}
305+
306+
re := regexp.MustCompile(`.*?(\w+-operator)-index.*`)
307+
name := re.ReplaceAllString(cs.Name, "${1}")
308+
cs.Name = strings.Replace(name, "operator", "operators", 1)
309+
310+
fileBytes, err = yaml.Marshal(cs)
311+
if err != nil {
312+
return err
313+
}
314+
}
315+
286316
manifestPath := fmt.Sprintf("%s/%s", extraManifestsPath, filepath.Base(file))
287317
manifestFile := ignasset.FileFromBytes(manifestPath, "root", 0644, fileBytes)
288318
i.Config.Storage.Files = append(i.Config.Storage.Files, manifestFile)

pkg/consts/consts.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,5 @@ const (
7070
CreatePinnedImageSets = false
7171
EnableFips = false
7272
EnableInteractiveFlow = false
73+
UseDefaultSourceNames = false
7374
)

pkg/types/appliance_config_type.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type ApplianceConfig struct {
2323
StopLocalRegistry *bool `json:"stopLocalRegistry"`
2424
CreatePinnedImageSets *bool `json:"createPinnedImageSets"`
2525
EnableInteractiveFlow *bool `json:"enableInteractiveFlow"`
26+
UseDefaultSourceNames *bool `json:"useDefaultSourceNames"`
2627
AdditionalImages *[]Image `json:"additionalImages,omitempty"`
2728
Operators *[]Operator `json:"operators,omitempty"`
2829
}

0 commit comments

Comments
 (0)