From a7e6b1f7a77e764d338baffe999f80abbf6d6079 Mon Sep 17 00:00:00 2001 From: adi6496 Date: Thu, 30 Apr 2020 13:18:56 -0400 Subject: [PATCH] Added Gstreamer setup and destroy commands --- cmd/gstreamer-destroy.go | 85 ++++++++++++++++++++++++ cmd/gstreamer-setup.go | 83 +++++++++++++++++++++++ cmd/gstreamer.go | 52 +++++++++++++++ yamls/gstreamer/gstreamer-deploy.yaml | 17 +++++ yamls/gstreamer/gstreamer-namespace.yaml | 4 ++ 5 files changed, 241 insertions(+) create mode 100644 cmd/gstreamer-destroy.go create mode 100644 cmd/gstreamer-setup.go create mode 100644 cmd/gstreamer.go create mode 100644 yamls/gstreamer/gstreamer-deploy.yaml create mode 100644 yamls/gstreamer/gstreamer-namespace.yaml diff --git a/cmd/gstreamer-destroy.go b/cmd/gstreamer-destroy.go new file mode 100644 index 0000000..1ffbc0c --- /dev/null +++ b/cmd/gstreamer-destroy.go @@ -0,0 +1,85 @@ +/* +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 ( + "log" + + "github.com/IoTCLI/cmd/utils" + "github.com/spf13/cobra" + "k8s.io/cli-runtime/pkg/genericclioptions" + "k8s.io/kubectl/pkg/cmd/delete" +) + +func gstreamerDestroy() { + + //Make command options for Kafka Setup + co := utils.NewCommandOptions() + + _ = utils.DownloadAndUncompress("oc.gz", "https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest/openshift-client-linux.tar.gz") + log.Println("oc Source folder: ", "oc") + + //Fill in the commands that must be applied to + co.Commands = append(co.Commands, "/home/adkadam/work/golang/iot-dev/yamls/gstreamer/gstreamer-deploy.yaml") + co.Commands = append(co.Commands, "/home/adkadam/work/golang/iot-dev/yamls/gstreamer/gstreamer-namespace.yaml") + + IOStreams, _, out, _ := genericclioptions.NewTestIOStreams() + + co.SwitchContext("gstreamer") + + log.Println("Destroy Gstreamer deployment from cluster") + for _, command := range co.Commands { + cmd := delete.NewCmdDelete(co.CurrentFactory, IOStreams) + err := cmd.Flags().Set("filename", command) + if err != nil { + log.Fatal(err) + } + cmd.Run(cmd, []string{}) + log.Print(out.String()) + out.Reset() + } + //Remove tempfile when done +} + +// destroyCmd represents the destroy command +var gstreamerDestroyCmd = &cobra.Command{ + Use: "destroy", + 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("Gstreamer destroy called") + gstreamerDestroy() + }, +} + +func init() { + gstreamerCmd.AddCommand(gstreamerDestroyCmd) + + // Here you will define your flags and configuration settings. + + // Cobra supports Persistent Flags which will work for this command + // and all subcommands, e.g.: + // destroyCmd.PersistentFlags().String("foo", "", "A help for foo") + + // Cobra supports local flags which will only run when this command + // is called directly, e.g.: + // destroyCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} diff --git a/cmd/gstreamer-setup.go b/cmd/gstreamer-setup.go new file mode 100644 index 0000000..22cf78f --- /dev/null +++ b/cmd/gstreamer-setup.go @@ -0,0 +1,83 @@ +/* +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 ( + "fmt" + "log" + + "github.com/IoTCLI/cmd/utils" + "github.com/spf13/cobra" + "k8s.io/cli-runtime/pkg/genericclioptions" + "k8s.io/kubectl/pkg/cmd/apply" +) + +// setupCmd represents the setup command +var gstreamerSetupCmd = &cobra.Command{ + Use: "setup", + Short: "A brief description of your command", + Long: `A longer descriptSion 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) { + fmt.Println(" gstreamer setup called") + gstreamerSetup() + }, +} + +func gstreamerSetup() { + //Make command options for Kafka Setup + co := utils.NewCommandOptions() + //This section is mimicking the instructions to setup the Strimzi Operator, I.E download the install yaml, and set namespace using sed + //functionality + + //Fill in the commands that must be applied to + co.Commands = append(co.Commands, "/home/adkadam/work/golang/iot-dev/yamls/gstreamer/gstreamer-namespace.yaml") + co.Commands = append(co.Commands, "/home/adkadam/work/golang/iot-dev/yamls/gstreamer/gstreamer-deploy.yaml") + // + IOStreams, _, out, _ := genericclioptions.NewTestIOStreams() + + co.SwitchContext("gstreamer") + + log.Println("Provision gstreamer") + for _, command := range co.Commands { + cmd := apply.NewCmdApply("kubectl", co.CurrentFactory, IOStreams) + err := cmd.Flags().Set("filename", command) + if err != nil { + log.Fatal(err) + } + cmd.Run(cmd, []string{}) + log.Print(out.String()) + out.Reset() + } +} + +func init() { + gstreamerCmd.AddCommand(gstreamerSetupCmd) + + // Here you will define your flags and configuration settings. + + // Cobra supports Persistent Flags which will work for this command + // and all subcommands, e.g.: + // setupCmd.PersistentFlags().String("foo", "", "A help for foo") + + // Cobra supports local flags which will only run when this command + // is called directly, e.g.: + // setupCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} diff --git a/cmd/gstreamer.go b/cmd/gstreamer.go new file mode 100644 index 0000000..4cec986 --- /dev/null +++ b/cmd/gstreamer.go @@ -0,0 +1,52 @@ +/* +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 ( + "fmt" + //"k8s.io/cli-runtime/pkg/genericclioptions" + //"k8s.io/kubectl/pkg/cmd/apply" + "github.com/spf13/cobra" +) + +// gstreamerCmd represents the gstreamer command +var gstreamerCmd = &cobra.Command{ + Use: "gstreamer", + 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) { + fmt.Println("gstreamer called") + }, +} + +func init() { + rootCmd.AddCommand(gstreamerCmd) + + // Here you will define your flags and configuration settings. + + // Cobra supports Persistent Flags which will work for this command + // and all subcommands, e.g.: + // gstreamerCmd.PersistentFlags().String("foo", "", "A help for foo") + + // Cobra supports local flags which will only run when this command + // is called directly, e.g.: + // gstreamerCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} diff --git a/yamls/gstreamer/gstreamer-deploy.yaml b/yamls/gstreamer/gstreamer-deploy.yaml new file mode 100644 index 0000000..0c28505 --- /dev/null +++ b/yamls/gstreamer/gstreamer-deploy.yaml @@ -0,0 +1,17 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: gstreamer-deployment +spec: + replicas: 1 + template: + metadata: + labels: + app: gstreamer + spec: + containers: + - name: gstreamer + image: gcr.io/knative-releases/github.com/knative/eventing-sources/cmd/event_display@sha256:37ace92b63fc516ad4c8331b6b3b2d84e4ab2d8ba898e387c0b6f68f0e3081c4 + ports: + - containerPort: 8080 + diff --git a/yamls/gstreamer/gstreamer-namespace.yaml b/yamls/gstreamer/gstreamer-namespace.yaml new file mode 100644 index 0000000..2f051dd --- /dev/null +++ b/yamls/gstreamer/gstreamer-namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: gstreamer \ No newline at end of file