K8s list deployments (#921)
* Outline of ListDeployments method * Added implementation of DeploymentList
This commit is contained in:
@@ -103,7 +103,7 @@ func (r *Request) Body(in interface{}) *Request {
|
||||
// Params isused to set paramters on a request
|
||||
func (r *Request) Params(p *Params) *Request {
|
||||
for k, v := range p.LabelSelector {
|
||||
r.params.Add("labelSelectors", k+"="+v)
|
||||
r.params.Add("labelSelector", k+"="+v)
|
||||
}
|
||||
|
||||
return r
|
||||
|
@@ -90,7 +90,7 @@ func detectNamespace() (string, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateDeployment
|
||||
// UpdateDeployment patches kubernetes deployment with metadata provided in body
|
||||
func (c *client) UpdateDeployment(name string, body interface{}) error {
|
||||
return api.NewRequest(c.opts).
|
||||
Patch().
|
||||
@@ -100,3 +100,16 @@ func (c *client) UpdateDeployment(name string, body interface{}) error {
|
||||
Do().
|
||||
Error()
|
||||
}
|
||||
|
||||
// ListDeployments lists all kubernetes deployments with given labels
|
||||
func (c *client) ListDeployments(labels map[string]string) (*DeploymentList, error) {
|
||||
var deployments DeploymentList
|
||||
err := api.NewRequest(c.opts).
|
||||
Get().
|
||||
Resource("deployments").
|
||||
Params(&api.Params{LabelSelector: labels}).
|
||||
Do().
|
||||
Into(&deployments)
|
||||
|
||||
return &deployments, err
|
||||
}
|
||||
|
@@ -4,9 +4,30 @@ package client
|
||||
type Kubernetes interface {
|
||||
// UpdateDeployment patches deployment annotations with new metadata
|
||||
UpdateDeployment(string, interface{}) error
|
||||
// ListDeployments lists all micro deployments
|
||||
ListDeployments(labels map[string]string) (*DeploymentList, error)
|
||||
}
|
||||
|
||||
// Metadata defines api request metadata
|
||||
type Metadata struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Labels map[string]string `json:"labels,omitempty"`
|
||||
Annotations map[string]string `json:"annotations,omitempty"`
|
||||
}
|
||||
|
||||
// DeploymentList
|
||||
type DeploymentList struct {
|
||||
Items []Deployment `json:"items"`
|
||||
}
|
||||
|
||||
// Deployment is Kubernetes deployment
|
||||
type Deployment struct {
|
||||
Metadata *Metadata `json:"metadata"`
|
||||
Status *Status `json:"status"`
|
||||
}
|
||||
|
||||
// Status is Kubernetes deployment status
|
||||
type Status struct {
|
||||
Replicas int `json:"replicas"`
|
||||
AvailableReplicas int `json:"availablereplicas"`
|
||||
}
|
||||
|
Reference in New Issue
Block a user