From 619982c9e3dbb6e4af042c5e33db0f2db7fe1611 Mon Sep 17 00:00:00 2001 From: astoycos Date: Tue, 5 May 2020 12:21:00 -0400 Subject: [PATCH] Update Readme for Ceph user command --- README.md | 43 ++++++++++---------- cmd/ceph-user.go | 101 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+), 21 deletions(-) create mode 100644 cmd/ceph-user.go diff --git a/README.md b/README.md index d0b3a9f..aba0c18 100644 --- a/README.md +++ b/README.md @@ -80,24 +80,25 @@ Persistent storage is implemented using [Ceph Object Storage](https://ceph.io/ce ## Command Reference -| Command1 (Tool) | Command2(Module) | Command3(Module command) | Argument (module input) | Flags | Function | -|-------------------|------------------|--------------------------|------------------------------------|--------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------| -| ceph | destroy | None | None | None | Return user secrets for c | -| ceph | secrets | None | None | None | Return user secrets for ceph deployment | -| ceph | setup | None | None | None | Setup Ceph Object Storage via the Rook Operator | -| enmasse | destroy | None | None | None | Remove Enmasse from openshift cluster | -| enmasse | IoT | addDevice | ``, `` | None | Add a Device with specified ID to the Enmasse device registry for a specified messaging TenantSetup default Credentials | -| enmasse | IoT | project | None | --namespace | Make a new enmasse IoT project in the specified namespace, defaults to “myapp” | -| enmasse | setup | None | None | None | Download Enmasse Source, store in current directory. Setup Enmasse Setup IoT services | -| kafka | bridge | None | None | --namespace | Deploy kafka HTTP bridge Deploy nginx ingress to access bridge from outside the cluster (will be transitioned to a route) | -| kafka | destroy | None | None | --namespace | Destroy the kafka deployment located at the specified namespace | -| kafka | setup | None | None | --namespace | Setup a kafka cluster viat the strimzi operator at the specified namespace | -| knative | setup | None | None | --status=true/false | Setup Knative serverless on openshift clusterConfigures both Knative-Eventing and Knative-ServingSet --status=true to check on Knative deployment | -| knative | destroy | None | None | None | Remove Knative deployment from openshift cluster | -| knative | service | None | `` | --status=true/false--namespace | Deploy a knative service Set --status=true to check on Knative service deploymentDefault namespace is “knative-eventing” | -| knative | service | destroy | `` | --namespace | Remove a specified Knative service from the cluster at specified namespace Default namespace is “knative-eventing” | -| knative | source | None | `` `` | --namespace | Deploy a Knative Source at specified namespace Defaults to namespace “knative-eventing” | -| knative | source | destroy | `` | --namespace | Remove a specified knative source from the cluster from specified namespaceDefault namespace is “knative-eventing” | -| login | None | None | None | None | Login to your openshift cluster with the username and password | -| tensorflowServing | setup | None | None | --namespace | Deploy a tensorflow serving deployment and service Default namespace is “default” | -| tensorflowServing | destroy | None | None | --namesapce | Deploy a tensorflow serving deployment and serviceDefault namespace is “default” | +| Command1 (Tool) | Command2(Module) | Command3(Module command) | Argument (module input) | Flags | Function | +|-------------------|------------------|--------------------------|-------------------------------------|--------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------| +| ceph | destroy | None | None | None | Destroy the ceph object store instance on the cluster | +| ceph | user | None | `` | None | Create an Ceph Object Store User | +| ceph | secrets | None | `` | None | Return user secrets for ceph deployment | +| ceph | setup | None | None | None | Setup Ceph Object Storage via the Rook Operator | +| enmasse | destroy | None | None | None | Remove Enmasse from openshift cluster | +| enmasse | IoT | addDevice | ``, `` | None | Add a Device with specified ID to the Enmasse device registry for a specified messaging TenantSetup default Credentials | +| enmasse | IoT | project | None | --namespace | Make a new enmasse IoT project in the specified namespace, defaults to “myapp” | +| enmasse | setup | None | None | None | Download Enmasse Source, store in current directory. Setup Enmasse Setup IoT services | +| kafka | bridge | None | None | --namespace | Deploy kafka HTTP bridge Deploy nginx ingress to access bridge from outside the cluster (will be transitioned to a route) | +| kafka | destroy | None | None | --namespace | Destroy the kafka deployment located at the specified namespace | +| kafka | setup | None | None | --namespace | Setup a kafka cluster viat the strimzi operator at the specified namespace | +| knative | setup | None | None | --status=true/false | Setup Knative serverless on openshift clusterConfigures both Knative-Eventing and Knative-ServingSet --status=true to check on Knative deployment | +| knative | destroy | None | None | None | Remove Knative deployment from openshift cluster | +| knative | service | None | `` | --status=true/false--namespace | Deploy a knative service Set --status=true to check on Knative service deploymentDefault namespace is “knative-eventing” | +| knative | service | destroy | `` | --namespace | Remove a specified Knative service from the cluster at specified namespace Default namespace is “knative-eventing” | +| knative | source | None | `` | --namespace | Deploy a Knative Source at specified namespace Defaults to namespace “knative-eventing” | +| knative | source | destroy | `` | --namespace | Remove a specified knative source from the cluster from specified namespaceDefault namespace is “knative-eventing” | +| login | None | None | None | None | Login to your openshift cluster with the username and password | +| tensorflowServing | setup | None | None | --namespace | Deploy a tensorflow serving deployment and service Default namespace is “default” | +| tensorflowServing | destroy | None | None | --namesapce | Deploy a tensorflow serving deployment and serviceDefault namespace is “default” | \ No newline at end of file diff --git a/cmd/ceph-user.go b/cmd/ceph-user.go new file mode 100644 index 0000000..82a0aba --- /dev/null +++ b/cmd/ceph-user.go @@ -0,0 +1,101 @@ +/* +Copyright © 2020 NAME HERE + +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/IoTCLI/cmd/utils" + "github.com/spf13/cobra" + "io/ioutil" + "k8s.io/cli-runtime/pkg/genericclioptions" + "k8s.io/kubectl/pkg/cmd/apply" + "log" + "os" +) + +func cephUser(user string) { + co := utils.NewCommandOptions() + + co.Commands = append(co.Commands, "https://raw.githubusercontent.com/redhat-iot/iot-dev/master/yamls/ceph/setup/object-user.yaml") + + IOStreams, _, out, _ := genericclioptions.NewTestIOStreams() + + //Switch Context and Reload Config Flags + co.SwitchContext("rook-ceph") + + tmpFile, err := ioutil.TempFile(os.TempDir(), "service-") + if err != nil { + log.Fatal("Cannot create temporary file", err) + } + defer os.Remove(tmpFile.Name()) + + sedCommands := []string{`s/name: .*/name: ` + user + `/`, `s/displayName: .*/displayName: "` + user + `"/`} + + myOutput := utils.RemoteSed(sedCommands, "https://raw.githubusercontent.com/redhat-iot/iot-dev/master/yamls/ceph/setup/object-user.yaml") + + //Write updated yaml to tempfile + tmpFile.Write(myOutput.Bytes()) + log.Println("the Source file: ", myOutput.String()) + //Close Tempfile after writing + if err := tmpFile.Close(); err != nil { + log.Fatal(err) + } + co.Commands = append(co.Commands, tmpFile.Name()) + + log.Println("Provision Ceph User") + for _, command := range co.Commands { + cmd := apply.NewCmdApply("kubectl", co.CurrentFactory, IOStreams) + //Kubectl signals missing field, set validate to false to ignore this + //cmd.Flags().Set("validate", "false") + err := cmd.Flags().Set("filename", command) + if err != nil { + log.Fatal(err) + } + cmd.Run(cmd, []string{}) + log.Print(out.String()) + out.Reset() + } + +} + +// userCmd represents the user command +var userCmd = &cobra.Command{ + Use: "user", + Short: "A brief description of your command", + Long: `A longer description that spans multiple lines and likely contains examples +and usage of using your command. For example: + +Cobra is a CLI library for Go that empowers applications. +This application is a tool to generate the needed files +to quickly create a Cobra application.`, + Run: func(cmd *cobra.Command, args []string) { + log.Println("user called") + cephUser(args[0]) + }, +} + +func init() { + cephCmd.AddCommand(userCmd) + + // Here you will define your flags and configuration settings. + + // Cobra supports Persistent Flags which will work for this command + // and all subcommands, e.g.: + // userCmd.PersistentFlags().String("foo", "", "A help for foo") + + // Cobra supports local flags which will only run when this command + // is called directly, e.g.: + // userCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +}