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

Bug 1803941: close helm request on error #4088

Conversation

akashshinde
Copy link
Contributor

@openshift-ci-robot openshift-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. component/backend Related to backend labels Jan 28, 2020
Copy link
Contributor

@pedjak pedjak left a 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.

@akashshinde
Copy link
Contributor Author

@pedjak updated the commit message

@akashshinde
Copy link
Contributor Author

cc @benjaminapetersen

@akashshinde
Copy link
Contributor Author

/test analyze

Copy link
Contributor

@pedjak pedjak left a 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.

@akashshinde
Copy link
Contributor Author

@pedjak we would need to add unit tests to test handlers.

@pedjak
Copy link
Contributor

pedjak commented Feb 7, 2020

akashshinde#3 demonstrates how to add unit tests

@openshift-ci-robot openshift-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 10, 2020
@@ -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
Copy link
Contributor

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

@@ -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,
Copy link
Contributor

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.

request := httptest.NewRequest("", "/foo", strings.NewReader("{}"))
response := httptest.NewRecorder()

fakeHandlers.HandleHelmList(&auth.User{}, response, request)
Copy link
Contributor

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?

@@ -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)})
Copy link
Contributor

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 Show resolved Hide resolved
t.Error("Failed to install release")
}
if bytes.Compare(response.Body.Bytes(), []byte(tt.expectedMsg)) != 0 {
t.Error("response body not matching")
Copy link
Contributor

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.

@@ -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) {
Copy link
Contributor

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.

@@ -0,0 +1,30 @@
package fake
Copy link
Contributor

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.

@@ -16,10 +18,29 @@ var (
plog = capnslog.NewPackageLogger("github.com/openshift/console", "helm")
)

func NewHelmHandler(apiUrl string, transport http.RoundTripper) *HelmHandlers {
Copy link
Contributor

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.

@@ -16,10 +18,29 @@ var (
plog = capnslog.NewPackageLogger("github.com/openshift/console", "helm")
)

func NewHelmHandler(apiUrl string, transport http.RoundTripper) *HelmHandlers {
return &HelmHandlers{
Copy link
Contributor

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.

ApiServerHost: s.KubeAPIServerURL,
Transport: s.K8sClient.Transport,
}
helmConfig := handlers.NewHelmHandler(s.KubeAPIServerURL, s.K8sClient.Transport)
Copy link
Contributor

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

@pedjak pedjak force-pushed the fix-odc-2871-helm-err-response branch from a407c21 to fe32f1a Compare February 13, 2020 18:51
@pedjak
Copy link
Contributor

pedjak commented Feb 13, 2020

/assign benjaminapetersen

@pedjak
Copy link
Contributor

pedjak commented Feb 14, 2020

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Feb 14, 2020
@pedjak
Copy link
Contributor

pedjak commented Feb 14, 2020

/test analyze

@pedjak
Copy link
Contributor

pedjak commented Feb 18, 2020

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Feb 18, 2020
@jhadvig
Copy link
Member

jhadvig commented Feb 18, 2020

/lgtm

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)
Copy link
Contributor

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)

@pedjak pedjak force-pushed the fix-odc-2871-helm-err-response branch from 96ff893 to 501ba2d Compare February 18, 2020 15:48
@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Feb 18, 2020

import (
"errors"
"helm.sh/helm/v3/pkg/action"
Copy link
Contributor

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.
@pedjak pedjak force-pushed the fix-odc-2871-helm-err-response branch from 501ba2d to c54d7e8 Compare February 18, 2020 16:04
@@ -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"
Copy link
Contributor

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?

Copy link
Contributor

@benjaminapetersen benjaminapetersen left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Feb 18, 2020
@openshift-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 18, 2020
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

1 similar comment
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@pedjak
Copy link
Contributor

pedjak commented Feb 18, 2020

/retest

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

4 similar comments
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-merge-robot openshift-merge-robot merged commit e5ea3e8 into openshift:master Feb 19, 2020
@openshift-ci-robot
Copy link
Contributor

@akashshinde: All pull requests linked via external trackers have merged. Bugzilla bug 1803941 has been moved to the MODIFIED state.

In response to this:

Bug 1803941: close helm request on error

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.

@christianvogt
Copy link
Contributor

I guess this missed the cut off for 4.4.
/cherrypick release-4.4

@openshift-cherrypick-robot

@christianvogt: new pull request created: #4412

In response to this:

I guess this missed the cut off for 4.4.
/cherrypick release-4.4

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.

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. bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. component/backend Related to backend lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants