diff --git a/pkg/oci/instance/metadata/instance_metadata.go b/pkg/oci/instance/metadata/instance_metadata.go index 5f5c5e7ecb..18df28bda9 100644 --- a/pkg/oci/instance/metadata/instance_metadata.go +++ b/pkg/oci/instance/metadata/instance_metadata.go @@ -18,7 +18,6 @@ import ( "encoding/json" "go.uber.org/zap" "net/http" - "strings" "time" "github.com/pkg/errors" @@ -69,19 +68,9 @@ func (m *metadataGetter) Get() (*InstanceMetadata, error) { func (m *metadataGetter) executeRequest(req *http.Request) (*InstanceMetadata, error) { req.Header.Add("Authorization", "Bearer Oracle") resp, err := m.client.Do(req) - if err != nil || resp.StatusCode != http.StatusOK { - zap.S().With(zap.Error(err)).Warn("Failed to get instance metadata with endpoint v2. Falling back to v1.") - if resp != nil { - v2resp := resp - defer v2resp.Body.Close() - } - v1Req := *req - v1Path := strings.Replace(req.URL.Path, "/opc/v2", "/opc/v1", 1) - v1Req.URL.Path = v1Path - resp, err = m.client.Do(&v1Req) - if err != nil { - return nil, errors.Wrap(err, "Failed to get instance metadata with v1 endpoint after falling back from v2 endpoint") - } + if err != nil { + zap.S().With(zap.Error(err)).Warn("Failed to get instance metadata with v2 endpoint.") + return nil, errors.Wrap(err, "Failed to get instance metadata with v2 endpoint") } zap.S().Infof("Metadata endpoint %s returned response successfully", req.URL.Path) @@ -89,7 +78,7 @@ func (m *metadataGetter) executeRequest(req *http.Request) (*InstanceMetadata, e if resp != nil { defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - return nil, errors.Errorf("metadata endpoint v1 returned status %d; expected 200 OK", resp.StatusCode) + return nil, errors.Errorf("metadata endpoint v2 returned status %d; expected 200 OK", resp.StatusCode) } } md := &InstanceMetadata{} diff --git a/pkg/oci/instance/metadata/instance_metadata_test.go b/pkg/oci/instance/metadata/instance_metadata_test.go index 1833493e3a..f06268e23f 100644 --- a/pkg/oci/instance/metadata/instance_metadata_test.go +++ b/pkg/oci/instance/metadata/instance_metadata_test.go @@ -51,21 +51,6 @@ func TestGetMetadata(t *testing.T) { expected Result handlerFunc http.HandlerFunc }{ - { - name: "metadata v1 response returned successfully", - endpoint: "opc/v1/instance", - expected: Result{ - metadata: &InstanceMetadata{ - CompartmentID: "ocid1.compartment.oc1..abc", - Region: "phx", - CanonicalRegionName: "us-phoenix-1", - }, - err: "", - }, - handlerFunc: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - fmt.Fprint(w, exampleResponse) - }), - }, { name: "metadata v2 response returned successfully", endpoint: "opc/v2/instance", @@ -82,36 +67,15 @@ func TestGetMetadata(t *testing.T) { }), }, { - name: "metadata v1 and v2 response returned error", + name: "metadata v2 response returned error", endpoint: "opc/v2/instance", expected: Result{ metadata: nil, - err: fmt.Sprintf("metadata endpoint v1 returned status %d; expected 200 OK", 404), - }, - handlerFunc: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if strings.Contains(r.URL.Path, "opc/v2") { - w.WriteHeader(404) - } else if strings.Contains(r.URL.Path, "opc/v1") { - w.WriteHeader(404) - } - }), - }, - { - name: "metadata v2 response returned error but v1 success", - endpoint: "opc/v2/instance", - expected: Result{ - metadata: &InstanceMetadata{ - CompartmentID: "ocid1.compartment.oc1..abc", - Region: "phx", - CanonicalRegionName: "us-phoenix-1", - }, - err: "", + err: fmt.Sprintf("metadata endpoint v2 returned status %d; expected 200 OK", 404), }, handlerFunc: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if strings.Contains(r.URL.Path, "opc/v2") { w.WriteHeader(404) - } else if strings.Contains(r.URL.Path, "opc/v1") { - fmt.Fprint(w, exampleResponse) } }), },