Skip to content

Commit

Permalink
HMS-5056: add layered RH repos with feature name (#941)
Browse files Browse the repository at this point in the history
* HMS-5056: add layered RH repos with feature name

* store feature_name in db

* add index
  • Loading branch information
xbhouse authored Jan 16, 2025
1 parent 4447db6 commit 944fd44
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 64 deletions.
1 change: 1 addition & 0 deletions configs/config.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ options:
enable_notifications: true
template_event_topic: "platform.content-sources.template"
snapshot_retain_days_limit: 365
feature_filter: ["RHEL-OS-x86_64"]
metrics:
path: "/metrics"
port: 9000
Expand Down
2 changes: 1 addition & 1 deletion db/migrations.latest
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20241203143614
20250115112007
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BEGIN;

DROP INDEX IF EXISTS repo_config_feature_name;
ALTER TABLE repository_configurations DROP COLUMN feature_name;

COMMIT;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
BEGIN;

ALTER TABLE repository_configurations
ADD COLUMN IF NOT EXISTS feature_name VARCHAR (255) DEFAULT NULL;

CREATE INDEX IF NOT EXISTS repo_config_feature_name ON repository_configurations(feature_name);

COMMIT;
4 changes: 4 additions & 0 deletions deployments/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ objects:
value: ${OPTIONS_ENABLE_NOTIFICATIONS}
- name: OPTIONS_REPOSITORY_IMPORT_FILTER
value: ${OPTIONS_REPOSITORY_IMPORT_FILTER}
- name: OPTIONS_FEATURE_FILTER
value: ${OPTIONS_FEATURE_FILTER}
- name: TASKING_WORKER_COUNT
value: ${TASKING_WORKER_COUNT}
- name: CLIENTS_CANDLEPIN_SERVER
Expand Down Expand Up @@ -860,3 +862,5 @@ parameters:
description: Number of task workers running within a single worker process
- name: CLIENTS_CANDLEPIN_SERVER
default: ''
- name: OPTIONS_FEATURE_FILTER
description: Comma separated list of features that determine which repos to import
8 changes: 6 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,9 @@ type Options struct {
// url (https://servername) to access the api, used to reference gpg keys
// Supports partial hostnames (i.e. http://.server.example.com).
// If this is encountered (and clowder is used), it will prepend the envName from clowder
ExternalURL string `mapstructure:"external_url"`
SnapshotRetainDaysLimit int `mapstructure:"snapshot_retain_days_limit"`
ExternalURL string `mapstructure:"external_url"`
SnapshotRetainDaysLimit int `mapstructure:"snapshot_retain_days_limit"`
FeatureFilter []string `mapstructure:"feature_filter"` // Used to control which repos are imported based on feature name
}

type Metrics struct {
Expand All @@ -197,6 +198,8 @@ const (
DefaultIntrospectApiTimeLimitSec = 30
)

var featureFilter = [...]string{"RHEL-OS-x86_64"}

var LoadedConfig Configuration

func Get() *Configuration {
Expand Down Expand Up @@ -243,6 +246,7 @@ func setDefaults(v *viper.Viper) {
v.SetDefault("options.enable_notifications", false)
v.SetDefault("options.template_event_topic", "platform.content-sources.template")
v.SetDefault("options.repository_import_filter", "")
v.SetDefault("options.feature_filter", featureFilter)
v.SetDefault("options.external_url", "http://pulp.content:8000")
v.SetDefault("options.snapshot_retain_days_limit", 365)
v.SetDefault("logging.level", "info")
Expand Down
2 changes: 1 addition & 1 deletion pkg/dao/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type RepositoryConfigDao interface {
InternalOnly_FetchRepoConfigsForRepoUUID(ctx context.Context, uuid string) []api.RepositoryResponse
UpdateLastSnapshotTask(ctx context.Context, taskUUID string, orgID string, repoUUID string) error
UpdateLastSnapshot(ctx context.Context, orgID string, repoConfigUUID string, snapUUID string) error
InternalOnly_RefreshRedHatRepo(ctx context.Context, request api.RepositoryRequest, label string) (*api.RepositoryResponse, error)
InternalOnly_RefreshRedHatRepo(ctx context.Context, request api.RepositoryRequest, label string, featureName string) (*api.RepositoryResponse, error)
FetchWithoutOrgID(ctx context.Context, uuid string) (api.RepositoryResponse, error)
BulkExport(ctx context.Context, orgID string, reposToExport api.RepositoryExportRequest) ([]api.RepositoryExportResponse, error)
BulkImport(ctx context.Context, reposToImport []api.RepositoryRequest) ([]api.RepositoryImportResponse, []error)
Expand Down
5 changes: 3 additions & 2 deletions pkg/dao/repository_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ func isTimeout(err error) bool {
return false
}

func (r repositoryConfigDaoImpl) InternalOnly_RefreshRedHatRepo(ctx context.Context, request api.RepositoryRequest, label string) (*api.RepositoryResponse, error) {
func (r repositoryConfigDaoImpl) InternalOnly_RefreshRedHatRepo(ctx context.Context, request api.RepositoryRequest, label string, featureName string) (*api.RepositoryResponse, error) {
newRepoConfig := models.RepositoryConfiguration{}
newRepo := models.Repository{}

Expand All @@ -1256,6 +1256,7 @@ func (r repositoryConfigDaoImpl) InternalOnly_RefreshRedHatRepo(ctx context.Cont

newRepoConfig.OrgID = config.RedHatOrg
newRepoConfig.Label = label
newRepoConfig.FeatureName = featureName
newRepo.Origin = config.OriginRedHat
newRepo.Public = true // Ensure all RH repos can be searched

Expand All @@ -1278,7 +1279,7 @@ func (r repositoryConfigDaoImpl) InternalOnly_RefreshRedHatRepo(ctx context.Cont
result = r.db.WithContext(ctx).Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "repository_uuid"}, {Name: "org_id"}},
TargetWhere: clause.Where{Exprs: []clause.Expression{clause.Eq{Column: "deleted_at", Value: nil}}},
DoUpdates: clause.AssignmentColumns([]string{"name", "arch", "versions", "gpg_key", "label"})}).
DoUpdates: clause.AssignmentColumns([]string{"name", "arch", "versions", "gpg_key", "label", "feature_name"})}).
Create(&newRepoConfig)
if result.Error != nil {
return nil, result.Error
Expand Down
82 changes: 42 additions & 40 deletions pkg/dao/repository_configs_mock.go

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

4 changes: 2 additions & 2 deletions pkg/dao/repository_configs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2633,7 +2633,7 @@ func (suite *RepositoryConfigSuite) TestRefreshRedHatRepo() {
ContentType: utils.Ptr(config.ContentTypeRpm),
Snapshot: utils.Ptr(true),
}
response, err := dao.InternalOnly_RefreshRedHatRepo(context.Background(), rhRepo, "another-label")
response, err := dao.InternalOnly_RefreshRedHatRepo(context.Background(), rhRepo, "another-label", "test-feature")
assert.NoError(suite.T(), err)

assert.NotEmpty(suite.T(), response.UUID)
Expand All @@ -2644,7 +2644,7 @@ func (suite *RepositoryConfigSuite) TestRefreshRedHatRepo() {
// Change the name
rhRepo.Name = utils.Ptr("another name")

response, err = dao.InternalOnly_RefreshRedHatRepo(context.Background(), rhRepo, "some-label")
response, err = dao.InternalOnly_RefreshRedHatRepo(context.Background(), rhRepo, "some-label", "test-feature")
assert.NoError(suite.T(), err)

assert.Equal(suite.T(), *rhRepo.Name, response.Name)
Expand Down
8 changes: 6 additions & 2 deletions pkg/external_repos/redhat_repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type RedHatRepo struct {
Selector string `json:"selector"`
GpgKey string `json:"gpg_key"`
Label string `json:"content_label"`
FeatureName string `json:"feature_name"`
}

func (rhr RedHatRepo) ToRepositoryRequest() api.RepositoryRequest {
Expand Down Expand Up @@ -63,7 +64,7 @@ func (rhr *RedHatRepoImporter) LoadAndSave(ctx context.Context) error {
}
for _, r := range repos {
r.GpgKey = gpgKey
_, err = rhr.daoReg.RepositoryConfig.InternalOnly_RefreshRedHatRepo(ctx, r.ToRepositoryRequest(), r.Label)
_, err = rhr.daoReg.RepositoryConfig.InternalOnly_RefreshRedHatRepo(ctx, r.ToRepositoryRequest(), r.Label, r.FeatureName)
if err != nil {
return err
}
Expand Down Expand Up @@ -96,9 +97,12 @@ func (rhr *RedHatRepoImporter) loadFromFile() ([]RedHatRepo, error) {
}
filteredRepos := []RedHatRepo{}
filter := config.Get().Options.RepositoryImportFilter
features := config.Get().Options.FeatureFilter
for _, repo := range repos {
if filter == "" || repo.Selector == filter {
filteredRepos = append(filteredRepos, repo)
if utils.Contains(features, repo.FeatureName) {
filteredRepos = append(filteredRepos, repo)
}
}
}
return filteredRepos, nil
Expand Down
Loading

0 comments on commit 944fd44

Please sign in to comment.