Skip to content

Commit

Permalink
update to latest knative.
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Nichols committed Jun 27, 2019
1 parent bd04427 commit dc38bdd
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 115 deletions.
15 changes: 2 additions & 13 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions cmd/graph/kodata/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
margin: 0 auto;
}

svg {
vertical-align: middle;
display: block;
margin: auto;
}

.graph-content {
border-radius: 15px;
padding: 20px 30px;
Expand Down
2 changes: 1 addition & 1 deletion cmd/graph/kodata/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<main class="graph-main mdl-layout__content">

{{template "main.html"}}
{{template "main.html" .}}

</main>
<footer class="graph-footer mdl-mini-footer">
Expand Down
11 changes: 6 additions & 5 deletions cmd/graph/kodata/templates/main.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<div class="graph-container mdl-grid">
{{ if (eq .Format "svg")}}
{{.Image}}
<div class="mdl-cell mdl-cell--12-col">
{{ if eq .Format "svg" }}
{{ .Image }}
{{ else }}
<img src="data:{{.Format}},{{.Image}}">
<img src="data:{{ .Format }},{{ .Image }}">
{{ end }}
</div>

</div>
</div>
2 changes: 1 addition & 1 deletion config/graph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ metadata:
spec:
template:
spec:
serviceAccountName: n3wscott-graph
containers:
- image: github.com/n3wscott/graph/cmd/graph
serviceAccountName: n3wscott-graph
env:
- name: NAMESPACE
value: default
2 changes: 0 additions & 2 deletions config/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: n3wscott-graph-resolver
labels:
events.cloud.run/release: devel
subjects:
- kind: ServiceAccount
name: controller
Expand Down
23 changes: 0 additions & 23 deletions pkg/controller/ce.go

This file was deleted.

1 change: 0 additions & 1 deletion pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func (c *Controller) Mux() *http.ServeMux {
c.once.Do(func() {
m := http.NewServeMux()
m.HandleFunc("/ui", c.RootHandler)
http.HandleFunc("/favicon.ico", c.Favicon)
c.mux = m
})

Expand Down
23 changes: 0 additions & 23 deletions pkg/controller/favicon.go

This file was deleted.

34 changes: 22 additions & 12 deletions pkg/controller/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ func getQueryParam(r *http.Request, key string) string {
return keys[0]
}

// TODO: support just fetching the graph image

var defaultFormat = "svg" // or png
var defaultFocus = "trigger" // or png

func (c *Controller) RootHandler(w http.ResponseWriter, r *http.Request) {
once.Do(func() {
t, _ = template.ParseFiles(
var err error
t, err = template.ParseFiles(
c.root+"/templates/index.html",
c.root+"/templates/main.html",
)
if err != nil {
log.Printf("Failed to parse template: %v\n", err)
}
})

c.GraphHTML(w, r)
}

// TODO: support just fetching the graph image

var defaultFormat = "svg" // or png
var defaultFocus = "trigger" // or png

func (c *Controller) GraphHTML(w http.ResponseWriter, r *http.Request) {
format := getQueryParam(r, "format")
if format == "" {
format = defaultFormat
Expand Down Expand Up @@ -71,13 +71,18 @@ func (c *Controller) GraphHTML(w http.ResponseWriter, r *http.Request) {
return
}
img, err := ioutil.ReadFile(file)
if err != nil {
log.Printf("read file error %s", err)
}

defer os.Remove(file) // clean up

var data map[string]interface{}
log.Printf("Image is %s", format)
if format == "svg" {
data = map[string]interface{}{
"Image": img,
"svg": true,
"Image": template.HTML(string(img)),
"Format": format,
}
} else {
Expand All @@ -86,7 +91,12 @@ func (c *Controller) GraphHTML(w http.ResponseWriter, r *http.Request) {
"Format": fmt.Sprintf("image/%s;base64", format),
}
}
_ = t.Execute(w, data)
data["Dot"] = dotGraph

err = t.Execute(w, data)
if err != nil {
log.Printf("template execute error %s", err)
}
}

var dot string
Expand Down
35 changes: 10 additions & 25 deletions pkg/graph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package graph
import (
"fmt"
eventingv1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1"
knduckv1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1"
servingv1beta1 "github.com/knative/serving/pkg/apis/serving/v1beta1"
duckv1alpha1 "github.com/n3wscott/knap/pkg/apis/duck/v1alpha1"
"github.com/tmc/dot"
"k8s.io/apimachinery/pkg/runtime/schema"
"strings"

duckv1alpha1 "github.com/n3wscott/graph/pkg/apis/duck/v1alpha1"
)

type Graph struct {
Expand Down Expand Up @@ -50,7 +50,8 @@ func (g *Graph) newEdge(src, dst *dot.Node) *dot.Edge {

func (g *Graph) AddChannel(channel eventingv1alpha1.Channel) {
ck := channelKey(channel.Name)
dns := addressableDNS(channel.Status.Address)
uri := channel.Status.Address.GetURL()
dns := (&uri).String()
cn := dot.NewNode("Channel " + channel.Name)

setNodeShapeForKind(cn, channel.Kind, channel.APIVersion)
Expand Down Expand Up @@ -96,7 +97,8 @@ func (g *Graph) AddSubscription(subscription eventingv1alpha1.Subscription) {

func (g *Graph) AddBroker(broker eventingv1alpha1.Broker) {
key := brokerKey(broker.Name)
dns := addressableDNS(broker.Status.Address)
uri := broker.Status.Address.GetURL()
dns := (&uri).String()
bn := dot.NewNode("Broker " + dns)
_ = bn.Set("shape", "oval")
_ = bn.Set("label", "Ingress")
Expand Down Expand Up @@ -195,16 +197,7 @@ func (g *Graph) AddKnService(service servingv1beta1.Service) {
value: http://default-broker.default.svc.cluster.local/
*/

var config servingv1beta1.ConfigurationSpec
if service.Spec.RunLatest != nil {
config = service.Spec.RunLatest.Configuration
} else if service.Spec.Release != nil {
config = service.Spec.Release.Configuration
} else {
// nope out.
return
}
_ = config
config := service.Spec.ConfigurationSpec

key := servingKey(service.Kind, service.Name)

Expand All @@ -226,7 +219,7 @@ func (g *Graph) AddKnService(service servingv1beta1.Service) {
g.AddNode(svc)
}

for _, env := range config.RevisionTemplate.Spec.Container.Env {
for _, env := range config.Template.Spec.Containers[0].Env {
switch env.Name {
case "SINK":
fallthrough
Expand All @@ -240,7 +233,7 @@ func (g *Graph) AddKnService(service servingv1beta1.Service) {
}

func setNodeShapeForKind(node *dot.Node, kind, apiVersion string) {
if apiVersion == "serving.knative.dev/v1alpha1" {
if apiVersion == "serving.knative.dev/v1beta1" {
switch kind {
case "Service":
_ = node.Set("shape", "septagon")
Expand Down Expand Up @@ -321,14 +314,6 @@ func sinkDNS(source duckv1alpha1.SourceType) string {
return ""
}

func addressableDNS(address knduckv1alpha1.Addressable) string {
uri := fmt.Sprintf("http://%s", address.Hostname)
if !strings.HasSuffix(uri, "/") {
uri += "/"
}
return uri
}

func channelKey(name string) string {
return eventingKey("channel", name)
}
Expand Down Expand Up @@ -362,7 +347,7 @@ func eventingKey(kind, name string) string {
}

func servingKey(kind, name string) string {
return key("serving.knative.dev", "v1alpha1", kind, name)
return key("serving.knative.dev", "v1beta1", kind, name)
}

func triggerKey(name string) string {
Expand Down
2 changes: 1 addition & 1 deletion pkg/graph/triggers.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package graph

import (
"github.com/n3wscott/knap/pkg/knative"
"github.com/n3wscott/graph/pkg/knative"
"k8s.io/client-go/dynamic"
)

Expand Down
17 changes: 11 additions & 6 deletions pkg/knative/eventing.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"

eventingv1alpha1 "github.com/knative/eventing/pkg/apis/eventing/v1alpha1"
duckv1alpha1 "github.com/n3wscott/knap/pkg/apis/duck/v1alpha1"
duckv1alpha1 "github.com/n3wscott/graph/pkg/apis/duck/v1alpha1"
)

func (c *Client) Sources(namespace string) []duckv1alpha1.SourceType {
Expand Down Expand Up @@ -46,7 +46,8 @@ func (c *Client) Triggers(namespace string) []eventingv1alpha1.Trigger {

list, err := c.dc.Resource(gvr).Namespace(namespace).List(metav1.ListOptions{})
if err != nil {
log.Fatalf("Failed to List Triggers, %v", err)
log.Printf("Failed to List Triggers, %v", err)
return nil
}

all := make([]eventingv1alpha1.Trigger, len(list.Items))
Expand All @@ -73,7 +74,8 @@ func (c *Client) Brokers(namespace string) []eventingv1alpha1.Broker {

list, err := c.dc.Resource(gvr).Namespace(namespace).List(metav1.ListOptions{})
if err != nil {
log.Fatalf("Failed to List Brokers, %v", err)
log.Printf("Failed to List Brokers, %v", err)
return nil
}

all := make([]eventingv1alpha1.Broker, len(list.Items))
Expand All @@ -100,7 +102,8 @@ func (c *Client) Channels(namespace string) []eventingv1alpha1.Channel {

list, err := c.dc.Resource(gvr).Namespace(namespace).List(metav1.ListOptions{})
if err != nil {
log.Fatalf("Failed to List Channels, %v", err)
log.Printf("Failed to List Channels, %v", err)
return nil
}

all := make([]eventingv1alpha1.Channel, len(list.Items))
Expand All @@ -127,7 +130,8 @@ func (c *Client) Subscriptions(namespace string) []eventingv1alpha1.Subscription

list, err := c.dc.Resource(gvr).Namespace(namespace).List(metav1.ListOptions{})
if err != nil {
log.Fatalf("Failed to List Subscriptions, %v", err)
log.Printf("Failed to List Subscriptions, %v", err)
return nil
}

all := make([]eventingv1alpha1.Subscription, len(list.Items))
Expand All @@ -154,7 +158,8 @@ func (c *Client) EventTypes(namespace string) []eventingv1alpha1.EventType {

list, err := c.dc.Resource(gvr).Namespace(namespace).List(metav1.ListOptions{})
if err != nil {
log.Fatalf("Failed to List EventTypes, %v", err)
log.Printf("Failed to List EventTypes, %v", err)
return nil
}

all := make([]eventingv1alpha1.EventType, len(list.Items))
Expand Down
3 changes: 2 additions & 1 deletion pkg/knative/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ func (c *Client) SourceCRDs() []apiextensions.CustomResourceDefinition {

list, err := c.dc.Resource(gvr).List(metav1.ListOptions{LabelSelector: "eventing.knative.dev/source=true"})
if err != nil {
log.Fatalf("Failed to List Triggers, %v", err)
log.Printf("Failed to List Triggers, %v", err)
return nil
}

all := make([]apiextensions.CustomResourceDefinition, len(list.Items))
Expand Down
3 changes: 2 additions & 1 deletion pkg/knative/serving.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ func (c *Client) KnServices(namespace string) []servingv1beta1.Service {

list, err := c.dc.Resource(gvr).Namespace(namespace).List(metav1.ListOptions{})
if err != nil {
log.Fatalf("Failed to List Services, %v", err)
log.Printf("Failed to List Services, %v", err)
return nil
}

all := make([]servingv1beta1.Service, len(list.Items))
Expand Down

0 comments on commit dc38bdd

Please # to comment.