Skip to content

Commit

Permalink
Added REST endpoint for provenance query operators
Browse files Browse the repository at this point in the history
  • Loading branch information
devdattakulkarni committed Aug 8, 2018
1 parent 93a7435 commit 63cb202
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 19 deletions.
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,37 +79,37 @@ Scripts are provided to help with building the API server container image and de
`$ ./delete-provenance-artifacts.sh`


Once the kubediscovery API server is running, you can find the dynamic composition information by using following type of commands:
Once the kubediscovery API server is running, you can find provenance information by using following type of commands:


1) Get dynamic composition for all deployments
1) Get list of versions for testobj deployment

```
kubectl get --raw /apis/kubeprovenance.cloudark.io/v1/namespaces/default/deployments/*/compositions | python -mjson.tool
kubectl get --raw /apis/kubeprovenance.cloudark.io/v1/namespaces/default/deployments/testobj/versions
```

![alt text](https://github.com/cloud-ark/kubeprovenance/raw/master/docs/deployments.png)


2) Get dynamic composition for a particular deployment
2) Get Spec history for testobj deployment

```
kubectl get --raw /apis/kubeprovenance.cloudark.io/v1/namespaces/default/deployments/<dep-name>/compositions | python -mjson.tool
kubectl get --raw /apis/kubeprovenance.cloudark.io/v1/namespaces/default/deployments/testobj/spechistory
```

![alt text](https://github.com/cloud-ark/kubeprovenance/raw/master/docs/hello-minikube-deployment.png)
3) Get diff of Spec for testobj deployment between version v1 and version v2

```
kubectl get --raw /apis/kubeprovenance.cloudark.io/v1/namespaces/default/deployments/testobj/diff?start=v1&end=v2
```

3) Get dynamic composition of all etcdclusters custom resource
4) Get diff of field abc for testobj deployment between version v1 and version v2

```
kubectl get --raw /apis/kubeprovenance.cloudark.io/v1/namespaces/default/etcdclusters/*/compositions | python -mjson.tool
kubectl get --raw "/apis/kubeprovenance.cloudark.io/v1/namespaces/default/deployments/testobj/diff?start=v1&end=v2&field=abc"
```

![alt text](https://github.com/cloud-ark/kubeprovenance/raw/master/docs/etcd-clusters.png)

You can use above style of commands with all the Kinds that you have defined in kind_compositions.yaml
5) Find out which version field abc for testobj deployment was given value def

```
kubectl get --raw "/apis/kubeprovenance.cloudark.io/v1/namespaces/default/deployments/testobj/bisect?field=abc&value=def"
```

## Troubleshooting tips:

Expand Down
107 changes: 103 additions & 4 deletions pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,26 @@ func installCompositionProvenanceWebService(provenanceServer *ProvenanceServer)
ws.Path(path).
Consumes(restful.MIME_JSON, restful.MIME_XML).
Produces(restful.MIME_JSON, restful.MIME_XML)
getPath := "/{resource-id}/compositions"
ws.Route(ws.GET(getPath).To(getCompositions))
getPath := "/{resource-id}/versions"
fmt.Println("Get Path:" + getPath)
ws.Route(ws.GET(getPath).To(getVersions))

historyPath := "/{resource-id}/spechistory"
fmt.Println("History Path:" + historyPath)
ws.Route(ws.GET(historyPath).To(getHistory))

diffPath := "/{resource-id}/diff"
fmt.Println("Diff Path:" + diffPath)
ws.Route(ws.GET(diffPath).To(getDiff))

bisectPath := "/{resource-id}/bisect"
fmt.Println("Bisect Path:" + bisectPath)
ws.Route(ws.GET(bisectPath).To(bisect))

provenanceServer.GenericAPIServer.Handler.GoRestfulContainer.Add(ws)

}
fmt.Println("Done registering.")
}

func getWebService() *restful.WebService {
Expand All @@ -147,7 +163,44 @@ func getWebService() *restful.WebService {
return ws
}

func getCompositions(request *restful.Request, response *restful.Response) {
func getVersions(request *restful.Request, response *restful.Response) {
resourceName := request.PathParameter("resource-id")
requestPath := request.Request.URL.Path
//fmt.Printf("Printing Provenance\n")
//provenance.TotalClusterProvenance.PrintProvenance()

// Path looks as follows:
// /apis/kubeprovenance.cloudark.io/v1/namespaces/default/deployments/dep1/compositions
resourcePathSlice := strings.Split(requestPath, "/")
resourceKind := resourcePathSlice[6] // Kind is 7th element in the slice
//provenanceInfo := provenance.TotalClusterProvenance.GetProvenance(resourceKind, resourceName)
provenanceInfo := "Resource Name:" + resourceName + " Resource Kind:" + resourceKind
fmt.Println(provenanceInfo)

response.Write([]byte(provenanceInfo))
}

func getHistory(request *restful.Request, response *restful.Response) {
fmt.Println("Inside getHistory")
resourceName := request.PathParameter("resource-id")
requestPath := request.Request.URL.Path
//fmt.Printf("Printing Provenance\n")
//provenance.TotalClusterProvenance.PrintProvenance()

// Path looks as follows:
// /apis/kubeprovenance.cloudark.io/v1/namespaces/default/deployments/dep1/compositions
resourcePathSlice := strings.Split(requestPath, "/")
resourceKind := resourcePathSlice[6] // Kind is 7th element in the slice
// provenanceInfo := provenance.TotalClusterProvenance.GetProvenance(resourceKind, resourceName)

provenanceInfo := "Resource Name:" + resourceName + " Resource Kind:" + resourceKind
fmt.Println(provenanceInfo)

response.Write([]byte(provenanceInfo))
}

func bisect(request *restful.Request, response *restful.Response) {
fmt.Println("Inside bisect")
resourceName := request.PathParameter("resource-id")
requestPath := request.Request.URL.Path
//fmt.Printf("Printing Provenance\n")
Expand All @@ -157,7 +210,53 @@ func getCompositions(request *restful.Request, response *restful.Response) {
// /apis/kubeprovenance.cloudark.io/v1/namespaces/default/deployments/dep1/compositions
resourcePathSlice := strings.Split(requestPath, "/")
resourceKind := resourcePathSlice[6] // Kind is 7th element in the slice
provenanceInfo := provenance.TotalClusterProvenance.GetProvenance(resourceKind, resourceName)

var provenanceInfo string
//provenanceInfo = provenance.TotalClusterProvenance.GetProvenance(resourceKind, resourceName)
provenanceInfo = "Resource Name:" + resourceName + " Resource Kind:" + resourceKind
fmt.Println(provenanceInfo)

field := request.QueryParameter("field")
value := request.QueryParameter("value")

provenanceInfo = provenanceInfo + " Field:" + field + " Value:" + value

fmt.Println("ProvenanceInfo:%v", provenanceInfo)

response.Write([]byte(provenanceInfo))
}


func getDiff(request *restful.Request, response *restful.Response) {
fmt.Println("Inside getDiff")
resourceName := request.PathParameter("resource-id")
requestPath := request.Request.URL.Path

// Path looks as follows:
// /apis/kubeprovenance.cloudark.io/v1/namespaces/default/deployments/dep1/compositions
resourcePathSlice := strings.Split(requestPath, "/")
resourceKind := resourcePathSlice[6] // Kind is 7th element in the slice

fmt.Println("Resource Name:%s, Resource Kind:%s", resourceName, resourceKind)

start := request.QueryParameter("start")
end := request.QueryParameter("end")
field := request.QueryParameter("field")

var diffInfo string
if ( start == "" || end == "" ) {
fmt.Println("Start:%s", start)
fmt.Println("End:%s", end)
diffInfo = "start and end query parameters missing\n"
} else {
fmt.Println("Start:%s", start)
fmt.Println("End:%s", end)
if field != "" {
fmt.Println("Diff for Field requested. Field:%s", field)
} else {
fmt.Println("Diff for Spec requested.")
}
diffInfo = "This is Diff Info: " + start + " " + end + " " + field
}
response.Write([]byte(diffInfo))
}

0 comments on commit 63cb202

Please sign in to comment.