* Add Virtual Kubelet provider for OpenStack Zun Initial virtual kubelet provider for OpenStack Zun. This provider currently handles creating, starting and deleting a pod via OpenStack Zun. Currently the configmap and secret is not support in Zun. Currently the Volume is supported in Zun and will implementation the support in virtual kubelet in next several patches. Will add document to elaborate this development status. Change-Id: Id80f18d89b22c535214aef95254f5c3c7ae23139 Signed-off-by: Kevin Zhao <kevin.zhao@arm.com> * trying to fix dependencies Change-Id: I8e6f2e0234a11591ff2be74e22dca1fb91bf8f47 Signed-off-by: Davanum Srinivas <davanum@gmail.com> * Add dummy ExecInContainer method Change-Id: Idece5695bd81b0911538660526484895cdd8832c Signed-off-by: Davanum Srinivas <davanum@gmail.com> * better use of fmt.Errorf Change-Id: Ic402c80bd2302ac4f26b0025f110cbf9977ca862 Signed-off-by: Davanum Srinivas <davanum@gmail.com> * fix gofmt error Signed-off-by: Kevin Zhao <kevinzs2048@gmail.com> * add gophercloud vendor Signed-off-by: Kevin Zhao <kevinzs2048@gmail.com> * add provider register for openstack Signed-off-by: Kevin Zhao <kevinzs2048@gmail.com> * fix build error Signed-off-by: Kevin Zhao <kevinzs2048@gmail.com> * excluded aci test case Signed-off-by: Kevin Zhao <kevinzs2048@gmail.com> * Zun: several fixes on openstack provider * Remove 'zunCapStatusToPodPhase' since it is not used anymore. * Remove the handling of first container in capsule. * Remove 'ApiVersion' from CapsuleTemplate Signed-off-by: Hongbin Lu <hongbin034@gmail.com> * Update gophercloud to latest * Zun: use Zun API micro version 1.32 Signed-off-by: Hongbin Lu <hongbin034@gmail.com> * Zun: wait for capsule to be deleted Resource deletion in OpenStack Zun is asynchronous which means the resource is not deleted immediately right after the delete request. This commit make the provider wait for resource deletion to complete on DeletePod. Signed-off-by: Hongbin Lu <hongbin034@gmail.com> * Change the build tag to openstack_provider Signed-off-by: Hongbin Lu <hongbin034@gmail.com>
155 lines
5.1 KiB
Go
155 lines
5.1 KiB
Go
package gophercloud
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
// ServiceClient stores details required to interact with a specific service API implemented by a provider.
|
|
// Generally, you'll acquire these by calling the appropriate `New` method on a ProviderClient.
|
|
type ServiceClient struct {
|
|
// ProviderClient is a reference to the provider that implements this service.
|
|
*ProviderClient
|
|
|
|
// Endpoint is the base URL of the service's API, acquired from a service catalog.
|
|
// It MUST end with a /.
|
|
Endpoint string
|
|
|
|
// ResourceBase is the base URL shared by the resources within a service's API. It should include
|
|
// the API version and, like Endpoint, MUST end with a / if set. If not set, the Endpoint is used
|
|
// as-is, instead.
|
|
ResourceBase string
|
|
|
|
// This is the service client type (e.g. compute, sharev2).
|
|
// NOTE: FOR INTERNAL USE ONLY. DO NOT SET. GOPHERCLOUD WILL SET THIS.
|
|
// It is only exported because it gets set in a different package.
|
|
Type string
|
|
|
|
// The microversion of the service to use. Set this to use a particular microversion.
|
|
Microversion string
|
|
|
|
// MoreHeaders allows users (or Gophercloud) to set service-wide headers on requests. Put another way,
|
|
// values set in this field will be set on all the HTTP requests the service client sends.
|
|
MoreHeaders map[string]string
|
|
}
|
|
|
|
// ResourceBaseURL returns the base URL of any resources used by this service. It MUST end with a /.
|
|
func (client *ServiceClient) ResourceBaseURL() string {
|
|
if client.ResourceBase != "" {
|
|
return client.ResourceBase
|
|
}
|
|
return client.Endpoint
|
|
}
|
|
|
|
// ServiceURL constructs a URL for a resource belonging to this provider.
|
|
func (client *ServiceClient) ServiceURL(parts ...string) string {
|
|
return client.ResourceBaseURL() + strings.Join(parts, "/")
|
|
}
|
|
|
|
func (client *ServiceClient) initReqOpts(url string, JSONBody interface{}, JSONResponse interface{}, opts *RequestOpts) {
|
|
if v, ok := (JSONBody).(io.Reader); ok {
|
|
opts.RawBody = v
|
|
} else if JSONBody != nil {
|
|
opts.JSONBody = JSONBody
|
|
}
|
|
|
|
if JSONResponse != nil {
|
|
opts.JSONResponse = JSONResponse
|
|
}
|
|
|
|
if opts.MoreHeaders == nil {
|
|
opts.MoreHeaders = make(map[string]string)
|
|
}
|
|
|
|
if client.Microversion != "" {
|
|
client.setMicroversionHeader(opts)
|
|
}
|
|
}
|
|
|
|
// Get calls `Request` with the "GET" HTTP verb.
|
|
func (client *ServiceClient) Get(url string, JSONResponse interface{}, opts *RequestOpts) (*http.Response, error) {
|
|
if opts == nil {
|
|
opts = new(RequestOpts)
|
|
}
|
|
client.initReqOpts(url, nil, JSONResponse, opts)
|
|
return client.Request("GET", url, opts)
|
|
}
|
|
|
|
// Post calls `Request` with the "POST" HTTP verb.
|
|
func (client *ServiceClient) Post(url string, JSONBody interface{}, JSONResponse interface{}, opts *RequestOpts) (*http.Response, error) {
|
|
if opts == nil {
|
|
opts = new(RequestOpts)
|
|
}
|
|
client.initReqOpts(url, JSONBody, JSONResponse, opts)
|
|
return client.Request("POST", url, opts)
|
|
}
|
|
|
|
// Put calls `Request` with the "PUT" HTTP verb.
|
|
func (client *ServiceClient) Put(url string, JSONBody interface{}, JSONResponse interface{}, opts *RequestOpts) (*http.Response, error) {
|
|
if opts == nil {
|
|
opts = new(RequestOpts)
|
|
}
|
|
client.initReqOpts(url, JSONBody, JSONResponse, opts)
|
|
return client.Request("PUT", url, opts)
|
|
}
|
|
|
|
// Patch calls `Request` with the "PATCH" HTTP verb.
|
|
func (client *ServiceClient) Patch(url string, JSONBody interface{}, JSONResponse interface{}, opts *RequestOpts) (*http.Response, error) {
|
|
if opts == nil {
|
|
opts = new(RequestOpts)
|
|
}
|
|
client.initReqOpts(url, JSONBody, JSONResponse, opts)
|
|
return client.Request("PATCH", url, opts)
|
|
}
|
|
|
|
// Delete calls `Request` with the "DELETE" HTTP verb.
|
|
func (client *ServiceClient) Delete(url string, opts *RequestOpts) (*http.Response, error) {
|
|
if opts == nil {
|
|
opts = new(RequestOpts)
|
|
}
|
|
client.initReqOpts(url, nil, nil, opts)
|
|
return client.Request("DELETE", url, opts)
|
|
}
|
|
|
|
// Head calls `Request` with the "HEAD" HTTP verb.
|
|
func (client *ServiceClient) Head(url string, opts *RequestOpts) (*http.Response, error) {
|
|
if opts == nil {
|
|
opts = new(RequestOpts)
|
|
}
|
|
client.initReqOpts(url, nil, nil, opts)
|
|
return client.Request("HEAD", url, opts)
|
|
}
|
|
|
|
func (client *ServiceClient) setMicroversionHeader(opts *RequestOpts) {
|
|
switch client.Type {
|
|
case "compute":
|
|
opts.MoreHeaders["X-OpenStack-Nova-API-Version"] = client.Microversion
|
|
case "sharev2":
|
|
opts.MoreHeaders["X-OpenStack-Manila-API-Version"] = client.Microversion
|
|
case "volume":
|
|
opts.MoreHeaders["X-OpenStack-Volume-API-Version"] = client.Microversion
|
|
case "baremetal":
|
|
opts.MoreHeaders["X-OpenStack-Ironic-API-Version"] = client.Microversion
|
|
case "baremetal-introspection":
|
|
opts.MoreHeaders["X-OpenStack-Ironic-Inspector-API-Version"] = client.Microversion
|
|
}
|
|
|
|
if client.Type != "" {
|
|
opts.MoreHeaders["OpenStack-API-Version"] = client.Type + " " + client.Microversion
|
|
}
|
|
}
|
|
|
|
// Request carries out the HTTP operation for the service client
|
|
func (client *ServiceClient) Request(method, url string, options *RequestOpts) (*http.Response, error) {
|
|
if len(client.MoreHeaders) > 0 {
|
|
if options == nil {
|
|
options = new(RequestOpts)
|
|
}
|
|
for k, v := range client.MoreHeaders {
|
|
options.MoreHeaders[k] = v
|
|
}
|
|
}
|
|
return client.ProviderClient.Request(method, url, options)
|
|
}
|