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

fix: inducing overridden DockerRegistryId in case docker registry is overridden #4178

Merged
merged 2 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
64 changes: 41 additions & 23 deletions pkg/dockerRegistry/DockerRegistryIpsConfigService.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,20 @@ type DockerRegistryIpsConfigServiceImpl struct {
clusterService cluster.ClusterService
ciPipelineRepository pipelineConfig.CiPipelineRepository
dockerArtifactStoreRepository repository.DockerArtifactStoreRepository
ciTemplateOverrideRepository pipelineConfig.CiTemplateOverrideRepository
}

func NewDockerRegistryIpsConfigServiceImpl(logger *zap.SugaredLogger, dockerRegistryIpsConfigRepository repository.DockerRegistryIpsConfigRepository,
k8sUtil *k8s.K8sUtil, clusterService cluster.ClusterService, ciPipelineRepository pipelineConfig.CiPipelineRepository,
dockerArtifactStoreRepository repository.DockerArtifactStoreRepository) *DockerRegistryIpsConfigServiceImpl {
dockerArtifactStoreRepository repository.DockerArtifactStoreRepository, ciTemplateOverrideRepository pipelineConfig.CiTemplateOverrideRepository) *DockerRegistryIpsConfigServiceImpl {
return &DockerRegistryIpsConfigServiceImpl{
logger: logger,
dockerRegistryIpsConfigRepository: dockerRegistryIpsConfigRepository,
k8sUtil: k8sUtil,
clusterService: clusterService,
ciPipelineRepository: ciPipelineRepository,
dockerArtifactStoreRepository: dockerArtifactStoreRepository,
ciTemplateOverrideRepository: ciTemplateOverrideRepository,
}
}

Expand Down Expand Up @@ -83,29 +85,11 @@ func (impl DockerRegistryIpsConfigServiceImpl) HandleImagePullSecretOnApplicatio
return valuesFileContent, nil
}

ciPipeline, err := impl.ciPipelineRepository.FindById(ciPipelineId)
dockerRegistryId, err := impl.getDockerRegistryIdForCiPipeline(ciPipelineId)
if err != nil {
impl.logger.Errorw("error in fetching ciPipeline", "ciPipelineId", ciPipelineId, "error", err)
if err == pg.ErrNoRows {
return valuesFileContent, nil
} else {
return nil, err
}
}

if ciPipeline.IsExternal && ciPipeline.ParentCiPipeline == 0 {
impl.logger.Warn("Ignoring for external ci")
return valuesFileContent, nil
}

if ciPipeline.CiTemplate == nil {
impl.logger.Warn("returning as ciPipeline.CiTemplate is found nil")
return valuesFileContent, nil
}

dockerRegistryId := ciPipeline.CiTemplate.DockerRegistryId
if len(*dockerRegistryId) == 0 {
impl.logger.Warn("returning as dockerRegistryId is found empty")
impl.logger.Errorw("error in getting docker registry", "dockerRegistryId", dockerRegistryId, "error", err)
return valuesFileContent, err
} else if dockerRegistryId == nil {
return valuesFileContent, nil
}

Expand Down Expand Up @@ -154,6 +138,40 @@ func (impl DockerRegistryIpsConfigServiceImpl) HandleImagePullSecretOnApplicatio
return updatedValuesFileContent, nil
}

func (impl DockerRegistryIpsConfigServiceImpl) getDockerRegistryIdForCiPipeline(ciPipelineId int) (*string, error) {
ciPipeline, err := impl.ciPipelineRepository.FindById(ciPipelineId)
if err != nil {
impl.logger.Errorw("error in fetching ciPipeline", "ciPipelineId", ciPipelineId, "error", err)
return nil, err
}

if ciPipeline.IsExternal && ciPipeline.ParentCiPipeline == 0 {
impl.logger.Warn("Ignoring for external ci")
return nil, nil
}

if ciPipeline.CiTemplate == nil {
impl.logger.Warn("returning as ciPipeline.CiTemplate is found nil")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is response in this case

return nil, nil
}

dockerRegistryId := ciPipeline.CiTemplate.DockerRegistryId
if len(*dockerRegistryId) == 0 {
impl.logger.Warn("returning as dockerRegistryId is found empty")
return nil, nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw custom error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This custom error was not being thrown earlier also, so don't know it may impact other flows also outside this function which will increase the scope of this maybe

}

if ciPipeline.IsDockerConfigOverridden {
//set dockerRegistryId value with the DockerRegistryId of the overridden dockerRegistry
ciTemplateOverride, err := impl.ciTemplateOverrideRepository.FindByCiPipelineId(ciPipelineId)
if err != nil {
impl.logger.Errorw("error in getting ciTemplateOverride by ciPipelineId", "ciPipelineId", ciPipelineId, "error", err)
return nil, err
}
dockerRegistryId = &ciTemplateOverride.DockerRegistryId
}
return dockerRegistryId, nil
}
func (impl DockerRegistryIpsConfigServiceImpl) createOrUpdateDockerRegistryImagePullSecret(clusterId int, namespace string, ipsName string, dockerRegistryBean *repository.DockerArtifactStore) error {
impl.logger.Infow("creating/updating ips", "ipsName", ipsName, "clusterId", clusterId)

Expand Down
4 changes: 2 additions & 2 deletions wire_gen.go

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

Loading