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

misc: Ignore cache error improvement #6247

Open
wants to merge 1 commit into
base: develop
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
6 changes: 3 additions & 3 deletions pkg/pipeline/CiCdPipelineOrchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ type CiCdPipelineOrchestrator interface {
GetSourceCiDownStreamInfo(ctx context.Context, sourceCIPipeline int, req *bean2.SourceCiDownStreamFilters) (pagination.PaginatedResponse[bean2.SourceCiDownStreamResponse], error)
GetSourceCiPipelineForArtifact(ciPipeline pipelineConfig.CiPipeline) (*pipelineConfig.CiPipeline, error)
GetGitCommitEnvVarDataForCICDStage(gitTriggers map[int]pipelineConfig.GitCommit) (map[string]string, *gitSensor.WebhookAndCiData, error)
GetWorkflowCacheConfig(appType helper.AppType, pipelineType string, pipelineWorkflowCacheConfig common2.WorkflowCacheConfigType) bean.WorkflowCacheConfig
GetWorkflowCacheConfig(appType helper.AppType, pipelineType string, pipelineWorkflowCacheConfig common2.WorkflowCacheConfigType) (bean.WorkflowCacheConfig, error)
}

type CiCdPipelineOrchestratorImpl struct {
Expand Down Expand Up @@ -2430,9 +2430,9 @@ func (impl *CiCdPipelineOrchestratorImpl) GetGitCommitEnvVarDataForCICDStage(git
return extraEnvVariables, webhookAndCiData, nil
}

func (impl *CiCdPipelineOrchestratorImpl) GetWorkflowCacheConfig(appType helper.AppType, pipelineType string, pipelineWorkflowCacheConfig common2.WorkflowCacheConfigType) bean.WorkflowCacheConfig {
func (impl *CiCdPipelineOrchestratorImpl) GetWorkflowCacheConfig(appType helper.AppType, pipelineType string, pipelineWorkflowCacheConfig common2.WorkflowCacheConfigType) (bean.WorkflowCacheConfig, error) {
if appType == helper.Job {
return util4.GetWorkflowCacheConfig(pipelineWorkflowCacheConfig, impl.workflowCacheConfig.IgnoreJob)
return util4.GetWorkflowCacheConfig(pipelineWorkflowCacheConfig, impl.workflowCacheConfig.IgnoreJob), nil
} else {
if pipelineType == string(constants3.CI_JOB) {
return util4.GetWorkflowCacheConfigWithBackwardCompatibility(pipelineWorkflowCacheConfig, impl.ciConfig.WorkflowCacheConfig, impl.workflowCacheConfig.IgnoreCIJob, impl.ciConfig.SkipCiJobBuildCachePushPull)
Expand Down
6 changes: 5 additions & 1 deletion pkg/pipeline/CiService.go
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,11 @@ func (impl *CiServiceImpl) buildWfRequestForCiPipeline(pipeline *pipelineConfig.
workflowRequest.AppName = pipeline.App.DisplayName
}
//in oss, there is no pipeline level workflow cache config, so we pass inherit to get the app level config
workflowCacheConfig := impl.ciCdPipelineOrchestrator.GetWorkflowCacheConfig(pipeline.App.AppType, trigger.PipelineType, common.WorkflowCacheConfigInherit)
workflowCacheConfig, err := impl.ciCdPipelineOrchestrator.GetWorkflowCacheConfig(pipeline.App.AppType, trigger.PipelineType, common.WorkflowCacheConfigInherit)
if err != nil {
impl.Logger.Errorw("error in getting workflow cache config", "appType", pipeline.App.AppType, "pipelineType", trigger.PipelineType, "err", err)
return nil, err
}
workflowRequest.IgnoreDockerCachePush = !workflowCacheConfig.Value
workflowRequest.IgnoreDockerCachePull = !workflowCacheConfig.Value
impl.Logger.Debugw("Ignore Cache values", "IgnoreDockerCachePush", workflowRequest.IgnoreDockerCachePush, "IgnoreDockerCachePull", workflowRequest.IgnoreDockerCachePull)
Expand Down
12 changes: 7 additions & 5 deletions pkg/pipeline/util/CiCdUtil.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,23 @@ func GetWorkflowCacheConfig(WorkflowCacheConfig common.WorkflowCacheConfigType,
}

// in oss, only WorkflowCacheConfigInherit is supported
func GetWorkflowCacheConfigWithBackwardCompatibility(WorkflowCacheConfig common.WorkflowCacheConfigType, WorkflowCacheConfigEnv string, globalValue bool, oldGlobalValue bool) bean.WorkflowCacheConfig {
isEmptyJson, _ := util.IsEmptyJSONForJsonString(WorkflowCacheConfigEnv)
//TODO: error handling in next phase
func GetWorkflowCacheConfigWithBackwardCompatibility(WorkflowCacheConfig common.WorkflowCacheConfigType, WorkflowCacheConfigEnv string, globalValue bool, oldGlobalValue bool) (bean.WorkflowCacheConfig, error) {
isEmptyJson, err := util.IsEmptyJSON([]byte(WorkflowCacheConfigEnv))
if err != nil {
return bean.WorkflowCacheConfig{}, err
}
if isEmptyJson {
//this means new global flag is not configured
return bean.WorkflowCacheConfig{
Type: common.WorkflowCacheConfigInherit,
Value: !oldGlobalValue,
GlobalValue: !oldGlobalValue,
}
}, nil
} else {
return bean.WorkflowCacheConfig{
Type: common.WorkflowCacheConfigInherit,
Value: !globalValue,
GlobalValue: !globalValue,
}
}, nil
}
}
23 changes: 11 additions & 12 deletions util/JsonHelper.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package util

import "encoding/json"
import (
"encoding/json"
"fmt"
)

// IsEmptyJSON checks if a given string represents an empty JSON object
func IsEmptyJSONForJsonString(jsonStr string) (bool, error) {
var data interface{}
err := json.Unmarshal([]byte(jsonStr), &data)
// IsEmptyJSON checks if the given json is empty or not and only throws error if there is some issue in unmarshalling
func IsEmptyJSON(s []byte) (bool, error) {
var result map[string]interface{}
err := json.Unmarshal(s, &result)
if err != nil {
// If unmarshaling fails, it's not valid JSON
fmt.Println("Error unmarshalling:", err)
return false, err
}

// Check if data is an empty map
if obj, ok := data.(map[string]interface{}); ok {
return len(obj) == 0, nil
if len(result) == 0 {
return true, nil
}

// If not a JSON object, return false
return false, nil
}
Loading