From 2375a306f9c0e85fb486ef58aa6d5aebba8dc8b2 Mon Sep 17 00:00:00 2001 From: Yi Chen Date: Fri, 6 Dec 2024 13:08:00 +0800 Subject: [PATCH] Move sparkctl to cmd directory (#2347) * Move spark-operator Signed-off-by: Yi Chen * Move sparkctl to cmd directory Signed-off-by: Yi Chen * Remove unnecessary app package/directory Signed-off-by: Yi Chen --------- Signed-off-by: Yi Chen --- Makefile | 6 ++-- cmd/main.go | 31 ------------------- cmd/operator/{root.go => main.go} | 14 +++++++-- {sparkctl => cmd/sparkctl}/README.md | 0 {sparkctl/cmd => cmd/sparkctl/app}/client.go | 2 +- {sparkctl/cmd => cmd/sparkctl/app}/create.go | 2 +- .../cmd => cmd/sparkctl/app}/create_test.go | 2 +- {sparkctl/cmd => cmd/sparkctl/app}/delete.go | 2 +- {sparkctl/cmd => cmd/sparkctl/app}/event.go | 2 +- {sparkctl/cmd => cmd/sparkctl/app}/forward.go | 2 +- {sparkctl/cmd => cmd/sparkctl/app}/gcs.go | 2 +- {sparkctl/cmd => cmd/sparkctl/app}/list.go | 2 +- {sparkctl/cmd => cmd/sparkctl/app}/log.go | 2 +- {sparkctl/cmd => cmd/sparkctl/app}/root.go | 2 +- {sparkctl/cmd => cmd/sparkctl/app}/s3.go | 2 +- {sparkctl/cmd => cmd/sparkctl/app}/status.go | 2 +- .../app}/testdata/hadoop-conf/binary.dat | 0 .../app}/testdata/hadoop-conf/core-site.xml | 0 .../sparkctl/app}/testdata/test-app.yaml | 0 {sparkctl/cmd => cmd/sparkctl/app}/utils.go | 2 +- {sparkctl => cmd/sparkctl}/main.go | 4 +-- 21 files changed, 30 insertions(+), 51 deletions(-) delete mode 100644 cmd/main.go rename cmd/operator/{root.go => main.go} (84%) rename {sparkctl => cmd/sparkctl}/README.md (100%) rename {sparkctl/cmd => cmd/sparkctl/app}/client.go (99%) rename {sparkctl/cmd => cmd/sparkctl/app}/create.go (99%) rename {sparkctl/cmd => cmd/sparkctl/app}/create_test.go (99%) rename {sparkctl/cmd => cmd/sparkctl/app}/delete.go (99%) rename {sparkctl/cmd => cmd/sparkctl/app}/event.go (99%) rename {sparkctl/cmd => cmd/sparkctl/app}/forward.go (99%) rename {sparkctl/cmd => cmd/sparkctl/app}/gcs.go (99%) rename {sparkctl/cmd => cmd/sparkctl/app}/list.go (99%) rename {sparkctl/cmd => cmd/sparkctl/app}/log.go (99%) rename {sparkctl/cmd => cmd/sparkctl/app}/root.go (99%) rename {sparkctl/cmd => cmd/sparkctl/app}/s3.go (99%) rename {sparkctl/cmd => cmd/sparkctl/app}/status.go (99%) rename {sparkctl/cmd => cmd/sparkctl/app}/testdata/hadoop-conf/binary.dat (100%) rename {sparkctl/cmd => cmd/sparkctl/app}/testdata/hadoop-conf/core-site.xml (100%) rename {sparkctl/cmd => cmd/sparkctl/app}/testdata/test-app.yaml (100%) rename {sparkctl/cmd => cmd/sparkctl/app}/utils.go (98%) rename {sparkctl => cmd/sparkctl}/main.go (90%) diff --git a/Makefile b/Makefile index 49a2713c14..255a9ba9d5 100644 --- a/Makefile +++ b/Makefile @@ -173,12 +173,12 @@ override LDFLAGS += \ .PHONY: build-operator build-operator: ## Build Spark operator. echo "Building spark-operator binary..." - go build -o $(SPARK_OPERATOR) -ldflags '${LDFLAGS}' cmd/main.go + go build -o $(SPARK_OPERATOR) -ldflags '${LDFLAGS}' cmd/operator/main.go .PHONY: build-sparkctl build-sparkctl: ## Build sparkctl binary. echo "Building sparkctl binary..." - CGO_ENABLED=0 go build -o $(SPARKCTL) -buildvcs=false sparkctl/main.go + CGO_ENABLED=0 go build -o $(SPARKCTL) -buildvcs=false cmd/sparkctl/main.go .PHONY: install-sparkctl install-sparkctl: build-sparkctl ## Install sparkctl binary. @@ -191,7 +191,7 @@ clean: ## Clean spark-operator and sparktcl binaries. rm -f $(SPARKCTL) .PHONY: build-api-docs -build-api-docs: gen-crd-api-reference-docs ## Build api documentaion. +build-api-docs: gen-crd-api-reference-docs ## Build api documentation. $(GEN_CRD_API_REFERENCE_DOCS) \ -config hack/api-docs/config.json \ -api-dir github.com/kubeflow/spark-operator/api/v1beta2 \ diff --git a/cmd/main.go b/cmd/main.go deleted file mode 100644 index 38085497b7..0000000000 --- a/cmd/main.go +++ /dev/null @@ -1,31 +0,0 @@ -/* -Copyright 2024 The Kubeflow 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 main - -import ( - "fmt" - "os" - - "github.com/kubeflow/spark-operator/cmd/operator" -) - -func main() { - if err := operator.NewCommand().Execute(); err != nil { - fmt.Fprintf(os.Stderr, "%v\n", err) - os.Exit(1) - } -} diff --git a/cmd/operator/root.go b/cmd/operator/main.go similarity index 84% rename from cmd/operator/root.go rename to cmd/operator/main.go index 2ddaa900d8..a6d41c002d 100644 --- a/cmd/operator/root.go +++ b/cmd/operator/main.go @@ -5,7 +5,7 @@ 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 - https://www.apache.org/licenses/LICENSE-2.0 + 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, @@ -14,9 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -package operator +package main import ( + "fmt" + "os" + "github.com/spf13/cobra" "github.com/kubeflow/spark-operator/cmd/operator/controller" @@ -37,3 +40,10 @@ func NewCommand() *cobra.Command { command.AddCommand(version.NewCommand()) return command } + +func main() { + if err := NewCommand().Execute(); err != nil { + fmt.Fprintf(os.Stderr, "%v\n", err) + os.Exit(1) + } +} diff --git a/sparkctl/README.md b/cmd/sparkctl/README.md similarity index 100% rename from sparkctl/README.md rename to cmd/sparkctl/README.md diff --git a/sparkctl/cmd/client.go b/cmd/sparkctl/app/client.go similarity index 99% rename from sparkctl/cmd/client.go rename to cmd/sparkctl/app/client.go index e22d26afa1..0ab01ad876 100644 --- a/sparkctl/cmd/client.go +++ b/cmd/sparkctl/app/client.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package cmd +package app import ( "context" diff --git a/sparkctl/cmd/create.go b/cmd/sparkctl/app/create.go similarity index 99% rename from sparkctl/cmd/create.go rename to cmd/sparkctl/app/create.go index eddad79257..9509b9d7e4 100644 --- a/sparkctl/cmd/create.go +++ b/cmd/sparkctl/app/create.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package cmd +package app import ( "context" diff --git a/sparkctl/cmd/create_test.go b/cmd/sparkctl/app/create_test.go similarity index 99% rename from sparkctl/cmd/create_test.go rename to cmd/sparkctl/app/create_test.go index aa3d89615d..28d62fddac 100644 --- a/sparkctl/cmd/create_test.go +++ b/cmd/sparkctl/app/create_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package cmd +package app import ( "strings" diff --git a/sparkctl/cmd/delete.go b/cmd/sparkctl/app/delete.go similarity index 99% rename from sparkctl/cmd/delete.go rename to cmd/sparkctl/app/delete.go index f75dc65df5..06021b2716 100644 --- a/sparkctl/cmd/delete.go +++ b/cmd/sparkctl/app/delete.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package cmd +package app import ( "context" diff --git a/sparkctl/cmd/event.go b/cmd/sparkctl/app/event.go similarity index 99% rename from sparkctl/cmd/event.go rename to cmd/sparkctl/app/event.go index 63a0a5b880..37ced1ad0a 100644 --- a/sparkctl/cmd/event.go +++ b/cmd/sparkctl/app/event.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package cmd +package app import ( "context" diff --git a/sparkctl/cmd/forward.go b/cmd/sparkctl/app/forward.go similarity index 99% rename from sparkctl/cmd/forward.go rename to cmd/sparkctl/app/forward.go index caeb7638f9..43b817daf8 100644 --- a/sparkctl/cmd/forward.go +++ b/cmd/sparkctl/app/forward.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package cmd +package app import ( "context" diff --git a/sparkctl/cmd/gcs.go b/cmd/sparkctl/app/gcs.go similarity index 99% rename from sparkctl/cmd/gcs.go rename to cmd/sparkctl/app/gcs.go index fc807f8927..5601497afb 100644 --- a/sparkctl/cmd/gcs.go +++ b/cmd/sparkctl/app/gcs.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package cmd +package app import ( "fmt" diff --git a/sparkctl/cmd/list.go b/cmd/sparkctl/app/list.go similarity index 99% rename from sparkctl/cmd/list.go rename to cmd/sparkctl/app/list.go index 5777d14db9..63c2bf3b8a 100644 --- a/sparkctl/cmd/list.go +++ b/cmd/sparkctl/app/list.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package cmd +package app import ( "context" diff --git a/sparkctl/cmd/log.go b/cmd/sparkctl/app/log.go similarity index 99% rename from sparkctl/cmd/log.go rename to cmd/sparkctl/app/log.go index c917ccceaf..9ccdf4a8fe 100644 --- a/sparkctl/cmd/log.go +++ b/cmd/sparkctl/app/log.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package cmd +package app import ( "context" diff --git a/sparkctl/cmd/root.go b/cmd/sparkctl/app/root.go similarity index 99% rename from sparkctl/cmd/root.go rename to cmd/sparkctl/app/root.go index 6ba1c5cae8..e845b8be89 100644 --- a/sparkctl/cmd/root.go +++ b/cmd/sparkctl/app/root.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package cmd +package app import ( "fmt" diff --git a/sparkctl/cmd/s3.go b/cmd/sparkctl/app/s3.go similarity index 99% rename from sparkctl/cmd/s3.go rename to cmd/sparkctl/app/s3.go index 28e9350ae1..4bdbeaa6c9 100644 --- a/sparkctl/cmd/s3.go +++ b/cmd/sparkctl/app/s3.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package cmd +package app import ( "context" diff --git a/sparkctl/cmd/status.go b/cmd/sparkctl/app/status.go similarity index 99% rename from sparkctl/cmd/status.go rename to cmd/sparkctl/app/status.go index cd773454a0..59d2a05faa 100644 --- a/sparkctl/cmd/status.go +++ b/cmd/sparkctl/app/status.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package cmd +package app import ( "fmt" diff --git a/sparkctl/cmd/testdata/hadoop-conf/binary.dat b/cmd/sparkctl/app/testdata/hadoop-conf/binary.dat similarity index 100% rename from sparkctl/cmd/testdata/hadoop-conf/binary.dat rename to cmd/sparkctl/app/testdata/hadoop-conf/binary.dat diff --git a/sparkctl/cmd/testdata/hadoop-conf/core-site.xml b/cmd/sparkctl/app/testdata/hadoop-conf/core-site.xml similarity index 100% rename from sparkctl/cmd/testdata/hadoop-conf/core-site.xml rename to cmd/sparkctl/app/testdata/hadoop-conf/core-site.xml diff --git a/sparkctl/cmd/testdata/test-app.yaml b/cmd/sparkctl/app/testdata/test-app.yaml similarity index 100% rename from sparkctl/cmd/testdata/test-app.yaml rename to cmd/sparkctl/app/testdata/test-app.yaml diff --git a/sparkctl/cmd/utils.go b/cmd/sparkctl/app/utils.go similarity index 98% rename from sparkctl/cmd/utils.go rename to cmd/sparkctl/app/utils.go index d2b2aa5050..0786c8a5ba 100644 --- a/sparkctl/cmd/utils.go +++ b/cmd/sparkctl/app/utils.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package cmd +package app import ( "time" diff --git a/sparkctl/main.go b/cmd/sparkctl/main.go similarity index 90% rename from sparkctl/main.go rename to cmd/sparkctl/main.go index 80c89a81b6..4f0e00e654 100644 --- a/sparkctl/main.go +++ b/cmd/sparkctl/main.go @@ -19,9 +19,9 @@ package main import ( _ "k8s.io/client-go/plugin/pkg/client/auth" - "github.com/kubeflow/spark-operator/sparkctl/cmd" + "github.com/kubeflow/spark-operator/cmd/sparkctl/app" ) func main() { - cmd.Execute() + app.Execute() }