示例#1
0
func (k *kubeClient) GetServicesForNamespace(namespace string, labelSelector ...string) (*[]models.Service, error) {
	if len(labelSelector) > 1 {
		return nil, fmt.Errorf("too many parameters")
	}
	params := map[string]string{"pretty": "true"}
	if len(labelSelector) > 0 {
		params["labelSelector"] = labelSelector[0]
	}
	path := fmt.Sprintf("/api/v1/namespaces/%s/services", namespace)
	json, _, err := k.service.Get(path, params)
	if err != nil {
		return nil, fmt.Errorf("error getting services: %s", err)
	}

	return models.NewServicesJSON(string(json))
}
示例#2
0
// GetServices retrieves a json representation of existing services
func (k *kubeClient) GetServices(labelSelector ...string) (*[]models.Service, error) {
	if len(labelSelector) > 1 {
		return nil, fmt.Errorf("too many parameters")
	}
	params := map[string]string{"pretty": "true"}
	if len(labelSelector) > 0 {
		params["labelSelector"] = labelSelector[0]
	}
	json, _, err := k.service.Get("/api/v1/services", params)
	if err != nil {
		return nil, fmt.Errorf("error getting services: %s", err)
	}

	srv, err := models.NewServicesJSON(string(json))
	if err != nil {
		return nil, fmt.Errorf("error parsing json: %s %s", err, json)
	}
	return srv, nil
}