Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c4eb42b
migration virtual cluster v2
iamayushm Jun 21, 2023
03d0508
migration column name changed
iamayushm Jun 21, 2023
096b6a8
migration update
iamayushm Jun 22, 2023
9b669c5
refactoring gitops code
iamayushm Jun 26, 2023
a6303ed
OCI registry integration
Ash-exp Jun 26, 2023
da62350
added validation for container storage type action
Ash-exp Jun 26, 2023
f68ecf7
refactoring gitops code
iamayushm Jun 26, 2023
be50ccb
migration update
iamayushm Jun 26, 2023
436b369
migration update
iamayushm Jun 26, 2023
9cb5d94
manifest_push_config dto update
iamayushm Jun 26, 2023
00a0d93
manifest push config dto correction
iamayushm Jun 27, 2023
e64030c
wip
iamayushm Jun 27, 2023
de7962b
gitops refactoring merge
iamayushm Jun 27, 2023
55e84f3
db object correction
iamayushm Jun 27, 2023
efa4f8d
manifest push config get function
iamayushm Jun 27, 2023
7a20267
cleaning code
iamayushm Jun 27, 2023
b256665
added integration test cases for docker_artifact_store
Ash-exp Jun 27, 2023
ff9a739
skipped integration test cases for built and modified logs
Ash-exp Jun 27, 2023
e09de30
updated validation condition
Ash-exp Jun 27, 2023
097d6e6
updated docker_artifact_store query condition for OCI config relations
Ash-exp Jun 27, 2023
7e7fd3f
moving save timeline call
iamayushm Jun 28, 2023
fd8aa68
handled nil pointer issue of existing registry update
Ash-exp Jun 28, 2023
2373fcd
Merge remote-tracking branch 'origin/virtual-cluster-v2' into virtual…
iamayushm Jun 30, 2023
66601a4
cleaning code- removing unused functions
iamayushm Jul 5, 2023
fce6c39
trigger event refactor for unit test case
iamayushm Jul 5, 2023
766c0a6
wip
iamayushm Jul 5, 2023
254d28b
Merge branch 'main' into virtual-cluster-v2
iamayushm Jul 5, 2023
5e6c4df
migration-update
iamayushm Jul 6, 2023
bd60c92
wip
iamayushm Jul 10, 2023
11a4d04
Merge branch 'main' into virtual-cluster-v2
Ash-exp Jul 13, 2023
8346ff5
updated wire_gen.go
Ash-exp Jul 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ func InitializeApp() (*App, error) {
wire.Bind(new(dockerRegistryRepository.DockerArtifactStoreRepository), new(*dockerRegistryRepository.DockerArtifactStoreRepositoryImpl)),
dockerRegistryRepository.NewDockerRegistryIpsConfigRepositoryImpl,
wire.Bind(new(dockerRegistryRepository.DockerRegistryIpsConfigRepository), new(*dockerRegistryRepository.DockerRegistryIpsConfigRepositoryImpl)),
dockerRegistryRepository.NewOCIRegistryConfigRepositoryImpl,
wire.Bind(new(dockerRegistryRepository.OCIRegistryConfigRepository), new(*dockerRegistryRepository.OCIRegistryConfigRepositoryImpl)),
util.NewChartTemplateServiceImpl,
wire.Bind(new(util.ChartTemplateService), new(*util.ChartTemplateServiceImpl)),
util.NewChartDeploymentServiceImpl,
Expand Down Expand Up @@ -855,6 +857,10 @@ func InitializeApp() (*App, error) {
wire.Bind(new(appGroup2.AppGroupMappingRepository), new(*appGroup2.AppGroupMappingRepositoryImpl)),
pipeline.NewArgoWorkflowExecutorImpl,
wire.Bind(new(pipeline.ArgoWorkflowExecutor), new(*pipeline.ArgoWorkflowExecutorImpl)),
repository5.NewManifestPushConfigRepository,
wire.Bind(new(repository5.ManifestPushConfigRepository), new(*repository5.ManifestPushConfigRepositoryImpl)),
app.NewGitOpsManifestPushServiceImpl,
wire.Bind(new(app.GitOpsPushService), new(*app.GitOpsManifestPushServiceImpl)),
)
return &App{}, nil
}
3 changes: 2 additions & 1 deletion api/bean/ValuesOverrideRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ type ReleaseStatusUpdateRequest struct {
}

type TriggerEvent struct {
PerformGitOps bool
PerformChartPush bool
PerformDeploymentOnCluster bool
GetManifestInResponse bool
DeploymentAppType string
ManifestStorageType string
TriggeredBy int32
TriggerdAt time.Time
}
59 changes: 54 additions & 5 deletions api/restHandler/DockerRegRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ package restHandler

import (
"encoding/json"
"fmt"
"github.com/devtron-labs/devtron/api/restHandler/common"
repository "github.com/devtron-labs/devtron/internal/sql/repository/dockerRegistry"
delete2 "github.com/devtron-labs/devtron/pkg/delete"
"github.com/devtron-labs/devtron/pkg/user/casbin"
"k8s.io/utils/strings/slices"
"net/http"
"strings"

Expand Down Expand Up @@ -79,6 +82,27 @@ func NewDockerRegRestHandlerImpl(dockerRegistryConfig pipeline.DockerRegistryCon
}
}

func ValidateDockerArtifactStoreRequestBean(bean pipeline.DockerArtifactStoreBean) bool {
// validating secure connection configs
if (bean.Connection == secureWithCert && bean.Cert == "") ||
(bean.Connection != secureWithCert && bean.Cert != "") {
return false
}
// validating OCI Registry configs
if bean.IsOCICompliantRegistry {
if bean.OCIRegistryConfig == nil {
return false
}
containerStorageActionType, containerStorageActionExists := bean.OCIRegistryConfig[repository.OCI_REGISRTY_REPO_TYPE_CONTAINER]
if containerStorageActionExists && containerStorageActionType != repository.STORAGE_ACTION_TYPE_PULL_AND_PUSH {
return false
}
} else if bean.OCIRegistryConfig != nil {
return false
}
return true
}

func (impl DockerRegRestHandlerImpl) SaveDockerRegistryConfig(w http.ResponseWriter, r *http.Request) {
decoder := json.NewDecoder(r.Body)
userId, err := impl.userAuthService.GetLoggedInUser(r)
Expand All @@ -94,7 +118,9 @@ func (impl DockerRegRestHandlerImpl) SaveDockerRegistryConfig(w http.ResponseWri
return
}
bean.User = userId
if (bean.Connection == secureWithCert && bean.Cert == "") || (bean.Connection != secureWithCert && bean.Cert != "") {
if !ValidateDockerArtifactStoreRequestBean(bean) {
err = fmt.Errorf("invalid payload, missing or incorrect values for required fields")
impl.logger.Errorw("validation err, SaveDockerRegistryConfig", "err", err, "payload", bean)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
} else {
Expand Down Expand Up @@ -222,7 +248,9 @@ func (impl DockerRegRestHandlerImpl) UpdateDockerRegistryConfig(w http.ResponseW
return
}
bean.User = userId
if (bean.Connection == secureWithCert && bean.Cert == "") || (bean.Connection != secureWithCert && bean.Cert != "") {
if !ValidateDockerArtifactStoreRequestBean(bean) {
err = fmt.Errorf("invalid payload, missing or incorrect values for required fields")
impl.logger.Errorw("validation err, SaveDockerRegistryConfig", "err", err, "payload", bean)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
} else {
Expand Down Expand Up @@ -267,15 +295,36 @@ func (impl DockerRegRestHandlerImpl) FetchAllDockerRegistryForAutocomplete(w htt
}

func (impl DockerRegRestHandlerImpl) IsDockerRegConfigured(w http.ResponseWriter, r *http.Request) {
v := r.URL.Query()
storageType := v.Get("storageType")
if storageType == "" {
storageType = repository.OCI_REGISRTY_REPO_TYPE_CONTAINER
}
if !slices.Contains(repository.OCI_REGISRTY_REPO_TYPE_LIST, storageType) {
common.WriteJsonResp(w, fmt.Errorf("invalid query parameters"), nil, http.StatusBadRequest)
return
}
storageAction := v.Get("storageAction")
if storageAction == "" {
storageAction = repository.STORAGE_ACTION_TYPE_PUSH
}
if !(storageAction == repository.STORAGE_ACTION_TYPE_PULL || storageAction == repository.STORAGE_ACTION_TYPE_PUSH) {
common.WriteJsonResp(w, fmt.Errorf("invalid query parameters"), nil, http.StatusBadRequest)
return
}
isConfigured := false
res, err := impl.dockerRegistryConfig.ListAllActive()
registryConfigs, err := impl.dockerRegistryConfig.ListAllActive()
if err != nil && err != pg.ErrNoRows {
impl.logger.Errorw("service err, IsDockerRegConfigured", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
if len(res) > 0 {
isConfigured = true
if len(registryConfigs) > 0 {
// Filter out all registries with CONTAINER push or pull/push access
res := impl.dockerRegistryConfig.FilterRegistryBeanListBasedOnStorageTypeAndAction(registryConfigs, storageType, storageAction, repository.STORAGE_ACTION_TYPE_PULL_AND_PUSH)
if len(res) > 0 {
isConfigured = true
}
}

common.WriteJsonResp(w, err, isConfigured, http.StatusOK)
Expand Down
29 changes: 25 additions & 4 deletions api/restHandler/app/AutoCompleteRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ package app

import (
"context"
"fmt"
"github.com/devtron-labs/devtron/api/restHandler/common"
repository "github.com/devtron-labs/devtron/internal/sql/repository/dockerRegistry"
"github.com/devtron-labs/devtron/internal/sql/repository/helper"
"github.com/devtron-labs/devtron/pkg/pipeline"
"github.com/devtron-labs/devtron/pkg/user/casbin"
"github.com/gorilla/mux"
"go.opentelemetry.io/otel"
"k8s.io/utils/strings/slices"
"net/http"
"strconv"
)

type DevtronAppAutoCompleteRestHandler interface {
GitListAutocomplete(w http.ResponseWriter, r *http.Request)
DockerListAutocomplete(w http.ResponseWriter, r *http.Request)
RegistriesListAutocomplete(w http.ResponseWriter, r *http.Request)
TeamListAutocomplete(w http.ResponseWriter, r *http.Request)
EnvironmentListAutocomplete(w http.ResponseWriter, r *http.Request)
GetAppListForAutocomplete(w http.ResponseWriter, r *http.Request)
Expand Down Expand Up @@ -166,14 +169,32 @@ func (handler PipelineConfigRestHandlerImpl) GitListAutocomplete(w http.Response
common.WriteJsonResp(w, err, res, http.StatusOK)
}

func (handler PipelineConfigRestHandlerImpl) DockerListAutocomplete(w http.ResponseWriter, r *http.Request) {
func (handler PipelineConfigRestHandlerImpl) RegistriesListAutocomplete(w http.ResponseWriter, r *http.Request) {
token := r.Header.Get("token")
vars := mux.Vars(r)
appId, err := strconv.Atoi(vars["appId"])
if err != nil {
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
v := r.URL.Query()
storageType := v.Get("storageType")
if storageType == "" {
storageType = repository.OCI_REGISRTY_REPO_TYPE_CONTAINER
}
if !slices.Contains(repository.OCI_REGISRTY_REPO_TYPE_LIST, storageType) {
common.WriteJsonResp(w, fmt.Errorf("invalid query parameters"), nil, http.StatusBadRequest)
return
}
storageAction := v.Get("storageAction")
if storageAction == "" {
storageAction = repository.STORAGE_ACTION_TYPE_PUSH
}
if !(storageAction == repository.STORAGE_ACTION_TYPE_PULL || storageAction == repository.STORAGE_ACTION_TYPE_PUSH) {
common.WriteJsonResp(w, fmt.Errorf("invalid query parameters"), nil, http.StatusBadRequest)
return
}

handler.Logger.Infow("request payload, DockerListAutocomplete", "appId", appId)
//RBAC
object := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
Expand All @@ -182,13 +203,13 @@ func (handler PipelineConfigRestHandlerImpl) DockerListAutocomplete(w http.Respo
return
}
//RBAC
res, err := handler.dockerRegistryConfig.ListAllActive()
registryConfigs, err := handler.dockerRegistryConfig.ListAllActive()
if err != nil {
handler.Logger.Errorw("service err, DockerListAutocomplete", "err", err, "appId", appId)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}

res := handler.dockerRegistryConfig.FilterRegistryBeanListBasedOnStorageTypeAndAction(registryConfigs, storageType, storageAction, repository.STORAGE_ACTION_TYPE_PULL_AND_PUSH)
common.WriteJsonResp(w, err, res, http.StatusOK)
}

Expand Down
9 changes: 9 additions & 0 deletions api/restHandler/app/BuildPipelineRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/devtron-labs/devtron/api/restHandler/common"
"github.com/devtron-labs/devtron/client/gitSensor"
"github.com/devtron-labs/devtron/internal/sql/repository"
dockerRegistryRepository "github.com/devtron-labs/devtron/internal/sql/repository/dockerRegistry"
"github.com/devtron-labs/devtron/internal/sql/repository/helper"
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
"github.com/devtron-labs/devtron/internal/util"
Expand Down Expand Up @@ -102,6 +103,14 @@ func (handler PipelineConfigRestHandlerImpl) CreateCiConfig(w http.ResponseWrite
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
// validates if the dockerRegistry can store CONTAINER
isValid := handler.dockerRegistryConfig.ValidateRegistryStorageType(createRequest.DockerRegistry, dockerRegistryRepository.OCI_REGISRTY_REPO_TYPE_CONTAINER, dockerRegistryRepository.STORAGE_ACTION_TYPE_PUSH, dockerRegistryRepository.STORAGE_ACTION_TYPE_PULL_AND_PUSH)
if !isValid {
err = fmt.Errorf("invalid registry type")
handler.Logger.Errorw("validation err, create ci config", "err", err, "create request", createRequest)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
token := r.Header.Get("token")
app, err := handler.pipelineBuilder.GetApp(createRequest.AppId)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion api/router/PipelineConfigRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (router PipelineConfigRouterImpl) initPipelineConfigRouter(configRouter *mu

configRouter.Path("/{appId}/autocomplete/environment").HandlerFunc(router.restHandler.EnvironmentListAutocomplete).Methods("GET")
configRouter.Path("/{appId}/autocomplete/git").HandlerFunc(router.restHandler.GitListAutocomplete).Methods("GET")
configRouter.Path("/{appId}/autocomplete/docker").HandlerFunc(router.restHandler.DockerListAutocomplete).Methods("GET")
configRouter.Path("/{appId}/autocomplete/docker").HandlerFunc(router.restHandler.RegistriesListAutocomplete).Methods("GET")
configRouter.Path("/{appId}/autocomplete/team").HandlerFunc(router.restHandler.TeamListAutocomplete).Methods("GET")

configRouter.Path("/cd-pipeline/defaultStrategy/{appId}/{envId}").HandlerFunc(router.restHandler.GetDefaultDeploymentPipelineStrategy).Methods("GET")
Expand Down
2 changes: 1 addition & 1 deletion cmd/external-app/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading