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
Bug 1803941: close helm request on error #4088
Bug 1803941: close helm request on error #4088
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should have some tests that could catch regressions later. Also the commit message could be improved to describe what we are fixing.
7781f5f
to
d107f9b
Compare
@pedjak updated the commit message |
/test analyze |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add tests that could catch later regressions.
@pedjak we would need to add unit tests to test handlers. |
akashshinde#3 demonstrates how to add unit tests |
pkg/helm/handlers/handlers.go
Outdated
@@ -20,6 +21,14 @@ var ( | |||
type HelmHandlers struct { | |||
ApiServerHost string | |||
Transport http.RoundTripper | |||
|
|||
// helm action configurator | |||
GetActionConfigurations func(string, string, string, *http.RoundTripper) *action.Configuration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no need to make these functions public, see akashshinde#3
pkg/server/server.go
Outdated
@@ -302,8 +303,12 @@ func (s *Server) HTTPHandler() http.Handler { | |||
|
|||
// Helm Endpoints | |||
helmConfig := &handlers.HelmHandlers{ | |||
ApiServerHost: s.KubeAPIServerURL, | |||
Transport: s.K8sClient.Transport, | |||
ApiServerHost: s.KubeAPIServerURL, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use a constructor, as demonstrated in akashshinde#3 - server
does not need to know anything about actions
package.
pkg/helm/handlers/handler_test.go
Outdated
request := httptest.NewRequest("", "/foo", strings.NewReader("{}")) | ||
response := httptest.NewRecorder() | ||
|
||
fakeHandlers.HandleHelmList(&auth.User{}, response, request) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see here no assertions.. how do we know if the test passes/fails?
pkg/helm/handlers/handlers.go
Outdated
@@ -43,7 +43,7 @@ func (h *HelmHandlers) HandleHelmRenderManifests(user *auth.User, w http.Respons | |||
conf := h.GetActionConfigurations(h.ApiServerHost, req.Namespace, user.Token, &h.Transport) | |||
resp, err := h.RenderManifests(req.Name, req.ChartUrl, req.Values, conf) | |||
if err != nil { | |||
serverutils.SendResponse(w, http.StatusBadGateway, serverutils.ApiError{fmt.Sprintf("Failed to render manifests: %v", err)}) | |||
serverutils.SendResponse(w, http.StatusBadRequest, serverutils.ApiError{fmt.Sprintf("Failed to render manifests: %v", err)}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we changing contract here? The ticket is about fixing a bug, we should not change the contract. If really needed, we should open another ticket for that.
pkg/helm/handlers/handler_test.go
Outdated
t.Error("Failed to install release") | ||
} | ||
if bytes.Compare(response.Body.Bytes(), []byte(tt.expectedMsg)) != 0 { | ||
t.Error("response body not matching") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would display here what was expected and what was received - it would help to spot the issue faster.
pkg/helm/fake/fake_actions.go
Outdated
@@ -17,6 +18,10 @@ func InstallChart(ns string, name string, url string, values map[string]interfac | |||
}, nil | |||
} | |||
|
|||
func InstallChartFailed(ns string, name string, url string, values map[string]interface{}, conf *action.Configuration) (*release.Release, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move these functions close to the tests, i.e. into the very same test file.
8c541b7
to
a407c21
Compare
pkg/helm/fake/fake_actions.go
Outdated
@@ -0,0 +1,30 @@ | |||
package fake |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you have introduced here a package that could be accessed and used from the production code as well, and IMHO we should avoid that. Thus, I propose that we move the content of this file in handler_test.go
. This allows us as well to make all functions private.
pkg/helm/handlers/handlers.go
Outdated
@@ -16,10 +18,29 @@ var ( | |||
plog = capnslog.NewPackageLogger("github.com/openshift/console", "helm") | |||
) | |||
|
|||
func NewHelmHandler(apiUrl string, transport http.RoundTripper) *HelmHandlers { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the package name is handler
, thus no need to repeat that in this constructor, I would say NewContext
, because this structure represent now a context.
pkg/helm/handlers/handlers.go
Outdated
@@ -16,10 +18,29 @@ var ( | |||
plog = capnslog.NewPackageLogger("github.com/openshift/console", "helm") | |||
) | |||
|
|||
func NewHelmHandler(apiUrl string, transport http.RoundTripper) *HelmHandlers { | |||
return &HelmHandlers{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's give a better name to this structure, it is a kind of context, thus let's call it helmContext
- the structure does not need to public anymore.
pkg/server/server.go
Outdated
ApiServerHost: s.KubeAPIServerURL, | ||
Transport: s.K8sClient.Transport, | ||
} | ||
helmConfig := handlers.NewHelmHandler(s.KubeAPIServerURL, s.K8sClient.Transport) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's rename it to helmContext
a407c21
to
fe32f1a
Compare
/assign benjaminapetersen |
fe32f1a
to
a3f55f6
Compare
/lgtm |
/test analyze |
/lgtm |
/lgtm |
pkg/server/server.go
Outdated
handle("/api/helm/template", authHandlerWithUser(helmConfig.HandleHelmRenderManifests)) | ||
handle("/api/helm/releases", authHandlerWithUser(helmConfig.HandleHelmList)) | ||
handle("/api/helm/release", authHandlerWithUser(helmConfig.HandleHelmInstall)) | ||
helmHandlers := helmHandlers.New(s.KubeAPIServerURL, s.K8sClient.Transport) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're redefining here, no?
// camel case the var, don't camelcase the package.
helmHandlers := helmhandlers.New(s.KubeAPIServerURL, s.K8sClient.Transport)
If this is confusing, you can do:
// make the package even more clear (convention is not to camel case the import)
helmhandlerspkg "github.com/openshift/console/pkg/helm/handlers"
// and this isn't such a subtle difference
helmHandlers := helmhandlerspkg.New(s.KubeAPIServerURL, s.K8sClient.Transport)
96ff893
to
501ba2d
Compare
pkg/helm/handlers/handler_test.go
Outdated
|
||
import ( | ||
"errors" | ||
"helm.sh/helm/v3/pkg/action" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imports order, puts yours together:
import(
// std lib
"errors"
"strings"
....
// deps
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/release"
// operator
"github.com/openshift/console/pkg/auth"
...
// yours, if any
)
Code refactored a bit so that unit tests could be written.
501ba2d
to
c54d7e8
Compare
@@ -20,7 +20,7 @@ export GOFLAGS="-mod=vendor" | |||
# Invoke ./cover for HTML output | |||
COVER=${COVER:-"-cover"} | |||
|
|||
TESTABLE="pkg/auth pkg/proxy pkg/server" | |||
TESTABLE="pkg/auth pkg/proxy pkg/server pkg/helm/actions pkg/helm/handlers" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pedjak want to open a follow where we change this to cmd pkg
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: akashshinde, benjaminapetersen, jhadvig, pedjak 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 |
/retest Please review the full test history for this PR and help us cut down flakes. |
1 similar comment
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest |
/retest Please review the full test history for this PR and help us cut down flakes. |
4 similar comments
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
@akashshinde: All pull requests linked via external trackers have merged. Bugzilla bug 1803941 has been moved to the MODIFIED state. In response to this:
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 guess this missed the cut off for 4.4. |
@christianvogt: new pull request created: #4412 In response to this:
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. |
This PR fixes: https://issues.redhat.com/browse/ODC-2871