Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions internal/cmd/catalog_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package cmd

import (
"io"
"strings"
"time"

"github.com/operator-framework/api/pkg/operators/v1alpha1"
"github.com/operator-framework/operator-registry/pkg/image/containerdregistry"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand All @@ -18,6 +20,8 @@ func newCatalogAddCmd(cfg *action.Configuration) *cobra.Command {
a := internalaction.NewCatalogAdd(cfg)
a.Logf = log.Printf

var extractContentStr string

cmd := &cobra.Command{
Use: "add <name> <index_image>",
Short: "Add an operator catalog",
Expand All @@ -33,6 +37,28 @@ func newCatalogAddCmd(cfg *action.Configuration) *cobra.Command {
a.CatalogSourceName = args[0]
a.IndexImage = args[1]

if extractContentStr != "" {
extractContentSettings := strings.Split(extractContentStr, ",")
extractContentMap := map[string]string{}
for _, setting := range extractContentSettings {
key, value, ok := strings.Cut(setting, "=")
if !ok {
log.Fatalf("invalid extract content setting %q: found key without value", setting)
}
extractContentMap[key] = value
}
if catalogDir, ok := extractContentMap["catalog"]; !ok {
log.Fatal("invalid extract content: catalog not found")
} else if cacheDir, ok := extractContentMap["cache"]; !ok {
log.Fatal("invalid extract content: cache not found")
} else {
a.ExtractContent = &v1alpha1.ExtractContentConfig{
CatalogDir: catalogDir,
CacheDir: cacheDir,
}
}
}

cs, err := a.Run(cmd.Context())
if err != nil {
log.Fatalf("failed to add catalog: %v", err)
Expand All @@ -41,13 +67,15 @@ func newCatalogAddCmd(cfg *action.Configuration) *cobra.Command {
},
}
bindCatalogAddFlags(cmd.Flags(), a)
cmd.Flags().StringVar(&extractContentStr, "extract-content", "", "Use OLM-provided catalog server with provided paths (e.g. --extract-content=catalog=/configs,cache=/tmp/cache)")

return cmd
}

func bindCatalogAddFlags(fs *pflag.FlagSet, a *internalaction.CatalogAdd) {
fs.StringVarP(&a.DisplayName, "display-name", "d", "", "display name of the index")
fs.StringVarP(&a.Publisher, "publisher", "p", "", "publisher of the index")
fs.StringVar(&a.SecurityContextConfig, "security-context-config", "restricted", "security context config to use to run the catalog")
fs.DurationVar(&a.CleanupTimeout, "cleanup-timeout", time.Minute, "the amount of time to wait before cancelling cleanup")

fs.StringArrayVarP(&a.InjectBundles, "inject-bundles", "b", nil, "inject extra bundles into the index at runtime")
Expand Down
25 changes: 18 additions & 7 deletions internal/pkg/action/catalog_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ const (
type CatalogAdd struct {
config *action.Configuration

CatalogSourceName string
IndexImage string
InjectBundles []string
InjectBundleMode string
DisplayName string
Publisher string
CleanupTimeout time.Duration
CatalogSourceName string
IndexImage string
InjectBundles []string
InjectBundleMode string
DisplayName string
Publisher string
SecurityContextConfig string
ExtractContent *v1alpha1.ExtractContentConfig
CleanupTimeout time.Duration

Logf func(string, ...interface{})
RegistryOptions []containerdregistry.RegistryOption
Expand Down Expand Up @@ -87,9 +89,18 @@ func (a *CatalogAdd) Run(ctx context.Context) (*v1alpha1.CatalogSource, error) {

a.setDefaults(labels)

grpcPodConfig := &v1alpha1.GrpcPodConfig{}
if a.SecurityContextConfig != "" {
grpcPodConfig.SecurityContextConfig = v1alpha1.SecurityConfig(a.SecurityContextConfig)
}
if a.ExtractContent != nil {
grpcPodConfig.ExtractContent = a.ExtractContent
}

opts := []catalogsource.Option{
catalogsource.DisplayName(a.DisplayName),
catalogsource.Publisher(a.Publisher),
catalogsource.GRPCPodConfig(grpcPodConfig),
}

if len(a.InjectBundles) == 0 {
Expand Down
6 changes: 6 additions & 0 deletions internal/pkg/catalogsource/catalogsource.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ func Publisher(v string) Option {
}
}

func GRPCPodConfig(grpcPodConfig *v1alpha1.GrpcPodConfig) Option {
return func(cs *v1alpha1.CatalogSource) {
cs.Spec.GrpcPodConfig = grpcPodConfig
}
}

func Build(key types.NamespacedName, opts ...Option) *v1alpha1.CatalogSource {
cs := &v1alpha1.CatalogSource{
ObjectMeta: metav1.ObjectMeta{
Expand Down