-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Stream changes to gui (#53)
- Loading branch information
Showing
25 changed files
with
1,136 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package controllers | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/gimlet-io/capacitor/pkg/streaming" | ||
"github.com/sirupsen/logrus" | ||
apps_v1 "k8s.io/api/apps/v1" | ||
v1 "k8s.io/api/core/v1" | ||
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/fields" | ||
"k8s.io/client-go/dynamic" | ||
"k8s.io/client-go/kubernetes" | ||
"k8s.io/client-go/tools/cache" | ||
) | ||
|
||
func DeploymentController( | ||
client *kubernetes.Clientset, | ||
dynamicClient *dynamic.DynamicClient, | ||
clientHub *streaming.ClientHub, | ||
) (*Controller, error) { | ||
deploymentListWatcher := cache.NewListWatchFromClient(client.AppsV1().RESTClient(), "deployments", v1.NamespaceAll, fields.Everything()) | ||
deploymentController := NewController( | ||
"deployment", | ||
deploymentListWatcher, | ||
&apps_v1.Deployment{}, | ||
func(informerEvent Event, objectMeta meta_v1.ObjectMeta, obj interface{}) error { | ||
switch informerEvent.eventType { | ||
case "create": | ||
createdDeployment := obj.(*apps_v1.Deployment) | ||
deploymentBytes, err := json.Marshal(streaming.Envelope{ | ||
Type: streaming.DEPLOYMENT_CREATED, | ||
Payload: createdDeployment, | ||
}) | ||
if err != nil { | ||
logrus.Warnf("could not marshal event: %s", err) | ||
return nil | ||
} | ||
clientHub.Broadcast <- deploymentBytes | ||
case "update": | ||
deployment := obj.(*apps_v1.Deployment) | ||
deploymentBytes, err := json.Marshal(streaming.Envelope{ | ||
Type: streaming.DEPLOYMENT_UPDATED, | ||
Payload: deployment, | ||
}) | ||
if err != nil { | ||
logrus.Warnf("could not marshal event: %s", err) | ||
return nil | ||
} | ||
clientHub.Broadcast <- deploymentBytes | ||
case "delete": | ||
deploymentBytes, err := json.Marshal(streaming.Envelope{ | ||
Type: streaming.DEPLOYMENT_DELETED, | ||
Payload: informerEvent.key, | ||
}) | ||
if err != nil { | ||
logrus.Warnf("could not marshal event: %s", err) | ||
return nil | ||
} | ||
clientHub.Broadcast <- deploymentBytes | ||
} | ||
return nil | ||
}) | ||
return deploymentController, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package controllers | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/gimlet-io/capacitor/pkg/streaming" | ||
"github.com/sirupsen/logrus" | ||
v1 "k8s.io/api/core/v1" | ||
networking_v1 "k8s.io/api/networking/v1" | ||
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/fields" | ||
"k8s.io/client-go/dynamic" | ||
"k8s.io/client-go/kubernetes" | ||
"k8s.io/client-go/tools/cache" | ||
) | ||
|
||
func IngressController( | ||
client *kubernetes.Clientset, | ||
dynamicClient *dynamic.DynamicClient, | ||
clientHub *streaming.ClientHub, | ||
) (*Controller, error) { | ||
ingressListWatcher := cache.NewListWatchFromClient(client.NetworkingV1().RESTClient(), "ingresses", v1.NamespaceAll, fields.Everything()) | ||
ingressController := NewController( | ||
"ingress", | ||
ingressListWatcher, | ||
&networking_v1.Ingress{}, | ||
func(informerEvent Event, objectMeta meta_v1.ObjectMeta, obj interface{}) error { | ||
switch informerEvent.eventType { | ||
case "create": | ||
createdIngress := obj.(*networking_v1.Ingress) | ||
ingressBytes, err := json.Marshal(streaming.Envelope{ | ||
Type: streaming.INGRESS_CREATED, | ||
Payload: createdIngress, | ||
}) | ||
if err != nil { | ||
logrus.Warnf("could not marshal event: %s", err) | ||
return nil | ||
} | ||
clientHub.Broadcast <- ingressBytes | ||
case "update": | ||
ingress := obj.(*networking_v1.Ingress) | ||
ingressBytes, err := json.Marshal(streaming.Envelope{ | ||
Type: streaming.INGRESS_UPDATED, | ||
Payload: ingress, | ||
}) | ||
if err != nil { | ||
logrus.Warnf("could not marshal event: %s", err) | ||
return nil | ||
} | ||
clientHub.Broadcast <- ingressBytes | ||
case "delete": | ||
ingressBytes, err := json.Marshal(streaming.Envelope{ | ||
Type: streaming.INGRESS_DELETED, | ||
Payload: informerEvent.key, | ||
}) | ||
if err != nil { | ||
logrus.Warnf("could not marshal event: %s", err) | ||
return nil | ||
} | ||
clientHub.Broadcast <- ingressBytes | ||
} | ||
return nil | ||
}) | ||
return ingressController, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.