Skip to content

Commit

Permalink
Get compartment from metadata when not set in cfg
Browse files Browse the repository at this point in the history
Fixes: #168
  • Loading branch information
jhorwit2 authored and prydie committed Apr 5, 2018
1 parent b456b5b commit 108a923
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/oci/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"k8s.io/client-go/tools/cache"

"github.com/golang/glog"
"github.com/oracle/oci-cloud-controller-manager/pkg/oci/instancemeta"
"github.com/oracle/oci-go-sdk/common"
"github.com/oracle/oci-go-sdk/core"
"github.com/oracle/oci-go-sdk/loadbalancer"
Expand Down Expand Up @@ -103,6 +104,15 @@ func New(config *Config) (Interface, error) {
subnetCache: cache.NewTTLStore(subnetCacheKeyFn, time.Duration(24)*time.Hour),
}

if config.Auth.CompartmentOCID == "" {
glog.Info("Compartment not supplied in config: attempting to infer from instance metadata")
metadata, err := instancemeta.New().Get()
if err != nil {
return nil, err
}
config.Auth.CompartmentOCID = metadata.CompartmentOCID
}

vcnID := config.VCNID
if vcnID == "" {
glog.Infof("No vcn provided in cloud provider config. Falling back to looking up VCN via LB subnet.")
Expand Down

0 comments on commit 108a923

Please sign in to comment.