Skip to content

Commit

Permalink
[artemiscloud#348] remove float32 fields from address settings in fav…
Browse files Browse the repository at this point in the history
…our of brokerProperties, revert for v1alpha5

(cherry picked from commit 111470f)

downstream: ENTMQBR-7363
  • Loading branch information
gtully authored and brusdev committed Oct 27, 2022
1 parent 454be94 commit 02e139a
Show file tree
Hide file tree
Showing 14 changed files with 132 additions and 106 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,14 @@ help: ## Display this help.
manifests: controller-gen kustomize
ifeq ($(ENABLE_WEBHOOKS),true)
## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
## v2alpha3, v2alpha4 and v2alpha3 requires allowDangerousTypes=true because they use float32 type
cd config/manager && $(KUSTOMIZE) edit add resource webhook_secret.yaml
$(CONTROLLER_GEN) rbac:roleName=$(OPERATOR_CLUSTER_ROLE_NAME) crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
$(CONTROLLER_GEN) rbac:roleName=$(OPERATOR_CLUSTER_ROLE_NAME) crd:allowDangerousTypes=true webhook paths="./..." output:crd:artifacts:config=config/crd/bases
else
## Generate ClusterRole and CustomResourceDefinition objects.
## v2alpha3, v2alpha4 and v2alpha3 requires allowDangerousTypes=true because they use float32 type
cd config/manager && $(KUSTOMIZE) edit remove resource webhook_secret.yaml
$(CONTROLLER_GEN) rbac:roleName=$(OPERATOR_CLUSTER_ROLE_NAME) crd paths="./..." output:crd:artifacts:config=config/crd/bases
$(CONTROLLER_GEN) rbac:roleName=$(OPERATOR_CLUSTER_ROLE_NAME) crd:allowDangerousTypes=true paths="./..." output:crd:artifacts:config=config/crd/bases
endif

generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
Expand Down
9 changes: 7 additions & 2 deletions api/v1beta1/activemqartemis_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,15 @@ type AddressSettingType struct {
MaxExpiryDelay *int32 `json:"maxExpiryDelay,omitempty"`
// the time (in ms) to wait before redelivering a cancelled message.
RedeliveryDelay *int32 `json:"redeliveryDelay,omitempty"`

// dropping these two fields due to historicatl incorrect conversion from *float32 to *string
// without conversion support. Existing CR's with these set cannot be reconciled
//
// multiplier to apply to the redelivery-delay
RedeliveryDelayMultiplier *string `json:"redeliveryDelayMultiplier,omitempty"`
//RedeliveryDelayMultiplier *string
// factor by which to modify the redelivery delay slightly to avoid collisions
RedeliveryCollisionAvoidanceFactor *string `json:"redeliveryCollisionAvoidanceFactor,omitempty"`
//RedeliveryCollisionAvoidanceFactor *string

// Maximum value for the redelivery-delay
MaxRedeliveryDelay *int32 `json:"maxRedeliveryDelay,omitempty"`
// how many times to attempt to deliver a message before sending to dead letter address
Expand Down
10 changes: 0 additions & 10 deletions api/v1beta1/zz_generated.deepcopy.go

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

6 changes: 3 additions & 3 deletions api/v2alpha3/activemqartemis_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ type AddressSettingType struct {
MaxExpiryDelay *int32 `json:"maxExpiryDelay,omitempty"`
RedeliveryDelay *int32 `json:"redeliveryDelay,omitempty"`
RedeliveryDelayMultiplier *int32 `json:"redeliveryDelayMultiplier,omitempty"`
// controller-gen currently doesn't support float types
// RedeliveryCollisionAvoidanceFactor *float32 `json:"redeliveryCollisionAvoidanceFactor,omitempty"`
RedeliveryCollisionAvoidanceFactor *string `json:"redeliveryCollisionAvoidanceFactor,omitempty"`
//
RedeliveryCollisionAvoidanceFactor *float32 `json:"redeliveryCollisionAvoidanceFactor,omitempty"` // controller-gen requires crd:allowDangerousTypes=true to allow support float types
//
MaxRedeliveryDelay *int32 `json:"maxRedeliveryDelay,omitempty"`
MaxDeliveryAttempts *int32 `json:"maxDeliveryAttempts,omitempty"`
MaxSizeBytes *string `json:"maxSizeBytes,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion api/v2alpha3/zz_generated.deepcopy.go

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

6 changes: 3 additions & 3 deletions api/v2alpha4/activemqartemis_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ type AddressSettingType struct {
MaxExpiryDelay *int32 `json:"maxExpiryDelay,omitempty"`
RedeliveryDelay *int32 `json:"redeliveryDelay,omitempty"`
RedeliveryDelayMultiplier *int32 `json:"redeliveryDelayMultiplier,omitempty"`
// currentl controller-gen doesn't support float type
// RedeliveryCollisionAvoidanceFactor *float32 `json:"redeliveryCollisionAvoidanceFactor,omitempty"`
RedeliveryCollisionAvoidanceFactor *string `json:"redeliveryCollisionAvoidanceFactor,omitempty"`
//
RedeliveryCollisionAvoidanceFactor *float32 `json:"redeliveryCollisionAvoidanceFactor,omitempty"` // controller-gen requires crd:allowDangerousTypes=true to allow support float types
//
MaxRedeliveryDelay *int32 `json:"maxRedeliveryDelay,omitempty"`
MaxDeliveryAttempts *int32 `json:"maxDeliveryAttempts,omitempty"`
MaxSizeBytes *string `json:"maxSizeBytes,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion api/v2alpha4/zz_generated.deepcopy.go

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

9 changes: 4 additions & 5 deletions api/v2alpha5/activemqartemis_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,10 @@ type AddressSettingType struct {
MinExpiryDelay *int32 `json:"minExpiryDelay,omitempty"`
MaxExpiryDelay *int32 `json:"maxExpiryDelay,omitempty"`
RedeliveryDelay *int32 `json:"redeliveryDelay,omitempty"`
// controller-gen currently doesn't support float types
// RedeliveryDelayMultiplier *float32 `json:"redeliveryDelayMultiplier,omitempty"`
// RedeliveryCollisionAvoidanceFactor *float32 `json:"redeliveryCollisionAvoidanceFactor,omitempty"`
RedeliveryDelayMultiplier *string `json:"redeliveryDelayMultiplier,omitempty"`
RedeliveryCollisionAvoidanceFactor *string `json:"redeliveryCollisionAvoidanceFactor,omitempty"`
//
RedeliveryDelayMultiplier *float32 `json:"redeliveryDelayMultiplier,omitempty"` // controller-gen requires crd:allowDangerousTypes=true to allow support float types
RedeliveryCollisionAvoidanceFactor *float32 `json:"redeliveryCollisionAvoidanceFactor,omitempty"` // controller-gen requires crd:allowDangerousTypes=true to allow support float types
//
MaxRedeliveryDelay *int32 `json:"maxRedeliveryDelay,omitempty"`
MaxDeliveryAttempts *int32 `json:"maxDeliveryAttempts,omitempty"`
MaxSizeBytes *string `json:"maxSizeBytes,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions api/v2alpha5/zz_generated.deepcopy.go

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

22 changes: 4 additions & 18 deletions config/crd/bases/broker.amq.io_activemqartemises.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -394,18 +394,11 @@ spec:
description: The page size in bytes to use for an address.
Supports byte notation like K, Mb, GB, etc.
type: string
redeliveryCollisionAvoidanceFactor:
description: factor by which to modify the redelivery delay
slightly to avoid collisions
type: string
redeliveryDelay:
description: the time (in ms) to wait before redelivering
a cancelled message.
format: int32
type: integer
redeliveryDelayMultiplier:
description: multiplier to apply to the redelivery-delay
type: string
redistributionDelay:
description: how long (in ms) to wait after the last consumer
is closed on a queue before redistributing messages.
Expand Down Expand Up @@ -2612,9 +2605,7 @@ spec:
pageSizeBytes:
type: string
redeliveryCollisionAvoidanceFactor:
description: controller-gen currently doesn't support float
types RedeliveryCollisionAvoidanceFactor *float32 `json:"redeliveryCollisionAvoidanceFactor,omitempty"`
type: string
type: number
redeliveryDelay:
format: int32
type: integer
Expand Down Expand Up @@ -2979,9 +2970,7 @@ spec:
pageSizeBytes:
type: string
redeliveryCollisionAvoidanceFactor:
description: currentl controller-gen doesn't support float
type RedeliveryCollisionAvoidanceFactor *float32 `json:"redeliveryCollisionAvoidanceFactor,omitempty"`
type: string
type: number
redeliveryDelay:
format: int32
type: integer
Expand Down Expand Up @@ -3361,15 +3350,12 @@ spec:
pageSizeBytes:
type: string
redeliveryCollisionAvoidanceFactor:
type: string
type: number
redeliveryDelay:
format: int32
type: integer
redeliveryDelayMultiplier:
description: controller-gen currently doesn't support float
types RedeliveryDelayMultiplier *float32 `json:"redeliveryDelayMultiplier,omitempty"`
RedeliveryCollisionAvoidanceFactor *float32 `json:"redeliveryCollisionAvoidanceFactor,omitempty"`
type: string
type: number
redistributionDelay:
format: int32
type: integer
Expand Down
96 changes: 96 additions & 0 deletions controllers/activemqartemis_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

"github.com/artemiscloud/activemq-artemis-operator/api/v1beta1"
brokerv2alpha4 "github.com/artemiscloud/activemq-artemis-operator/api/v2alpha4"
"github.com/artemiscloud/activemq-artemis-operator/api/v2alpha5"
"github.com/artemiscloud/activemq-artemis-operator/pkg/resources/environments"
"github.com/artemiscloud/activemq-artemis-operator/pkg/resources/pods"
"github.com/artemiscloud/activemq-artemis-operator/pkg/resources/secrets"
Expand Down Expand Up @@ -223,6 +224,101 @@ var _ = Describe("artemis controller", func() {
yacfgProfileVersion = version.YacfgProfileVersionFromFullVersion[version.FullVersionFromCompactVersion[compactVersionToUse]]
Expect(yacfgProfileVersion).To(Equal("7.10.0"))
})
})

Context("CrVersionConversionTest", func() {
It("can reconcile different version", func() {

var float32Var = float32(2.3)
var ma = "all"
toCreate := v2alpha5.ActiveMQArtemis{
TypeMeta: metav1.TypeMeta{
Kind: "ActiveMQArtemis",
APIVersion: v2alpha5.GroupVersion.Identifier(),
},
ObjectMeta: metav1.ObjectMeta{
Name: randString(),
Namespace: defaultNamespace,
},
Spec: v2alpha5.ActiveMQArtemisSpec{
AddressSettings: v2alpha5.AddressSettingsType{
ApplyRule: &ma,
AddressSetting: []v2alpha5.AddressSettingType{
{
Match: "#",
RedeliveryDelayMultiplier: &float32Var,
RedeliveryCollisionAvoidanceFactor: &float32Var,
},
},
},
},
}

By("deploying v2lpha5 with float32, ignored")
Expect(k8sClient.Create(context.TODO(), &toCreate)).Should(Succeed())

key := types.NamespacedName{Name: namer.CrToSS(toCreate.Name), Namespace: defaultNamespace}
createdSs := &appsv1.StatefulSet{}
Eventually(func(g Gomega) {
g.Expect(k8sClient.Get(ctx, key, createdSs)).Should(Succeed())
}, timeout, interval).Should(Succeed())

By("checking status - using original version - exercise in marshalling")
key = types.NamespacedName{Name: toCreate.Name, Namespace: toCreate.Namespace}
createdCrdv2alpha5 := &v2alpha5.ActiveMQArtemis{}
Eventually(func(g Gomega) {
g.Expect(k8sClient.Get(ctx, key, createdCrdv2alpha5)).Should(Succeed())
g.Expect(len(createdCrdv2alpha5.Status.PodStatus.Stopped)).Should(BeEquivalentTo(1))
}, timeout, interval).Should(Succeed())

By("checking status - using served version - with conditions")
key = types.NamespacedName{Name: toCreate.Name, Namespace: toCreate.Namespace}
createdCrd := &brokerv1beta1.ActiveMQArtemis{}
Eventually(func(g Gomega) {
g.Expect(k8sClient.Get(ctx, key, createdCrd)).Should(Succeed())
g.Expect(len(createdCrd.Status.PodStatus.Stopped)).Should(BeEquivalentTo(1))
}, timeout, interval).Should(Succeed())

Expect(k8sClient.Delete(ctx, createdCrd)).Should(Succeed())
})

It("can reconcile latest version with config in brokerProperties", func() {

toCreate := brokerv1beta1.ActiveMQArtemis{
TypeMeta: metav1.TypeMeta{
Kind: "ActiveMQArtemis",
APIVersion: brokerv1beta1.GroupVersion.Identifier(),
},
ObjectMeta: metav1.ObjectMeta{
Name: randString(),
Namespace: defaultNamespace,
},
Spec: brokerv1beta1.ActiveMQArtemisSpec{
BrokerProperties: []string{
"addressesSettings.#.redeliveryDelayMultiplier=2.3",
"addressesSettings.#.redeliveryCollisionAvoidanceFactor=1.2",
},
},
}

Expect(k8sClient.Create(context.TODO(), &toCreate)).Should(Succeed())

key := types.NamespacedName{Name: namer.CrToSS(toCreate.Name), Namespace: defaultNamespace}
createdSs := &appsv1.StatefulSet{}
Eventually(func(g Gomega) {
g.Expect(k8sClient.Get(ctx, key, createdSs)).Should(Succeed())
}, timeout, interval).Should(Succeed())

key = types.NamespacedName{Name: toCreate.Name, Namespace: toCreate.Namespace}
createdCrd := &v1beta1.ActiveMQArtemis{}
Eventually(func(g Gomega) {
g.Expect(k8sClient.Get(ctx, key, createdCrd)).Should(Succeed())
g.Expect(len(createdCrd.Status.PodStatus.Stopped)).Should(BeEquivalentTo(1))
}, existingClusterTimeout, existingClusterInterval).Should(Succeed())

Expect(k8sClient.Delete(ctx, createdCrd)).Should(Succeed())

})

It("testing broker image resolve", Label("amq-versions-test"), func() {
manager := "../deploy/operator.yaml"
Expand Down
17 changes: 4 additions & 13 deletions deploy/crds/broker_activemqartemis_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -303,16 +303,10 @@ spec:
pageSizeBytes:
description: The page size in bytes to use for an address. Supports byte notation like K, Mb, GB, etc.
type: string
redeliveryCollisionAvoidanceFactor:
description: factor by which to modify the redelivery delay slightly to avoid collisions
type: string
redeliveryDelay:
description: the time (in ms) to wait before redelivering a cancelled message.
format: int32
type: integer
redeliveryDelayMultiplier:
description: multiplier to apply to the redelivery-delay
type: string
redistributionDelay:
description: how long (in ms) to wait after the last consumer is closed on a queue before redistributing messages.
format: int32
Expand Down Expand Up @@ -1864,8 +1858,7 @@ spec:
pageSizeBytes:
type: string
redeliveryCollisionAvoidanceFactor:
description: controller-gen currently doesn't support float types RedeliveryCollisionAvoidanceFactor *float32 `json:"redeliveryCollisionAvoidanceFactor,omitempty"`
type: string
type: number
redeliveryDelay:
format: int32
type: integer
Expand Down Expand Up @@ -2220,8 +2213,7 @@ spec:
pageSizeBytes:
type: string
redeliveryCollisionAvoidanceFactor:
description: currentl controller-gen doesn't support float type RedeliveryCollisionAvoidanceFactor *float32 `json:"redeliveryCollisionAvoidanceFactor,omitempty"`
type: string
type: number
redeliveryDelay:
format: int32
type: integer
Expand Down Expand Up @@ -2591,13 +2583,12 @@ spec:
pageSizeBytes:
type: string
redeliveryCollisionAvoidanceFactor:
type: string
type: number
redeliveryDelay:
format: int32
type: integer
redeliveryDelayMultiplier:
description: controller-gen currently doesn't support float types RedeliveryDelayMultiplier *float32 `json:"redeliveryDelayMultiplier,omitempty"` RedeliveryCollisionAvoidanceFactor *float32 `json:"redeliveryCollisionAvoidanceFactor,omitempty"`
type: string
type: number
redistributionDelay:
format: int32
type: integer
Expand Down
22 changes: 0 additions & 22 deletions pkg/utils/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,28 +159,6 @@ func IsEqualV1Beta1(currentAddressSetting []brokerv1beta1.AddressSettingType, ne
} else {
return false
}
if newSetting.RedeliveryDelayMultiplier == nil {
if curSetting.RedeliveryDelayMultiplier != nil {
return false
}
} else if curSetting.RedeliveryDelayMultiplier != nil {
if *curSetting.RedeliveryDelayMultiplier != *newSetting.RedeliveryDelayMultiplier {
return false
}
} else {
return false
}
if newSetting.RedeliveryCollisionAvoidanceFactor == nil {
if curSetting.RedeliveryCollisionAvoidanceFactor != nil {
return false
}
} else if curSetting.RedeliveryCollisionAvoidanceFactor != nil {
if *curSetting.RedeliveryCollisionAvoidanceFactor != *newSetting.RedeliveryCollisionAvoidanceFactor {
return false
}
} else {
return false
}
if newSetting.MaxRedeliveryDelay == nil {
if curSetting.MaxRedeliveryDelay != nil {
return false
Expand Down

0 comments on commit 02e139a

Please sign in to comment.