Skip to content

chore: added supoort for backup in update repo api #6462

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

Merged
merged 5 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 0 deletions client/gitSensor/GitSensorGrpcClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ func (client *GrpcApiClientImpl) AddRepo(ctx context.Context, materials []*GitMa
Deleted: item.Deleted,
FilterPattern: item.FilterPattern,
CloningMode: item.CloningMode,
CreateBackup: item.CreateBackup,
})
}
}
Expand Down Expand Up @@ -191,6 +192,7 @@ func (client *GrpcApiClientImpl) UpdateRepo(ctx context.Context, material *GitMa
Deleted: material.Deleted,
FilterPattern: material.FilterPattern,
CloningMode: material.CloningMode,
CreateBackup: material.CreateBackup,
}

_, err = serviceClient.UpdateRepo(ctx, mappedMaterial)
Expand Down
1 change: 1 addition & 0 deletions client/gitSensor/GitSensorRestClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type GitMaterial struct {
FetchSubmodules bool
FilterPattern []string
CloningMode string
CreateBackup bool
}
type GitProvider struct {
Id int
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.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require (
github.com/devtron-labs/authenticator v0.4.35-0.20240809073103-6e11da8083f8
github.com/devtron-labs/common-lib v0.18.1-0.20241001061923-eda545dc839e
github.com/devtron-labs/go-bitbucket v0.9.60-beta
github.com/devtron-labs/protos v0.0.3-0.20240802105333-92ee9bb85d80
github.com/devtron-labs/protos v0.0.3-0.20250323220609-ecf8a0f7305e
github.com/evanphx/json-patch v5.9.0+incompatible
github.com/gammazero/workerpool v1.1.3
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -798,8 +798,8 @@ github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250313102545-75df8a
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250313102545-75df8a5bec13/go.mod h1:1QJJLpgJSkb5Jm9xPeKAk+kXb0QgBOOOgJj0cgYhAVA=
github.com/devtron-labs/go-bitbucket v0.9.60-beta h1:VEx1jvDgdtDPS6A1uUFoaEi0l1/oLhbr+90xOwr6sDU=
github.com/devtron-labs/go-bitbucket v0.9.60-beta/go.mod h1:GnuiCesvh8xyHeMCb+twm8lBR/kQzJYSKL28ZfObp1Y=
github.com/devtron-labs/protos v0.0.3-0.20240802105333-92ee9bb85d80 h1:xwbTeijNTf4/j1v+tSfwVqwLVnReas/NqEKeQHvSTys=
github.com/devtron-labs/protos v0.0.3-0.20240802105333-92ee9bb85d80/go.mod h1:ypUknVph8Ph4dxSlrFoouf7wLedQxHku2LQwgRrdgS4=
github.com/devtron-labs/protos v0.0.3-0.20250323220609-ecf8a0f7305e h1:U6UdYbW8a7xn5IzFPd8cywjVVPfutGJCudjePAfL/Hs=
github.com/devtron-labs/protos v0.0.3-0.20250323220609-ecf8a0f7305e/go.mod h1:1TqULGlTey+VNhAu/ag7NJuUvByJemkqodsc9L5PHJk=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
Expand Down
1 change: 1 addition & 0 deletions pkg/bean/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ type GitMaterial struct {
FetchSubmodules bool `json:"fetchSubmodules"`
IsUsedInCiConfig bool `json:"isUsedInCiConfig"`
FilterPattern []string `json:"filterPattern"`
CreateBackup bool `json:"createBackup"`
}

// UpdateSanitisedGitRepoUrl will remove all trailing slashes , leading and trailing spaces from git repository url
Expand Down
22 changes: 17 additions & 5 deletions pkg/pipeline/CiCdPipelineOrchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@ func (impl CiCdPipelineOrchestratorImpl) DeleteApp(appId int, userId int32) erro

impl.logger.Debug("deleting materials in git_sensor")
for _, m := range materials {
err = impl.updateRepositoryToGitSensor(m, "")
err = impl.updateRepositoryToGitSensor(m, "", false)
if err != nil {
impl.logger.Errorw("error in updating to git-sensor", "err", err)
return err
Expand Down Expand Up @@ -1467,7 +1467,8 @@ func (impl CiCdPipelineOrchestratorImpl) UpdateMaterial(updateMaterialDTO *bean.
return nil, err
}

err = impl.updateRepositoryToGitSensor(updatedMaterial, "")
err = impl.updateRepositoryToGitSensor(updatedMaterial, "",
updateMaterialDTO.Material.CreateBackup)
if err != nil {
impl.logger.Errorw("error in updating to git-sensor", "err", err)
return nil, err
Expand All @@ -1480,7 +1481,8 @@ func (impl CiCdPipelineOrchestratorImpl) UpdateMaterial(updateMaterialDTO *bean.
return updateMaterialDTO, nil
}

func (impl CiCdPipelineOrchestratorImpl) updateRepositoryToGitSensor(material *repository6.GitMaterial, cloningMode string) error {
func (impl CiCdPipelineOrchestratorImpl) updateRepositoryToGitSensor(material *repository6.GitMaterial,
cloningMode string, createBackup bool) error {
sensorMaterial := &gitSensor.GitMaterial{
Name: material.Name,
Url: material.Url,
Expand All @@ -1491,8 +1493,16 @@ func (impl CiCdPipelineOrchestratorImpl) updateRepositoryToGitSensor(material *r
FetchSubmodules: material.FetchSubmodules,
FilterPattern: material.FilterPattern,
CloningMode: cloningMode,
CreateBackup: createBackup,
}
return impl.GitSensorClient.UpdateRepo(context.Background(), sensorMaterial)
timeout := 10 * time.Minute
if createBackup {
// additional time may be required for dir snapshot
timeout = 15 * time.Minute
}
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
return impl.GitSensorClient.UpdateRepo(ctx, sensorMaterial)
}

func (impl CiCdPipelineOrchestratorImpl) addRepositoryToGitSensor(materials []*bean.GitMaterial, cloningMode string) error {
Expand All @@ -1510,7 +1520,9 @@ func (impl CiCdPipelineOrchestratorImpl) addRepositoryToGitSensor(materials []*b
}
sensorMaterials = append(sensorMaterials, sensorMaterial)
}
return impl.GitSensorClient.AddRepo(context.Background(), sensorMaterials)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
defer cancel()
return impl.GitSensorClient.AddRepo(ctx, sensorMaterials)
}

// FIXME: not thread safe
Expand Down
Loading
Loading