Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't require a compartment #82

Merged
merged 2 commits into from
Oct 30, 2017
Merged

Don't require a compartment #82

merged 2 commits into from
Oct 30, 2017

Conversation

alapidas
Copy link
Contributor

Fixes #81

return metadata, nil
}

// A concrete InstanceMetadataService implementation.
Copy link
Member

@owainlewis owainlewis Oct 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor lint error which failed build

comment on exported function InstanceMetadataFromAPI should be of the form "InstanceMetadataFromAPI ...

// InstanceMetadataFromAPI returns a ...

}
defer rs.Body.Close()

body, err := ioutil.ReadAll(rs.Body)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should just be

md := &InstanceMetadata{}
err = json.NewDecoder(rs.Body).Decode(md)
if err != nil {
  return nil, err
}

return md, nil

and you can delete the other method


const (
instanceMetaDataAPI = "http://169.254.169.254"
instanceMetaDataEndpoint = instanceMetaDataAPI + "/opc/v1/instance/"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/MetaData/Metadata

t.Fatalf("Got unexpected error %s", err)
}
if metadata.InstanceOCID != expected.InstanceOCID {
t.Fatalf("%v != %v", metadata.InstanceOCID, expected.InstanceOCID)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use Errorf for these checks.

}
defer rs.Body.Close()

body, err := ioutil.ReadAll(rs.Body)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should make sure the status code is OK.

@@ -148,9 +148,19 @@ func New(cfg *Config) (Interface, error) {
return nil, err
}

compartmentOCID := cfg.Auth.CompartmentOCID
if compartmentOCID == "" {
glog.Info("Compartment not supplied in config - attempting to infer from instance metadata")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Compartment/compartment since it's not capitalized in the config.

)

// InstanceMetadata holds OCI API details about the node the driver is executing
// on.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

// InstanceMetadataService defines a capability to obtain the OCI InstanceMetadata.
type InstanceMetadataService func() (*InstanceMetadata, error)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used anywhere? If not I recommend removing it.


body, err := ioutil.ReadAll(rs.Body)
if err != nil {
return nil, fmt.Errorf("failed to read node api metadata: %s", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/node/instance for these errors since it's the instance metadata endpoint & struct.

@alapidas
Copy link
Contributor Author

So ... the instance metadata code was copied wholesale from https://github.com/oracle/oci-volume-provisioner/blob/master/cmd/oci-volume-provisioner/instance_metadata.go in an attempt to quickly get this working. Would it make more sense to just import from oci-flexvolume-provisioner instead and it can be improved upon in that repository?

@jhorwit2

@jhorwit2
Copy link
Member

We can just land it as is and I'll clean it up later. That's ok with me. I don't see anything that's a show stopper.

I'd prefer to not share code that way since that adds dependencies across projects (e.g. one may be public before the other and depending on layout you could be forced to share dependencies). IMO, it'd be nicest to have a metadata part added to the go sdk 👼 .

@prydie
Copy link
Contributor

prydie commented Oct 23, 2017

I recently rewrote the instance metadata code in the Flexvolume driver (https://github.com/oracle/oci-flexvolume-driver/blob/master/pkg/oci/instancemeta/instance_metadata.go). Some of your comments still apply @jhorwit2 so I'll apply them to the Flexvolume repos and then open a PR here with the updated code if everyone's happy w/ that.

prydie added a commit to oracle/oci-flexvolume-driver that referenced this pull request Oct 23, 2017
@alapidas
Copy link
Contributor Author

That sounds fine w/me. I am having some trouble testing this fix out in an OKE cluster, but will update the MR once I can test it end2end.

@prydie prydie force-pushed the task/dontRequireCompartment branch from 7553688 to 27fc5ec Compare October 30, 2017 16:14
@prydie prydie force-pushed the task/dontRequireCompartment branch from 27fc5ec to bc1d32c Compare October 30, 2017 16:18
@prydie prydie changed the title WIP: Don't require a compartment Don't require a compartment Oct 30, 2017
// Get either returns the cached metadata for the current instance or queries
// the instance metadata API, populates the cache, and returns the result.
func (m *metadataGetter) Get() (*InstanceMetadata, error) {
req, err := http.NewRequest("GET", m.baseURL+metadataEndpoint, nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should use path.Join(m.baseURL, metadataEndpoint)

"testing"
)

const exampleResponse = `{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: test cases should live in the test method itself or be the return of a helper func.

@jhorwit2 jhorwit2 merged commit 734a28c into master Oct 30, 2017
@prydie prydie deleted the task/dontRequireCompartment branch October 30, 2017 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants