diff --git a/federation/cmd/kubefed/BUILD b/federation/cmd/kubefed/BUILD new file mode 100644 index 00000000000..f973c5723e9 --- /dev/null +++ b/federation/cmd/kubefed/BUILD @@ -0,0 +1,18 @@ +package(default_visibility = ["//visibility:public"]) + +licenses(["notice"]) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_binary", + "go_library", + "go_test", + "cgo_library", +) + +go_binary( + name = "kubefed", + srcs = ["kubefed.go"], + tags = ["automanaged"], + deps = ["//federation/cmd/kubefed/app:go_default_library"], +) diff --git a/federation/cmd/kubefed/app/BUILD b/federation/cmd/kubefed/app/BUILD new file mode 100644 index 00000000000..7ba37ca64c0 --- /dev/null +++ b/federation/cmd/kubefed/app/BUILD @@ -0,0 +1,24 @@ +package(default_visibility = ["//visibility:public"]) + +licenses(["notice"]) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_binary", + "go_library", + "go_test", + "cgo_library", +) + +go_library( + name = "go_default_library", + srcs = ["kubefed.go"], + tags = ["automanaged"], + deps = [ + "//federation/pkg/kubefed:go_default_library", + "//pkg/client/metrics/prometheus:go_default_library", + "//pkg/kubectl/cmd/util:go_default_library", + "//pkg/util/logs:go_default_library", + "//pkg/version/prometheus:go_default_library", + ], +) diff --git a/federation/cmd/kubefed/app/kubefed.go b/federation/cmd/kubefed/app/kubefed.go new file mode 100644 index 00000000000..7feb5059d3f --- /dev/null +++ b/federation/cmd/kubefed/app/kubefed.go @@ -0,0 +1,35 @@ +/* +Copyright 2016 The Kubernetes 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 app + +import ( + "os" + + "k8s.io/kubernetes/federation/pkg/kubefed" + _ "k8s.io/kubernetes/pkg/client/metrics/prometheus" // for client metric registration + cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" + "k8s.io/kubernetes/pkg/util/logs" + _ "k8s.io/kubernetes/pkg/version/prometheus" // for version metric registration +) + +func Run() error { + logs.InitLogs() + defer logs.FlushLogs() + + cmd := kubefed.NewKubeFedCommand(cmdutil.NewFactory(nil), os.Stdin, os.Stdout, os.Stderr) + return cmd.Execute() +} diff --git a/federation/cmd/kubefed/kubefed.go b/federation/cmd/kubefed/kubefed.go new file mode 100644 index 00000000000..72a03efc6fd --- /dev/null +++ b/federation/cmd/kubefed/kubefed.go @@ -0,0 +1,30 @@ +/* +Copyright 2016 The Kubernetes 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 ( + "os" + + "k8s.io/kubernetes/federation/cmd/kubefed/app" +) + +func main() { + if err := app.Run(); err != nil { + os.Exit(1) + } + os.Exit(0) +} diff --git a/federation/pkg/kubefed/BUILD b/federation/pkg/kubefed/BUILD index 9559f3d48a2..d63f19cbbe9 100644 --- a/federation/pkg/kubefed/BUILD +++ b/federation/pkg/kubefed/BUILD @@ -14,6 +14,7 @@ go_library( name = "go_default_library", srcs = [ "join.go", + "kubefed.go", "unjoin.go", ], tags = ["automanaged"], @@ -30,6 +31,7 @@ go_library( "//pkg/kubectl/cmd/util:go_default_library", "//pkg/kubectl/resource:go_default_library", "//pkg/runtime:go_default_library", + "//pkg/util/flag:go_default_library", "//vendor:github.com/golang/glog", "//vendor:github.com/spf13/cobra", ], diff --git a/federation/pkg/kubefed/kubefed.go b/federation/pkg/kubefed/kubefed.go new file mode 100644 index 00000000000..497368c8c18 --- /dev/null +++ b/federation/pkg/kubefed/kubefed.go @@ -0,0 +1,74 @@ +/* +Copyright 2016 The Kubernetes 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 kubefed + +import ( + "io" + + "k8s.io/kubernetes/pkg/client/unversioned/clientcmd" + kubectl "k8s.io/kubernetes/pkg/kubectl/cmd" + "k8s.io/kubernetes/pkg/kubectl/cmd/templates" + cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" + "k8s.io/kubernetes/pkg/util/flag" + + "github.com/spf13/cobra" +) + +// NewKubeFedCommand creates the `kubefed` command and its nested children. +func NewKubeFedCommand(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cobra.Command { + // Parent command to which all subcommands are added. + cmds := &cobra.Command{ + Use: "kubefed", + Short: "kubefed controls a Kubernetes Cluster Federation", + Long: templates.LongDesc(` + kubefed controls a Kubernetes Cluster Federation. + + Find more information at https://github.com/kubernetes/kubernetes.`), + Run: runHelp, + } + + f.BindFlags(cmds.PersistentFlags()) + f.BindExternalFlags(cmds.PersistentFlags()) + + // From this point and forward we get warnings on flags that contain "_" separators + cmds.SetGlobalNormalizationFunc(flag.WarnWordSepNormalizeFunc) + + groups := templates.CommandGroups{ + { + Message: "Basic Commands:", + Commands: []*cobra.Command{ + NewCmdJoin(f, out, NewJoinFederationConfig(clientcmd.NewDefaultPathOptions())), + NewCmdUnjoin(f, out, err, NewJoinFederationConfig(clientcmd.NewDefaultPathOptions())), + }, + }, + } + groups.Add(cmds) + + filters := []string{ + "options", + } + templates.ActsAsRootCommand(cmds, filters, groups...) + + cmds.AddCommand(kubectl.NewCmdVersion(f, out)) + cmds.AddCommand(kubectl.NewCmdOptions(out)) + + return cmds +} + +func runHelp(cmd *cobra.Command, args []string) { + cmd.Help() +} diff --git a/hack/.linted_packages b/hack/.linted_packages index 5556742c422..e518356d439 100644 --- a/hack/.linted_packages +++ b/hack/.linted_packages @@ -52,6 +52,7 @@ federation/apis/federation/install federation/cmd/federation-apiserver federation/cmd/federation-controller-manager federation/cmd/genfeddocs +federation/cmd/kubefed hack/boilerplate/test hack/cmd/teststale pkg/api diff --git a/hack/lib/golang.sh b/hack/lib/golang.sh index 7a73b64691b..34177640206 100755 --- a/hack/lib/golang.sh +++ b/hack/lib/golang.sh @@ -95,6 +95,7 @@ fi # The set of client targets that we are building for all platforms readonly KUBE_CLIENT_TARGETS=( cmd/kubectl + federation/cmd/kubefed ) readonly KUBE_CLIENT_BINARIES=("${KUBE_CLIENT_TARGETS[@]##*/}") readonly KUBE_CLIENT_BINARIES_WIN=("${KUBE_CLIENT_BINARIES[@]/%/.exe}")