Skip to content

Commit

Permalink
Added Gstreamer setup and destroy commands
Browse files Browse the repository at this point in the history
  • Loading branch information
adi6496 committed Apr 30, 2020
1 parent 704f51b commit a7e6b1f
Show file tree
Hide file tree
Showing 5 changed files with 241 additions and 0 deletions.
85 changes: 85 additions & 0 deletions cmd/gstreamer-destroy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
Copyright © 2020 NAME HERE <EMAIL ADDRESS>
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")
}
83 changes: 83 additions & 0 deletions cmd/gstreamer-setup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
Copyright © 2020 NAME HERE <EMAIL ADDRESS>
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")
}
52 changes: 52 additions & 0 deletions cmd/gstreamer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
Copyright © 2020 NAME HERE <EMAIL ADDRESS>
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")
}
17 changes: 17 additions & 0 deletions yamls/gstreamer/gstreamer-deploy.yaml
Original file line number Diff line number Diff line change
@@ -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

4 changes: 4 additions & 0 deletions yamls/gstreamer/gstreamer-namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: gstreamer

0 comments on commit a7e6b1f

Please sign in to comment.