aboutsummaryrefslogtreecommitdiff
path: root/middleware/kubernetes/k8sclient/dataobjects.go
blob: b17adeba4165cbdefb9f6d586162cd75cd76ef02 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package k8sclient

import (
	"encoding/json"
	"net/http"
)

// getK8sAPIResponse wraps the http.Get(url) function to provide dependency
// injection for unit testing.
var getK8sAPIResponse = func(url string) (resp *http.Response, err error) {
	resp, err = http.Get(url)
	return resp, err
}

func parseJson(url string, target interface{}) error {
	r, err := getK8sAPIResponse(url)
	if err != nil {
		return err
	}
	defer r.Body.Close()

	return json.NewDecoder(r.Body).Decode(target)
}

// Kubernetes Resource List
type ResourceList struct {
	Kind         string     `json:"kind"`
	GroupVersion string     `json:"groupVersion"`
	Resources    []resource `json:"resources"`
}

type resource struct {
	Name       string `json:"name"`
	Namespaced bool   `json:"namespaced"`
	Kind       string `json:"kind"`
}

// Kubernetes NamespaceList
type NamespaceList struct {
	Kind       string          `json:"kind"`
	APIVersion string          `json:"apiVersion"`
	Metadata   apiListMetadata `json:"metadata"`
	Items      []nsItems       `json:"items"`
}

type apiListMetadata struct {
	SelfLink        string `json:"selfLink"`
	ResourceVersion string `json:"resourceVersion"`
}

type nsItems struct {
	Metadata nsMetadata `json:"metadata"`
	Spec     nsSpec     `json:"spec"`
	Status   nsStatus   `json:"status"`
}

type nsMetadata struct {
	Name              string `json:"name"`
	SelfLink          string `json:"selfLink"`
	Uid               string `json:"uid"`
	ResourceVersion   string `json:"resourceVersion"`
	CreationTimestamp string `json:"creationTimestamp"`
}

type nsSpec struct {
	Finalizers []string `json:"finalizers"`
}

type nsStatus struct {
	Phase string `json:"phase"`
}

// Kubernetes ServiceList
type ServiceList struct {
	Kind       string          `json:"kind"`
	APIVersion string          `json:"apiVersion"`
	Metadata   apiListMetadata `json:"metadata"`
	Items      []ServiceItem   `json:"items"`
}

type ServiceItem struct {
	Metadata serviceMetadata `json:"metadata"`
	Spec     serviceSpec     `json:"spec"`
	//    Status     serviceStatus    `json:"status"`
}

type serviceMetadata struct {
	Name              string `json:"name"`
	Namespace         string `json:"namespace"`
	SelfLink          string `json:"selfLink"`
	Uid               string `json:"uid"`
	ResourceVersion   string `json:"resourceVersion"`
	CreationTimestamp string `json:"creationTimestamp"`
	// labels
}

type serviceSpec struct {
	Ports           []servicePort `json:"ports"`
	ClusterIP       string        `json:"clusterIP"`
	Type            string        `json:"type"`
	SessionAffinity string        `json:"sessionAffinity"`
}

type servicePort struct {
	Name       string `json:"name"`
	Protocol   string `json:"protocol"`
	Port       int    `json:"port"`
	TargetPort int    `json:"targetPort"`
}

type serviceStatus struct {
	LoadBalancer string `json:"loadBalancer"`
}