Skip to content

Commit

Permalink
remove flags from clusterctl boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
karan committed May 7, 2018
1 parent 3efe03d commit 391dbbc
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 93 deletions.
26 changes: 9 additions & 17 deletions clusterctl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,23 @@ Read the [experience doc here](https://docs.google.com/document/d/1-sYb3EdkRga49

### Prerequisites

Follow the steps listed at [CONTRIBUTING.md](https://github.com/kubernetes/kube-deploy/blob/master/cluster-api/clusterctl/CONTRIBUTING.md) to:
Follow the steps listed at [CONTRIBUTING.md](https://github.com/kubernetes-sigs/cluster-api/blob/master/cluster-api/clusterctl/CONTRIBUTING.md) to:

1. Build the `clusterctl` tool
3. Create a `machines.yaml` file configured for your cluster. See the provided template for an example.
1. Build the `clusterctl` tool

### Limitation
```
go build
```

2. Create a `machines.yaml` file configured for your cluster. See the provided template for an example.

### Limitations


### Creating a cluster

**NOT YET SUPPORTED!**

In order to create a cluster with the Cluster API, the user will supply these:

* Cluster which defines the spec common across the entire cluster.
* Machine which defines the spec of a machine. Further abstractions of
MachineSets and MachineClass and MachineDeployments are supported as well.
* Extras (optional) spec extras.yaml file with specs of all controllers
(ConfigMaps) that the cluster needs. This would include the Machine controller,
MachineSet controller, Machine Setup ConfigMap etc. Note that this is not a new API
object. There will be defaults running. This will make the tool easily pluggage
(change the controller spec) instead of changing the tool or mucking with flags.

1. Create a cluster: `./clusterctl create cluster -c cluster.yaml -m machines.yaml -e extras.yaml`

### Interacting with your cluster

Once you have created a cluster, you can interact with the cluster and machine
Expand Down
45 changes: 3 additions & 42 deletions clusterctl/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,55 +17,16 @@ limitations under the License.
package cmd

import (
"os"

//"fmt"
"github.com/golang/glog"
"github.com/spf13/cobra"
"sigs.k8s.io/cluster-api/errors"
)

type CreateOptions struct {
Cluster string
Machine string
Extras string
}

var co = &CreateOptions{}

var createCmd = &cobra.Command{
Use: "create",
Short: "Create kubernetes cluster",
Long: `Create a kubernetes cluster with one command`,
Run: func(cmd *cobra.Command, args []string) {
if co.Cluster == "" {
glog.Error("Please provide yaml file for cluster definition.")
cmd.Help()
os.Exit(1)
}
if co.Machine == "" {
glog.Error("Please provide yaml file for machine definition.")
cmd.Help()
os.Exit(1)
}
if co.Extras == "" {
glog.Error("Please provide a yaml file for extra definitions (controllers, Addons etc).")
cmd.Help()
os.Exit(1)
}
if err := RunCreate(co); err != nil {
glog.Exit(err)
}
},
Short: "Create a cluster API resource",
Long: `Create a cluster API resource with one command`,
}

func RunCreate(co *CreateOptions) error {
return errors.NotImplementedError
}
func init() {
createCmd.Flags().StringVarP(&co.Cluster, "cluster", "c", "", "cluster yaml file")
createCmd.Flags().StringVarP(&co.Machine, "machines", "m", "", "machine yaml file")
createCmd.Flags().StringVarP(&co.Extras, "extras", "e", "", "extras yaml file")

createCmd.AddCommand(NewCmdCreateCluster())
RootCmd.AddCommand(createCmd)
}
59 changes: 59 additions & 0 deletions clusterctl/cmd/create_cluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
Copyright 2018 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 cmd

import (
"github.com/golang/glog"
"github.com/spf13/cobra"
"sigs.k8s.io/cluster-api/errors"
)

type CreateOptions struct {
Cluster string
Machine string
Extras string
}

var co = &CreateOptions{}

func NewCmdCreateCluster() *cobra.Command {
cmd := &cobra.Command{
Use: "cluster",
Short: "Create kubernetes cluster",
Long: `Create a kubernetes cluster with one command`,
Run: func(cmd *cobra.Command, args []string) {
if co.Cluster == "" {
exitWithHelp(cmd, "Please provide yaml file for cluster definition.")
}
if co.Machine == "" {
exitWithHelp(cmd, "Please provide yaml file for machine definition.")
}
if co.Extras == "" {
exitWithHelp(cmd, "Please provide a yaml file for extra definitions (controllers, Addons etc).")
}
if err := RunCreate(co); err != nil {
glog.Exit(err)
}
},
}

return cmd
}

func RunCreate(co *CreateOptions) error {
return errors.NotImplementedError
}
30 changes: 3 additions & 27 deletions clusterctl/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,16 @@ limitations under the License.
package cmd

import (
"github.com/golang/glog"
"github.com/spf13/cobra"
"os"
"sigs.k8s.io/cluster-api/errors"
)

type DeleteOptions struct {
ClusterName string
}

var do = &DeleteOptions{}

var deleteCmd = &cobra.Command{
Use: "delete",
Short: "Delete kubernetes cluster",
Long: `Delete a kubernetes cluster with one command`,
Run: func(cmd *cobra.Command, args []string) {
if do.ClusterName == "" {
glog.Error("Please provide cluster name.")
cmd.Help()
os.Exit(1)
}
if err := RunDelete(); err != nil {
glog.Exit(err)
}
},
}

func RunDelete() error {
return errors.NotImplementedError
Short: "Delete a cluster API resource",
Long: `Delete a cluster API resource with one command`,
}

func init() {
deleteCmd.Flags().StringVarP(&do.ClusterName, "cluster-name", "n", "", "cluster name")

deleteCmd.AddCommand(NewCmdDeleteCluster())
RootCmd.AddCommand(deleteCmd)
}
51 changes: 51 additions & 0 deletions clusterctl/cmd/delete_cluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright 2018 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 cmd

import (
"github.com/golang/glog"
"github.com/spf13/cobra"
"sigs.k8s.io/cluster-api/errors"
)

type DeleteOptions struct {
ClusterName string
}

var do = &DeleteOptions{}

func NewCmdDeleteCluster() *cobra.Command {
cmd := &cobra.Command{
Use: "delete",
Short: "Delete kubernetes cluster",
Long: `Delete a kubernetes cluster with one command`,
Run: func(cmd *cobra.Command, args []string) {
if do.ClusterName == "" {
exitWithHelp(cmd, "Please provide cluster name.")
}
if err := RunDelete(); err != nil {
glog.Exit(err)
}
},
}

return cmd
}

func RunDelete() error {
return errors.NotImplementedError
}
2 changes: 0 additions & 2 deletions clusterctl/cmd/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,5 @@ func RunRegister(co *RegisterOptions) error {
}

func init() {
registerCmd.Flags().StringVarP(&ro.RegistryEndpoint, "registry-endpoint", "r", "", "registry endpoint")

RootCmd.AddCommand(registerCmd)
}
12 changes: 7 additions & 5 deletions clusterctl/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package cmd
import (
"flag"
"io/ioutil"
"os"

"github.com/ghodss/yaml"
"github.com/golang/glog"
Expand All @@ -38,10 +39,6 @@ var RootCmd = &cobra.Command{
},
}

var (
kubeConfig string
)

func Execute() {
if err := RootCmd.Execute(); err != nil {
glog.Exit(err)
Expand Down Expand Up @@ -78,8 +75,13 @@ func parseMachinesYaml(file string) ([]*clusterv1.Machine, error) {
return util.MachineP(machines.Items), nil
}

func exitWithHelp(cmd *cobra.Command, err string) {
glog.Error(err)
cmd.Help()
os.Exit(1)
}

func init() {
RootCmd.PersistentFlags().StringVarP(&kubeConfig, "kubeconfig", "k", "", "location for the kubernetes config file. If not provided, $HOME/.kube/config is used")
flag.CommandLine.Parse([]string{})
logs.InitLogs()
}

0 comments on commit 391dbbc

Please sign in to comment.