Skip to content

Commit

Permalink
Add flags for certified, community operatros and redhat marketplace i…
Browse files Browse the repository at this point in the history
…ndex images
  • Loading branch information
shanedell committed Jan 23, 2024
1 parent ff552bc commit 5086a10
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 59 deletions.
109 changes: 78 additions & 31 deletions cmd/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ import (
)

var (
openshiftVersion string
pullSecret string
platform string
redhatOperatorIndexImage string
catalogVersion string
catalogs []string
skipExisting bool
skipRelease bool
skipCatalogs bool
skipRhcos bool
openshiftVersion string
pullSecret string
platform string
redhatOperatorIndexImage string
redhatMarketplaceIndexImage string
certifiedOperatorIndexImage string
communityOperatorIndexImage string
catalogVersion string
catalogs []string
skipExisting bool
skipRelease bool
skipCatalogs bool
skipRhcos bool
)

var bundleHelp = "bundle the OpenShift content"
Expand Down Expand Up @@ -50,6 +53,33 @@ func addBundleSkipFlags(cmd *cobra.Command) {
)
}

func addIndexImageFlags(cmd *cobra.Command) {
cmd.PersistentFlags().StringVar(
&redhatOperatorIndexImage,
"redhat-operator-index-image",
"",
"version of image to use for redhat-operator catalogs",
)
cmd.PersistentFlags().StringVar(
&redhatMarketplaceIndexImage,
"redhat-marketplace-index-image",
"",
"version of image to use for redhat-marketplace catalogs",
)
cmd.PersistentFlags().StringVar(
&certifiedOperatorIndexImage,
"certified-operator-index-image",
"",
"version of image to use for certified-operator catalogs",
)
cmd.PersistentFlags().StringVar(
&communityOperatorIndexImage,
"community-operator-index-image",
"",
"version of image to use for community-operator catalogs",
)
}

func NewBundleCommand() *cobra.Command {
bundleCommand := &cobra.Command{
Use: "bundle",
Expand Down Expand Up @@ -104,14 +134,9 @@ func NewBundleCommand() *cobra.Command {
"",
"version of images to use for catalogs",
)
addBundleSkipFlags(bundleCommand)

bundleCommand.PersistentFlags().StringVar(
&redhatOperatorIndexImage,
"redhat-operator-index-image",
"",
"version of images to use for catalogs",
)
addBundleSkipFlags(bundleCommand)
addIndexImageFlags(bundleCommand)

return bundleCommand
}
Expand Down Expand Up @@ -167,27 +192,49 @@ func bundleMain(_ *cobra.Command, _ []string) error {
catalogVersion = openshiftVersion
}

versionMinor := utils.GetVersionMinor(openshiftVersion)

if redhatOperatorIndexImage == "" {
versionMinor := utils.GetVersionMinor(openshiftVersion)
redhatOperatorIndexImage = fmt.Sprintf(
"registry.redhat.io/redhat/redhat-operator-index:v%s", versionMinor,
)
}

if redhatMarketplaceIndexImage == "" {
redhatMarketplaceIndexImage = fmt.Sprintf(
"registry.redhat.io/redhat/redhat-marketplace-index:v%s", versionMinor,
)
}

if certifiedOperatorIndexImage == "" {
certifiedOperatorIndexImage = fmt.Sprintf(
"registry.redhat.io/redhat/certified-operator-index:v%s", versionMinor,
)
}

if communityOperatorIndexImage == "" {
communityOperatorIndexImage = fmt.Sprintf(
"registry.redhat.io/redhat/community-operator-index:v%s", versionMinor,
)
}

bundleData := &utils.BundleDataType{
BundleDir: bundleDir,
CatalogVersion: catalogVersion,
Catalogs: catalogs,
Platform: platform,
PreRelease: preRelease,
PullSecret: pullSecret,
OpenshiftVersion: openshiftVersion,
RedhatOperatorIndexImage: redhatOperatorIndexImage,
SkipExisting: skipExisting,
SkipRelease: skipRelease,
SkipCatalogs: skipCatalogs,
SkipRhcos: skipRhcos,
TargetRegistry: targetRegistry,
BundleDir: bundleDir,
CatalogVersion: catalogVersion,
Catalogs: catalogs,
Platform: platform,
PreRelease: preRelease,
PullSecret: pullSecret,
OpenshiftVersion: openshiftVersion,
RedhatOperatorIndexImage: redhatOperatorIndexImage,
RedhatMarketplaceIndexImage: redhatMarketplaceIndexImage,
CertifiedOperatorIndexImage: certifiedOperatorIndexImage,
CommunityOperatorIndexImage: communityOperatorIndexImage,
SkipExisting: skipExisting,
SkipRelease: skipRelease,
SkipCatalogs: skipCatalogs,
SkipRhcos: skipRhcos,
TargetRegistry: targetRegistry,
}

return app.Bundle(bundleData)
Expand Down
19 changes: 4 additions & 15 deletions pkg/utils/init.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
package utils

import (
"fmt"
"path/filepath"
"strings"
)

func Initialize(bundleDataIn *BundleDataType) error {
BundleData = bundleDataIn

versionMinor := BundleData.OpenshiftVersion
if !strings.Contains(BundleData.OpenshiftVersion, "latest-") {
versionMinor = GetVersionMinor(BundleData.OpenshiftVersion)
}

if BundleData.BundleDir != "" {
BundleDir = filepath.Join(Cwd, BundleData.BundleDir, BundleData.OpenshiftVersion)
} else {
Expand All @@ -28,14 +21,10 @@ func Initialize(bundleDataIn *BundleDataType) error {
}

CatalogIndexes = map[string]string{
"redhat-operators": BundleData.RedhatOperatorIndexImage,
"certified-operators": fmt.Sprintf(
"registry.redhat.io/redhat/certified-operator-index:v%s", versionMinor,
),
"redhat-marketplace": fmt.Sprintf(
"registry.redhat.io/redhat/redhat-marketplace-index:v%s", versionMinor,
),
"community-operators": "registry.redhat.io/redhat/community-operator-index:latest",
"redhat-operators": BundleData.RedhatOperatorIndexImage,
"redhat-marketplace": BundleData.RedhatMarketplaceIndexImage,
"certified-operators": BundleData.CertifiedOperatorIndexImage,
"community-operators": BundleData.CommunityOperatorIndexImage,
}

if err := CreateBundlesDir(); err != nil {
Expand Down
29 changes: 16 additions & 13 deletions pkg/utils/structs.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package utils

type BundleDataType struct {
BundleDir string
CatalogVersion string
Catalogs []string
OpenshiftVersion string
Platform string
PreRelease bool
PullSecret string
RedhatOperatorIndexImage string
SkipExisting bool
SkipRelease bool
SkipCatalogs bool
SkipRhcos bool
TargetRegistry string
BundleDir string
CatalogVersion string
Catalogs []string
OpenshiftVersion string
Platform string
PreRelease bool
PullSecret string
RedhatOperatorIndexImage string
RedhatMarketplaceIndexImage string
CertifiedOperatorIndexImage string
CommunityOperatorIndexImage string
SkipExisting bool
SkipRelease bool
SkipCatalogs bool
SkipRhcos bool
TargetRegistry string
}

type BundleDirsType struct {
Expand Down

0 comments on commit 5086a10

Please sign in to comment.