Skip to content

Commit

Permalink
Fix some things before release 0.3.0
Browse files Browse the repository at this point in the history
Wait for kafka deployment to be ready before exiting

Add error checking for # of inputs
  • Loading branch information
astoycos committed May 14, 2020
1 parent d8a81ef commit 359c7f4
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 22 deletions.
15 changes: 9 additions & 6 deletions cmd/ceph-destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ func cephDestroy() {

co.Commands = append(co.Commands, "https://raw.githubusercontent.com/redhat-iot/iot-dev/master/yamls/ceph/setup/route.yaml")
co.Commands = append(co.Commands, "https://raw.githubusercontent.com/redhat-iot/iot-dev/master/yamls/ceph/setup/object-user.yaml")
co.Commands = append(co.Commands, "https://raw.githubusercontent.com/redhat-iot/iot-dev/master/yamls/ceph/setup/object.yaml")
co.Commands = append(co.Commands, "https://raw.githubusercontent.com/redhat-iot/iot-dev/master/yamls/ceph/setup/object-openshift.yaml")
co.Commands = append(co.Commands, "https://raw.githubusercontent.com/redhat-iot/iot-dev/master/yamls/ceph/setup/toolbox.yaml")
co.Commands = append(co.Commands, "https://raw.githubusercontent.com/redhat-iot/iot-dev/master/yamls/ceph/setup/cluster.yaml")
co.Commands = append(co.Commands, "https://raw.githubusercontent.com/redhat-iot/iot-dev/master/yamls/ceph/setup/operator.yaml")
co.Commands = append(co.Commands, "https://raw.githubusercontent.com/redhat-iot/iot-dev/master/yamls/ceph/setup/scc.yaml")
co.Commands = append(co.Commands, "https://raw.githubusercontent.com/redhat-iot/iot-dev/master/yamls/ceph/setup/cluster-on-pvc.yaml")
co.Commands = append(co.Commands, "https://raw.githubusercontent.com/redhat-iot/iot-dev/master/yamls/ceph/setup/operator-openshift.yaml")
co.Commands = append(co.Commands, "https://raw.githubusercontent.com/redhat-iot/iot-dev/master/yamls/ceph/setup/common.yaml")

IOStreams, _, out, _ := genericclioptions.NewTestIOStreams()

//Switch Context and Reload Config Flags
co.SwitchContext("rook-ceph-system")

log.Println("Provision Knative Source")
log.Println("Removing Ceph Via Rook v1.3.2")
for _, command := range co.Commands {
cmd := delete.NewCmdDelete(co.CurrentFactory, IOStreams)
//Kubectl signals missing field, set validate to false to ignore this
Expand All @@ -56,7 +56,10 @@ func cephDestroy() {
out.Reset()

}

log.Println("For removal to be complete the user must manually remove rook related files from the worker nodes in the following directorys:")
log.Println("1./var/lib/rook")
log.Println("2./var/lib/kubelet/plugins")
log.Println("3./var/lib/kubelet/plugins-registry")
}

// destroyCmd represents the destroy command
Expand Down
14 changes: 10 additions & 4 deletions cmd/ceph-secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/kubectl/pkg/cmd/get"
"strconv"
)

func getCredentials(user string) {
Expand All @@ -33,14 +34,14 @@ func getCredentials(user string) {
//Switch Context and Reload Config Flags
co.SwitchContext("rook-ceph")

log.Info("Get S3 secrets, save for possible later use:")
log.Print("Get S3 secrets, save for possible later use:")
cmd := get.NewCmdGet("kubectl", co.CurrentFactory, IOStreams)
cmd.Flags().Set("output", "jsonpath=.data")
cmd.Flags().Set("output", "jsonpath={.data}")
cmd.Run(cmd, []string{co.Commands[0], "rook-ceph-object-user-my-store-" + user})
log.Info(out.String())
out.Reset()

log.Info("Ceph Endpoint URL: ")
log.Print("Ceph Endpoint URL: ")
cmd = get.NewCmdGet("kubectl", co.CurrentFactory, IOStreams)
cmd.Flags().Set("output", "jsonpath={.spec.host}")
cmd.Run(cmd, []string{"route", "ceph-route"})
Expand All @@ -60,7 +61,12 @@ This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
log.Info("Ceph Secrets called")
getCredentials(args[0])
cobra.ExactArgs(1)
if len(args) != 1 {
log.Fatal("Wrong number of Input arguments expected 1 ceph user got " + strconv.Itoa(len(args)))
} else {
getCredentials(args[0])
}
},
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/ceph-setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func cephSetup() {
//Switch Context and Reload Config Flags
co.SwitchContext("rook-ceph")

log.Println("Setup Ceph Object Storage with Rook Operator")
log.Println("Setup Ceph Object Storage with Rook Operator v1.3.2")
for commandNumber, command := range co.Commands {

if commandNumber == 4 {
Expand All @@ -58,7 +58,7 @@ func cephSetup() {
cmd.Run(cmd, []string{command})
podStatus.CountPods(out.Bytes())
log.Debug(podStatus)
log.Info("Waiting...")
log.Info("Waiting on Ceph Deployment...")
out.Reset()
time.Sleep(5 * time.Second)
}
Expand Down
35 changes: 33 additions & 2 deletions cmd/kafka-bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/kubectl/pkg/cmd/apply"
"k8s.io/kubectl/pkg/cmd/get"
"time"
)

var (
Expand Down Expand Up @@ -55,6 +56,21 @@ func kafkaBridgeRoute() {
out.Reset()
}

//After pods for Kafka bridge is provisioned wait for them to become ready before moving on
log.Print("Waiting for Kafka Bridge to be ready")
podStatus := utils.NewpodStatus()
for podStatus.Running >= 5 {
cmd := get.NewCmdGet("kubectl", co.CurrentFactory, IOStreams)
cmd.Flags().Set("output", "yaml")
cmd.Run(cmd, []string{"pods"})
podStatus.CountPods(out.Bytes())
log.Debug(podStatus)
log.Info("Waiting for Kafka Bridge...")
out.Reset()
time.Sleep(5 * time.Second)
}
log.Print("Kafka Deployment is ready")

cmd := get.NewCmdGet("kubectl", co.CurrentFactory, IOStreams)
cmd.Flags().Set("output", "jsonpath={.spec.host}")
cmd.Run(cmd, []string{"route", "my-bridge-route"})
Expand Down Expand Up @@ -94,6 +110,21 @@ func kafkaBridge() {
out.Reset()
}

//After pods for Kafka bridge is provisioned wait for them to become ready before moving on
log.Print("Waiting for Kafka Bridge to be ready")
podStatus := utils.NewpodStatus()
for podStatus.Running != 5 {
cmd := get.NewCmdGet("kubectl", co.CurrentFactory, IOStreams)
cmd.Flags().Set("output", "yaml")
cmd.Run(cmd, []string{"pods"})
podStatus.CountPods(out.Bytes())
log.Debug(podStatus)
log.Info("Waiting for Kafka Bridge...")
out.Reset()
time.Sleep(5 * time.Second)
}
log.Print("Kafka Deployment is ready")

cmd := get.NewCmdGet("kubectl", co.CurrentFactory, IOStreams)
cmd.Flags().Set("output", "jsonpath={.spec.host}")
cmd.Run(cmd, []string{"pods"})
Expand Down Expand Up @@ -139,6 +170,6 @@ func init() {
// is called directly, e.g.:
// bridgeCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
kafkaBridgeCmd.Flags().StringVarP(&kafkaBridgeNamespaceFlag, "namespace", "n", "kafka", "Option to specify namespace for kafka deletion, defaults to 'kafka'")

kafkaBridgeCmd.Flags().BoolP("route", "r", false, "Setup kafka bridge using route, defaults to using ingress")
//Default to using Route
kafkaBridgeCmd.Flags().BoolP("route", "r", true, "Setup kafka bridge using route, defaults to using ingress")
}
2 changes: 1 addition & 1 deletion cmd/kafka-setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func kafkaSetup() {
cmd.Run(cmd, []string{"pods"})
podStatus.CountPods(out.Bytes())
log.Debug(podStatus)
log.Info("Waiting...")
log.Info("Waiting for Kafka deployment...")
out.Reset()
time.Sleep(5 * time.Second)
}
Expand Down
19 changes: 12 additions & 7 deletions cmd/knative-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/kubectl/pkg/cmd/apply"
"k8s.io/kubectl/pkg/cmd/get"
"strconv"
)

var (
Expand Down Expand Up @@ -207,13 +208,17 @@ 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("Knative Service called")

if status {
serviceStatus()
} else if logView {
//logs(args[0])
cobra.ExactArgs(1)
if len(args) != 1 {
log.Fatal("Wrong number of Input arguments expected 1 ceph user got " + strconv.Itoa(len(args)))
} else {
service(args[0])
if status {
serviceStatus()
} else if logView {
//logs(args[0])
} else {
service(args[0])
}
}
},
}
Expand All @@ -231,7 +236,7 @@ func init() {
// is called directly, e.g.:
// serviceCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
knativeServiceCmd.Flags().BoolVarP(&status, "status", "S", false, "Show Status of the Service")
knativeServiceCmd.Flags().BoolVarP(&logView, "logView", "l", false, "Show logs of the Service")
//knativeServiceCmd.Flags().BoolVarP(&logView, "logView", "l", false, "Show logs of the Service")
knativeServiceCmd.Flags().StringVarP(&knativeServiceNamespaceFlag, "namespace", "n", "knative-eventing", "Option to specify namespace for knative service deployment, defaults to 'knative-eventing'")
knativeServiceCmd.Flags().StringVarP(&cephEndpoint, "cephEndpoint", "c", "", "Option to specify ceph object storage endpoint to service")
knativeServiceCmd.Flags().StringVarP(&cephAccessKey, "cephAccessKey", "a", "", "Option to specify ceph object storage access key to service")
Expand Down

0 comments on commit 359c7f4

Please sign in to comment.