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

cmd/operator-sdk,internal: remove legacy CLI, clean up utils #3533

Merged
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
48 changes: 3 additions & 45 deletions cmd/operator-sdk/build/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@ package build

import (
"fmt"
"os"
"os/exec"
"path"
"path/filepath"
"strings"

"github.com/operator-framework/operator-sdk/internal/scaffold"
kbutil "github.com/operator-framework/operator-sdk/internal/util/kubebuilder"
"github.com/operator-framework/operator-sdk/internal/util/projutil"

"github.com/google/shlex"
Expand Down Expand Up @@ -65,7 +60,7 @@ For example:
"Tool to build OCI images. One of: [docker, podman, buildah]")

// todo: remove when the legacy layout is no longer supported
if !kbutil.HasProjectFile() {
if !projutil.HasProjectFile() {
Copy link
Contributor

@camilamacedo86 camilamacedo86 Jul 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be removed. All projects for 1.0.0 should have HasProjectFile
The code inside of this checks is related to legacy layout. See the too comment.

buildCmd.Flags().StringVar(&goBuildArgs, "go-build-args", "",
"Extra Go build arguments as one string such as \"-ldflags -X=main.xyz=abc\"")
}
Expand Down Expand Up @@ -104,9 +99,8 @@ func buildFunc(cmd *cobra.Command, args []string) error {
}

image := args[0]
projutil.MustInProjectRoot()

if kbutil.HasProjectFile() {
if projutil.HasProjectFile() {
estroz marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be removed. All projects for 1.0.0 should have HasProjectFile
The code inside of this checks is related to legacy layout.

if err := doImageBuild("Dockerfile", image); err != nil {
log.Fatalf("Failed to build image %s: %v", image, err)
}
Expand All @@ -115,48 +109,12 @@ func buildFunc(cmd *cobra.Command, args []string) error {

// todo: remove when the legacy layout is no longer supported
// note that the above if will no longer be required as well.
if err := doLegacyBuild(image); err != nil {
if err := doImageBuild(filepath.Join("build", "Dockerfile"), image); err != nil {
log.Fatalf("Failed to build image %s: %v", image, err)
}
return nil
}

// todo: remove when the legacy layout is no longer supported
// Deprecated: Used just for the legacy layout
// --
// doLegacyBuild will build projects with the legacy layout.
func doLegacyBuild(image string) error {
goBuildEnv := append(os.Environ(), "GOOS=linux")
// If CGO_ENABLED is not set, set it to '0'.
if _, ok := os.LookupEnv("CGO_ENABLED"); !ok {
goBuildEnv = append(goBuildEnv, "CGO_ENABLED=0")
}
absProjectPath := projutil.MustGetwd()
projectName := filepath.Base(absProjectPath)

// Don't need to build Go code if a non-Go Operator.
if projutil.IsOperatorGo() {
trimPath := fmt.Sprintf("all=-trimpath=%s", filepath.Dir(absProjectPath))
args := []string{"-gcflags", trimPath, "-asmflags", trimPath}

if goBuildArgs != "" {
splitArgs := strings.Fields(goBuildArgs)
args = append(args, splitArgs...)
}

opts := projutil.GoCmdOptions{
BinName: filepath.Join(absProjectPath, scaffold.BuildBinDir, projectName),
PackagePath: path.Join(projutil.GetGoPkg(), filepath.ToSlash(scaffold.ManagerDir)),
Args: args,
Env: goBuildEnv,
}
if err := projutil.GoBuild(opts); err != nil {
log.Fatalf("Failed to build operator binary: %v", err)
}
}
return doImageBuild("build/Dockerfile", image)
}

// doImageBuild will execute the build command for the given Dockerfile path and image
func doImageBuild(dockerFilePath, image string) error {
log.Infof("Building OCI image %s", image)
Expand Down
2 changes: 1 addition & 1 deletion cmd/operator-sdk/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ import (
)

var commands = []*cobra.Command{
scorecard.NewCmd(),
build.NewCmd(),
bundle.NewCmd(),
cleanup.NewCmd(),
completion.NewCmd(),
generate.NewCmd(),
olm.NewCmd(),
run.NewCmd(),
scorecard.NewCmd(),
version.NewCmd(),
}

Expand Down
113 changes: 0 additions & 113 deletions cmd/operator-sdk/cli/legacy.go

This file was deleted.

4 changes: 2 additions & 2 deletions cmd/operator-sdk/generate/bundle/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"

kbutil "github.com/operator-framework/operator-sdk/internal/util/kubebuilder"
"github.com/operator-framework/operator-sdk/internal/util/projutil"
)

//nolint:maligned
Expand Down Expand Up @@ -68,7 +68,7 @@ func NewCmd() *cobra.Command {
c.metadata = true
}

cfg, err := kbutil.ReadConfig()
cfg, err := projutil.ReadConfig()
if err != nil {
return fmt.Errorf("error reading configuration: %v", err)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/operator-sdk/generate/kustomize/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (

gencsv "github.com/operator-framework/operator-sdk/internal/generate/clusterserviceversion"
"github.com/operator-framework/operator-sdk/internal/plugins/util/kustomize"
kbutil "github.com/operator-framework/operator-sdk/internal/util/kubebuilder"
"github.com/operator-framework/operator-sdk/internal/util/projutil"
)

Expand Down Expand Up @@ -94,7 +93,7 @@ func newManifestsCmd() *cobra.Command {
}
}

cfg, err := kbutil.ReadConfig()
cfg, err := projutil.ReadConfig()
if err != nil {
return fmt.Errorf("error reading configuration: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/operator-sdk/generate/packagemanifests/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"

kbutil "github.com/operator-framework/operator-sdk/internal/util/kubebuilder"
"github.com/operator-framework/operator-sdk/internal/util/projutil"
)

//nolint:maligned
Expand Down Expand Up @@ -59,7 +59,7 @@ func NewCmd() *cobra.Command {
return fmt.Errorf("command %s doesn't accept any arguments", cmd.CommandPath())
}

cfg, err := kbutil.ReadConfig()
cfg, err := projutil.ReadConfig()
if err != nil {
log.Fatal(fmt.Errorf("error reading configuration: %v", err))
}
Expand Down
37 changes: 2 additions & 35 deletions cmd/operator-sdk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,49 +15,16 @@
package main

import (

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that `exec-entrypoint` and `run` can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"

"github.com/operator-framework/operator-sdk/cmd/operator-sdk/cli"
kbutil "github.com/operator-framework/operator-sdk/internal/util/kubebuilder"
"github.com/operator-framework/operator-sdk/internal/util/projutil"

log "github.com/sirupsen/logrus"

"github.com/operator-framework/operator-sdk/cmd/operator-sdk/cli"
)

func main() {
// Use the new KB CLI when running inside a Kubebuilder project with an existing PROJECT file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we not still showing a msg:

if is not show the info that is required to migrate the project when has not the Project file. See: https://github.com/operator-framework/operator-sdk/pull/3539/files#diff-fc95fb53b164f1e3dc64775883195e7bR28-R35


Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. SDK v1.0 has no knowledge of the legacy CLI/project layout.

Copy link
Contributor

@camilamacedo86 camilamacedo86 Jul 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has its pros and cons, I agree. But for alpha at least I think that is valid for we do not see many new issues raised asking about the same issue.

if kbutil.HasProjectFile() {
if err := cli.Run(); err != nil {
log.Fatal(err)
}
return
}

// Use the legacy CLI if inside of a Go/Helm/Ansible legacy project
operatorType := projutil.GetOperatorType()
switch operatorType {
case projutil.OperatorTypeGo, projutil.OperatorTypeHelm, projutil.OperatorTypeAnsible:
// Deprecation warning for Go projects
// TODO/Discuss: UX wise, is displaying this notice on every command that runs
// in the legacy Go projects too loud.
if operatorType == projutil.OperatorTypeGo {
depMsg := "Operator SDK has a new CLI and project layout that is aligned with Kubebuilder.\n" +
"See `operator-sdk init -h` and the following doc on how to scaffold a new project:\n" +
"https://sdk.operatorframework.io/docs/golang/quickstart/\n" +
"To migrate existing projects to the new layout see:\n" +
"https://sdk.operatorframework.io/docs/golang/project_migration_guide/\n"
projutil.PrintDeprecationWarning(depMsg)
}
if err := cli.RunLegacy(); err != nil {
log.Fatal(err)
}
return
}

// Run the KB CLI when not running in either legacy or new projects
if err := cli.Run(); err != nil {
log.Fatal(err)
}
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ require (
github.com/kr/text v0.1.0
github.com/markbates/inflect v1.0.4
github.com/mattn/go-isatty v0.0.12
github.com/mitchellh/go-homedir v1.1.0
github.com/onsi/ginkgo v1.12.1
github.com/onsi/gomega v1.10.1
github.com/operator-framework/api v0.3.8
github.com/operator-framework/operator-lib v0.0.0-20200724203809-f6728cc91ac6
github.com/operator-framework/operator-registry v1.12.6-0.20200611222234-275301b779f8
github.com/prometheus/client_golang v1.5.1
github.com/rogpeppe/go-internal v1.5.0
github.com/sergi/go-diff v1.0.0
github.com/sirupsen/logrus v1.5.0
github.com/spf13/afero v1.2.2
Expand Down
3 changes: 1 addition & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -658,9 +658,8 @@ github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6So
github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.3.2/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.4.0 h1:LUa41nrWTQNGhzdsZ5lTnkwbNjj6rXTdazA1cSdjkOY=
github.com/rogpeppe/go-internal v1.4.0/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.5.0 h1:Usqs0/lDK/NqTkvrmKSwA/3XkZAs7ZAW/eLeQ2MVBTw=
github.com/rogpeppe/go-internal v1.5.0/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rubenv/sql-migrate v0.0.0-20200212082348-64f95ea68aa3 h1:xkBtI5JktwbW/vf4vopBbhYsRFTGfQWHYXzC0/qYwxI=
github.com/rubenv/sql-migrate v0.0.0-20200212082348-64f95ea68aa3/go.mod h1:rtQlpHw+eR6UrqaS3kX1VYeaCxzCVdimDS7g5Ln4pPc=
github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo=
Expand Down
Loading