Skip to content

Commit

Permalink
MGMT-17412: Change fallbck behavior when error occuring in OpenShift …
Browse files Browse the repository at this point in the history
…Release Syncer - if there are release images already in the DB, continue using the stale data instead of failing / truncating the table (#6145) (#6186)
  • Loading branch information
danmanor authored Apr 18, 2024
1 parent dffc2f9 commit 4dcebe4
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 22 deletions.
14 changes: 7 additions & 7 deletions internal/versions/rest_api_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
"github.com/lib/pq"
"github.com/openshift/assisted-service/internal/common"
"github.com/openshift/assisted-service/internal/oc"
models "github.com/openshift/assisted-service/models"
Expand Down Expand Up @@ -49,17 +50,16 @@ func (h *restAPIVersionsHandler) GetReleaseImage(_ context.Context, openshiftVer
if cpuArchitecture == common.MultiCPUArchitecture {
query = query.Where("cardinality(cpu_architectures) > 1")
} else {
query = query.Where(h.db.Session(&gorm.Session{}).Where("? = ANY(cpu_architectures)", cpuArchitecture).Or("cpu_architecture = ?", cpuArchitecture))
query = query.Where(h.db.Session(&gorm.Session{}).
Where("cpu_architectures @> ? AND ? @> cpu_architectures", pq.StringArray{cpuArchitecture}, pq.StringArray{cpuArchitecture}).
Or("cpu_architecture = ?", cpuArchitecture))
}

// Find the exact version
if versionFormat == common.MajorMinorPatchVersion {
editedVersion := openshiftVersion
// add multi suffix if missing
if cpuArchitecture == common.MultiCPUArchitecture && !strings.HasSuffix(openshiftVersion, "-multi") {
editedVersion = editedVersion + "-multi"
}
query = query.Where("version = ?", editedVersion)
query = query.Where(h.db.Session(&gorm.Session{}).
Where("version = ?", openshiftVersion).
Or("version = ?", openshiftVersion+"-multi"))
var releaseImage models.ReleaseImage
err := query.Take(&releaseImage).Error
if err != nil {
Expand Down
100 changes: 99 additions & 1 deletion internal/versions/rest_api_versions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,15 @@ var _ = Describe("GetReleaseImage", func() {
SupportLevel: models.ReleaseImageSupportLevelProduction,
Default: false,
},

{
OpenshiftVersion: swag.String("4.14-multi"),
Version: swag.String("4.14.3-multi"),
CPUArchitecture: swag.String(common.MultiCPUArchitecture),
CPUArchitectures: []string{common.X86CPUArchitecture, common.ARM64CPUArchitecture},
URL: swag.String("quay.io/openshift-release-dev/ocp-release:4.14.3-multi"),
SupportLevel: models.ReleaseImageSupportLevelProduction,
Default: false,
},
{
OpenshiftVersion: swag.String("4.15"),
Version: swag.String("4.15.1"),
Expand All @@ -122,6 +130,24 @@ var _ = Describe("GetReleaseImage", func() {
SupportLevel: models.OpenshiftVersionSupportLevelBeta,
Default: false,
},
{
OpenshiftVersion: swag.String("4.16-multi"),
Version: swag.String("4.16.1-multi"),
CPUArchitecture: swag.String(common.MultiCPUArchitecture),
CPUArchitectures: []string{common.X86CPUArchitecture, common.ARM64CPUArchitecture},
URL: swag.String("quay.io/openshift-release-dev/ocp-release:4.16.1-multi"),
SupportLevel: models.ReleaseImageSupportLevelProduction,
Default: false,
},
{
OpenshiftVersion: swag.String("4.16"),
Version: swag.String("4.16.1"),
CPUArchitecture: swag.String(common.X86CPUArchitecture),
CPUArchitectures: []string{common.X86CPUArchitecture},
URL: swag.String("quay.io/openshift-release-dev/ocp-release:4.16.1-x86_64"),
SupportLevel: models.ReleaseImageSupportLevelProduction,
Default: false,
},
}

err := db.Create(releaseImages).Error
Expand All @@ -134,6 +160,10 @@ var _ = Describe("GetReleaseImage", func() {
releaseImage, err = handler.GetReleaseImage(ctx, "4.15", common.X86CPUArchitecture, pullSecret)
Expect(err).ShouldNot(HaveOccurred())
Expect(*releaseImage.Version).Should(Equal("4.15.2"))

releaseImage, err = handler.GetReleaseImage(ctx, "4.16", common.X86CPUArchitecture, pullSecret)
Expect(err).ShouldNot(HaveOccurred())
Expect(*releaseImage.Version).Should(Equal("4.16.1"))
})

It("gets the exact matching release image with major.minor.patch / prerelease openshiftVersion", func() {
Expand Down Expand Up @@ -206,6 +236,40 @@ var _ = Describe("GetReleaseImage", func() {
Expect(*releaseImage.Version).Should(Equal("4.14.2"))
})

It("gets successfully image using major.minor.patch openshiftVersion in multiarch query with different version format", func() {
releaseImages := models.ReleaseImages{
{
OpenshiftVersion: swag.String("4.16.0-0.nightly-arm64-2024-04-08-123354"),
Version: swag.String("4.16.0-0.nightly-arm64-2024-04-08-123354"),
CPUArchitecture: swag.String(common.ARM64CPUArchitecture),
CPUArchitectures: []string{common.ARM64CPUArchitecture},
URL: swag.String("quay.io/foobar/4.16.0-0.nightly-arm64-2024-04-08-123354@foobar"),
SupportLevel: models.ReleaseImageSupportLevelProduction,
Default: false,
},
{
OpenshiftVersion: swag.String("4.16.0-0.nightly-multi-2024-04-08-123354"),
Version: swag.String("4.16.0-0.nightly-multi-2024-04-08-123354"),
CPUArchitecture: swag.String(common.MultiCPUArchitecture),
CPUArchitectures: []string{common.X86CPUArchitecture, common.ARM64CPUArchitecture},
URL: swag.String("quay.io/foobar/4.16.0-0.nightly-multi-2024-04-08-123354@foobar"),
SupportLevel: models.ReleaseImageSupportLevelProduction,
Default: false,
},
}

err := db.Create(releaseImages).Error
Expect(err).ShouldNot(HaveOccurred())

releaseImage, err := handler.GetReleaseImage(ctx, "4.16.0-0.nightly-arm64-2024-04-08-123354", common.ARM64CPUArchitecture, pullSecret)
Expect(err).ShouldNot(HaveOccurred())
Expect(*releaseImage.Version).Should(Equal("4.16.0-0.nightly-arm64-2024-04-08-123354"))

releaseImage, err = handler.GetReleaseImage(ctx, "4.16.0-0.nightly-multi-2024-04-08-123354", common.MultiCPUArchitecture, pullSecret)
Expect(err).ShouldNot(HaveOccurred())
Expect(*releaseImage.Version).Should(Equal("4.16.0-0.nightly-multi-2024-04-08-123354"))
})

It("gets release image successfully with major.minor.patch openshiftVersion and old syntax", func() {
releaseImages := models.ReleaseImages{
{
Expand Down Expand Up @@ -374,6 +438,40 @@ var _ = Describe("GetReleaseImage", func() {
Expect(*releaseImage.Version).Should(Equal("4.14.2-multi"))
})

It("gets successfully image using major.minor.patch openshiftVersion in multiarch query with different version format", func() {
releaseImages := models.ReleaseImages{
{
OpenshiftVersion: swag.String("4.16.0-0.nightly-arm64-2024-04-08-123354"),
Version: swag.String("4.16.0-0.nightly-arm64-2024-04-08-123354"),
CPUArchitecture: swag.String(common.ARM64CPUArchitecture),
CPUArchitectures: []string{common.ARM64CPUArchitecture},
URL: swag.String("quay.io/foobar/4.16.0-0.nightly-arm64-2024-04-08-123354@foobar"),
SupportLevel: models.ReleaseImageSupportLevelProduction,
Default: false,
},
{
OpenshiftVersion: swag.String("4.16.0-0.nightly-multi-2024-04-08-123354"),
Version: swag.String("4.16.0-0.nightly-multi-2024-04-08-123354"),
CPUArchitecture: swag.String(common.MultiCPUArchitecture),
CPUArchitectures: []string{common.X86CPUArchitecture, common.ARM64CPUArchitecture},
URL: swag.String("quay.io/foobar/4.16.0-0.nightly-multi-2024-04-08-123354@foobar"),
SupportLevel: models.ReleaseImageSupportLevelProduction,
Default: false,
},
}

err := db.Create(releaseImages).Error
Expect(err).ShouldNot(HaveOccurred())

releaseImage, err := handler.GetReleaseImage(ctx, "4.16.0-0.nightly-arm64-2024-04-08-123354", common.ARM64CPUArchitecture, pullSecret)
Expect(err).ShouldNot(HaveOccurred())
Expect(*releaseImage.Version).Should(Equal("4.16.0-0.nightly-arm64-2024-04-08-123354"))

releaseImage, err = handler.GetReleaseImage(ctx, "4.16.0-0.nightly-multi-2024-04-08-123354", common.MultiCPUArchitecture, pullSecret)
Expect(err).ShouldNot(HaveOccurred())
Expect(*releaseImage.Version).Should(Equal("4.16.0-0.nightly-multi-2024-04-08-123354"))
})

It("returns an error when using major.minor.patch openshiftVersion but no exact match found", func() {
releaseImages := models.ReleaseImages{
{
Expand Down
8 changes: 4 additions & 4 deletions subsystem/cluster_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,15 +536,15 @@ var _ = Describe("[V2ClusterTests] multiarch", func() {
var tmpPullSecret string
var clusterID strfmt.UUID

registerClusterForMultiArch := func(cpuArchitecture string) *models.Cluster {
registerClusterForMultiArch := func() *models.Cluster {
clusterReq, err := user2BMClient.Installer.V2RegisterCluster(ctx, &installer.V2RegisterClusterParams{
NewClusterParams: &models.ClusterCreateParams{
Name: swag.String("test-cluster"),
OpenshiftVersion: swag.String("4.12"),
PullSecret: swag.String(fmt.Sprintf(psTemplate, FakePS2)),
BaseDNSDomain: "example.com",
UserManagedNetworking: swag.Bool(true),
CPUArchitecture: cpuArchitecture,
CPUArchitecture: common.MultiCPUArchitecture,
},
})
Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -572,7 +572,7 @@ var _ = Describe("[V2ClusterTests] multiarch", func() {
})

It("Default image type on s390x", func() {
cluster := registerClusterForMultiArch(models.ClusterCPUArchitectureS390x)
cluster := registerClusterForMultiArch()
infraEnv := registerInfraEnvSpecificVersionAndArch(cluster.ID, "", common.S390xCPUArchitecture, "")
Expect(*infraEnv.Type).To(Equal(models.ImageTypeFullIso))

Expand All @@ -591,7 +591,7 @@ var _ = Describe("[V2ClusterTests] multiarch", func() {
Expect(err).To(HaveOccurred())
})
It("Default image type on ppc64le", func() {
cluster := registerClusterForMultiArch(models.ClusterCPUArchitecturePpc64le)
cluster := registerClusterForMultiArch()
infraEnv := registerInfraEnvSpecificVersionAndArch(cluster.ID, "", common.PowerCPUArchitecture, "")
Expect(*infraEnv.Type).To(Equal(models.ImageTypeFullIso))

Expand Down
20 changes: 10 additions & 10 deletions subsystem/feature_support_levels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ var _ = Describe("Feature support levels API", func() {
})

Context("Update cluster", func() {
It("Update umn true won't fail on 4.13 with s390x without infra-env", func() {
cluster, err := registerNewCluster("4.13", "s390x", models.ClusterHighAvailabilityModeFull, swag.Bool(true))
It("Update umn true won't fail on 4.13 with multi release without infra-env", func() {
cluster, err := registerNewCluster("4.13", common.MultiCPUArchitecture, models.ClusterHighAvailabilityModeFull, swag.Bool(true))
Expect(err).NotTo(HaveOccurred())
Expect(cluster.Payload.CPUArchitecture).To(Equal("multi"))
Expect(cluster.Payload.CPUArchitecture).To(Equal(common.MultiCPUArchitecture))

_, err = user2BMClient.Installer.V2UpdateCluster(ctx, &installer.V2UpdateClusterParams{
ClusterUpdateParams: &models.V2ClusterUpdateParams{
Expand All @@ -117,9 +117,9 @@ var _ = Describe("Feature support levels API", func() {

It("Update umn true fail on 4.13 with s390x with infra-env", func() {
expectedError := "cannot use Cluster Managed Networking because it's not compatible with the s390x architecture on version 4.13"
cluster, err := registerNewCluster("4.13", "s390x", models.ClusterHighAvailabilityModeFull, swag.Bool(true))
cluster, err := registerNewCluster("4.13", common.MultiCPUArchitecture, models.ClusterHighAvailabilityModeFull, swag.Bool(true))
Expect(err).NotTo(HaveOccurred())
Expect(cluster.Payload.CPUArchitecture).To(Equal("multi"))
Expect(cluster.Payload.CPUArchitecture).To(Equal(common.MultiCPUArchitecture))

infraEnv, err := registerNewInfraEnv(cluster.Payload.ID, "4.13", "s390x")
Expect(err).NotTo(HaveOccurred())
Expand All @@ -138,9 +138,9 @@ var _ = Describe("Feature support levels API", func() {

It("Create infra-env after updating OLM operators on s390x architecture ", func() {
expectedError := "cannot use OpenShift Virtualization because it's not compatible with the s390x architecture on version 4.13"
cluster, err := registerNewCluster("4.13", "s390x", models.ClusterHighAvailabilityModeFull, swag.Bool(true))
cluster, err := registerNewCluster("4.13", common.MultiCPUArchitecture, models.ClusterHighAvailabilityModeFull, swag.Bool(true))
Expect(err).NotTo(HaveOccurred())
Expect(cluster.Payload.CPUArchitecture).To(Equal("multi"))
Expect(cluster.Payload.CPUArchitecture).To(Equal(common.MultiCPUArchitecture))

_, err = user2BMClient.Installer.V2UpdateCluster(ctx, &installer.V2UpdateClusterParams{
ClusterUpdateParams: &models.V2ClusterUpdateParams{
Expand Down Expand Up @@ -212,13 +212,13 @@ var _ = Describe("Feature support levels API", func() {
It("Register cluster won't fail on 4.13 with s390x", func() {
cluster, err := registerNewCluster("4.13", "s390x", models.ClusterHighAvailabilityModeFull, swag.Bool(true))
Expect(err).NotTo(HaveOccurred())
Expect(cluster.Payload.CPUArchitecture).To(Equal("multi"))
Expect(cluster.Payload.CPUArchitecture).To(Equal(common.S390xCPUArchitecture))
})

It("Register cluster won't fail on 4.13 with s390x without UMN", func() {
cluster, err := registerNewCluster("4.13", "s390x", models.ClusterHighAvailabilityModeFull, nil)
Expect(err).NotTo(HaveOccurred())
Expect(cluster.Payload.CPUArchitecture).To(Equal("multi"))
Expect(cluster.Payload.CPUArchitecture).To(Equal(common.S390xCPUArchitecture))
})

It("SNO with s390x 4.10 fails on architecture- failure", func() {
Expand All @@ -231,7 +231,7 @@ var _ = Describe("Feature support levels API", func() {
It("SNO with s390x fails on SNO isn't compatible with architecture success on 4.13", func() {
cluster, err := registerNewCluster("4.13", "s390x", models.ClusterHighAvailabilityModeNone, nil)
Expect(err).NotTo(HaveOccurred())
Expect(cluster.Payload.CPUArchitecture).To(Equal("multi"))
Expect(cluster.Payload.CPUArchitecture).To(Equal(common.S390xCPUArchitecture))
Expect(swag.StringValue(cluster.Payload.HighAvailabilityMode)).To(Equal(models.ClusterHighAvailabilityModeNone))

})
Expand Down

0 comments on commit 4dcebe4

Please sign in to comment.