Fix duplicate proto error in kubectl 1.8.0-alpha.

- Remove vendor'ed package go.pedge.io/pb/go/google/protobuf.
- Update vendor'ed package github.com/libopenstorage/openstorage.
This commit is contained in:
Aditya Dani
2017-09-07 02:53:38 +01:00
parent 3168bd4b12
commit b59855d48a
37 changed files with 1947 additions and 2353 deletions

View File

@@ -16,7 +16,7 @@ var (
)
// NewClient returns a new REST client for specified server.
func NewClient(host string, version string) (*Client, error) {
func NewClient(host, version, userAgent string) (*Client, error) {
baseURL, err := url.Parse(host)
if err != nil {
return nil, err
@@ -25,14 +25,48 @@ func NewClient(host string, version string) (*Client, error) {
baseURL.Path = "/"
}
unix2HTTP(baseURL)
hClient := getHTTPClient(host)
if hClient == nil {
return nil, fmt.Errorf("Unable to parse provided url: %v", host)
}
c := &Client{
base: baseURL,
version: version,
httpClient: getHttpClient(host),
base: baseURL,
version: version,
httpClient: hClient,
authstring: "",
accesstoken: "",
userAgent: fmt.Sprintf("%v/%v", userAgent, version),
}
return c, nil
}
// NewAuthClient returns a new REST client for specified server.
func NewAuthClient(host, version, authstring, accesstoken, userAgent string) (*Client, error) {
baseURL, err := url.Parse(host)
if err != nil {
return nil, err
}
if baseURL.Path == "" {
baseURL.Path = "/"
}
unix2HTTP(baseURL)
hClient := getHTTPClient(host)
if hClient == nil {
return nil, fmt.Errorf("Unable to parse provided url: %v", host)
}
c := &Client{
base: baseURL,
version: version,
httpClient: hClient,
authstring: authstring,
accesstoken: accesstoken,
userAgent: fmt.Sprintf("%v/%v", userAgent, version),
}
return c, nil
}
// GetUnixServerPath returns a unix domain socket prepended with the
// provided path.
func GetUnixServerPath(socketName string, paths ...string) string {
serverPath := "unix://"
for _, path := range paths {
@@ -42,13 +76,15 @@ func GetUnixServerPath(socketName string, paths ...string) string {
return serverPath
}
// Client is an HTTP REST wrapper. Use one of Get/Post/Put/Delete to get a request
// object.
type Client struct {
base *url.URL
version string
httpClient *http.Client
base *url.URL
version string
httpClient *http.Client
authstring string
accesstoken string
userAgent string
}
// Status sends a Status request at the /status REST endpoint.
@@ -58,7 +94,7 @@ func (c *Client) Status() (*Status, error) {
return status, err
}
// Version send a request at the /versions REST endpoint.
// Versions send a request at the /versions REST endpoint.
func (c *Client) Versions(endpoint string) ([]string, error) {
versions := []string{}
err := c.Get().Resource(endpoint + "/versions").Do().Unmarshal(&versions)
@@ -67,22 +103,22 @@ func (c *Client) Versions(endpoint string) ([]string, error) {
// Get returns a Request object setup for GET call.
func (c *Client) Get() *Request {
return NewRequest(c.httpClient, c.base, "GET", c.version)
return NewRequest(c.httpClient, c.base, "GET", c.version, c.authstring, c.userAgent)
}
// Post returns a Request object setup for POST call.
func (c *Client) Post() *Request {
return NewRequest(c.httpClient, c.base, "POST", c.version)
return NewRequest(c.httpClient, c.base, "POST", c.version, c.authstring, c.userAgent)
}
// Put returns a Request object setup for PUT call.
func (c *Client) Put() *Request {
return NewRequest(c.httpClient, c.base, "PUT", c.version)
return NewRequest(c.httpClient, c.base, "PUT", c.version, c.authstring, c.userAgent)
}
// Put returns a Request object setup for DELETE call.
// Delete returns a Request object setup for DELETE call.
func (c *Client) Delete() *Request {
return NewRequest(c.httpClient, c.base, "DELETE", c.version)
return NewRequest(c.httpClient, c.base, "DELETE", c.version, c.authstring, c.userAgent)
}
func unix2HTTP(u *url.URL) {
@@ -94,7 +130,12 @@ func unix2HTTP(u *url.URL) {
}
}
func newHTTPClient(u *url.URL, tlsConfig *tls.Config, timeout time.Duration) *http.Client {
func newHTTPClient(
u *url.URL,
tlsConfig *tls.Config,
timeout time.Duration,
responseTimeout time.Duration,
) *http.Client {
httpTransport := &http.Transport{
TLSClientConfig: tlsConfig,
}
@@ -114,28 +155,24 @@ func newHTTPClient(u *url.URL, tlsConfig *tls.Config, timeout time.Duration) *ht
}
}
return &http.Client{Transport: httpTransport}
return &http.Client{Transport: httpTransport, Timeout: responseTimeout}
}
func getHttpClient(host string) *http.Client {
func getHTTPClient(host string) *http.Client {
cacheLock.Lock()
defer cacheLock.Unlock()
c, ok := httpCache[host]
if !ok {
cacheLock.Lock()
defer cacheLock.Unlock()
c, ok = httpCache[host]
if !ok {
u, err := url.Parse(host)
if err != nil {
// TODO(pedge): clean up
fmt.Println("Failed to parse into url", host)
return nil
}
if u.Path == "" {
u.Path = "/"
}
c = newHTTPClient(u, nil, 10*time.Second)
httpCache[host] = c
u, err := url.Parse(host)
if err != nil {
return nil
}
if u.Path == "" {
u.Path = "/"
}
c = newHTTPClient(u, nil, 10*time.Second, 5*time.Minute)
httpCache[host] = c
}
return c
}

View File

@@ -11,6 +11,7 @@ import (
"strconv"
"strings"
"time"
"math/rand"
)
// Request is contructed iteratively by the client and finally dispatched.
@@ -31,6 +32,8 @@ type Request struct {
req *http.Request
resp *http.Response
timeout time.Duration
authstring string
accesstoken string
}
// Response is a representation of HTTP response received from the server.
@@ -48,14 +51,17 @@ type Status struct {
}
// NewRequest instance
func NewRequest(client *http.Client, base *url.URL, verb string, version string) *Request {
return &Request{
func NewRequest(client *http.Client, base *url.URL, verb string, version string, authstring, userAgent string) *Request {
r := &Request{
client: client,
verb: verb,
base: base,
path: base.Path,
version: version,
authstring: authstring,
}
r.SetHeader("User-Agent", userAgent)
return r
}
func checkExists(mustExist string, before string) error {
@@ -251,8 +257,19 @@ func (r *Request) Do() *Response {
if r.headers == nil {
r.headers = http.Header{}
}
req.Header = r.headers
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Date", time.Now().String())
if len(r.authstring) > 0 {
req.Header.Set("Authorization", "Basic "+ r.authstring)
}
if len(r.accesstoken) > 0 {
req.Header.Set("Access-Token", r.accesstoken)
}
resp, err = r.client.Do(req)
if err != nil {
return &Response{err: err}
@@ -295,10 +312,21 @@ func (r Response) Error() error {
return r.err
}
// FormatError formats the error
func (r Response) FormatError() error {
if len(r.body) == 0 {
return fmt.Errorf("Error: %v", r.err)
} else {
return fmt.Errorf("HTTP-%d: %s", r.statusCode, string(r.body))
}
return fmt.Errorf("HTTP-%d: %s", r.statusCode, string(r.body))
}
func digest(method string, path string) string {
now := time.Now().String()
s1 := rand.NewSource(time.Now().UnixNano())
r1 := rand.New(s1)
nonce := r1.Intn(10)
return method + "+" + path + "+" + now + "+" + strconv.Itoa(nonce)
}

View File

@@ -195,6 +195,21 @@ func (v *volumeClient) Snapshot(volumeID string, readonly bool,
return "", nil
}
// Restore specified volume to given snapshot state
func (v *volumeClient) Restore(volumeID string, snapID string) error {
response := &api.VolumeResponse{}
req := v.c.Post().Resource(snapPath + "/restore").Instance(volumeID)
req.QueryOption(api.OptSnapID, snapID)
if err := req.Do().Unmarshal(response); err != nil {
return err
}
if response.Error != "" {
return errors.New(response.Error)
}
return nil
}
// Stats for specified volume.
// Errors ErrEnoEnt may be returned
func (v *volumeClient) Stats(
@@ -205,21 +220,20 @@ func (v *volumeClient) Stats(
req := v.c.Get().Resource(volumePath + "/stats").Instance(volumeID)
req.QueryOption(api.OptCumulative, strconv.FormatBool(cumulative))
if err := req.Do().Unmarshal(stats); err != nil {
return nil, err
}
err := req.Do().Unmarshal(stats)
return stats, err
return stats, nil
}
// Alerts on this volume.
// UsedSize returns allocated volume size.
// Errors ErrEnoEnt may be returned
func (v *volumeClient) Alerts(volumeID string) (*api.Alerts, error) {
alerts := &api.Alerts{}
if err := v.c.Get().Resource(volumePath + "/alerts").Instance(volumeID).Do().Unmarshal(alerts); err != nil {
return nil, err
}
return alerts, nil
func (v *volumeClient) UsedSize(
volumeID string,
) (uint64, error) {
var usedSize uint64
req := v.c.Get().Resource(volumePath + "/usedsize").Instance(volumeID)
err := req.Do().Unmarshal(&usedSize)
return usedSize, err
}
// Active Requests on all volume.
@@ -289,13 +303,14 @@ func (v *volumeClient) SnapEnumerate(ids []string,
// Attach map device to the host.
// On success the devicePath specifies location where the device is exported
// Errors ErrEnoEnt, ErrVolAttached may be returned.
func (v *volumeClient) Attach(volumeID string) (string, error) {
func (v *volumeClient) Attach(volumeID string, attachOptions map[string]string) (string, error) {
response, err := v.doVolumeSetGetResponse(
volumeID,
&api.VolumeSetRequest{
Action: &api.VolumeStateAction{
Attach: api.VolumeActionParam_VOLUME_ACTION_PARAM_ON,
},
Options: attachOptions,
},
)
if err != nil {
@@ -313,12 +328,13 @@ func (v *volumeClient) Attach(volumeID string) (string, error) {
// Detach device from the host.
// Errors ErrEnoEnt, ErrVolDetached may be returned.
func (v *volumeClient) Detach(volumeID string) error {
func (v *volumeClient) Detach(volumeID string, unmountBeforeDetach bool) error {
return v.doVolumeSet(
volumeID,
&api.VolumeSetRequest{
Action: &api.VolumeStateAction{
Attach: api.VolumeActionParam_VOLUME_ACTION_PARAM_OFF,
Attach: api.VolumeActionParam_VOLUME_ACTION_PARAM_OFF,
UnmountBeforeDetach: unmountBeforeDetach,
},
},
)

View File

@@ -2,9 +2,9 @@ package volume
import (
"fmt"
"github.com/libopenstorage/openstorage/api"
"github.com/libopenstorage/openstorage/api/client"
"github.com/libopenstorage/openstorage/volume"
"github.com/libopenstorage/openstorage/api"
)
// VolumeDriver returns a REST wrapper for the VolumeDriver interface.
@@ -12,10 +12,10 @@ func VolumeDriver(c *client.Client) volume.VolumeDriver {
return newVolumeClient(c)
}
// NewDriver returns a new REST client of the supplied version for specified driver.
// NewAuthDriverClient returns a new REST client of the supplied version for specified driver.
// host: REST endpoint [http://<ip>:<port> OR unix://<path-to-unix-socket>]. default: [unix:///var/lib/osd/<driverName>.sock]
// version: Volume API version
func NewDriverClient(host, driverName, version string) (*client.Client, error) {
func NewAuthDriverClient(host, driverName, version, authstring, accesstoken, userAgent string) (*client.Client, error) {
if driverName == "" {
return nil, fmt.Errorf("Driver Name cannot be empty")
}
@@ -26,7 +26,24 @@ func NewDriverClient(host, driverName, version string) (*client.Client, error) {
// Set the default version
version = volume.APIVersion
}
return client.NewClient(host, version)
return client.NewAuthClient(host, version, authstring, accesstoken, userAgent)
}
// NewDriverClient returns a new REST client of the supplied version for specified driver.
// host: REST endpoint [http://<ip>:<port> OR unix://<path-to-unix-socket>]. default: [unix:///var/lib/osd/<driverName>.sock]
// version: Volume API version
func NewDriverClient(host, driverName, version, userAgent string) (*client.Client, error) {
if driverName == "" {
return nil, fmt.Errorf("Driver Name cannot be empty")
}
if host == "" {
host = client.GetUnixServerPath(driverName, volume.DriverAPIBase)
}
if version == "" {
// Set the default version
version = volume.APIVersion
}
return client.NewClient(host, version, userAgent)
}
// GetSupportedDriverVersions returns a list of supported versions
@@ -38,7 +55,7 @@ func GetSupportedDriverVersions(driverName, host string) ([]string, error) {
host = client.GetUnixServerPath(driverName, volume.DriverAPIBase)
}
client, err := client.NewClient(host, "")
client, err := client.NewClient(host, "", "")
if err != nil {
return []string{}, err
}