Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
jrjyipee committed Jul 16, 2018
1 parent ba90965 commit 056ce95
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 27 deletions.
9 changes: 9 additions & 0 deletions kubeaccess.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

import (
// "context"
)

func getK8sResource(id string) map[string]interface{} {
return nil
}
4 changes: 4 additions & 0 deletions label.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ type labelResolver struct {
l *label
}

func mapToLabels(lMap map[string]interface{}) *[]label {
return nil
}

func (r *labelResolver) Name() string {
return r.l.Name
}
Expand Down
42 changes: 24 additions & 18 deletions metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,28 @@ type metadataResolver struct {
m *metadata
}

func mapToMetadata(jsonObj map[string]interface{}) metadata {
var m metadata
if ct, ok := jsonObj["CreationTimestamp"].(string); ok {
m.CreationTimestamp = &ct
} else {
m.CreationTimestamp = nil
}
m.GenerateName = jsonObj["GenerateName"].(string)
m.Labels = mapToLabels(mapItem(jsonObj, "labels"))
m.Name = jsonObj["Name"].(string)
m.Namespace = jsonObj["Namespace"].(string)
m.OwnerReferences = mapToOwnerReferences(mapItem(jsonObj, "OwnerReferences"))
m.SelfLink = jsonObj["SelfLink"].(string)
m.Uid = jsonObj["Uid"].(string)

return m
}

func mapToOwnerReferences(orMap map[string]interface{}) *[]resource {
return nil
}

func (r *metadataResolver) CreationTimestamp() *string {
return r.m.CreationTimestamp
}
Expand All @@ -31,11 +53,7 @@ func (r *metadataResolver) GenerateName() string {

func (r *metadataResolver) Labels() []*labelResolver {
var labelResolvers []*labelResolver
labels := r.m.Labels
if labels == nil {
labels = getMetadataLabels(r.m)
}
for _, label := range *labels {
for _, label := range *r.m.Labels {
lab := label
labelResolvers = append(labelResolvers, &labelResolver{r.ctx, &lab})
}
Expand All @@ -52,11 +70,7 @@ func (r *metadataResolver) Namespace() string {

func (r *metadataResolver) OwnerReferences() []*resourceResolver {
var ownerResolvers []*resourceResolver
owners := r.m.OwnerReferences
if owners == nil {
owners = getMetadataOwnerReferences(r.m)
}
for _, owner := range *owners {
for _, owner := range *r.m.OwnerReferences {
own := owner
ownerResolvers = append(ownerResolvers, &resourceResolver{r.ctx, &own})
}
Expand All @@ -74,11 +88,3 @@ func (r *metadataResolver) SelfLink() string {
func (r *metadataResolver) Uid() string {
return r.m.Uid
}

func getMetadataLabels(m *metadata) *[]label {
return nil
}

func getMetadataOwnerReferences(m *metadata) *[]resource {
return nil
}
48 changes: 39 additions & 9 deletions pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

type pod struct {
ID string
Id string
Metadata *metadata
Owner *resource
RootOwner *resource
Expand All @@ -16,8 +16,17 @@ type podResolver struct {
p *pod
}

func (r *podResolver) ID() string {
return r.p.ID
func mapToPod(jsonObj map[string]interface{}) pod {
owner, rootOwner := getOwners(jsonObj)
meta := mapToMetadata(mapItem(jsonObj, "metadata"))
return pod{(mapItem(jsonObj, "metadata")["uid"]).(string),
&meta,
owner,
rootOwner}
}

func (r *podResolver) Id() string {
return r.p.Id
}

func (r *podResolver) Metadata() *metadataResolver {
Expand All @@ -31,27 +40,48 @@ func (r *podResolver) Metadata() *metadataResolver {
func (r *podResolver) Owner() *resourceResolver {
owner := r.p.Owner
if owner == nil {
owner = getPodOwner(r.p)
owner = getPodOwner(r.p.Id)
}
return &resourceResolver{r.ctx, owner}
}

func (r *podResolver) RootOwner() *resourceResolver {
rootOwner := r.p.RootOwner
if rootOwner == nil {
rootOwner = getPodRootOwner(r.p)
rootOwner = getPodRootOwner(r.p.Id)
}
return &resourceResolver{r.ctx, rootOwner}
}

func getPodMetadata(p *pod) *metadata {
return nil
meta := mapToMetadata(mapItem(getK8sResource(p.Id), "Metadata"))
return &meta
}

func getPodOwner(p *pod) *resource {
func getPodOwner(pid string) *resource {
if podval := getK8sResource(pid); podval != nil {
if orefs := podval["OwnerReferences"]; orefs != nil {
orefArray := orefs.([]map[string]interface{})
if len(orefArray) > 0 {
if res := getK8sResource(
orefArray[0]["uid"].(string)); res != nil {
return mapToResource(res)
}
}
} else {
return mapToResource(podval)
}
}

return nil
}

func getPodRootOwner(p *pod) *resource {
return nil
func getPodRootOwner(pid string) *resource {
result := getPodOwner(pid)

if (*result).Id() == pid {
return result
}

return getPodRootOwner((*getPodOwner((*result).Id())).Id())
}
4 changes: 4 additions & 0 deletions resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ type resourceResolver struct {
r *resource
}

func mapToResource(rMap map[string]interface{}) *resource {
return nil
}

func (r *resourceResolver) Id() string {
return (*r.r).Id()
}
Expand Down
13 changes: 13 additions & 0 deletions util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
// "context"
)

func getOwners(resourceMap map[string]interface{}) (*resource, *resource) {
return nil, nil
}

func mapItem(obj map[string]interface{}, item string) map[string]interface{} {
return obj[item].(map[string]interface{})
}

0 comments on commit 056ce95

Please sign in to comment.