Skip to content

Commit

Permalink
[arkmq-org#905] Adding watch resources owned by the operator
Browse files Browse the repository at this point in the history
  • Loading branch information
howardgao authored and gaohoward committed Apr 26, 2024
1 parent a44c87c commit a808a09
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
15 changes: 14 additions & 1 deletion controllers/activemqartemis_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
netv1 "k8s.io/api/networking/v1"
policyv1 "k8s.io/api/policy/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -40,6 +42,7 @@ import (
"github.com/artemiscloud/activemq-artemis-operator/pkg/utils/certutil"
"github.com/artemiscloud/activemq-artemis-operator/pkg/utils/namer"
"github.com/go-logr/logr"
routev1 "github.com/openshift/api/route/v1"
"github.com/pkg/errors"

brokerv1beta1 "github.com/artemiscloud/activemq-artemis-operator/api/v1beta1"
Expand Down Expand Up @@ -741,7 +744,17 @@ func (r *ActiveMQArtemisReconciler) SetupWithManager(mgr ctrl.Manager) error {
builder := ctrl.NewControllerManagedBy(mgr).
For(&brokerv1beta1.ActiveMQArtemis{}).
Owns(&appsv1.StatefulSet{}).
Owns(&corev1.Pod{})
Owns(&corev1.Pod{}).
Owns(&corev1.Secret{}).
Owns(&corev1.ConfigMap{}).
Owns(&corev1.Service{}).
Owns(&netv1.Ingress{}).
Owns(&policyv1.PodDisruptionBudget{})

if isOpenshift, err := common.DetectOpenshift(); err == nil && isOpenshift {
builder.Owns(&routev1.Route{})
}

var err error
controller, err := builder.Build(r)
if err == nil {
Expand Down
35 changes: 35 additions & 0 deletions controllers/activemqartemis_controller2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch"

brokerv1beta1 "github.com/artemiscloud/activemq-artemis-operator/api/v1beta1"
Expand Down Expand Up @@ -88,6 +89,40 @@ var _ = Describe("artemis controller 2", func() {
})

Context("persistent volumes tests", Label("controller-2-test"), func() {
It("controller resource recover test", Label("controller-resource-recover-test"), func() {

By("deploy a broker cr")
_, crd := DeployCustomBroker(defaultNamespace, nil)

brokerKey := types.NamespacedName{
Name: crd.Name,
Namespace: defaultNamespace,
}

brokerPropSecretName := crd.Name + "-props"
brokerPropSecretKey := types.NamespacedName{
Name: brokerPropSecretName,
Namespace: defaultNamespace,
}
brokerPropSecret := corev1.Secret{}
var secretId types.UID
Eventually(func(g Gomega) {
g.Expect(k8sClient.Get(ctx, brokerKey, crd)).Should(Succeed())
g.Expect(k8sClient.Get(ctx, brokerPropSecretKey, &brokerPropSecret)).Should(Succeed())
secretId = brokerPropSecret.UID
}, timeout, interval).Should(Succeed())

By("delete the broker properties secret")
Expect(k8sClient.Delete(ctx, &brokerPropSecret)).Should(Succeed())

Eventually(func(g Gomega) {
g.Expect(k8sClient.Get(ctx, brokerPropSecretKey, &brokerPropSecret)).Should(Succeed())
newSecretId := brokerPropSecret.UID
g.Expect(newSecretId).ShouldNot(Equal(secretId))
}, timeout, interval).Should(Succeed())

CleanResource(crd, crd.Name, defaultNamespace)
})
It("external volumes attach", func() {
if os.Getenv("USE_EXISTING_CLUSTER") == "true" {

Expand Down

0 comments on commit a808a09

Please sign in to comment.