-
Notifications
You must be signed in to change notification settings - Fork 468
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
feat: Flux app detail #5331
Closed
Closed
feat: Flux app detail #5331
Changes from 42 commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
57e2b33
app list logic completed and proto is yet to generate
6852607
resolved the proto file issue
RajeevRanjan27 71dbc35
modified the proto and go routine call handling
RajeevRanjan27 8e74bfd
corrected the proto file datatype changes
RajeevRanjan27 8a8f760
applied the list of flux apps in given cluster
ae6f68a
resolved the conversations
3bf74dd
incorporated the review changes
27a0d9b
modified the fluxhandler and handlled the errros
668a1ad
resolved the coversations
5f3a04b
implemented the flush for streaming the data to client
41ee5d5
resolve the conflicts
53dc30a
incorporated comments
7d71b8c
Merge branch 'main' into flux-app-list
6137d5c
Added the spec file for fluxcd App listing
60fc2e2
Merge branch 'main' into flux-app-list
693ad55
Merge branch 'main' into flux-app-list
eb3befc
added the app type in the struct
RajeevRanjan27 87f0611
changed the fluxAppType data type
RajeevRanjan27 8f8b4a9
resolve
RajeevRanjan27 78df27f
resolve
RajeevRanjan27 80251ff
redefined the query params to process with
RajeevRanjan27 0c24d05
specs for flux app list added
RajeevRanjan27 134e08c
Merge branch 'main' into flux-app-list
RajeevRanjan27 3184637
Merge branch 'flux-app-list' into flux-app-detail
RajeevRanjan27 560a344
added the flux app detail
RajeevRanjan27 77db907
minor changes around the app listing response
RajeevRanjan27 74d47b5
Resolved the decoder appId function
RajeevRanjan27 4fb9e37
Added the spec for the app detail api
RajeevRanjan27 c82fa28
changed the field of flux app detail dto
RajeevRanjan27 9a855a6
taken merge from flux-app-list
RajeevRanjan27 a345b10
taken merge from main and grpc code resolved
RajeevRanjan27 252d199
taken merge from main and wire run
RajeevRanjan27 df08766
handled the error in listing of apps with errror field in grpc
RajeevRanjan27 4c23e11
Revert "taken merge from main and wire run"
RajeevRanjan27 9b09b56
Revert "handled the error in listing of apps with errror field in grpc"
RajeevRanjan27 24abc12
Added the error in the Listing of flux apps
RajeevRanjan27 b9106bf
Merge remote-tracking branch 'origin/flux-app-detail' into flux-app-d…
RajeevRanjan27 31148ad
generated the grpc code
RajeevRanjan27 efd2814
modified the logic for error handling in flux app listing and app det…
RajeevRanjan27 4e19367
Merge branch 'main' into flux-app-detail
RajeevRanjan27 5db5e18
took merge from main and run make
RajeevRanjan27 0eaf481
added the handler message for the root app i.e flux-system
RajeevRanjan27 7c03c65
minor changes: resolved the review comments after review
RajeevRanjan27 7726cdf
Merge branch 'main' into flux-app-detail
RajeevRanjan27 90982a9
took merge from main and executed the make cmd too
RajeevRanjan27 891a43d
added the debugger points in the flux app listing
RajeevRanjan27 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package fluxApplication | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"github.com/devtron-labs/devtron/api/restHandler/common" | ||
"github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin" | ||
clientErrors "github.com/devtron-labs/devtron/pkg/errors" | ||
"github.com/devtron-labs/devtron/pkg/fluxApplication" | ||
"github.com/gorilla/mux" | ||
"go.uber.org/zap" | ||
"net/http" | ||
) | ||
|
||
type FluxApplicationRestHandler interface { | ||
ListFluxApplications(w http.ResponseWriter, r *http.Request) | ||
GetApplicationDetail(w http.ResponseWriter, r *http.Request) | ||
} | ||
|
||
type FluxApplicationRestHandlerImpl struct { | ||
fluxApplicationService fluxApplication.FluxApplicationService | ||
logger *zap.SugaredLogger | ||
enforcer casbin.Enforcer | ||
} | ||
|
||
func NewFluxApplicationRestHandlerImpl(fluxApplicationService fluxApplication.FluxApplicationService, | ||
logger *zap.SugaredLogger, enforcer casbin.Enforcer) *FluxApplicationRestHandlerImpl { | ||
return &FluxApplicationRestHandlerImpl{ | ||
fluxApplicationService: fluxApplicationService, | ||
logger: logger, | ||
enforcer: enforcer, | ||
} | ||
|
||
} | ||
|
||
func (handler *FluxApplicationRestHandlerImpl) ListFluxApplications(w http.ResponseWriter, r *http.Request) { | ||
|
||
//handle super-admin RBAC | ||
token := r.Header.Get("token") | ||
if ok := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionGet, "*"); !ok { | ||
common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden) | ||
return | ||
} | ||
v := r.URL.Query() | ||
clusterIdString := v.Get("clusterIds") | ||
var clusterIds []int | ||
var err error | ||
|
||
//handling when the clusterIds string is empty ,it will not support the | ||
if len(clusterIdString) == 0 { | ||
handler.logger.Errorw("error in getting cluster ids", "error", err, "clusterIds", clusterIds) | ||
common.WriteJsonResp(w, errors.New("error in getting cluster ids"), nil, http.StatusBadRequest) | ||
return | ||
} | ||
clusterIds, err = common.ExtractIntArrayQueryParam(w, r, "clusterIds") | ||
if err != nil { | ||
handler.logger.Errorw("error in getting cluster ids", "error", err, "clusterIds", clusterIds) | ||
return | ||
} | ||
handler.fluxApplicationService.ListFluxApplications(r.Context(), clusterIds, w) | ||
} | ||
|
||
func (handler *FluxApplicationRestHandlerImpl) GetApplicationDetail(w http.ResponseWriter, r *http.Request) { | ||
vars := mux.Vars(r) | ||
clusterIdString := vars["appId"] | ||
RajeevRanjan27 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
appIdentifier, err := fluxApplication.DecodeFluxExternalAppAppId(clusterIdString) | ||
if err != nil { | ||
common.WriteJsonResp(w, err, nil, http.StatusBadRequest) | ||
return | ||
} | ||
if appIdentifier.IsKustomizeApp == true && appIdentifier.Name == "flux-system" && appIdentifier.Namespace == "flux-system" { | ||
|
||
Comment on lines
+71
to
+72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make "flux-system" constant |
||
common.WriteJsonResp(w, errors.New("cannot proceed for the flux system root level "), nil, http.StatusBadRequest) | ||
return | ||
} | ||
|
||
// handle super-admin RBAC | ||
token := r.Header.Get("token") | ||
if ok := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionGet, "*"); !ok { | ||
common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden) | ||
return | ||
} | ||
|
||
res, err := handler.fluxApplicationService.GetFluxAppDetail(context.Background(), appIdentifier) | ||
if err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. context.Background() -> r.Context() |
||
apiError := clientErrors.ConvertToApiError(err) | ||
if apiError != nil { | ||
err = apiError | ||
} | ||
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) | ||
return | ||
} | ||
common.WriteJsonResp(w, err, res, http.StatusOK) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package fluxApplication | ||
|
||
import ( | ||
"github.com/gorilla/mux" | ||
) | ||
|
||
type FluxApplicationRouter interface { | ||
InitFluxApplicationRouter(fluxApplicationRouter *mux.Router) | ||
} | ||
|
||
type FluxApplicationRouterImpl struct { | ||
fluxApplicationRestHandler FluxApplicationRestHandler | ||
} | ||
|
||
func NewFluxApplicationRouterImpl(fluxApplicationRestHandler FluxApplicationRestHandler) *FluxApplicationRouterImpl { | ||
return &FluxApplicationRouterImpl{ | ||
fluxApplicationRestHandler: fluxApplicationRestHandler, | ||
} | ||
} | ||
|
||
func (impl *FluxApplicationRouterImpl) InitFluxApplicationRouter(fluxApplicationRouter *mux.Router) { | ||
fluxApplicationRouter.Path(""). | ||
Methods("GET"). | ||
HandlerFunc(impl.fluxApplicationRestHandler.ListFluxApplications) | ||
fluxApplicationRouter.Path("/app").Queries("appId", "{appId}"). | ||
HandlerFunc(impl.fluxApplicationRestHandler.GetApplicationDetail).Methods("GET") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package fluxApplication | ||
|
||
import ( | ||
"github.com/devtron-labs/devtron/pkg/fluxApplication" | ||
"github.com/google/wire" | ||
) | ||
|
||
var FluxApplicationWireSet = wire.NewSet( | ||
fluxApplication.NewFluxApplicationServiceImpl, | ||
wire.Bind(new(fluxApplication.FluxApplicationService), new(*fluxApplication.FluxApplicationServiceImpl)), | ||
|
||
NewFluxApplicationRestHandlerImpl, | ||
wire.Bind(new(FluxApplicationRestHandler), new(*FluxApplicationRestHandlerImpl)), | ||
|
||
NewFluxApplicationRouterImpl, | ||
wire.Bind(new(FluxApplicationRouter), new(*FluxApplicationRouterImpl)), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
make this error "error in getting cluster ids" constant since used multiple times , also the comment above if check is incomplete
We can use util.ApiError with a proper http status code 404 not found error , and this error string can go in UserMessage as well as Internal message
If there are more such known error strings make them constant and leverage util.ApiError to send error resp with proper https status code