Skip to content

Commit d24a603

Browse files
committed
RHINENG-18242: remove candlepin call from listener
system's enviroment is in both reporters no need to call API anymore
1 parent 9746ff3 commit d24a603

5 files changed

Lines changed: 5 additions & 94 deletions

File tree

base/candlepin/candlepin.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,6 @@ type ConsumersUpdateResponse struct {
2121
Message string `json:"displayMessage"`
2222
}
2323

24-
type ConsumersDetailResponse struct {
25-
Environments []ConsumersEnvironment `json:"environments"`
26-
}
27-
28-
type ConsumersEnvironment struct {
29-
ID string `json:"id"`
30-
}
31-
3224
var ErrCandlepin = errors.New("candlepin error")
3325

3426
var (

deploy/clowdapp.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,6 @@ objects:
141141
- {name: DB_USER, value: listener}
142142
- {name: DB_PASSWD, valueFrom: {secretKeyRef: {name: patchman-engine-database-passwords,
143143
key: listener-database-password}}}
144-
- {name: CANDLEPIN_ADDRESS, value: '${CANDLEPIN_ADDRESS}'}
145-
- {name: CANDLEPIN_CERT, valueFrom: {secretKeyRef: {name: candlepin, key: cert}}}
146-
- {name: CANDLEPIN_KEY, valueFrom: {secretKeyRef: {name: candlepin, key: key}}}
147-
- {name: CANDLEPIN_CA, valueFrom: {secretKeyRef: {name: candlepin, key: ca}}}
148144
- {name: KAFKA_GROUP, value: patchman}
149145
- {name: KAFKA_READER_MAX_ATTEMPTS, value: '${KAFKA_READER_MAX_ATTEMPTS}'}
150146
- {name: KAFKA_WRITER_MAX_ATTEMPTS, value: '${KAFKA_WRITER_MAX_ATTEMPTS}'}

listener/rhsm.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
package listener
22

33
import (
4-
"app/base/candlepin"
54
"app/base/models"
65
"app/base/utils"
7-
"context"
8-
"net/http"
96

10-
"github.com/pkg/errors"
117
"gorm.io/gorm"
128
)
139

@@ -41,27 +37,3 @@ func getTemplate(db *gorm.DB, accountID int, environments []string) (*int64, err
4137
}
4238
return templateID, nil
4339
}
44-
45-
func callCandlepinEnvironment(ctx context.Context, consumer string) (
46-
*candlepin.ConsumersDetailResponse, error) {
47-
candlepinEnvConsumersURL := utils.CoreCfg.CandlepinAddress + "/consumers/" + consumer
48-
candlepinFunc := func() (interface{}, *http.Response, error) {
49-
candlepinResp := candlepin.ConsumersDetailResponse{}
50-
resp, err := candlepinClient.Request(&ctx, http.MethodGet, candlepinEnvConsumersURL, nil, &candlepinResp)
51-
statusCode := utils.TryGetStatusCode(resp)
52-
utils.LogDebug("candlepin_url", candlepinEnvConsumersURL, "status_code", statusCode, "err", err)
53-
if err != nil {
54-
err = errors.Wrap(candlepin.ErrCandlepin, err.Error())
55-
} else if statusCode != http.StatusOK && statusCode != http.StatusNoContent {
56-
err = errors.Errorf("candlepin API status %d", statusCode)
57-
}
58-
return &candlepinResp, resp, err
59-
}
60-
61-
candlepinRespPtr, err := utils.HTTPCallRetry(candlepinFunc,
62-
candlepin.CandlepinExpRetries, candlepin.CandlepinRetries, http.StatusServiceUnavailable)
63-
if err != nil {
64-
return nil, errors.Wrap(err, "candlepin /consumers call failed")
65-
}
66-
return candlepinRespPtr.(*candlepin.ConsumersDetailResponse), nil
67-
}

listener/upload.go

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package listener
33
import (
44
"app/base"
55
"app/base/api"
6-
"app/base/candlepin"
76
"app/base/database"
87
"app/base/inventory"
98
"app/base/models"
@@ -51,7 +50,6 @@ const (
5150
RepoPathPattern = "(/content/.*)"
5251
RepoBasearchPlaceholder = "$basearch"
5352
RepoReleaseverPlaceholder = "$releasever"
54-
TemplateRepoPattern = `^https://cert\.console.*/api/pulp-content/(cs-)?[[:xdigit:]]+/templates/`
5553
)
5654

5755
var (
@@ -65,12 +63,10 @@ var (
6563
)
6664

6765
var (
68-
repoPathRegex = regexp.MustCompile(RepoPathPattern)
69-
spacesRegex = regexp.MustCompile(`^\s*$`)
70-
templateRepoPath = regexp.MustCompile(TemplateRepoPattern)
71-
httpClient *api.Client
72-
candlepinClient = candlepin.CreateCandlepinClient()
73-
metricByErr = map[error]string{
66+
repoPathRegex = regexp.MustCompile(RepoPathPattern)
67+
spacesRegex = regexp.MustCompile(`^\s*$`)
68+
httpClient *api.Client
69+
metricByErr = map[error]string{
7470
ErrNoPackages: ReceivedWarnNoPackages,
7571
ErrReporter: ReceivedWarnExcludedReporter,
7672
ErrHostType: ReceivedWarnExcludedHostType,
@@ -332,31 +328,11 @@ func hostTemplate(tx *gorm.DB, accountID int, host *Host) *int64 {
332328
var templateID *int64
333329
var err error
334330
switch host.Reporter {
335-
case rhsmReporter:
331+
case rhsmReporter, puptooReporter:
336332
templateID, err = getTemplate(tx, accountID, host.SystemProfile.Rhsm.Environments)
337333
if err != nil {
338334
utils.LogWarn("inventoryID", host.ID, "err", errors.Wrap(err, "Unable to assign templates"))
339335
}
340-
case puptooReporter:
341-
if hasTemplateRepo(&host.SystemProfile) {
342-
// check system's env in candlepin
343-
resp, err := callCandlepinEnvironment(base.Context, host.SystemProfile.ConsumerID)
344-
if err != nil {
345-
utils.LogWarn("inventoryID", host.ID, "err", errors.Wrap(err, "Unable to assign templates"))
346-
}
347-
348-
// get template from candlepin
349-
if resp != nil {
350-
envs := make([]string, 0, len(resp.Environments))
351-
for _, env := range resp.Environments {
352-
envs = append(envs, env.ID)
353-
}
354-
templateID, err = getTemplate(tx, accountID, envs)
355-
if err != nil {
356-
utils.LogWarn("inventoryID", host.ID, "err", errors.Wrap(err, "Unable to assign templates"))
357-
}
358-
}
359-
}
360336
}
361337
return templateID
362338
}
@@ -667,16 +643,6 @@ func getRepoPath(systemProfile *inventory.SystemProfile, repo *inventory.YumRepo
667643
return repoPath, nil
668644
}
669645

670-
func hasTemplateRepo(systemProfile *inventory.SystemProfile) bool {
671-
yumRepos := systemProfile.GetYumRepos()
672-
for _, r := range yumRepos {
673-
if r.Enabled && templateRepoPath.MatchString(r.BaseURL) {
674-
return true
675-
}
676-
}
677-
return false
678-
}
679-
680646
func processRepos(systemProfile *inventory.SystemProfile) ([]string, []string) {
681647
yumRepos := systemProfile.GetYumRepos()
682648
seen := make(map[string]bool, len(yumRepos))

platform/candlepin.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"io"
88
"net/http"
99
"slices"
10-
"strings"
1110

1211
"github.com/gin-gonic/gin"
1312
)
@@ -23,19 +22,6 @@ func candlepinConsumersPutHandler(c *gin.Context) {
2322
c.Data(http.StatusOK, gin.MIMEJSON, []byte{})
2423
}
2524

26-
func candlepinConsumersGetHandler(c *gin.Context) {
27-
consumer := c.Param("consumer")
28-
utils.LogInfo("GET consumer", consumer, "body")
29-
env := strings.ReplaceAll(consumer, "-", "")
30-
env = strings.Replace(env, "000", "999", 1)
31-
response := candlepin.ConsumersDetailResponse{
32-
Environments: []candlepin.ConsumersEnvironment{
33-
{ID: env},
34-
},
35-
}
36-
c.JSON(http.StatusOK, response)
37-
}
38-
3925
func candlepinConsumersEnvironmentsHandler(c *gin.Context) {
4026
owner := c.Param("owner")
4127
jsonData, _ := io.ReadAll(c.Request.Body)
@@ -56,6 +42,5 @@ func candlepinConsumersEnvironmentsHandler(c *gin.Context) {
5642

5743
func initCandlepin(app *gin.Engine) {
5844
app.PUT("/candlepin/consumers/:consumer", candlepinConsumersPutHandler)
59-
app.GET("/candlepin/consumers/:consumer", candlepinConsumersGetHandler)
6045
app.PUT("/candlepin/owners/:owner/consumers/environments", candlepinConsumersEnvironmentsHandler)
6146
}

0 commit comments

Comments
 (0)