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

nil-check-handle #5631

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -1588,7 +1588,7 @@ func (handler *PipelineConfigRestHandlerImpl) CancelWorkflow(w http.ResponseWrit
if handler.appWorkflowService.CheckCdPipelineByCiPipelineId(pipelineId) {
for _, envId := range environmentIds {
envObject := handler.enforcerUtil.GetEnvRBACNameByCiPipelineIdAndEnvId(pipelineId, envId)
if ok := handler.enforcer.Enforce(token, casbin.ResourceEnvironment, casbin.ActionUpdate, envObject); !ok {
if ok := handler.enforcer.Enforce(token, casbin.ResourceEnvironment, casbin.ActionTrigger, envObject); !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
return
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/deployment/manifest/ManifestCreationService.go
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ func (impl *ManifestCreationServiceImpl) getArgoCdHPAResourceManifest(ctx contex
recv, argoErr := impl.acdClient.GetResource(newCtx, query)
if argoErr != nil {
grpcCode, errMsg := util.GetClientDetailedError(argoErr)
if grpcCode.IsInvalidArgumentCode() {
if grpcCode.IsInvalidArgumentCode() || grpcCode.IsNotFoundCode() {
// this is a valid case for hibernated applications, so returning nil
// for hibernated applications, we don't have any hpa resource manifest
return resourceManifest, nil
Expand Down Expand Up @@ -914,6 +914,11 @@ func (impl *ManifestCreationServiceImpl) autoscalingCheckBeforeTrigger(ctx conte
if len(resourceManifest) > 0 {
statusMap := resourceManifest["status"].(map[string]interface{})
currentReplicaVal := statusMap["currentReplicas"]
// currentReplicas key might not be available in manifest while k8s is calculating replica count
// it's a valid case so, we are not throwing error
if currentReplicaVal == nil {
return merged, err
}
currentReplicaCount, err := util4.ParseFloatNumber(currentReplicaVal)
if err != nil {
impl.logger.Errorw("error occurred while parsing replica count", "currentReplicas", currentReplicaVal, "err", err)
Expand Down
8 changes: 4 additions & 4 deletions pkg/deployment/trigger/devtronApps/TriggerService.go
Original file line number Diff line number Diff line change
Expand Up @@ -788,10 +788,10 @@ func (impl *TriggerServiceImpl) TriggerRelease(overrideRequest *bean3.ValuesOver
valuesOverrideResponse, builtChartPath, err := impl.manifestCreationService.BuildManifestForTrigger(overrideRequest, triggeredAt, newCtx)

if envDeploymentConfig == nil || (envDeploymentConfig != nil && envDeploymentConfig.Id == 0) {
envDeploymentConfig, err = impl.deploymentConfigService.GetAndMigrateConfigIfAbsentForDevtronApps(overrideRequest.AppId, overrideRequest.EnvId)
if err != nil {
impl.logger.Errorw("error in getting deployment config by appId and envId", "appId", overrideRequest.AppId, "envId", overrideRequest.EnvId, "err", err)
return releaseNo, err
envDeploymentConfig, err1 := impl.deploymentConfigService.GetAndMigrateConfigIfAbsentForDevtronApps(overrideRequest.AppId, overrideRequest.EnvId)
if err1 != nil {
impl.logger.Errorw("error in getting deployment config by appId and envId", "appId", overrideRequest.AppId, "envId", overrideRequest.EnvId, "err", err1)
return releaseNo, err1
}
valuesOverrideResponse.DeploymentConfig = envDeploymentConfig
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/pipeline/BuildPipelineConfigService.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,16 @@ func (impl *CiPipelineConfigServiceImpl) patchCiPipelineUpdateSource(baseCiConfi
impl.logger.Errorw("error in fetching pipeline", "id", modifiedCiPipeline.Id, "err", err)
return nil, err
}
// updating PipelineType from db if not present in request
if modifiedCiPipeline.PipelineType == "" {
if CiPipeline.PipelineType(pipeline.PipelineType) != "" {
modifiedCiPipeline.PipelineType = CiPipeline.PipelineType(pipeline.PipelineType)
} else {
// updating default pipelineType if not present in request
modifiedCiPipeline.PipelineType = CiPipeline.DefaultPipelineType

}
}
if !modifiedCiPipeline.PipelineType.IsValidPipelineType() {
impl.logger.Debugw(" Invalid PipelineType", "PipelineType", modifiedCiPipeline.PipelineType)
errorMessage := fmt.Sprintf(CiPipeline.PIPELINE_TYPE_IS_NOT_VALID, modifiedCiPipeline.Name)
Expand Down
9 changes: 8 additions & 1 deletion pkg/pipeline/CiService.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ func (impl *CiServiceImpl) TriggerCiPipeline(trigger types.Trigger) (int, error)

// checking if user has given run time parameters for externalCiArtifact, if given then sending git material to Ci-Runner
externalCiArtifact, exists := trigger.ExtraEnvironmentVariables["externalCiArtifact"]
// validate externalCiArtifact as docker image
if exists {
if !strings.Contains(externalCiArtifact, ":") {
impl.Logger.Errorw("validation error", "externalCiArtifact", externalCiArtifact)
return 0, fmt.Errorf("invalid image name given in externalCiArtifact")
}
}
if trigger.PipelineType == string(CiPipeline.CI_JOB) && len(ciMaterials) != 0 && !exists && externalCiArtifact == "" {
ciMaterials = []*pipelineConfig.CiPipelineMaterial{ciMaterials[0]}
ciMaterials[0].GitMaterial = nil
Expand Down Expand Up @@ -569,7 +576,7 @@ func (impl *CiServiceImpl) buildWfRequestForCiPipeline(pipeline *pipelineConfig.
}
ciBuildConfigBean = templateOverrideBean.CiBuildConfig
// updating args coming from ciBaseBuildConfigEntity because it is not part of Ci override
if ciBuildConfigBean != nil && ciBuildConfigBean.DockerBuildConfig != nil {
if ciBuildConfigBean != nil && ciBuildConfigBean.DockerBuildConfig != nil && ciBaseBuildConfigBean != nil && ciBaseBuildConfigBean.DockerBuildConfig != nil {
ciBuildConfigBean.DockerBuildConfig.Args = ciBaseBuildConfigBean.DockerBuildConfig.Args
}
templateOverride := templateOverrideBean.CiTemplateOverride
Expand Down
3 changes: 3 additions & 0 deletions pkg/pipeline/bean/CiPipeline/CiBuildConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ const PIPELINE_TYPE_IS_NOT_VALID = "PipelineType is not valid for pipeline %s"

type PipelineType string

// default PipelineType
const DefaultPipelineType = CI_BUILD

const (
CI_BUILD PipelineType = "CI_BUILD"
LINKED PipelineType = "LINKED"
Expand Down
Loading