Skip to content

Commit

Permalink
Merge pull request #318 from dims/automated-cherry-pick-of-#317-upstr…
Browse files Browse the repository at this point in the history
…eam-release-1.12

Automated cherry pick of #317: Export some methods in anticipation of a standalone cinder
  • Loading branch information
k8s-ci-robot authored Oct 9, 2018
2 parents 34be7c0 + a3f79b0 commit a9aac4a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
1 change: 1 addition & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions pkg/cloudprovider/providers/openstack/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,14 @@ type Config struct {
}

func init() {
registerMetrics()
RegisterMetrics()

cloudprovider.RegisterCloudProvider(ProviderName, func(config io.Reader) (cloudprovider.Interface, error) {
cfg, err := readConfig(config)
cfg, err := ReadConfig(config)
if err != nil {
return nil, err
}
return newOpenStack(cfg)
return NewOpenStack(cfg)
})
}

Expand Down Expand Up @@ -256,7 +256,7 @@ func configFromEnv() (cfg Config, ok bool) {
return
}

func readConfig(config io.Reader) (Config, error) {
func ReadConfig(config io.Reader) (Config, error) {
if config == nil {
return Config{}, fmt.Errorf("no OpenStack cloud provider config file given")
}
Expand Down Expand Up @@ -330,7 +330,7 @@ func checkOpenStackOpts(openstackOpts *OpenStack) error {
return checkMetadataSearchOrder(openstackOpts.metadataOpts.SearchOrder)
}

func newOpenStack(cfg Config) (*OpenStack, error) {
func NewOpenStack(cfg Config) (*OpenStack, error) {
provider, err := openstack.NewClient(cfg.Global.AuthURL)
if err != nil {
return nil, err
Expand Down
15 changes: 11 additions & 4 deletions pkg/cloudprovider/providers/openstack/openstack_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ limitations under the License.

package openstack

import "github.com/prometheus/client_golang/prometheus"
import (
"github.com/golang/glog"
"github.com/prometheus/client_golang/prometheus"
)

const (
openstackSubsystem = "openstack"
Expand Down Expand Up @@ -44,7 +47,11 @@ var (
)
)

func registerMetrics() {
prometheus.MustRegister(openstackOperationsLatency)
prometheus.MustRegister(openstackAPIRequestErrors)
func RegisterMetrics() {
if err := prometheus.Register(openstackOperationsLatency); err != nil {
glog.V(5).Infof("unable to register for latency metrics")
}
if err := prometheus.Register(openstackAPIRequestErrors); err != nil {
glog.V(5).Infof("unable to register for error metrics")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestRoutes(t *testing.T) {
t.Skipf("No config found in environment")
}

os, err := newOpenStack(cfg)
os, err := NewOpenStack(cfg)
if err != nil {
t.Fatalf("Failed to construct/authenticate OpenStack: %s", err)
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/cloudprovider/providers/openstack/openstack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func WaitForVolumeStatus(t *testing.T, os *OpenStack, volumeName string, status
}

func TestReadConfig(t *testing.T) {
_, err := readConfig(nil)
_, err := ReadConfig(nil)
if err == nil {
t.Errorf("Should fail when no config is provided: %s", err)
}
Expand All @@ -99,7 +99,7 @@ func TestReadConfig(t *testing.T) {
os.Setenv("OS_TENANT_NAME", "admin")
defer os.Unsetenv("OS_TENANT_NAME")

cfg, err := readConfig(strings.NewReader(`
cfg, err := ReadConfig(strings.NewReader(`
[Global]
auth-url = http://auth.url
user-id = user
Expand Down Expand Up @@ -613,7 +613,7 @@ func TestNewOpenStack(t *testing.T) {
t.Skip("No config found in environment")
}

_, err := newOpenStack(cfg)
_, err := NewOpenStack(cfg)
if err != nil {
t.Fatalf("Failed to construct/authenticate OpenStack: %s", err)
}
Expand All @@ -631,7 +631,7 @@ func TestLoadBalancer(t *testing.T) {
t.Logf("Trying LBVersion = '%s'\n", v)
cfg.LoadBalancer.LBVersion = v

os, err := newOpenStack(cfg)
os, err := NewOpenStack(cfg)
if err != nil {
t.Fatalf("Failed to construct/authenticate OpenStack: %s", err)
}
Expand Down Expand Up @@ -689,7 +689,7 @@ func TestVolumes(t *testing.T) {
t.Skip("No config found in environment")
}

os, err := newOpenStack(cfg)
os, err := NewOpenStack(cfg)
if err != nil {
t.Fatalf("Failed to construct/authenticate OpenStack: %s", err)
}
Expand Down

0 comments on commit a9aac4a

Please sign in to comment.