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

Reimplement a way to retrieve an aws-sdk-go-v2 config from backplane #257

Merged
merged 2 commits into from
Nov 19, 2023

Conversation

mjlshen
Copy link
Contributor

@mjlshen mjlshen commented Nov 18, 2023

What type of PR is this?

bug/feature

What this PR does / Why we need it?

This functionality was originally added in #66, but was mistakenly removed in #237

Since we are now required to pass AWS calls through a proxy, this PR adds additional logic to ensure the aws-sdk-go-v2 client returned by this function enforces the use of the provided proxy_url in a user's backplane config file.

Which Jira/Github issue(s) does this PR fix?

OSD-19711

Special notes for your reviewer

This is semi-urgent to merge+release because osdctl builds an aws-sdk-go-v2 client using this function https://github.com/openshift/osdctl/blob/1b906de67017e15057a6312d698ac28565250941/pkg/osdCloud/aws.go#L182-L190 pinned on an older version where it still exists: https://github.com/openshift/osdctl/blob/1b906de67017e15057a6312d698ac28565250941/go.mod#L38 so SRE's using commands like osdctl network verify-egress, osdctl cluster resize infra, etc. are not going through the proxy configured in backplane.

Pre-checks (if applicable)

  • Ran unit tests locally
  • Validated the changes in a cluster
  • Included documentation changes with PR

@mjlshen
Copy link
Contributor Author

mjlshen commented Nov 18, 2023

On the testing side, I modified osdctl to build off my local copy of backplane-cli and verified that osdctl network verify-egress now uses the proxy with these fixes. openshift/osdctl#482

@codecov-commenter
Copy link

codecov-commenter commented Nov 18, 2023

Codecov Report

Merging #257 (b75e6ce) into main (23570ca) will decrease coverage by 3.22%.
The diff coverage is 14.08%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #257      +/-   ##
==========================================
- Coverage   51.87%   48.66%   -3.22%     
==========================================
  Files          52       52              
  Lines        3433     3438       +5     
==========================================
- Hits         1781     1673     -108     
- Misses       1357     1504     +147     
+ Partials      295      261      -34     
Files Coverage Δ
cmd/ocm-backplane/cloud/common.go 59.64% <100.00%> (-33.58%) ⬇️
pkg/utils/cluster.go 88.23% <ø> (+3.32%) ⬆️
pkg/utils/ocmWrapper.go 0.00% <0.00%> (ø)
pkg/credentials/aws.go 21.05% <0.00%> (-78.95%) ⬇️
cmd/ocm-backplane/cloud/credentials.go 40.31% <0.00%> (-22.19%) ⬇️

... and 3 files with indirect coverage changes

@mjlshen mjlshen force-pushed the OSD-19711 branch 2 times, most recently from 4d2a30c to a644f77 Compare November 19, 2023 20:25
This was originally added in #66, but was mistakenly removed in #237

Since we are now required to pass AWS calls through a proxy, this PR
adds additional logic to ensure the aws-sdk-go-v2 client returned by
this function enforces the use of the provided proxy_url in a user's
backplane config file.

Signed-off-by: Michael Shen <mshen@redhat.com>
Comment on lines -162 to -183
It("should fail when AWS Unavailable", func() {
fakeAWSResp.StatusCode = http.StatusInternalServerError

mockClientUtil.EXPECT().GetBackplaneClient(proxyURI).Return(mockClient, nil).AnyTimes()
mockClient.EXPECT().GetCloudCredentials(gomock.Any(), trueClusterID).Return(fakeAWSResp, nil)
_, err := getCloudCredential(proxyURI, trueClusterID)
Expect(err).NotTo(BeNil())

Expect(err.Error()).To(ContainSubstring("error from backplane: \n Status Code: 500\n"))

})

It("should fail when GCP Unavailable", func() {
fakeGCloudResp.StatusCode = http.StatusInternalServerError

mockClientUtil.EXPECT().GetBackplaneClient(proxyURI).Return(mockClient, nil).AnyTimes()
mockClient.EXPECT().GetCloudCredentials(gomock.Any(), trueClusterID).Return(fakeGCloudResp, nil)
_, err := getCloudCredential(proxyURI, trueClusterID)
Expect(err).NotTo(BeNil())

Expect(err.Error()).To(ContainSubstring("error from backplane: \n Status Code: 500\n"))

Copy link
Contributor

Choose a reason for hiding this comment

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

Any reson to remove existing tests with AWS v2 approch ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm ok with receiving pushback on this, but to share my reasoning mostly because they aren't passing anymore and it's critical to make sure that osdctl AWS calls are going through the proxy haha.

My personal preference is to refactor/add some tests back in a future PR, but I can add it into this PR if that's best. My functional "changes" are in the first commit in the PR and you can see all the refactored/mostly removed tests in the second commit.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point, @mjlshen .. Let's add/refactor unit-test in future PR's .. ( we are on a journey to reach 80% code coverage for bp-cli :) )

Comment on lines +53 to +56
proxyURL, err := url.Parse(bpConfig.ProxyURL)
if err != nil {
return aws.Config{}, fmt.Errorf("failed to parse proxy_url from backplane config file: %w", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This may already checked when login to the cluster

if config.ProxyURL != "" {

Copy link
Contributor Author

@mjlshen mjlshen Nov 19, 2023

Choose a reason for hiding this comment

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

Yeah, but this function will not be called after ocm backplane login - e.g. https://github.com/openshift/osdctl/blob/1b906de67017e15057a6312d698ac28565250941/pkg/osdCloud/aws.go#L182-L190 so we cannot depend on that check

Though in general, ocm backplane cloud * can be called without needing to ocm backplane login

Copy link
Contributor

Choose a reason for hiding this comment

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

ahh got your point, We should move all config validation to pkg/cli/config rather than individual sub-commands .. I'll create a card for moving that. I'm fine to keep it here for now.

Copy link
Member

Choose a reason for hiding this comment

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

thanks @samanthajayasinghe , let's create a card for tracking this.

Signed-off-by: Michael Shen <mshen@redhat.com>
Copy link
Contributor

openshift-ci bot commented Nov 19, 2023

@mjlshen: all tests passed!

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@wanghaoran1988
Copy link
Member

/lgtm
/approve

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Nov 19, 2023
Copy link
Contributor

openshift-ci bot commented Nov 19, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mjlshen, wanghaoran1988

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 19, 2023
@openshift-merge-bot openshift-merge-bot bot merged commit aa6130d into openshift:main Nov 19, 2023
7 checks passed
@mjlshen mjlshen deleted the OSD-19711 branch November 19, 2023 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants