|
|
@@ -7,10 +7,13 @@ import (
|
|
|
"io"
|
|
|
|
|
|
"github.com/gorilla/websocket"
|
|
|
+ appsv1 "k8s.io/api/apps/v1"
|
|
|
v1 "k8s.io/api/core/v1"
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
"k8s.io/cli-runtime/pkg/genericclioptions"
|
|
|
+ "k8s.io/client-go/informers"
|
|
|
"k8s.io/client-go/kubernetes"
|
|
|
+ "k8s.io/client-go/tools/cache"
|
|
|
)
|
|
|
|
|
|
// Agent is a Kubernetes agent for performing operations that interact with the
|
|
|
@@ -52,12 +55,11 @@ func (a *Agent) GetPodLogs(namespace string, name string, conn *websocket.Conn)
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("Cannot open log stream for pod %s", name)
|
|
|
}
|
|
|
- defer podLogs.Close()
|
|
|
|
|
|
r := bufio.NewReader(podLogs)
|
|
|
for {
|
|
|
bytes, err := r.ReadBytes('\n')
|
|
|
-
|
|
|
+ fmt.Println(bytes)
|
|
|
if writeErr := conn.WriteMessage(websocket.TextMessage, bytes); writeErr != nil {
|
|
|
return writeErr
|
|
|
}
|
|
|
@@ -70,3 +72,36 @@ func (a *Agent) GetPodLogs(namespace string, name string, conn *websocket.Conn)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+// StreamDeploymentStatus streams deployment status.
|
|
|
+func (a *Agent) StreamDeploymentStatus(conn *websocket.Conn) error {
|
|
|
+ fmt.Println("===========================streaming dep status============================")
|
|
|
+
|
|
|
+ factory := informers.NewSharedInformerFactory(a.Clientset, 0)
|
|
|
+ informer := factory.Apps().V1().Deployments().Informer()
|
|
|
+ stopper := make(chan struct{})
|
|
|
+ defer close(stopper)
|
|
|
+ defer fmt.Println("closing...")
|
|
|
+
|
|
|
+ informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
|
|
+ AddFunc: func(obj interface{}) {
|
|
|
+ d := obj.(*appsv1.Deployment)
|
|
|
+ fmt.Printf("adding deployment %s\n", d.Name)
|
|
|
+ fmt.Println(d.Status.Replicas == d.Status.AvailableReplicas)
|
|
|
+ },
|
|
|
+ UpdateFunc: func(oldObj, newObj interface{}) {
|
|
|
+ d := newObj.(*appsv1.Deployment)
|
|
|
+ fmt.Printf("updating deployment %s\n", d.Name)
|
|
|
+ fmt.Println(d.Status.Replicas == d.Status.AvailableReplicas)
|
|
|
+ fmt.Println(d.Status.Conditions[0].Message)
|
|
|
+ },
|
|
|
+ DeleteFunc: func(obj interface{}) {
|
|
|
+ d := obj.(*appsv1.Deployment)
|
|
|
+ fmt.Printf("deleting deployment %s\n", d.Name)
|
|
|
+ fmt.Println(d.Status.Replicas == d.Status.AvailableReplicas)
|
|
|
+ },
|
|
|
+ })
|
|
|
+
|
|
|
+ informer.Run(stopper)
|
|
|
+ return nil
|
|
|
+}
|