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

MGMT-15114: remove event for cluster registration failed #5330

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 0 additions & 9 deletions docs/events.yaml
Expand Up @@ -31,15 +31,6 @@ x-events:
infra_env_id: UUID
cluster_id: UUID_PTR

- name: cluster_registration_failed
message: "Failed to register cluster. Error: {error}"
event_type: cluster
severity: "error"
properties:
cluster_id: UUID
error: string
cluster_kind: string

- name: cluster_registration_succeeded
message: "Successfully registered cluster"
event_type: cluster
Expand Down
3 changes: 0 additions & 3 deletions internal/bminventory/inventory.go
Expand Up @@ -525,9 +525,6 @@ func (b *bareMetalInventory) RegisterClusterInternal(
errStr := fmt.Sprintf("Failed to registered cluster %s with id %s", swag.StringValue(params.NewClusterParams.Name), id)
if err != nil {
errWrapperLog = log.WithError(err)
eventgen.SendClusterRegistrationFailedEvent(ctx, b.eventsHandler, id, err.Error(), models.ClusterKindCluster)
} else {
eventgen.SendClusterRegistrationFailedEvent(ctx, b.eventsHandler, id, errStr, models.ClusterKindCluster)
}
errWrapperLog.Errorf(errStr)
}
Expand Down
359 changes: 0 additions & 359 deletions internal/bminventory/inventory_test.go

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions internal/cluster/cluster.go
Expand Up @@ -212,11 +212,10 @@ func (m *Manager) RegisterCluster(ctx context.Context, c *common.Cluster) error
func (m *Manager) RegisterAddHostsCluster(ctx context.Context, c *common.Cluster) error {
err := m.registrationAPI.RegisterAddHostsCluster(ctx, c)
if err != nil {
eventgen.SendClusterRegistrationFailedEvent(ctx, m.eventsHandler, *c.ID, err.Error(), models.ClusterKindAddHostsCluster)
} else {
eventgen.SendClusterRegistrationSucceededEvent(ctx, m.eventsHandler, *c.ID, models.ClusterKindAddHostsCluster)
return err
}
return err
eventgen.SendClusterRegistrationSucceededEvent(ctx, m.eventsHandler, *c.ID, models.ClusterKindAddHostsCluster)
return nil
}

func (m *Manager) RegisterAddHostsOCPCluster(c *common.Cluster, db *gorm.DB) error {
Expand Down
81 changes: 0 additions & 81 deletions internal/common/events/events.go

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

@@ -0,0 +1,24 @@
package migrations

import (
gormigrate "github.com/go-gormigrate/gormigrate/v2"
"github.com/openshift/assisted-service/models"
"gorm.io/gorm"
)

func deleteEventsWithUnboundCluster() *gormigrate.Migration {
migrate := func(tx *gorm.DB) error {
db := tx.Unscoped()
return db.Where("cluster_id NOT IN (SELECT id FROM clusters)").Delete(&models.Event{}).Error
}
rollback := func(tx *gorm.DB) error {
// Can't really rollback a delete
return nil
}

return &gormigrate.Migration{
ID: "20230629113604",
Migrate: gormigrate.MigrateFunc(migrate),
Rollback: gormigrate.RollbackFunc(rollback),
}
}
@@ -0,0 +1,53 @@
package migrations

import (
"github.com/go-openapi/strfmt"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/openshift/assisted-service/internal/common"
"github.com/openshift/assisted-service/models"
"gorm.io/gorm"
)

var _ = Describe("deleteEventsWithUnboundCluster", func() {
var (
db *gorm.DB
dbName string
clusterID = strfmt.UUID("46a8d745-dfce-4fd8-9df0-549ee8eabb3d")
nonClusterID = strfmt.UUID("44444444-dfce-4fd8-9df0-549ee8eabb3d")
)

BeforeEach(func() {
db, dbName = common.PrepareTestDB()
cluster := common.Cluster{Cluster: models.Cluster{ID: &clusterID, OpenshiftClusterID: strfmt.UUID("134ce3ea-512e-4a11-bc4c-aeac1bdf3820"), UserName: "user1", OrgID: "org1"}}
Expect(db.Create(&cluster).Error).ShouldNot(HaveOccurred())
message := "this is my event"
event := common.Event{Event: models.Event{ClusterID: &clusterID, Message: &message}}
Expect(db.Create(&event).Error).ShouldNot(HaveOccurred())
event = common.Event{Event: models.Event{ClusterID: &nonClusterID, Message: &message}}
Expect(db.Create(&event).Error).ShouldNot(HaveOccurred())
})

AfterEach(func() {
common.DeleteTestDB(db, dbName)
})

It("Migrates up", func() {
numRawEvents := func(clusterID *strfmt.UUID) int {
var count int64
db.Model(&models.Event{}).Where("cluster_id = ?", clusterID).Count(&count)
return int(count)
}

err := migrateToBefore(db, "20230629113604")
Expect(err).ToNot(HaveOccurred())

Expect(numRawEvents(&clusterID)).To(Equal(1))
Expect(numRawEvents(&nonClusterID)).To(Equal(1))

err = migrateTo(db, "20230629113604")
Expect(err).NotTo(HaveOccurred())
Expect(numRawEvents(&clusterID)).To(Equal(1))
Expect(numRawEvents(&nonClusterID)).To(Equal(0))
})
})
1 change: 1 addition & 0 deletions internal/migrations/migrations.go
Expand Up @@ -41,6 +41,7 @@ func post() []*gormigrate.Migration {
dropClusterIgnitionOverrides(),
multipleVips(),
renameKernelArguments(),
deleteEventsWithUnboundCluster(),
}

sort.SliceStable(postMigrations, func(i, j int) bool { return postMigrations[i].ID < postMigrations[j].ID })
Expand Down