-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -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() { | ||
buildCmd.Flags().StringVar(&goBuildArgs, "go-build-args", "", | ||
"Extra Go build arguments as one string such as \"-ldflags -X=main.xyz=abc\"") | ||
} | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be removed. All projects for 1.0.0 should have |
||
if err := doImageBuild("Dockerfile", image); err != nil { | ||
log.Fatalf("Failed to build image %s: %v", image, err) | ||
} | ||
|
@@ -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) | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we not still showing a msg:
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
} | ||
|
There was a problem hiding this comment.
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.