From 44d4e798fc624d85a98d0b9286a7f67cce814474 Mon Sep 17 00:00:00 2001 From: "Adam D. Cornett" Date: Tue, 20 May 2025 15:22:43 -0700 Subject: [PATCH] removing package manifest cmds Signed-off-by: Adam D. Cornett --- internal/cmd/operator-sdk/cli/cli.go | 2 - .../cmd/operator-sdk/pkgmantobundle/cmd.go | 361 ------------------ .../operator-sdk/pkgmantobundle/cmd_test.go | 40 -- .../pkgmantobundle_suite_test.go | 27 -- .../pkgmantobundle/pkgmantobundle_test.go | 256 ------------- .../0.0.1/cache.example.com_memcacheds.yaml | 50 --- ...er-manager-metrics-service_v1_service.yaml | 16 - ...-controller-manager_v1_serviceaccount.yaml | 5 - ...-operator-manager-config_v1_configmap.yaml | 17 - ...c.authorization.k8s.io_v1_clusterrole.yaml | 10 - ...cached-operator.clusterserviceversion.yaml | 185 --------- .../0.0.1/scorecard-config.yaml | 49 --- .../0.0.2/cache.example.com_memcacheds.yaml | 50 --- ...er-manager-metrics-service_v1_service.yaml | 16 - ...-controller-manager_v1_serviceaccount.yaml | 5 - ...-operator-manager-config_v1_configmap.yaml | 17 - ...c.authorization.k8s.io_v1_clusterrole.yaml | 10 - ...cached-operator.clusterserviceversion.yaml | 185 --------- .../memcached-operator.package.yaml | 7 - internal/cmd/operator-sdk/run/cmd.go | 2 - internal/cmd/operator-sdk/run/cmd_test.go | 3 +- .../run/packagemanifests/packagemanifests.go | 68 ---- .../packagemanifests_suite_test.go | 27 -- .../packagemanifests/packagemanifests_test.go | 38 -- test/e2e/helm/olm_test.go | 58 --- test/integration/packagemanifests_test.go | 51 --- test/integration/suite_test.go | 18 - website/content/en/docs/cli/operator-sdk.md | 1 - .../docs/cli/operator-sdk_pkgman-to-bundle.md | 110 ------ 29 files changed, 1 insertion(+), 1683 deletions(-) delete mode 100644 internal/cmd/operator-sdk/pkgmantobundle/cmd.go delete mode 100644 internal/cmd/operator-sdk/pkgmantobundle/cmd_test.go delete mode 100644 internal/cmd/operator-sdk/pkgmantobundle/pkgmantobundle_suite_test.go delete mode 100644 internal/cmd/operator-sdk/pkgmantobundle/pkgmantobundle_test.go delete mode 100644 internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.1/cache.example.com_memcacheds.yaml delete mode 100644 internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.1/memcached-operator-controller-manager-metrics-service_v1_service.yaml delete mode 100644 internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.1/memcached-operator-controller-manager_v1_serviceaccount.yaml delete mode 100644 internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.1/memcached-operator-manager-config_v1_configmap.yaml delete mode 100644 internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.1/memcached-operator-metrics-reader_rbac.authorization.k8s.io_v1_clusterrole.yaml delete mode 100644 internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.1/memcached-operator.clusterserviceversion.yaml delete mode 100644 internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.1/scorecard-config.yaml delete mode 100644 internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.2/cache.example.com_memcacheds.yaml delete mode 100644 internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.2/memcached-operator-controller-manager-metrics-service_v1_service.yaml delete mode 100644 internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.2/memcached-operator-controller-manager_v1_serviceaccount.yaml delete mode 100644 internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.2/memcached-operator-manager-config_v1_configmap.yaml delete mode 100644 internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.2/memcached-operator-metrics-reader_rbac.authorization.k8s.io_v1_clusterrole.yaml delete mode 100644 internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.2/memcached-operator.clusterserviceversion.yaml delete mode 100644 internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/memcached-operator.package.yaml delete mode 100644 internal/cmd/operator-sdk/run/packagemanifests/packagemanifests.go delete mode 100644 internal/cmd/operator-sdk/run/packagemanifests/packagemanifests_suite_test.go delete mode 100644 internal/cmd/operator-sdk/run/packagemanifests/packagemanifests_test.go delete mode 100644 test/e2e/helm/olm_test.go delete mode 100644 test/integration/packagemanifests_test.go delete mode 100644 website/content/en/docs/cli/operator-sdk_pkgman-to-bundle.md diff --git a/internal/cmd/operator-sdk/cli/cli.go b/internal/cmd/operator-sdk/cli/cli.go index 99712f18e99..f062ca5d2c4 100644 --- a/internal/cmd/operator-sdk/cli/cli.go +++ b/internal/cmd/operator-sdk/cli/cli.go @@ -35,7 +35,6 @@ import ( "github.com/operator-framework/operator-sdk/internal/cmd/operator-sdk/cleanup" "github.com/operator-framework/operator-sdk/internal/cmd/operator-sdk/generate" "github.com/operator-framework/operator-sdk/internal/cmd/operator-sdk/olm" - "github.com/operator-framework/operator-sdk/internal/cmd/operator-sdk/pkgmantobundle" "github.com/operator-framework/operator-sdk/internal/cmd/operator-sdk/run" "github.com/operator-framework/operator-sdk/internal/cmd/operator-sdk/scorecard" "github.com/operator-framework/operator-sdk/internal/flags" @@ -54,7 +53,6 @@ var ( olm.NewCmd(), run.NewCmd(), scorecard.NewCmd(), - pkgmantobundle.NewCmd(), } alphaCommands = []*cobra.Command{ config3alphato3.NewCmd(), diff --git a/internal/cmd/operator-sdk/pkgmantobundle/cmd.go b/internal/cmd/operator-sdk/pkgmantobundle/cmd.go deleted file mode 100644 index 6924a4fef2a..00000000000 --- a/internal/cmd/operator-sdk/pkgmantobundle/cmd.go +++ /dev/null @@ -1,361 +0,0 @@ -// Copyright 2021 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package pkgmantobundle - -import ( - "errors" - "fmt" - "os" - "path/filepath" - "strings" - - "github.com/operator-framework/api/pkg/apis/scorecard/v1alpha3" - apimanifests "github.com/operator-framework/api/pkg/manifests" - log "github.com/sirupsen/logrus" - "github.com/spf13/cobra" - - "github.com/operator-framework/operator-sdk/internal/annotations/metrics" - "github.com/operator-framework/operator-sdk/internal/util/bundleutil" - "github.com/operator-framework/operator-sdk/internal/util/k8sutil" -) - -const ( - longHelp = ` -'pkgman-to-bundle' command helps in migrating OLM packagemanifests to bundles which is the preferred OLM packaging format. -This command takes an input packagemanifest directory and generates bundles for each of the versions of manifests present in -the input directory. Additionally, it also provides the flexibility to build bundle images for each of the generated bundles. - -The generated bundles are always written on disk. Location for the generated bundles can be specified using '--output-dir'. If not -specified, the default location would be 'bundle/' directory. - -The base container image name for the bundles can be provided using '--image-tag-base' flag. This should be provided without the tag, since the tag -for the images would be the bundle version, (ie) image names will be in the format :. - -Specify the build command for building container images using '--build-cmd' flag. The default build command is 'docker build'. The command will -need to be in the 'PATH' or fully qualified path name should be provided. -` - - examples = ` - -# Provide the packagemanifests directory as input to the command. Consider the packagemanifests directory to have the following -# structure: - -$ tree packagemanifests/ -packagemanifests -└── etcd - ├── 0.0.1 - │ ├── etcdcluster.crd.yaml - │ └── etcdoperator.clusterserviceversion.yaml - ├── 0.0.2 - │ ├── etcdbackup.crd.yaml - │ ├── etcdcluster.crd.yaml - │ ├── etcdoperator.v0.0.2.clusterserviceversion.yaml - │ └── etcdrestore.crd.yaml - └── etcd.package.yaml - -# Run the following command to generate bundles in the default 'bundle/' directory with the base-container image name -# to be 'quay.io/example/etcd' -$ operator-sdk pkgman-to-bundle packagemanifests --image-tag-base quay.io/example/etcd -INFO[0000] Packagemanifests will be migrated to bundles in bundle directory -INFO[0000] Creating bundle/bundle-0.0.1/bundle.Dockerfile -INFO[0000] Creating bundle/bundle-0.0.1/metadata/annotations.yaml -... - -# After running the above command, the bundles will be generated in 'bundles/' directory. -$ tree bundles/ -bundles/ -├── bundle-0.0.1 -│   ├── bundle -│   │   ├── manifests -│   │   │   ├── etcdcluster.crd.yaml -│   │   │   ├── etcdoperator.clusterserviceversion.yaml -│   │   ├── metadata -│   │   │   └── annotations.yaml -│   │   └── tests -│   │   └── scorecard -│   │   └── config.yaml -│   └── bundle.Dockerfile -└── bundle-0.0.2 - ├── bundle - │   ├── manifests - │   │   ├── etcdbackup.crd.yaml - │   │   ├── etcdcluster.crd.yaml - │   │   ├── etcdoperator.v0.0.2.clusterserviceversion.yaml - │   │   ├── etcdrestore.crd.yaml - │   └── metadata - │   └── annotations.yaml - └── bundle.Dockerfile - -A custom command to build bundle images can also be specified using the '--build-cmd' flag. For example, - -$ operator-sdk pkgman-to-bundle packagemanifests --image-tag-base quay.io/example/etcd --build-cmd "podman build -f bundle.Dockerfile . -t" - -Images for the both the bundles will be built with the following names: quay.io/example/etcd:0.0.1 and quay.io/example/etcd:0.0.2. -` -) - -var defaultSubBundleDir = "bundle" - -type pkgManToBundleCmd struct { - // Input packagemanifest directory. - pkgmanifestDir string - - // Optional flags for generating and building bundles. - outputDir string - baseImg string - buildCmd string -} - -// NewCmd returns the pkgManToBundleCmd configured with the provided input options. -func NewCmd() *cobra.Command { - p := pkgManToBundleCmd{} - - pkgManToBundleCmd := &cobra.Command{ - Use: "pkgman-to-bundle ", - Short: "Migrates packagemanifests to bundles", - Long: longHelp, - Example: examples, - PreRunE: func(_ *cobra.Command, args []string) (err error) { - return p.validate(args) - }, - RunE: func(_ *cobra.Command, args []string) (err error) { - p.pkgmanifestDir = args[0] - return p.run() - }, - } - - pkgManToBundleCmd.Flags().StringVar(&p.outputDir, "output-dir", "bundles", "Directory to write bundle to.") - pkgManToBundleCmd.Flags().StringVar(&p.baseImg, "image-tag-base", "", "Base container image name for bundle image tags, "+ - "ex. my.reg/foo/bar-operator-bundle will become my.reg/foo/bar-operator-bundle:${package-dir-name} for each child directory name in the packagemanifests directory") - - // TODO(varsha): enable users to provide a template to the command so that it can be run in all child directories to build image. - pkgManToBundleCmd.Flags().StringVar(&p.buildCmd, "build-cmd", "", "Build command to be run for building images. By default 'docker build' is run.") - - return pkgManToBundleCmd -} - -// Generate the bundles from the provided packagemanifest directory. -func (p *pkgManToBundleCmd) run() (err error) { - - // error if output bundle directory already exists. - if _, err = os.Stat(p.outputDir); !errors.Is(err, os.ErrNotExist) { - return fmt.Errorf("output directory: %s for bundles already exists", p.outputDir) - } - - log.Infof("Packagemanifests will be migrated to bundles in %s directory", p.outputDir) - - // Skipping bundles here, since that's not required and could be empty for a manifest directory. - packages, _, err := apimanifests.GetManifestsDir(p.pkgmanifestDir) - if err != nil { - return err - } - - if packages.IsEmpty() { - return fmt.Errorf("no packages found in the directory %s", p.pkgmanifestDir) - } - - // get package metadata required for annotations.yaml and bundle.Dockerfile. - packageName, defaultChannel, channelsByCSV, err := getPackageMetadata(packages) - if err != nil { - return fmt.Errorf("error obtaining metadata from directory %s: %v", p.pkgmanifestDir, err) - } - - directories, err := os.ReadDir(p.pkgmanifestDir) - if err != nil { - return err - } - - // iterate through each of the subdirectories to generate respective bundles for each of them. - for _, dir := range directories { - if dir.IsDir() { - // this is required to extract project layout and SDK version information. - otherLabels, channels, err := getSDKStampsAndChannels(filepath.Join(p.pkgmanifestDir, dir.Name()), defaultChannel, channelsByCSV) - if err != nil { - return fmt.Errorf("error getting CSV from provided packagemanifest %v", err) - } - - bundleMetaData := bundleutil.BundleMetaData{ - BundleDir: filepath.Join(p.outputDir, "bundle-"+dir.Name(), defaultSubBundleDir), - PackageName: packageName, - Channels: channels, - DefaultChannel: defaultChannel, - PkgmanifestPath: filepath.Join(p.pkgmanifestDir, dir.Name()), - OtherLabels: otherLabels, - BaseImage: p.baseImg, - BuildCommand: p.buildCmd, - } - - if err := bundleMetaData.CopyOperatorManifests(); err != nil { - return err - } - - // get the location of scorecard config file from the current packagemanifest directory. - scorecardConfigPath, err := getScorecardConfigPath(bundleMetaData.PkgmanifestPath) - if err != nil { - return err - } - - // if scorecard config is present, then copy it to tests/scorecard directory - // in bundle. - if scorecardConfigPath != "" { - bundleMetaData.IsScoreConfigPresent = true - if err := bundleMetaData.WriteScorecardConfig(scorecardConfigPath); err != nil { - return err - } - } - - if err := bundleMetaData.GenerateMetadata(); err != nil { - return err - } - - // build image when base image name is provided. - if p.baseImg != "" { - if err := bundleMetaData.BuildBundleImage(dir.Name()); err != nil { - return err - } - } - - } - } - return nil -} - -// getScorecardConfigPath looks for the path of scorecard config file in the directory. -func getScorecardConfigPath(inputDir string) (string, error) { - var scorecardConfigPath string - - err := filepath.Walk(inputDir, func(path string, info os.FileInfo, err error) error { - if err != nil { - return err - } - - if !info.IsDir() { - b, err := os.ReadFile(path) - if err != nil { - return err - } - - typeMeta, err := k8sutil.GetTypeMetaFromBytes(b) - if err != nil { - return err - } - - if typeMeta.Kind == v1alpha3.ConfigurationKind { - if len(scorecardConfigPath) != 0 { - return fmt.Errorf("multiple scorrecard config files found in packagemanifest directory %s", inputDir) - } - scorecardConfigPath = path - } - } - return nil - }) - if err != nil { - return "", err - } - return scorecardConfigPath, nil -} - -func getSDKStampsAndChannels(path, defaultChannel string, channelsByCSV map[string][]string) (map[string]string, string, error) { - bundle, err := apimanifests.GetBundleFromDir(path) - if err != nil { - return nil, "", err - } - - sdkLabels, err := getSDKStamps(bundle) - if err != nil { - return nil, "", err - } - - // Find channels matching the CSV names - channels := getChannelsByCSV(bundle, channelsByCSV, defaultChannel) - - return sdkLabels, channels, nil -} - -// getSDKStamps parses the CSV and gets SDK stamps. -func getSDKStamps(bundle *apimanifests.Bundle) (map[string]string, error) { - if bundle.CSV == nil { - return nil, fmt.Errorf("cannot find CSV from manifests package") - } - - // Extract SDK layout and version from CSV annotations. - csvAnnotations := bundle.CSV.GetAnnotations() - sdkLabels := make(map[string]string) - - for key, value := range csvAnnotations { - if key == metrics.BuilderObjectAnnotation { - sdkLabels[key] = value - } - - if key == metrics.LayoutObjectAnnotation { - sdkLabels[key] = value - } - } - - return sdkLabels, nil -} - -// getChannelsByCSV creates a list for channels for the currentCSV. For other versions of manifests which -// are not present in the manifest, the defaultChannel is added. -func getChannelsByCSV(bundle *apimanifests.Bundle, channelsByCSV map[string][]string, defaultChannel string) (channels string) { - // Find channels matching the CSV names - channelNames := channelsByCSV[bundle.CSV.GetName()] - channels = strings.Join(channelNames, ",") - - // TODO: verify if we have to add this validation since while building bundles if channel is not specified - // we add the default channel. - if channels == "" { - channels = defaultChannel - log.Infof("Supported channels cannot be identified from CSV %s, using default channel %s", bundle.CSV.GetName(), defaultChannel) - } - - return channels -} - -func getPackageMetadata(pkg *apimanifests.PackageManifest) (packagename, defaultChannel string, channelsByCSV map[string][]string, err error) { - packagename = pkg.PackageName - if packagename == "" { - err = fmt.Errorf("cannot find packagename from the manifest directory") - return - } - - defaultChannel = pkg.DefaultChannelName - if defaultChannel == "" { - err = fmt.Errorf("cannot find the default channel for package %q", packagename) - return - } - - channelsByCSV = make(map[string][]string) - - for _, p := range pkg.Channels { - if _, ok := channelsByCSV[p.CurrentCSVName]; !ok { - channelsByCSV[p.CurrentCSVName] = make([]string, 0) - } - channelsByCSV[p.CurrentCSVName] = append(channelsByCSV[p.CurrentCSVName], p.Name) - } - - return -} - -func (p *pkgManToBundleCmd) validate(args []string) error { - if len(args) != 1 { - return fmt.Errorf("a package manifest directory argument is required") - } - - if len(p.baseImg) == 0 && len(p.buildCmd) != 0 { - return fmt.Errorf("base image needs to be specified to build bundle image") - } - return nil -} diff --git a/internal/cmd/operator-sdk/pkgmantobundle/cmd_test.go b/internal/cmd/operator-sdk/pkgmantobundle/cmd_test.go deleted file mode 100644 index 26007f20f27..00000000000 --- a/internal/cmd/operator-sdk/pkgmantobundle/cmd_test.go +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2021 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package pkgmantobundle - -import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" -) - -var _ = Describe("Migrating packagemanifests to bundle command", func() { - Describe("NewCmd", func() { - cmd := NewCmd() - Expect(cmd).NotTo(BeNil()) - - flag := cmd.Flags().Lookup("output-dir") - Expect(flag).NotTo(BeNil()) - Expect(flag.Usage).ToNot(Equal("")) - Expect(flag.DefValue).To(Equal("bundles")) - - flag = cmd.Flags().Lookup("image-tag-base") - Expect(flag).NotTo(BeNil()) - Expect(flag.Usage).ToNot(Equal("")) - - flag = cmd.Flags().Lookup("build-cmd") - Expect(flag).NotTo(BeNil()) - Expect(flag.Usage).ToNot(Equal("")) - }) -}) diff --git a/internal/cmd/operator-sdk/pkgmantobundle/pkgmantobundle_suite_test.go b/internal/cmd/operator-sdk/pkgmantobundle/pkgmantobundle_suite_test.go deleted file mode 100644 index 3d8fbf99a94..00000000000 --- a/internal/cmd/operator-sdk/pkgmantobundle/pkgmantobundle_suite_test.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2021 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package pkgmantobundle - -import ( - "testing" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" -) - -func TestPackagemanifestsToBundle(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "pkgman-To-Bundle Suite") -} diff --git a/internal/cmd/operator-sdk/pkgmantobundle/pkgmantobundle_test.go b/internal/cmd/operator-sdk/pkgmantobundle/pkgmantobundle_test.go deleted file mode 100644 index de684c661f2..00000000000 --- a/internal/cmd/operator-sdk/pkgmantobundle/pkgmantobundle_test.go +++ /dev/null @@ -1,256 +0,0 @@ -// Copyright 2021 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package pkgmantobundle - -import ( - "fmt" - "os" - "path/filepath" - "reflect" - - apimanifests "github.com/operator-framework/api/pkg/manifests" - operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1" - "github.com/operator-framework/operator-sdk/internal/util/projutil" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" -) - -var _ = Describe("Running pkgmanToBundle command", func() { - var ( - p pkgManToBundleCmd - pkgManDir string - outputDir string = "bundle-output" - ) - - BeforeEach(func() { - p = pkgManToBundleCmd{} - }) - - Describe("validate", func() { - It("fail if anything other than one argumanet for packagemanifest directory is provided", func() { - err := p.validate([]string{}) - Expect(err).To(HaveOccurred()) - - err = p.validate([]string{"one", "two"}) - Expect(err).To(HaveOccurred()) - }) - - It("succeeds if exactly one argument is provided", func() { - err := p.validate([]string{"inputdir"}) - Expect(err).NotTo(HaveOccurred()) - }) - }) - - Describe("migrate packagemanifests to bundle ", func() { - AfterEach(func() { - err := os.RemoveAll(outputDir) - Expect(err).NotTo(HaveOccurred()) - }) - - It("should generate multiple bundles for each version of manifests", func() { - // Specify input package manifest directory and output directory - pkgManDir = filepath.Join("testdata", "packagemanifests") - - p.pkgmanifestDir = pkgManDir - p.outputDir = outputDir - p.baseImg = "quay.io/example/memcached-operator" - - err := p.run() - Expect(err).NotTo(HaveOccurred()) - - By("Verifying the number of bundles created") - Expect(getNumberOfDirectories(p.outputDir)).To(BeEquivalentTo(2)) - - By("Verifying that each of them are valid bundles and their package name") - bundles, err := os.ReadDir(p.outputDir) - Expect(err).NotTo(HaveOccurred()) - - for _, bundle := range bundles { - b, err := apimanifests.GetBundleFromDir(filepath.Join(p.outputDir, bundle.Name())) - Expect(err).NotTo(HaveOccurred()) - Expect(b).NotTo(BeNil()) - - // Verifying that bundle contains required files - Expect(fileExists(filepath.Join(p.outputDir, bundle.Name(), "bundle.Dockerfile"))).To(BeTrue()) - Expect(fileExists(filepath.Join(p.outputDir, bundle.Name(), defaultSubBundleDir, "metadata", "annotations.yaml"))).To(BeTrue()) - Expect(b.CSV).NotTo(BeNil()) - Expect(b.V1CRDs).NotTo(BeNil()) - - // Verify if scorecard config exiss in the bundle - if bundle.Name() == "bundle-0.0.1" { - Expect(fileExists(filepath.Join(p.outputDir, bundle.Name(), defaultSubBundleDir, "tests", "scorecard", "config.yaml"))).To(BeTrue()) - } - } - }) - - It("should build image when build command is provided", func() { - // Specify input package manifest directory and output directory - pkgManDir = filepath.Join("testdata", "packagemanifests") - - p.pkgmanifestDir = pkgManDir - p.outputDir = outputDir - p.baseImg = "quay.io/example/memcached-operator" - p.buildCmd = "docker build -f bundle.Dockerfile . -t" - - err := p.run() - Expect(err).NotTo(HaveOccurred()) - }) - - It("should error when output directory already exists", func() { - err := os.Mkdir(outputDir, projutil.DirMode) - Expect(err).NotTo(HaveOccurred()) - - p.outputDir = outputDir - err = p.run() - Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("output directory: %s for bundles already exists", p.outputDir))) - }) - }) - - Describe("getSDKStampsAndChannels", func() { - Describe("getSDKStamps", func() { - It("should be able to extract SDK stamps from CSV", func() { - annotations := map[string]string{ - "operators.operatorframework.io/builder": "operator-sdk-v1.5.0", - "operators.operatorframework.io/project_layout": "go.kubebuilder.io/v4", - } - - csv := operatorsv1alpha1.ClusterServiceVersion{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: annotations, - }, - } - - bundle := apimanifests.Bundle{ - CSV: &csv, - } - - stamps, err := getSDKStamps(&bundle) - Expect(err).NotTo(HaveOccurred()) - Expect(len(stamps)).To(BeEquivalentTo(2)) - Expect(reflect.DeepEqual(annotations, stamps)).To(BeTrue()) - - }) - - It("should error when bundle is empty", func() { - stamps, err := getSDKStamps(&apimanifests.Bundle{}) - Expect(err).To(HaveOccurred()) - Expect(stamps).To(BeNil()) - - }) - }) - - Describe("getChannelsByCSV", func() { - bundle := apimanifests.Bundle{ - CSV: &operatorsv1alpha1.ClusterServiceVersion{ - ObjectMeta: metav1.ObjectMeta{ - Name: "memcached-operator:0.0.1", - }, - }, - } - - defaultChannel := "gamma" - - It("should get the list of channels for corresponding CSV", func() { - channels := map[string][]string{ - "memcached-operator:0.0.1": {"alpha", "beta"}, - } - - ch := getChannelsByCSV(&bundle, channels, defaultChannel) - Expect(ch).To(BeEquivalentTo("alpha,beta")) - }) - - It("if no channel is provided, default to candidate", func() { - channels := map[string][]string{} - ch := getChannelsByCSV(&bundle, channels, defaultChannel) - Expect(ch).To(BeEquivalentTo(defaultChannel)) - }) - }) - }) - - Describe("getPackageMetadata", func() { - var ( - pkg apimanifests.PackageManifest - ) - - BeforeEach(func() { - pkg = apimanifests.PackageManifest{ - PackageName: "memcached-operator", - DefaultChannelName: "alpha", - Channels: []apimanifests.PackageChannel{ - { - Name: "alpha", - CurrentCSVName: "memcached-operator:v1.0.0", - }, - { - Name: "beta", - CurrentCSVName: "memcached-operator:v1.0.1", - }, - { - Name: "alpha", - CurrentCSVName: "memcached-operator:v1.0.1", - }, - }, - } - - }) - - It("should return pkgName, channels and channelsByCSV", func() { - pkgName, defaultChannel, channelByCSV, err := getPackageMetadata(&pkg) - Expect(err).NotTo(HaveOccurred()) - Expect(defaultChannel).To(BeEquivalentTo("alpha")) - Expect(pkgName).To(BeEquivalentTo("memcached-operator")) - Expect(len(channelByCSV["memcached-operator:v1.0.0"])).To(BeEquivalentTo(1)) - Expect(len(channelByCSV["memcached-operator:v1.0.1"])).To(BeEquivalentTo(2)) - }) - - It("return error when packagename is not found", func() { - pkg.PackageName = "" - _, _, _, err := getPackageMetadata(&pkg) - Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(ContainSubstring("cannot find packagename from the manifest directory")) - }) - - It("should error when defaultChannel name is empty", func() { - pkg.DefaultChannelName = "" - _, _, _, err := getPackageMetadata(&pkg) - Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(ContainSubstring("cannot find the default channel for package")) - }) - }) -}) - -func getNumberOfDirectories(inputDir string) int { - count := 0 - - dirs, err := os.ReadDir(inputDir) - Expect(err).NotTo(HaveOccurred()) - - for _, d := range dirs { - if d.IsDir() { - count++ - } - } - return count -} - -func fileExists(path string) bool { - if _, err := os.Stat(path); !os.IsNotExist(err) { - return true - } - return false -} diff --git a/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.1/cache.example.com_memcacheds.yaml b/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.1/cache.example.com_memcacheds.yaml deleted file mode 100644 index d09374ccc98..00000000000 --- a/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.1/cache.example.com_memcacheds.yaml +++ /dev/null @@ -1,50 +0,0 @@ -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.4.1 - creationTimestamp: null - name: memcacheds.cache.example.com -spec: - group: cache.example.com - names: - kind: Memcached - listKind: MemcachedList - plural: memcacheds - singular: memcached - scope: Namespaced - versions: - - name: v1alpha1 - schema: - openAPIV3Schema: - description: Memcached is the Schema for the memcacheds API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: MemcachedSpec defines the desired state of Memcached - properties: - foo: - description: Foo is an example field of Memcached. Edit memcached_types.go to remove/update - type: string - type: object - status: - description: MemcachedStatus defines the observed state of Memcached - type: object - type: object - served: true - storage: true - subresources: - status: {} -status: - acceptedNames: - kind: "" - plural: "" - conditions: [] - storedVersions: [] diff --git a/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.1/memcached-operator-controller-manager-metrics-service_v1_service.yaml b/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.1/memcached-operator-controller-manager-metrics-service_v1_service.yaml deleted file mode 100644 index 157a0cefa11..00000000000 --- a/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.1/memcached-operator-controller-manager-metrics-service_v1_service.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - creationTimestamp: null - labels: - control-plane: controller-manager - name: memcached-operator-controller-manager-metrics-service -spec: - ports: - - name: https - port: 8443 - targetPort: https - selector: - control-plane: controller-manager -status: - loadBalancer: {} diff --git a/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.1/memcached-operator-controller-manager_v1_serviceaccount.yaml b/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.1/memcached-operator-controller-manager_v1_serviceaccount.yaml deleted file mode 100644 index adc7cf0c639..00000000000 --- a/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.1/memcached-operator-controller-manager_v1_serviceaccount.yaml +++ /dev/null @@ -1,5 +0,0 @@ -apiVersion: v1 -kind: ServiceAccount -metadata: - creationTimestamp: null - name: memcached-operator-controller-manager diff --git a/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.1/memcached-operator-manager-config_v1_configmap.yaml b/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.1/memcached-operator-manager-config_v1_configmap.yaml deleted file mode 100644 index ea42c599454..00000000000 --- a/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.1/memcached-operator-manager-config_v1_configmap.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v1 -data: - controller_manager_config.yaml: | - apiVersion: controller-runtime.sigs.k8s.io/v1alpha1 - kind: ControllerManagerConfig - health: - healthProbeBindAddress: :8081 - metrics: - bindAddress: 127.0.0.1:8080 - webhook: - port: 9443 - leaderElection: - leaderElect: true - resourceName: 86f835c3.example.com -kind: ConfigMap -metadata: - name: memcached-operator-manager-config diff --git a/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.1/memcached-operator-metrics-reader_rbac.authorization.k8s.io_v1_clusterrole.yaml b/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.1/memcached-operator-metrics-reader_rbac.authorization.k8s.io_v1_clusterrole.yaml deleted file mode 100644 index 42a2ae6ac4d..00000000000 --- a/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.1/memcached-operator-metrics-reader_rbac.authorization.k8s.io_v1_clusterrole.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - creationTimestamp: null - name: memcached-operator-metrics-reader -rules: -- nonResourceURLs: - - /metrics - verbs: - - get diff --git a/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.1/memcached-operator.clusterserviceversion.yaml b/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.1/memcached-operator.clusterserviceversion.yaml deleted file mode 100644 index 011671dd1f9..00000000000 --- a/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.1/memcached-operator.clusterserviceversion.yaml +++ /dev/null @@ -1,185 +0,0 @@ -apiVersion: operators.coreos.com/v1alpha1 -kind: ClusterServiceVersion -metadata: - annotations: - alm-examples: |- - [ - { - "apiVersion": "cache.example.com/v1alpha1", - "kind": "Memcached", - "metadata": { - "name": "memcached-sample" - }, - "spec": { - "foo": "bar" - } - } - ] - capabilities: Basic Install - operators.operatorframework.io/builder: operator-sdk-v1.5.0+git - operators.operatorframework.io/project_layout: go.kubebuilder.io/v3 - name: memcached-operator.v0.0.1 - namespace: placeholder -spec: - apiservicedefinitions: {} - customresourcedefinitions: - owned: - - description: Memcached is the Schema for the memcacheds API - displayName: Memcached - kind: Memcached - name: memcacheds.cache.example.com - version: v1alpha1 - description: description - displayName: memcached - icon: - - base64data: "" - mediatype: "" - install: - spec: - clusterPermissions: - - rules: - - apiGroups: - - cache.example.com - resources: - - memcacheds - verbs: - - create - - delete - - get - - list - - patch - - update - - watch - - apiGroups: - - cache.example.com - resources: - - memcacheds/finalizers - verbs: - - update - - apiGroups: - - cache.example.com - resources: - - memcacheds/status - verbs: - - get - - patch - - update - - apiGroups: - - authentication.k8s.io - resources: - - tokenreviews - verbs: - - create - - apiGroups: - - authorization.k8s.io - resources: - - subjectaccessreviews - verbs: - - create - serviceAccountName: memcached-operator-controller-manager - deployments: - - name: memcached-operator-controller-manager - spec: - replicas: 1 - selector: - matchLabels: - control-plane: controller-manager - strategy: {} - template: - metadata: - labels: - control-plane: controller-manager - spec: - containers: - - args: - - --secure-listen-address=0.0.0.0:8443 - - --upstream=http://127.0.0.1:8080/ - - --logtostderr=true - - --v=10 - image: gcr.io/kubebuilder/kube-rbac-proxy:v0.8.0 - name: kube-rbac-proxy - ports: - - containerPort: 8443 - name: https - resources: {} - - args: - - --health-probe-bind-address=:8081 - - --metrics-bind-address=127.0.0.1:8080 - - --leader-elect - command: - - /manager - image: controller:latest - livenessProbe: - httpGet: - path: /healthz - port: 8081 - initialDelaySeconds: 15 - periodSeconds: 20 - name: manager - readinessProbe: - httpGet: - path: /readyz - port: 8081 - initialDelaySeconds: 5 - periodSeconds: 10 - resources: - limits: - cpu: 100m - memory: 30Mi - requests: - cpu: 100m - memory: 20Mi - securityContext: - allowPrivilegeEscalation: false - securityContext: - runAsNonRoot: true - serviceAccountName: memcached-operator-controller-manager - terminationGracePeriodSeconds: 10 - permissions: - - rules: - - apiGroups: - - "" - - coordination.k8s.io - resources: - - configmaps - - leases - verbs: - - get - - list - - watch - - create - - update - - patch - - delete - - apiGroups: - - "" - resources: - - events - verbs: - - create - - patch - serviceAccountName: memcached-operator-controller-manager - strategy: deployment - installModes: - - supported: false - type: OwnNamespace - - supported: false - type: SingleNamespace - - supported: false - type: MultiNamespace - - supported: true - type: AllNamespaces - keywords: - - asd - - afd - links: - - name: Memcached Operator - url: https://memcached-operator.domain - maintainers: - - email: email - name: name - maturity: alpha - provider: - name: redhat - url: url - version: 0.0.1 diff --git a/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.1/scorecard-config.yaml b/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.1/scorecard-config.yaml deleted file mode 100644 index 074baca15d2..00000000000 --- a/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.1/scorecard-config.yaml +++ /dev/null @@ -1,49 +0,0 @@ -apiVersion: scorecard.operatorframework.io/v1alpha3 -kind: Configuration -metadata: - name: config -stages: -- parallel: true - tests: - - entrypoint: - - scorecard-test - - basic-check-spec - image: quay.io/operator-framework/scorecard-test:v1.5.0 - labels: - suite: basic - test: basic-check-spec-test - - entrypoint: - - scorecard-test - - olm-bundle-validation - image: quay.io/operator-framework/scorecard-test:v1.5.0 - labels: - suite: olm - test: olm-bundle-validation-test - - entrypoint: - - scorecard-test - - olm-crds-have-validation - image: quay.io/operator-framework/scorecard-test:v1.5.0 - labels: - suite: olm - test: olm-crds-have-validation-test - - entrypoint: - - scorecard-test - - olm-crds-have-resources - image: quay.io/operator-framework/scorecard-test:v1.5.0 - labels: - suite: olm - test: olm-crds-have-resources-test - - entrypoint: - - scorecard-test - - olm-spec-descriptors - image: quay.io/operator-framework/scorecard-test:v1.5.0 - labels: - suite: olm - test: olm-spec-descriptors-test - - entrypoint: - - scorecard-test - - olm-status-descriptors - image: quay.io/operator-framework/scorecard-test:v1.5.0 - labels: - suite: olm - test: olm-status-descriptors-test \ No newline at end of file diff --git a/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.2/cache.example.com_memcacheds.yaml b/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.2/cache.example.com_memcacheds.yaml deleted file mode 100644 index d09374ccc98..00000000000 --- a/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.2/cache.example.com_memcacheds.yaml +++ /dev/null @@ -1,50 +0,0 @@ -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.4.1 - creationTimestamp: null - name: memcacheds.cache.example.com -spec: - group: cache.example.com - names: - kind: Memcached - listKind: MemcachedList - plural: memcacheds - singular: memcached - scope: Namespaced - versions: - - name: v1alpha1 - schema: - openAPIV3Schema: - description: Memcached is the Schema for the memcacheds API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: MemcachedSpec defines the desired state of Memcached - properties: - foo: - description: Foo is an example field of Memcached. Edit memcached_types.go to remove/update - type: string - type: object - status: - description: MemcachedStatus defines the observed state of Memcached - type: object - type: object - served: true - storage: true - subresources: - status: {} -status: - acceptedNames: - kind: "" - plural: "" - conditions: [] - storedVersions: [] diff --git a/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.2/memcached-operator-controller-manager-metrics-service_v1_service.yaml b/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.2/memcached-operator-controller-manager-metrics-service_v1_service.yaml deleted file mode 100644 index 157a0cefa11..00000000000 --- a/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.2/memcached-operator-controller-manager-metrics-service_v1_service.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - creationTimestamp: null - labels: - control-plane: controller-manager - name: memcached-operator-controller-manager-metrics-service -spec: - ports: - - name: https - port: 8443 - targetPort: https - selector: - control-plane: controller-manager -status: - loadBalancer: {} diff --git a/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.2/memcached-operator-controller-manager_v1_serviceaccount.yaml b/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.2/memcached-operator-controller-manager_v1_serviceaccount.yaml deleted file mode 100644 index adc7cf0c639..00000000000 --- a/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.2/memcached-operator-controller-manager_v1_serviceaccount.yaml +++ /dev/null @@ -1,5 +0,0 @@ -apiVersion: v1 -kind: ServiceAccount -metadata: - creationTimestamp: null - name: memcached-operator-controller-manager diff --git a/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.2/memcached-operator-manager-config_v1_configmap.yaml b/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.2/memcached-operator-manager-config_v1_configmap.yaml deleted file mode 100644 index ea42c599454..00000000000 --- a/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.2/memcached-operator-manager-config_v1_configmap.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v1 -data: - controller_manager_config.yaml: | - apiVersion: controller-runtime.sigs.k8s.io/v1alpha1 - kind: ControllerManagerConfig - health: - healthProbeBindAddress: :8081 - metrics: - bindAddress: 127.0.0.1:8080 - webhook: - port: 9443 - leaderElection: - leaderElect: true - resourceName: 86f835c3.example.com -kind: ConfigMap -metadata: - name: memcached-operator-manager-config diff --git a/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.2/memcached-operator-metrics-reader_rbac.authorization.k8s.io_v1_clusterrole.yaml b/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.2/memcached-operator-metrics-reader_rbac.authorization.k8s.io_v1_clusterrole.yaml deleted file mode 100644 index 42a2ae6ac4d..00000000000 --- a/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.2/memcached-operator-metrics-reader_rbac.authorization.k8s.io_v1_clusterrole.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - creationTimestamp: null - name: memcached-operator-metrics-reader -rules: -- nonResourceURLs: - - /metrics - verbs: - - get diff --git a/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.2/memcached-operator.clusterserviceversion.yaml b/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.2/memcached-operator.clusterserviceversion.yaml deleted file mode 100644 index 5f2b8cb7610..00000000000 --- a/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/0.0.2/memcached-operator.clusterserviceversion.yaml +++ /dev/null @@ -1,185 +0,0 @@ -apiVersion: operators.coreos.com/v1alpha1 -kind: ClusterServiceVersion -metadata: - annotations: - alm-examples: |- - [ - { - "apiVersion": "cache.example.com/v1alpha1", - "kind": "Memcached", - "metadata": { - "name": "memcached-sample" - }, - "spec": { - "foo": "bar" - } - } - ] - capabilities: Basic Install - operators.operatorframework.io/builder: operator-sdk-v1.5.0+git - operators.operatorframework.io/project_layout: go.kubebuilder.io/v3 - name: memcached-operator.v0.0.2 - namespace: placeholder -spec: - apiservicedefinitions: {} - customresourcedefinitions: - owned: - - description: Memcached is the Schema for the memcacheds API - displayName: Memcached - kind: Memcached - name: memcacheds.cache.example.com - version: v1alpha1 - description: description - displayName: memcached - icon: - - base64data: "" - mediatype: "" - install: - spec: - clusterPermissions: - - rules: - - apiGroups: - - cache.example.com - resources: - - memcacheds - verbs: - - create - - delete - - get - - list - - patch - - update - - watch - - apiGroups: - - cache.example.com - resources: - - memcacheds/finalizers - verbs: - - update - - apiGroups: - - cache.example.com - resources: - - memcacheds/status - verbs: - - get - - patch - - update - - apiGroups: - - authentication.k8s.io - resources: - - tokenreviews - verbs: - - create - - apiGroups: - - authorization.k8s.io - resources: - - subjectaccessreviews - verbs: - - create - serviceAccountName: memcached-operator-controller-manager - deployments: - - name: memcached-operator-controller-manager - spec: - replicas: 1 - selector: - matchLabels: - control-plane: controller-manager - strategy: {} - template: - metadata: - labels: - control-plane: controller-manager - spec: - containers: - - args: - - --secure-listen-address=0.0.0.0:8443 - - --upstream=http://127.0.0.1:8080/ - - --logtostderr=true - - --v=10 - image: gcr.io/kubebuilder/kube-rbac-proxy:v0.8.0 - name: kube-rbac-proxy - ports: - - containerPort: 8443 - name: https - resources: {} - - args: - - --health-probe-bind-address=:8081 - - --metrics-bind-address=127.0.0.1:8080 - - --leader-elect - command: - - /manager - image: controller:latest - livenessProbe: - httpGet: - path: /healthz - port: 8081 - initialDelaySeconds: 15 - periodSeconds: 20 - name: manager - readinessProbe: - httpGet: - path: /readyz - port: 8081 - initialDelaySeconds: 5 - periodSeconds: 10 - resources: - limits: - cpu: 100m - memory: 30Mi - requests: - cpu: 100m - memory: 20Mi - securityContext: - allowPrivilegeEscalation: false - securityContext: - runAsNonRoot: true - serviceAccountName: memcached-operator-controller-manager - terminationGracePeriodSeconds: 10 - permissions: - - rules: - - apiGroups: - - "" - - coordination.k8s.io - resources: - - configmaps - - leases - verbs: - - get - - list - - watch - - create - - update - - patch - - delete - - apiGroups: - - "" - resources: - - events - verbs: - - create - - patch - serviceAccountName: memcached-operator-controller-manager - strategy: deployment - installModes: - - supported: false - type: OwnNamespace - - supported: false - type: SingleNamespace - - supported: false - type: MultiNamespace - - supported: true - type: AllNamespaces - keywords: - - asd - - afd - links: - - name: Memcached Operator - url: https://memcached-operator.domain - maintainers: - - email: email - name: name - maturity: alpha - provider: - name: redhat - url: url - version: 0.0.2 diff --git a/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/memcached-operator.package.yaml b/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/memcached-operator.package.yaml deleted file mode 100644 index 373fdedcb36..00000000000 --- a/internal/cmd/operator-sdk/pkgmantobundle/testdata/packagemanifests/memcached-operator.package.yaml +++ /dev/null @@ -1,7 +0,0 @@ -channels: -- currentCSV: memcached-operator.v0.0.1 - name: memcached-operator.v0.0.1 -- currentCSV: memcached-operator.v0.0.2 - name: memcached-operator.v0.0.2 -defaultChannel: alpha -packageName: memcached-operator diff --git a/internal/cmd/operator-sdk/run/cmd.go b/internal/cmd/operator-sdk/run/cmd.go index 5f46845aac1..f09f7efb074 100644 --- a/internal/cmd/operator-sdk/run/cmd.go +++ b/internal/cmd/operator-sdk/run/cmd.go @@ -19,7 +19,6 @@ import ( "github.com/operator-framework/operator-sdk/internal/cmd/operator-sdk/run/bundle" "github.com/operator-framework/operator-sdk/internal/cmd/operator-sdk/run/bundleupgrade" - "github.com/operator-framework/operator-sdk/internal/cmd/operator-sdk/run/packagemanifests" "github.com/operator-framework/operator-sdk/internal/olm/operator" ) @@ -35,7 +34,6 @@ func NewCmd() *cobra.Command { cmd.AddCommand( bundle.NewCmd(cfg), bundleupgrade.NewCmd(cfg), - packagemanifests.NewCmd(cfg), ) return cmd diff --git a/internal/cmd/operator-sdk/run/cmd_test.go b/internal/cmd/operator-sdk/run/cmd_test.go index 5519b7a06a0..f850a51257c 100644 --- a/internal/cmd/operator-sdk/run/cmd_test.go +++ b/internal/cmd/operator-sdk/run/cmd_test.go @@ -29,10 +29,9 @@ var _ = Describe("Running a run command", func() { Expect(cmd.Long).NotTo(BeNil()) subcommands := cmd.Commands() - Expect(subcommands).To(HaveLen(3)) + Expect(subcommands).To(HaveLen(2)) Expect(subcommands[0].Use).To(Equal("bundle ")) Expect(subcommands[1].Use).To(Equal("bundle-upgrade ")) - Expect(subcommands[2].Use).To(Equal("packagemanifests [packagemanifests-root-dir]")) }) }) }) diff --git a/internal/cmd/operator-sdk/run/packagemanifests/packagemanifests.go b/internal/cmd/operator-sdk/run/packagemanifests/packagemanifests.go deleted file mode 100644 index b45395a5134..00000000000 --- a/internal/cmd/operator-sdk/run/packagemanifests/packagemanifests.go +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2020 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package packagemanifests - -import ( - "context" - - log "github.com/sirupsen/logrus" - "github.com/spf13/cobra" - - "github.com/operator-framework/operator-sdk/internal/olm/operator" - "github.com/operator-framework/operator-sdk/internal/olm/operator/packagemanifests" -) - -func NewCmd(cfg *operator.Configuration) *cobra.Command { - i := packagemanifests.NewInstall(cfg) - cmd := &cobra.Command{ - Use: "packagemanifests [packagemanifests-root-dir]", - Deprecated: "support for the packagemanifests format will be removed in operator-sdk v2.0.0. Use bundles to " + - "package your operator instead. Migrate your packagemanifest to a bundle using " + - "'operator-sdk pkgman-to-bundle' command. Run 'operator-sdk pkgman-to-bundle --help' " + - "for more details.", - Short: "Deploy an Operator in the package manifests format with OLM", - Long: `'run packagemanifests' deploys an Operator's package manifests with OLM. The command's argument -will default to './packagemanifests' if unset; if set, the argument must be a package manifests root directory, -ex. '/packagemanifests'.`, - Aliases: []string{"pm"}, - Args: cobra.MaximumNArgs(1), - PreRunE: func(*cobra.Command, []string) error { return cfg.Load() }, - Run: func(cmd *cobra.Command, args []string) { - ctx, cancel := context.WithTimeout(cmd.Context(), cfg.Timeout) - defer cancel() - - if len(args) == 0 { - i.PackageManifestsDirectory = "packagemanifests" - } else { - i.PackageManifestsDirectory = args[0] - } - - // TODO(joelanford): Add cleanup logic if this fails? - _, err := i.Run(ctx) - if err != nil { - log.Fatalf("Failed to run packagemanifests: %v\n", err) - } - }, - } - - cfg.BindFlags(cmd.Flags()) - i.BindFlags(cmd.Flags()) - // Not implemented. - if err := cmd.Flags().MarkHidden("service-account"); err != nil { - log.Fatal(err) - } - - return cmd -} diff --git a/internal/cmd/operator-sdk/run/packagemanifests/packagemanifests_suite_test.go b/internal/cmd/operator-sdk/run/packagemanifests/packagemanifests_suite_test.go deleted file mode 100644 index 265bc9f63b3..00000000000 --- a/internal/cmd/operator-sdk/run/packagemanifests/packagemanifests_suite_test.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2020 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package packagemanifests_test - -import ( - "testing" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" -) - -func TestRun(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "Packagemanifests Cmd Suite") -} diff --git a/internal/cmd/operator-sdk/run/packagemanifests/packagemanifests_test.go b/internal/cmd/operator-sdk/run/packagemanifests/packagemanifests_test.go deleted file mode 100644 index d320ced6b7b..00000000000 --- a/internal/cmd/operator-sdk/run/packagemanifests/packagemanifests_test.go +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2020 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package packagemanifests - -import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - - "github.com/operator-framework/operator-sdk/internal/olm/operator" -) - -var _ = Describe("Running a run packagemanifests command", func() { - Describe("NewCmd", func() { - It("builds a cobra command", func() { - cfg := &operator.Configuration{} - cmd := NewCmd(cfg) - Expect(cmd).NotTo(BeNil()) - Expect(cmd.Use).NotTo(BeNil()) - Expect(cmd.Short).NotTo(BeNil()) - Expect(cmd.Long).NotTo(BeNil()) - aliases := cmd.Aliases - Expect(aliases).To(HaveLen(1)) - Expect(aliases[0]).To(Equal("pm")) - }) - }) -}) diff --git a/test/e2e/helm/olm_test.go b/test/e2e/helm/olm_test.go deleted file mode 100644 index 8855d7ce4b8..00000000000 --- a/test/e2e/helm/olm_test.go +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2020 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package e2e_helm_test - -import ( - "os/exec" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - - "github.com/operator-framework/operator-sdk/internal/util/projutil" -) - -var _ = Describe("Integrating Helm Projects with OLM", func() { - Context("with operator-sdk", func() { - const operatorVersion = "0.0.1" - - It("should generate and run a valid OLM bundle and packagemanifests", func() { - By("building the operator bundle image") - err := tc.Make("bundle-build", "BUNDLE_IMG="+tc.BundleImageName) - Expect(err).NotTo(HaveOccurred()) - - By("adding the 'packagemanifests' rule to the Makefile") - err = tc.AddPackagemanifestsTarget(projutil.OperatorTypeHelm) - Expect(err).NotTo(HaveOccurred()) - - By("generating the operator package manifests") - err = tc.Make("packagemanifests", "IMG="+tc.ImageName) - Expect(err).NotTo(HaveOccurred()) - - By("running the package") - runPkgManCmd := exec.Command(tc.BinaryName, "run", "packagemanifests", - "--install-mode", "AllNamespaces", - "--version", operatorVersion, - "--timeout", "4m") - _, err = tc.Run(runPkgManCmd) - Expect(err).NotTo(HaveOccurred()) - - By("destroying the deployed package manifests-formatted operator") - cleanupPkgManCmd := exec.Command(tc.BinaryName, "cleanup", tc.ProjectName, - "--timeout", "4m") - _, err = tc.Run(cleanupPkgManCmd) - Expect(err).NotTo(HaveOccurred()) - }) - }) -}) diff --git a/test/integration/packagemanifests_test.go b/test/integration/packagemanifests_test.go deleted file mode 100644 index 3ac7a0e0312..00000000000 --- a/test/integration/packagemanifests_test.go +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2020 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package integration - -import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" -) - -var _ = Describe("run packagemanifests", func() { - - var ( - err error - output string - ) - - AfterEach(func() { - By("cleaning up") - _, err = cleanup(&tc) - Expect(err).NotTo(HaveOccurred()) - }) - - It("should handle existing operator deployments correctly", func() { - output, err = cleanup(&tc) - Expect(err).NotTo(HaveOccurred()) - Expect(output).To(ContainSubstring(`package \"memcached-operator\" not found`)) - Expect(runPackageManifests(&tc, "--version", "0.0.1")).To(Succeed()) - Expect(runPackageManifests(&tc, "--version", "0.0.1")).NotTo(Succeed()) - _, err = cleanup(&tc) - Expect(err).NotTo(HaveOccurred()) - output, err = cleanup(&tc) - Expect(err).NotTo(HaveOccurred()) - Expect(output).To(ContainSubstring(`package \"memcached-operator\" not found`)) - }) - - It("should succeed with a single operator version in AllNamespaces mode", func() { - Expect(runPackageManifests(&tc, "--install-mode", "AllNamespaces", "--version", "0.0.1")).To(Succeed()) - }) -}) diff --git a/test/integration/suite_test.go b/test/integration/suite_test.go index 9ff74710745..42643cf5068 100644 --- a/test/integration/suite_test.go +++ b/test/integration/suite_test.go @@ -148,24 +148,6 @@ func warn(output string, err error) { } } -func runPackageManifests(tc *testutils.TestContext, args ...string) error { - allArgs := []string{"run", "packagemanifests", "--timeout", "6m", "--namespace", tc.Kubectl.Namespace} - output, err := tc.Run(exec.Command(tc.BinaryName, append(allArgs, args...)...)) - if err == nil { - fmt.Fprintln(GinkgoWriter, string(output)) - } - return err -} - -func cleanup(tc *testutils.TestContext) (string, error) { - allArgs := []string{"cleanup", tc.ProjectName, "--timeout", "4m", "--namespace", tc.Kubectl.Namespace} - output, err := tc.Run(exec.Command(tc.BinaryName, allArgs...)) - if err == nil { - fmt.Fprintln(GinkgoWriter, string(output)) - } - return string(output), err -} - func readCSV(tc *testutils.TestContext, version string, isBundle bool) (*v1alpha1.ClusterServiceVersion, error) { b, err := os.ReadFile(csvPath(tc, version, isBundle)) if err != nil { diff --git a/website/content/en/docs/cli/operator-sdk.md b/website/content/en/docs/cli/operator-sdk.md index 0ae1cef54c8..0c379f3d347 100644 --- a/website/content/en/docs/cli/operator-sdk.md +++ b/website/content/en/docs/cli/operator-sdk.md @@ -60,7 +60,6 @@ Default project version: "3" * [operator-sdk generate](../operator-sdk_generate) - Invokes a specific generator * [operator-sdk init](../operator-sdk_init) - Initialize a new project * [operator-sdk olm](../operator-sdk_olm) - Manage the Operator Lifecycle Manager installation in your cluster -* [operator-sdk pkgman-to-bundle](../operator-sdk_pkgman-to-bundle) - Migrates packagemanifests to bundles * [operator-sdk run](../operator-sdk_run) - Run an Operator in a variety of environments * [operator-sdk scorecard](../operator-sdk_scorecard) - Runs scorecard * [operator-sdk version](../operator-sdk_version) - Print the operator-sdk version diff --git a/website/content/en/docs/cli/operator-sdk_pkgman-to-bundle.md b/website/content/en/docs/cli/operator-sdk_pkgman-to-bundle.md deleted file mode 100644 index 7ed7e832e7b..00000000000 --- a/website/content/en/docs/cli/operator-sdk_pkgman-to-bundle.md +++ /dev/null @@ -1,110 +0,0 @@ ---- -title: "operator-sdk pkgman-to-bundle" ---- -## operator-sdk pkgman-to-bundle - -Migrates packagemanifests to bundles - -### Synopsis - - -'pkgman-to-bundle' command helps in migrating OLM packagemanifests to bundles which is the preferred OLM packaging format. -This command takes an input packagemanifest directory and generates bundles for each of the versions of manifests present in -the input directory. Additionally, it also provides the flexibility to build bundle images for each of the generated bundles. - -The generated bundles are always written on disk. Location for the generated bundles can be specified using '--output-dir'. If not -specified, the default location would be 'bundle/' directory. - -The base container image name for the bundles can be provided using '--image-tag-base' flag. This should be provided without the tag, since the tag -for the images would be the bundle version, (ie) image names will be in the format <base_image>:<bundle_version>. - -Specify the build command for building container images using '--build-cmd' flag. The default build command is 'docker build'. The command will -need to be in the 'PATH' or fully qualified path name should be provided. - - -``` -operator-sdk pkgman-to-bundle [flags] -``` - -### Examples - -``` - - -# Provide the packagemanifests directory as input to the command. Consider the packagemanifests directory to have the following -# structure: - -$ tree packagemanifests/ -packagemanifests -└── etcd - ├── 0.0.1 - │ ├── etcdcluster.crd.yaml - │ └── etcdoperator.clusterserviceversion.yaml - ├── 0.0.2 - │ ├── etcdbackup.crd.yaml - │ ├── etcdcluster.crd.yaml - │ ├── etcdoperator.v0.0.2.clusterserviceversion.yaml - │ └── etcdrestore.crd.yaml - └── etcd.package.yaml - -# Run the following command to generate bundles in the default 'bundle/' directory with the base-container image name -# to be 'quay.io/example/etcd' -$ operator-sdk pkgman-to-bundle packagemanifests --image-tag-base quay.io/example/etcd -INFO[0000] Packagemanifests will be migrated to bundles in bundle directory -INFO[0000] Creating bundle/bundle-0.0.1/bundle.Dockerfile -INFO[0000] Creating bundle/bundle-0.0.1/metadata/annotations.yaml -... - -# After running the above command, the bundles will be generated in 'bundles/' directory. -$ tree bundles/ -bundles/ -├── bundle-0.0.1 -│   ├── bundle -│   │   ├── manifests -│   │   │   ├── etcdcluster.crd.yaml -│   │   │   ├── etcdoperator.clusterserviceversion.yaml -│   │   ├── metadata -│   │   │   └── annotations.yaml -│   │   └── tests -│   │   └── scorecard -│   │   └── config.yaml -│   └── bundle.Dockerfile -└── bundle-0.0.2 - ├── bundle - │   ├── manifests - │   │   ├── etcdbackup.crd.yaml - │   │   ├── etcdcluster.crd.yaml - │   │   ├── etcdoperator.v0.0.2.clusterserviceversion.yaml - │   │   ├── etcdrestore.crd.yaml - │   └── metadata - │   └── annotations.yaml - └── bundle.Dockerfile - -A custom command to build bundle images can also be specified using the '--build-cmd' flag. For example, - -$ operator-sdk pkgman-to-bundle packagemanifests --image-tag-base quay.io/example/etcd --build-cmd "podman build -f bundle.Dockerfile . -t" - -Images for the both the bundles will be built with the following names: quay.io/example/etcd:0.0.1 and quay.io/example/etcd:0.0.2. - -``` - -### Options - -``` - --build-cmd string Build command to be run for building images. By default 'docker build' is run. - -h, --help help for pkgman-to-bundle - --image-tag-base string Base container image name for bundle image tags, ex. my.reg/foo/bar-operator-bundle will become my.reg/foo/bar-operator-bundle:${package-dir-name} for each child directory name in the packagemanifests directory - --output-dir string Directory to write bundle to. (default "bundles") -``` - -### Options inherited from parent commands - -``` - --plugins strings plugin keys to be used for this subcommand execution - --verbose Enable verbose logging -``` - -### SEE ALSO - -* [operator-sdk](../operator-sdk) - -