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
  • Loading branch information
gtully committed Oct 26, 2022
1 parent dfd62b0 commit cbf9a59
Show file tree
Hide file tree
Showing 14 changed files with 136 additions and 101 deletions.
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,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 All @@ -123,7 +125,7 @@ test-mk-do: manifests generate fmt vet envtest generate-deploy ## Run tests agai

##@ Build

build: generate fmt vet ## Build manager binary.
build: generate fmt vet manifests ## Build manager binary.
go build -ldflags=$(LDFLAGS) -o bin/manager main.go

run: manifests generate fmt vet ## Run a controller from your host.
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 @@ -82,10 +82,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 @@ -2790,9 +2783,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 @@ -3157,9 +3148,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 @@ -3539,15 +3528,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
99 changes: 99 additions & 0 deletions controllers/activemqartemis_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ import (
"strconv"
"strings"

"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/secrets"
ss "github.com/artemiscloud/activemq-artemis-operator/pkg/resources/statefulsets"
Expand Down Expand Up @@ -229,6 +231,103 @@ var _ = Describe("artemis controller", func() {
})
})

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: nameFromTest(),
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))
g.Expect(meta.IsStatusConditionFalse(createdCrd.Status.Conditions, brokerv1beta1.DeployedConditionType)).Should(BeTrue())
}, 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: nameFromTest(),
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))
g.Expect(meta.IsStatusConditionFalse(createdCrd.Status.Conditions, brokerv1beta1.DeployedConditionType)).Should(BeTrue())
}, existingClusterTimeout, existingClusterInterval).Should(Succeed())

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

})
})

Context("Console config test", func() {
It("Exposing secured console", Label("console-expose-ssl"), func() {
//we need to use existing cluster to differentiate testing
Expand Down
11 changes: 4 additions & 7 deletions deploy/crds/broker_activemqartemis_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1988,8 +1988,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 @@ -2344,8 +2343,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 @@ -2715,13 +2713,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 cbf9a59

Please sign in to comment.