Skip to content

Commit

Permalink
fix bug where env prefix was using wrong domain
Browse files Browse the repository at this point in the history
  • Loading branch information
jlsherrill committed Nov 1, 2024
1 parent afb5081 commit f3607cb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
33 changes: 22 additions & 11 deletions pkg/jobs/rename_domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package jobs
import (
"context"
"fmt"
"strings"

caliri "github.com/content-services/caliri/release/v4"
"github.com/content-services/content-sources-backend/pkg/api"
"github.com/content-services/content-sources-backend/pkg/candlepin_client"
"github.com/content-services/content-sources-backend/pkg/config"
Expand All @@ -25,24 +27,26 @@ func RenameDomains() {
// rename the red hat domain
rhDomain := models.Domain{}
res := db.DB.Where("org_id = ?", config.RedHatOrg).First(&rhDomain)
if rhDomain.DomainName != config.RedHatDomainName {
if res.Error != nil {
log.Error().Err(res.Error).Msg("failed to lookup RedHat domain")
} else {
err := renameDomain(ctx, db.DB, daoReg, config.RedHatOrg, config.RedHatDomainName)
if err != nil {
renameErrors[config.RedHatOrg] = err
}
if res.Error != nil {
log.Error().Err(res.Error).Msg("failed to lookup RedHat domain")
} else {
err := renameDomain(ctx, db.DB, daoReg, config.RedHatOrg, config.RedHatDomainName)
if err != nil {
renameErrors[config.RedHatOrg] = err
}
}

customDomains := []models.Domain{}
res = db.DB.Where("org_id != ? AND domain_name not like 'cs-%'", config.RedHatOrg).Find(&customDomains)
res = db.DB.Where("org_id != ?", config.RedHatOrg).Find(&customDomains)
if res.Error != nil {
log.Error().Err(res.Error).Msg("failed to lookup custom domains")
} else {
for _, domain := range customDomains {
err := renameDomain(ctx, db.DB, daoReg, domain.OrgId, fmt.Sprintf("cs-%v", domain.DomainName))
newName := domain.DomainName
if !strings.HasPrefix(newName, "cs-") {
newName = fmt.Sprintf("cs-%s", newName)
}
err := renameDomain(ctx, db.DB, daoReg, domain.OrgId, newName)
if err != nil {
renameErrors[config.RedHatOrg] = err
}
Expand All @@ -63,6 +67,8 @@ func renameDomain(ctx context.Context, DB *gorm.DB, daoReg *dao.DaoRegistry, org
return fmt.Errorf("could not fetch domain name: %v", err)
}

rhDomanName, err := daoReg.Domain.Fetch(ctx, config.RedHatOrg)

Check failure on line 70 in pkg/jobs/rename_domains.go

View workflow job for this annotation

GitHub Actions / Lint

ineffectual assignment to err (ineffassign)

templates, _, err := daoReg.Template.List(ctx, orgId, api.PaginationData{Limit: -1}, api.TemplateFilterData{})
if err != nil {
return fmt.Errorf("could not list templates for org: %v", err)
Expand All @@ -72,7 +78,7 @@ func renameDomain(ctx context.Context, DB *gorm.DB, daoReg *dao.DaoRegistry, org
return fmt.Errorf("could not get pulp path: %v", err)
}
for _, template := range templates.Data {
prefix, err := config.EnvironmentPrefix(pulpPath, newName, template.UUID)
prefix, err := config.EnvironmentPrefix(pulpPath, rhDomanName, template.UUID)
if err != nil {
return fmt.Errorf("could not get environment prefix: %v", err)
}
Expand All @@ -88,6 +94,11 @@ func renameDomain(ctx context.Context, DB *gorm.DB, daoReg *dao.DaoRegistry, org
}
}

err = tasks.RemoveUneededOverrides(ctx, cpClient, template.UUID, []caliri.ContentOverrideDTO{})
if err != nil {
return fmt.Errorf("could not clear overrides for update: %v", err)
}

overrideDtos, err := tasks.GenOverrideDTO(ctx, daoReg, orgId, newName, pulpPath, template)
if err != nil {
return fmt.Errorf("could not generate override: %v", err)
Expand Down
6 changes: 3 additions & 3 deletions pkg/tasks/candlepin_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ func GenOverrideDTO(ctx context.Context, daoReg *dao.DaoRegistry, orgId, domainN

uuids := strings.Join(template.RepositoryUUIDS, ",")
origins := strings.Join([]string{config.OriginExternal, config.OriginRedHat, config.OriginUpload}, ",")
customRepos, _, err := daoReg.RepositoryConfig.List(ctx, orgId, api.PaginationData{Limit: -1}, api.FilterData{UUID: uuids, Origin: origins})
repos, _, err := daoReg.RepositoryConfig.List(ctx, orgId, api.PaginationData{Limit: -1}, api.FilterData{UUID: uuids, Origin: origins})
if err != nil {
return mapping, err
}
for i := 0; i < len(customRepos.Data); i++ {
repoOver, err := ContentOverridesForRepo(orgId, domainName, template.UUID, contentPath, customRepos.Data[i])
for _, repo := range repos.Data {
repoOver, err := ContentOverridesForRepo(orgId, domainName, template.UUID, contentPath, repo)
if err != nil {
return mapping, err
}
Expand Down

0 comments on commit f3607cb

Please sign in to comment.