Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mock kubebuilder integration with 'operator-sdk alpha kubebuilder' cmd #2396

Merged
merged 1 commit into from
Jan 13, 2020
Merged
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
2 changes: 2 additions & 0 deletions cmd/operator-sdk/alpha/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package alpha

import (
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/alpha/kubebuilder"
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/alpha/olm"
"github.com/spf13/cobra"
)
Expand All @@ -26,5 +27,6 @@ func NewCmd() *cobra.Command {
}

cmd.AddCommand(olm.NewCmd())
cmd.AddCommand(kubebuilder.NewCmd())
return cmd
}
71 changes: 71 additions & 0 deletions cmd/operator-sdk/alpha/kubebuilder/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright 2019 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 kubebuilder

import (
"fmt"
"os/exec"

"github.com/operator-framework/operator-sdk/cmd/operator-sdk/alpha/kubebuilder/olmcatalog"
"github.com/operator-framework/operator-sdk/internal/util/projutil"

"github.com/google/shlex"
"github.com/spf13/cobra"
)

var kbFlags string

func NewCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "kubebuilder [init/create cmds]",
Short: "Kubebuilder aligned subcommands",
Long: `
This subcommand is a placeholder to test the integration of Kubebuilder and Operator SDK
subcommands until a plugin system is available to integrate the Kubebuilder CLI.
See: https://github.com/kubernetes-sigs/kubebuilder/pull/1250
and https://github.com/operator-framework/operator-sdk/blob/master/doc/proposals/openshift-4.4/kubebuilder-integration.md
`,
RunE: runKubebuilder,
Hidden: true,

Example: `
# Initialize your project
operator-sdk alpha kubebuilder init --kb-flags="--domain example.com --license apache2 --owner \"The Kubernetes authors\""

# Create a frigates API with Group: ship, Version: v1beta1 and Kind: Frigate
operator-sdk alpha kubebuilder create api --kb-flags="--group ship --version v1beta1 --kind Frigate"
`,
}

cmd.Flags().StringVar(&kbFlags, "kb-flags", "", "Extra kubebuilder flags passed to init/create commands \"--group cache --version=v1alpha1\"")

cmd.AddCommand(
olmcatalog.NewCmd(),
// newScorecardCmd(),
// newTestFrameworkCmd(),
)
return cmd
}

func runKubebuilder(cmd *cobra.Command, args []string) error {
splitArgs, err := shlex.Split(kbFlags)
if err != nil {
return fmt.Errorf("kb-flags is not parseable: %v", err)
}
args = append(args, splitArgs...)

kbCmd := exec.Command("kubebuilder", args...)
return projutil.ExecCmd(kbCmd)
}
34 changes: 34 additions & 0 deletions cmd/operator-sdk/alpha/kubebuilder/olmcatalog/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2018 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 olmcatalog

import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

func NewCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "olm-catalog <olm-catalog-command>",
Short: "Invokes a olm-catalog command",
Long: `The operator-sdk olm-catalog command invokes a command to perform
Catalog related actions.`,
Run: func(cmd *cobra.Command, args []string) {
log.Info("TODO")
},
}
// cmd.AddCommand(newGenCSVCmd())
return cmd
}
1 change: 1 addition & 0 deletions internal/util/projutil/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
func ExecCmd(cmd *exec.Cmd) error {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
log.Debugf("Running %#v", cmd.Args)
if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to exec %#v: %w", cmd.Args, err)
Expand Down