Skip to content

Commit

Permalink
Merge pull request artemiscloud#152 from gaohoward/i_6083
Browse files Browse the repository at this point in the history
Issue artemiscloud#151 No service is created for acceptor when "expose:false"
  • Loading branch information
gaohoward committed Feb 22, 2022
2 parents 006994f + fb666b5 commit ee0c9fa
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 21 deletions.
58 changes: 57 additions & 1 deletion controllers/activemqartemis_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ import (
. "github.com/onsi/gomega"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/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"
)

// Uncomment this and the "test" import if you want to debug this set of tests
Expand Down Expand Up @@ -408,6 +408,62 @@ 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 := generateArtemisSpec(namespace)

crd.Spec.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: crd.Name, Namespace: namespace}
err := k8sClient.Get(ctx, key, &crd)
return err == nil
}, timeout, interval).Should(BeTrue())

Eventually(func() bool {
key := types.NamespacedName{Name: crd.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: crd.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())
Expect(k8sClient.Delete(ctx, &crd)).Should(Succeed())

By("check it has gone")
Eventually(checkCrdDeleted(crd.Name, namespace, &crd), timeout, interval).Should(BeTrue())
})
})
})

func generateArtemisSpec(namespace string) brokerv1beta1.ActiveMQArtemis {
Expand Down
23 changes: 3 additions & 20 deletions controllers/activemqartemis_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -892,16 +892,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 @@ -944,16 +936,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 ee0c9fa

Please sign in to comment.