Skip to content

Commit

Permalink
changed to appen(s, spec). added doc to readme. but I am having probl…
Browse files Browse the repository at this point in the history
…ems actually validating the diff and versions. I need more time for this because my debugging isn't even showing up on the api calls, in the logs. It's like I am editing code from a different project, except all the paths and the imports look correct...
  • Loading branch information
djarotech committed Aug 13, 2018
1 parent 5ea8e48 commit d8f30b0
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 29 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ kubectl.sh get --raw "/apis/kubeprovenance.cloudark.io/v1/namespaces/default/pos
```
kubectl.sh get --raw "/apis/kubeprovenance.cloudark.io/v1/namespaces/default/postgreses/client25/bisect?field=abc&value=def"
```
![alt text](https://github.com/cloud-ark/kubeprovenance/raw/master/docs/spechistory.png)


## Try it on Minikube
Expand Down
Binary file added docs/spechistory.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 7 additions & 9 deletions pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,14 @@ func getVersions(request *restful.Request, response *restful.Response) {
requestPath := request.Request.URL.Path
resourcePathSlice := strings.Split(requestPath, "/")
resourceKind := resourcePathSlice[6] // Kind is 7th element in the slice
provenanceInfo := "Resource Name:" + resourceName + " Resource Kind:" + resourceKind
provenanceInfo := "Resource Name:" + resourceName + " Resource Kind: " + resourceKind + "\n"
fmt.Println(provenanceInfo)

response.Write([]byte(provenanceInfo))
intendedProvObj := provenance.FindProvenanceObjectByName(resourceName, provenance.AllProvenanceObjects)

//TODO: Validate request based on the correct namespace and the correct plural type. right now
//deployments is sort of just ignored intentionally. I have the namespace/pluralkind data
//in my ProvenanceOfObject struct so it is easy to make these changes later
//TODO: Validate request based on the correct namespace and the correct plural type.
//I have the namespace/pluralkind datain my ProvenanceOfObject struct so it is easy to make these changes later
if intendedProvObj == nil {
s := fmt.Sprintf("Could not find any provenance history for resource name: %s", resourceName)
response.Write([]byte(s))
Expand All @@ -197,13 +196,13 @@ func getHistory(request *restful.Request, response *restful.Response) {
response.Write([]byte(provenanceInfo))
intendedProvObj := provenance.FindProvenanceObjectByName(resourceName, provenance.AllProvenanceObjects)

//TODO: Validate request based on the correct namespace and the correct plural type. right now
//deployments is sort of just ignored intentionally. I have the namespace/pluralkind data
//in my ProvenanceOfObject struct so it is easy to make these changes later
//TODO: Validate request based on the correct namespace and the correct plural type.
//I have the namespace/pluralkind datain my ProvenanceOfObject struct so it is easy to make these changes later
if intendedProvObj == nil {
s := fmt.Sprintf("Could not find any provenance history for resource name: %s", resourceName)
response.Write([]byte(s))
} else {
//TODO: handle optional interval parameters
response.Write([]byte(intendedProvObj.ObjectFullHistory.SpecHistory()))
}

Expand Down Expand Up @@ -255,7 +254,6 @@ func getDiff(request *restful.Request, response *restful.Response) {
end := request.QueryParameter("end")
field := request.QueryParameter("field")
intendedProvObj := provenance.FindProvenanceObjectByName(resourceName, provenance.AllProvenanceObjects)

if intendedProvObj == nil {
s := fmt.Sprintf("Could not find any provenance history for resource name: %s", resourceName)
response.Write([]byte(s))
Expand All @@ -266,7 +264,7 @@ func getDiff(request *restful.Request, response *restful.Response) {
if start == "" || end == "" {
fmt.Printf("Start:%s", start)
fmt.Printf("End:%s", end)
diffInfo = "Start and end query parameters missing\n"
diffInfo = "Start and end query parameters are missing\n"
} else {
fmt.Printf("Start:%s", start)
fmt.Printf("End:%s", end)
Expand Down
62 changes: 42 additions & 20 deletions pkg/provenance/provenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ func init() {
func CollectProvenance() {
// fmt.Println("Inside CollectProvenance")
// for {

readKindCompositionFile()
parse()
// time.Sleep(time.Second * 5)
Expand Down Expand Up @@ -141,28 +140,41 @@ func (o ObjectLineage) String() string {
return b.String()
}

func (o ObjectLineage) LatestVersion() int {
return len(o)
}

func (o ObjectLineage) GetVersions() string {
arr := make([]string, 0)
versions := o.LatestVersion()
for index := 1; index <= versions; index++ {
arr = append(arr, string(index))
s := make([]Spec, 0)
for _, spec := range o {
s = append(s, spec)
}
return "[" + strings.Join(arr, ",") + "]"
sort.Slice(s, func(i, j int) bool {
return s[i].Version < s[i].Version
})
//get all versions, sort by version, make string array of them
versions := make([]string, 0)
for _, spec := range s {
fmt.Println(spec.Version)
versions = append(versions, fmt.Sprint(spec.Version))
}
fmt.Println(strings.Join(versions, ", "))
return "helloooooooo"
}

//what happens if I delete the object?
//need to delete the ObjectFullProvenance for the object
//add type of ObjectFullProvenance, postgreses for example
func (o ObjectLineage) SpecHistory() string {
s := make([]string, len(o))
for v, spec := range o {
s[v-1] = spec.String()
fmt.Println("inside spechistory")
s := make([]Spec, 0)
for _, spec := range o {
s = append(s, spec)
}
sort.Slice(s, func(i, j int) bool {
return s[i].Version < s[i].Version
})
specs := make([]string, 0)
for _, spec := range s {
specs = append(specs, spec.String())
}
return strings.Join(s, "\n")
return strings.Join(specs, "\n")
}
func (o ObjectLineage) Bisect(field, value string) string {
s := make([]Spec, 0)
Expand All @@ -186,14 +198,24 @@ func (o ObjectLineage) Bisect(field, value string) string {
return strconv.Itoa(-1)
}

func (o ObjectLineage) SpecHistoryInterval(vNumStart, vNumEnd int) []Spec {
s := make([]Spec, vNumEnd-vNumStart+1)
for v, spec := range o {
if v >= vNumStart && v <= vNumEnd {
s[v-vNumStart] = spec
//TODO: add optional parameters to spechistory route in apiserver.go, and call this method.
// Right now it is actually unused
func (o ObjectLineage) SpecHistoryInterval(vNumStart, vNumEnd int) []string {
//order keys so we append in order later, reference: https://blog.golang.org/go-maps-in-action#TOC_7.
s := make([]Spec, 0)
for _, spec := range o {
s = append(s, spec)
}
sort.Slice(s, func(i, j int) bool {
return s[i].Version < s[i].Version
})
specs := make([]string, 0)
for _, spec := range s {
if spec.Version >= vNumStart && spec.Version <= vNumEnd {
specs = append(specs, spec.String())
}
}
return s
return specs
}

func (o ObjectLineage) FullDiff(vNumStart, vNumEnd int) string {
Expand Down

0 comments on commit d8f30b0

Please sign in to comment.