Skip to content

Commit

Permalink
Issue artemiscloud#151 No service is created for acceptor when "expos…
Browse files Browse the repository at this point in the history
…e:false"

The bug is true for connectors too.
(ENTMQBR-6083)
  • Loading branch information
howardgao committed Feb 21, 2022
1 parent 6e03371 commit 2fe09ee
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 20 deletions.
79 changes: 79 additions & 0 deletions controllers/activemqartemis_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ import (

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"sigs.k8s.io/controller-runtime/pkg/client"

appsv1 "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

brokerv1beta1 "github.com/artemiscloud/activemq-artemis-operator/api/v1beta1"
"github.com/artemiscloud/activemq-artemis-operator/pkg/utils/namer"
corev1 "k8s.io/api/core/v1"
)

var _ = Describe("artemis controller", func() {
Expand All @@ -45,6 +48,19 @@ var _ = Describe("artemis controller", func() {
interval = time.Millisecond * 250
)

AfterEach(func() {
key := types.NamespacedName{Name: name, Namespace: namespace}
brokerCrd := &brokerv1beta1.ActiveMQArtemis{}
err := k8sClient.Get(context.Background(), key, brokerCrd)
if err != nil && errors.IsNotFound(err) {
fmt.Println("Resource not found, no need to cleanup")
}
Expect(err).To(BeNil())

err = k8sClient.Delete(context.Background(), brokerCrd, &client.DeleteOptions{})
Expect(err).To(BeNil())
})

Context("With delopyed controller", func() {
It("Expect pod desc", func() {
By("By creating a new crd")
Expand Down Expand Up @@ -107,4 +123,67 @@ var _ = Describe("artemis controller", func() {

})
})

Context("With delopyed controller", func() {
It("Checking acceptor service while expose is false", func() {
By("By creating a new crd")
ctx := context.Background()
crd := &brokerv1beta1.ActiveMQArtemis{
TypeMeta: metav1.TypeMeta{
Kind: "ActiveMQArtemis",
APIVersion: brokerv1beta1.GroupVersion.Identifier(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "t1",
Namespace: namespace,
},
Spec: brokerv1beta1.ActiveMQArtemisSpec{
DeploymentPlan: brokerv1beta1.DeploymentPlanType{
Size: 1,
},
},
}
crd.Spec.Acceptors = []brokerv1beta1.AcceptorType{
{
Name: "new-acceptor",
Port: 61616,
Expose: false,
},
}
crd.Spec.Connectors = []brokerv1beta1.ConnectorType{
{
Name: "new-connector",
Port: 61616,
Expose: false,
},
}
Expect(k8sClient.Create(ctx, crd)).Should(Succeed())

Eventually(func() bool {
key := types.NamespacedName{Name: name, Namespace: namespace}
err := k8sClient.Get(ctx, key, crd)
return err == nil
}, timeout, interval).Should(BeTrue())

Eventually(func() bool {
key := types.NamespacedName{Name: name + "-" + "new-acceptor-0-svc", Namespace: namespace}
acceptorService := &corev1.Service{}
err := k8sClient.Get(context.Background(), key, acceptorService)
if err != nil {
fmt.Printf("we got error getting acceptor service %v\n", err)
}
return err == nil
}, timeout, interval).Should(BeTrue())

Eventually(func() bool {
key := types.NamespacedName{Name: name + "-" + "new-connector-0-svc", Namespace: namespace}
connectorService := &corev1.Service{}
err := k8sClient.Get(context.Background(), key, connectorService)
if err != nil {
fmt.Printf("we got error getting connector service %v\n", err)
}
return err == nil
}, timeout, interval).Should(BeTrue())
})
})
})
23 changes: 3 additions & 20 deletions controllers/activemqartemis_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -874,16 +874,8 @@ func configureAcceptorsExposure(fsm *ActiveMQArtemisFSM, client rtclient.Client,

for _, acceptor := range fsm.customResource.Spec.Acceptors {
serviceDefinition := svc.NewServiceDefinitionForCR(namespacedName, acceptor.Name+"-"+ordinalString, acceptor.Port, serviceRoutelabels, fsm.namers.LabelBuilder.Labels())
serviceNamespacedName := types.NamespacedName{
Name: serviceDefinition.Name,
Namespace: fsm.customResource.Namespace,
}
if acceptor.Expose {
requestedResources = append(requestedResources, serviceDefinition)
//causedUpdate, err = resources.Enable(customResource, client, scheme, serviceNamespacedName, serviceDefinition)
} else {
causedUpdate, err = resources.Disable(fsm.customResource, client, scheme, serviceNamespacedName, serviceDefinition)
}

requestedResources = append(requestedResources, serviceDefinition)
targetPortName := acceptor.Name + "-" + ordinalString
targetServiceName := fsm.customResource.Name + "-" + targetPortName + "-svc"
routeDefinition := routes.NewRouteDefinitionForCR(namespacedName, serviceRoutelabels, targetServiceName, targetPortName, acceptor.SSLEnabled)
Expand Down Expand Up @@ -926,16 +918,7 @@ func configureConnectorsExposure(fsm *ActiveMQArtemisFSM, client rtclient.Client
for _, connector := range fsm.customResource.Spec.Connectors {
serviceDefinition := svc.NewServiceDefinitionForCR(namespacedName, connector.Name+"-"+ordinalString, connector.Port, serviceRoutelabels, fsm.namers.LabelBuilder.Labels())

serviceNamespacedName := types.NamespacedName{
Name: serviceDefinition.Name,
Namespace: fsm.customResource.Namespace,
}
if connector.Expose {
requestedResources = append(requestedResources, serviceDefinition)
//causedUpdate, err = resources.Enable(customResource, client, scheme, serviceNamespacedName, serviceDefinition)
} else {
causedUpdate, err = resources.Disable(fsm.customResource, client, scheme, serviceNamespacedName, serviceDefinition)
}
requestedResources = append(requestedResources, serviceDefinition)
targetPortName := connector.Name + "-" + ordinalString
targetServiceName := fsm.customResource.Name + "-" + targetPortName + "-svc"
routeDefinition := routes.NewRouteDefinitionForCR(namespacedName, serviceRoutelabels, targetServiceName, targetPortName, connector.SSLEnabled)
Expand Down

0 comments on commit 2fe09ee

Please sign in to comment.