Skip to content

Commit d72adf0

Browse files
flaper87k8s-ci-robot
authored andcommitted
Let clientconfig create the AuthOptions instance (openshift#70)
We were creating our own copy of AuthOptions rather than relying on the utilities provided by clientconfig. Our copy didn't have all the info required by gophercloud to authenticate. Closes openshift#69
1 parent ed3cfbd commit d72adf0

File tree

4 files changed

+15
-28
lines changed

4 files changed

+15
-28
lines changed

config/manager/manager.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ spec:
6060
- name: machine-setup
6161
mountPath: /etc/machinesetup
6262
- name: cloud-config
63-
mountPath: /etc/cloud
63+
mountPath: /etc/openstack
6464
- name: kubeadm
6565
mountPath: /usr/bin/kubeadm
6666
resources:
@@ -70,6 +70,11 @@ spec:
7070
limits:
7171
cpu: 100m
7272
memory: 30Mi
73+
env:
74+
- name: USER
75+
value: root
76+
- name: OS_CLOUD
77+
value: openstack
7378
volumes:
7479
- name: config
7580
hostPath:

pkg/cloud/openstack/clients/machineservice.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,11 @@ type InstanceListOpts struct {
6868
Name string `q:"name"`
6969
}
7070

71-
func NewInstanceService(cfg *clientconfig.Cloud) (*InstanceService, error) {
72-
opts := &gophercloud.AuthOptions{
73-
IdentityEndpoint: cfg.AuthInfo.AuthURL,
74-
Username: cfg.AuthInfo.Username,
75-
Password: cfg.AuthInfo.Password,
76-
DomainName: cfg.AuthInfo.DomainName,
77-
TenantID: cfg.AuthInfo.ProjectDomainID,
78-
TenantName: cfg.AuthInfo.ProjectDomainName,
79-
TokenID: cfg.AuthInfo.Token,
80-
AllowReauth: true,
71+
func NewInstanceService() (*InstanceService, error) {
72+
clientOpts := new(clientconfig.ClientOpts)
73+
opts, err := clientconfig.AuthOptions(clientOpts)
74+
if err != nil {
75+
return nil, err
8176
}
8277
provider, err := openstack.AuthenticatedClient(*opts)
8378
if err != nil {
@@ -91,7 +86,7 @@ func NewInstanceService(cfg *clientconfig.Cloud) (*InstanceService, error) {
9186
return nil, fmt.Errorf("Create identityClient err: %v", err)
9287
}
9388
serverClient, err := openstack.NewComputeV2(provider, gophercloud.EndpointOpts{
94-
Region: cfg.RegionName,
89+
Region: clientOpts.RegionName,
9590
})
9691
if err != nil {
9792
return nil, fmt.Errorf("Create serviceClient err: %v", err)

pkg/cloud/openstack/clients/machineservice_test.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,11 @@ package clients
1919
import (
2020
"strings"
2121
"testing"
22-
23-
"github.com/gophercloud/utils/openstack/clientconfig"
2422
)
2523

2624
func TestMachineServiceInstance(t *testing.T) {
27-
clientOpts := new(clientconfig.ClientOpts)
28-
cloud, err := clientconfig.GetCloudFromYAML(clientOpts)
29-
if err != nil {
30-
t.Errorf("Couldn't create clientconfig")
31-
}
32-
_, err = NewInstanceService(cloud)
33-
if !(strings.Contains(err.Error(), "i/o timeout")) {
25+
_, err := NewInstanceService()
26+
if !(strings.Contains(err.Error(), "[auth_url]")) {
3427
t.Errorf("Couldn't create instance service: %v", err)
3528
}
3629
}

pkg/cloud/openstack/machineactuator.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929

3030
"github.com/ghodss/yaml"
3131
"github.com/golang/glog"
32-
"github.com/gophercloud/utils/openstack/clientconfig"
3332
"k8s.io/apimachinery/pkg/runtime"
3433

3534
openstackconfigv1 "sigs.k8s.io/cluster-api-provider-openstack/pkg/apis/openstackproviderconfig/v1alpha1"
@@ -72,12 +71,7 @@ type OpenstackClient struct {
7271
}
7372

7473
func NewMachineActuator(machineClient client.Client, scheme *runtime.Scheme) (*OpenstackClient, error) {
75-
clientOpts := new(clientconfig.ClientOpts)
76-
cloud, err := clientconfig.GetCloudFromYAML(clientOpts)
77-
if err != nil {
78-
return nil, err
79-
}
80-
machineService, err := clients.NewInstanceService(cloud)
74+
machineService, err := clients.NewInstanceService()
8175
if err != nil {
8276
return nil, err
8377
}

0 commit comments

Comments
 (0)