Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f30cfde

Browse files
authoredNov 2, 2019
Merge pull request operator-framework#106 from kevinrizza/index-command
Add index build commands
2 parents 50a37f9 + 1be113b commit f30cfde

File tree

411 files changed

+219321
-108
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

411 files changed

+219321
-108
lines changed
 

‎Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ container-codegen:
4242
docker cp temp-codegen:/codegen/pkg/api/. ./pkg/api
4343
docker rm temp-codegen
4444

45+
generate-fakes:
46+
go install -mod=vendor ./vendor/github.com/maxbrunsfeld/counterfeiter/v6
47+
go generate ./...
48+
4549
clean:
4650
@rm -rf ./bin
4751

‎cmd/opm/index/add.go

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package index
2+
3+
import (
4+
"github.com/sirupsen/logrus"
5+
"github.com/spf13/cobra"
6+
7+
"github.com/operator-framework/operator-registry/pkg/lib/indexer"
8+
)
9+
10+
func newIndexAddCmd() *cobra.Command {
11+
indexCmd := &cobra.Command{
12+
Use: "add",
13+
Short: "add an operator bundle to an index",
14+
Long: `add an operator bundle to an index`,
15+
16+
PreRunE: func(cmd *cobra.Command, args []string) error {
17+
if debug, _ := cmd.Flags().GetBool("debug"); debug {
18+
logrus.SetLevel(logrus.DebugLevel)
19+
}
20+
return nil
21+
},
22+
23+
RunE: runIndexAddCmdFunc,
24+
}
25+
26+
indexCmd.Flags().Bool("debug", false, "enable debug logging")
27+
indexCmd.Flags().Bool("generate", false, "if enabled, just creates the dockerfile and saves it to local disk")
28+
indexCmd.Flags().StringP("out-dockerfile", "d", "", "if generating the dockerfile, this flag is used to (optionally) specify a dockerfile name")
29+
indexCmd.Flags().StringP("from-index", "f", "", "previous index to add to")
30+
indexCmd.Flags().StringSliceP("bundles", "b", nil, "comma separated list of bundles to add")
31+
if err := indexCmd.MarkFlagRequired("bundles"); err != nil {
32+
logrus.Panic("Failed to set required `bundles` flag for `index add`")
33+
}
34+
indexCmd.Flags().StringP("binary-image", "i", "", "container image for on-image `opm` command")
35+
indexCmd.Flags().StringP("container-tool", "c", "podman", "tool to interact with container images (save, build, etc.). One of: [docker, podman]")
36+
indexCmd.Flags().StringP("tag", "t", "", "custom tag for container image being built")
37+
indexCmd.Flags().Bool("permissive", false, "allow registry load errors")
38+
39+
if err := indexCmd.Flags().MarkHidden("debug"); err != nil {
40+
logrus.Panic(err.Error())
41+
}
42+
43+
return indexCmd
44+
45+
}
46+
47+
func runIndexAddCmdFunc(cmd *cobra.Command, args []string) error {
48+
generate, err := cmd.Flags().GetBool("generate")
49+
if err != nil {
50+
return err
51+
}
52+
53+
outDockerfile, err := cmd.Flags().GetString("out-dockerfile")
54+
if err != nil {
55+
return err
56+
}
57+
58+
fromIndex, err := cmd.Flags().GetString("from-index")
59+
if err != nil {
60+
return err
61+
}
62+
63+
bundles, err := cmd.Flags().GetStringSlice("bundles")
64+
if err != nil {
65+
return err
66+
}
67+
68+
binaryImage, err := cmd.Flags().GetString("binary-image")
69+
if err != nil {
70+
return err
71+
}
72+
73+
containerTool, err := cmd.Flags().GetString("container-tool")
74+
if err != nil {
75+
return err
76+
}
77+
78+
tag, err := cmd.Flags().GetString("tag")
79+
if err != nil {
80+
return err
81+
}
82+
83+
84+
permissive, err := cmd.Flags().GetBool("permissive")
85+
if err != nil {
86+
return err
87+
}
88+
89+
logger := logrus.WithFields(logrus.Fields{"bundles": bundles})
90+
91+
logger.Info("building the index")
92+
93+
indexAdder := indexer.NewIndexAdder(containerTool, logger)
94+
95+
request := indexer.AddToIndexRequest{
96+
Generate: generate,
97+
FromIndex: fromIndex,
98+
BinarySourceImage: binaryImage,
99+
OutDockerfile: outDockerfile,
100+
Tag: tag,
101+
Bundles: bundles,
102+
Permissive: permissive,
103+
}
104+
105+
err = indexAdder.AddToIndex(request)
106+
if err != nil {
107+
return err
108+
}
109+
110+
return nil
111+
}

0 commit comments

Comments
 (0)
Please sign in to comment.