Skip to content

Commit 944fd44

Browse files
authoredJan 16, 2025··
HMS-5056: add layered RH repos with feature name (#941)
* HMS-5056: add layered RH repos with feature name * store feature_name in db * add index
1 parent 4447db6 commit 944fd44

13 files changed

+149
-64
lines changed
 

‎configs/config.yaml.example

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ options:
6262
enable_notifications: true
6363
template_event_topic: "platform.content-sources.template"
6464
snapshot_retain_days_limit: 365
65+
feature_filter: ["RHEL-OS-x86_64"]
6566
metrics:
6667
path: "/metrics"
6768
port: 9000

‎db/migrations.latest

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20241203143614
1+
20250115112007
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
BEGIN;
2+
3+
DROP INDEX IF EXISTS repo_config_feature_name;
4+
ALTER TABLE repository_configurations DROP COLUMN feature_name;
5+
6+
COMMIT;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
BEGIN;
2+
3+
ALTER TABLE repository_configurations
4+
ADD COLUMN IF NOT EXISTS feature_name VARCHAR (255) DEFAULT NULL;
5+
6+
CREATE INDEX IF NOT EXISTS repo_config_feature_name ON repository_configurations(feature_name);
7+
8+
COMMIT;

‎deployments/deployment.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ objects:
134134
value: ${OPTIONS_ENABLE_NOTIFICATIONS}
135135
- name: OPTIONS_REPOSITORY_IMPORT_FILTER
136136
value: ${OPTIONS_REPOSITORY_IMPORT_FILTER}
137+
- name: OPTIONS_FEATURE_FILTER
138+
value: ${OPTIONS_FEATURE_FILTER}
137139
- name: TASKING_WORKER_COUNT
138140
value: ${TASKING_WORKER_COUNT}
139141
- name: CLIENTS_CANDLEPIN_SERVER
@@ -860,3 +862,5 @@ parameters:
860862
description: Number of task workers running within a single worker process
861863
- name: CLIENTS_CANDLEPIN_SERVER
862864
default: ''
865+
- name: OPTIONS_FEATURE_FILTER
866+
description: Comma separated list of features that determine which repos to import

‎pkg/config/config.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,9 @@ type Options struct {
175175
// url (https://servername) to access the api, used to reference gpg keys
176176
// Supports partial hostnames (i.e. http://.server.example.com).
177177
// If this is encountered (and clowder is used), it will prepend the envName from clowder
178-
ExternalURL string `mapstructure:"external_url"`
179-
SnapshotRetainDaysLimit int `mapstructure:"snapshot_retain_days_limit"`
178+
ExternalURL string `mapstructure:"external_url"`
179+
SnapshotRetainDaysLimit int `mapstructure:"snapshot_retain_days_limit"`
180+
FeatureFilter []string `mapstructure:"feature_filter"` // Used to control which repos are imported based on feature name
180181
}
181182

182183
type Metrics struct {
@@ -197,6 +198,8 @@ const (
197198
DefaultIntrospectApiTimeLimitSec = 30
198199
)
199200

201+
var featureFilter = [...]string{"RHEL-OS-x86_64"}
202+
200203
var LoadedConfig Configuration
201204

202205
func Get() *Configuration {
@@ -243,6 +246,7 @@ func setDefaults(v *viper.Viper) {
243246
v.SetDefault("options.enable_notifications", false)
244247
v.SetDefault("options.template_event_topic", "platform.content-sources.template")
245248
v.SetDefault("options.repository_import_filter", "")
249+
v.SetDefault("options.feature_filter", featureFilter)
246250
v.SetDefault("options.external_url", "http://pulp.content:8000")
247251
v.SetDefault("options.snapshot_retain_days_limit", 365)
248252
v.SetDefault("logging.level", "info")

‎pkg/dao/interfaces.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ type RepositoryConfigDao interface {
7676
InternalOnly_FetchRepoConfigsForRepoUUID(ctx context.Context, uuid string) []api.RepositoryResponse
7777
UpdateLastSnapshotTask(ctx context.Context, taskUUID string, orgID string, repoUUID string) error
7878
UpdateLastSnapshot(ctx context.Context, orgID string, repoConfigUUID string, snapUUID string) error
79-
InternalOnly_RefreshRedHatRepo(ctx context.Context, request api.RepositoryRequest, label string) (*api.RepositoryResponse, error)
79+
InternalOnly_RefreshRedHatRepo(ctx context.Context, request api.RepositoryRequest, label string, featureName string) (*api.RepositoryResponse, error)
8080
FetchWithoutOrgID(ctx context.Context, uuid string) (api.RepositoryResponse, error)
8181
BulkExport(ctx context.Context, orgID string, reposToExport api.RepositoryExportRequest) ([]api.RepositoryExportResponse, error)
8282
BulkImport(ctx context.Context, reposToImport []api.RepositoryRequest) ([]api.RepositoryImportResponse, []error)

‎pkg/dao/repository_configs.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,7 @@ func isTimeout(err error) bool {
12471247
return false
12481248
}
12491249

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

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

12571257
newRepoConfig.OrgID = config.RedHatOrg
12581258
newRepoConfig.Label = label
1259+
newRepoConfig.FeatureName = featureName
12591260
newRepo.Origin = config.OriginRedHat
12601261
newRepo.Public = true // Ensure all RH repos can be searched
12611262

@@ -1278,7 +1279,7 @@ func (r repositoryConfigDaoImpl) InternalOnly_RefreshRedHatRepo(ctx context.Cont
12781279
result = r.db.WithContext(ctx).Clauses(clause.OnConflict{
12791280
Columns: []clause.Column{{Name: "repository_uuid"}, {Name: "org_id"}},
12801281
TargetWhere: clause.Where{Exprs: []clause.Expression{clause.Eq{Column: "deleted_at", Value: nil}}},
1281-
DoUpdates: clause.AssignmentColumns([]string{"name", "arch", "versions", "gpg_key", "label"})}).
1282+
DoUpdates: clause.AssignmentColumns([]string{"name", "arch", "versions", "gpg_key", "label", "feature_name"})}).
12821283
Create(&newRepoConfig)
12831284
if result.Error != nil {
12841285
return nil, result.Error

‎pkg/dao/repository_configs_mock.go

+42-40
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pkg/dao/repository_configs_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2633,7 +2633,7 @@ func (suite *RepositoryConfigSuite) TestRefreshRedHatRepo() {
26332633
ContentType: utils.Ptr(config.ContentTypeRpm),
26342634
Snapshot: utils.Ptr(true),
26352635
}
2636-
response, err := dao.InternalOnly_RefreshRedHatRepo(context.Background(), rhRepo, "another-label")
2636+
response, err := dao.InternalOnly_RefreshRedHatRepo(context.Background(), rhRepo, "another-label", "test-feature")
26372637
assert.NoError(suite.T(), err)
26382638

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

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

26502650
assert.Equal(suite.T(), *rhRepo.Name, response.Name)

‎pkg/external_repos/redhat_repos.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type RedHatRepo struct {
2727
Selector string `json:"selector"`
2828
GpgKey string `json:"gpg_key"`
2929
Label string `json:"content_label"`
30+
FeatureName string `json:"feature_name"`
3031
}
3132

3233
func (rhr RedHatRepo) ToRepositoryRequest() api.RepositoryRequest {
@@ -63,7 +64,7 @@ func (rhr *RedHatRepoImporter) LoadAndSave(ctx context.Context) error {
6364
}
6465
for _, r := range repos {
6566
r.GpgKey = gpgKey
66-
_, err = rhr.daoReg.RepositoryConfig.InternalOnly_RefreshRedHatRepo(ctx, r.ToRepositoryRequest(), r.Label)
67+
_, err = rhr.daoReg.RepositoryConfig.InternalOnly_RefreshRedHatRepo(ctx, r.ToRepositoryRequest(), r.Label, r.FeatureName)
6768
if err != nil {
6869
return err
6970
}
@@ -96,9 +97,12 @@ func (rhr *RedHatRepoImporter) loadFromFile() ([]RedHatRepo, error) {
9697
}
9798
filteredRepos := []RedHatRepo{}
9899
filter := config.Get().Options.RepositoryImportFilter
100+
features := config.Get().Options.FeatureFilter
99101
for _, repo := range repos {
100102
if filter == "" || repo.Selector == filter {
101-
filteredRepos = append(filteredRepos, repo)
103+
if utils.Contains(features, repo.FeatureName) {
104+
filteredRepos = append(filteredRepos, repo)
105+
}
102106
}
103107
}
104108
return filteredRepos, nil

0 commit comments

Comments
 (0)
Please sign in to comment.