squakez commented on code in PR #6902:
URL: https://github.com/apache/camel-k/pull/6902#discussion_r4424924657


##########
.github/workflows/camel-monitor.yml:
##########
@@ -0,0 +1,88 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ---------------------------------------------------------------------------
+
+name: camel-monitor
+
+env:
+  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+  CAMEL_K_TEST_TIMEOUT_SHORT: 2m
+  CAMEL_K_TEST_TIMEOUT_MEDIUM: 5m
+  CAMEL_K_TEST_TIMEOUT_LONG: 10m
+
+on:
+  pull_request:
+    branches:
+      - main
+      - "release-*"
+    paths-ignore:
+      - 'docs/**'
+      - 'java/**'
+      - 'proposals/**'
+      - '**.adoc'
+      - '**.md'
+      - 'KEYS'
+      - 'LICENSE'
+      - 'NOTICE'
+  push:
+    branches:
+      - main
+      - "release-*"
+    paths-ignore:
+      - 'docs/**'
+      - 'java/**'
+      - 'proposals/**'
+      - '**.adoc'
+      - '**.md'
+      - 'KEYS'
+      - 'LICENSE'
+      - 'NOTICE'
+  workflow_dispatch:
+
+concurrency:
+  group: ${{ github.workflow }}-${{ github.event.pull_request.number || 
github.sha }}
+  cancel-in-progress: true
+
+jobs:
+  camel-monitor:
+    runs-on: ubuntu-latest
+    steps:
+    - name: Checkout code
+      uses: actions/checkout@v7
+      with:
+        persist-credentials: false
+        submodules: recursive
+
+    - name: Infra setting
+      uses: ./.github/actions/infra-setting
+
+    - name: Install Knative
+      shell: bash
+      run: |
+        ./e2e/knative/files/setup.sh
+
+    - name: Install CRDs

Review Comment:
   We probably can install entirely the Camel Monitor operator instead. It's a 
lightweight operator and it will provide the needed CRDs. Make sure to install 
it before installing Camel K operator.



##########
.github/workflows/camel-monitor.yml:
##########
@@ -0,0 +1,88 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ---------------------------------------------------------------------------
+
+name: camel-monitor
+
+env:
+  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+  CAMEL_K_TEST_TIMEOUT_SHORT: 2m
+  CAMEL_K_TEST_TIMEOUT_MEDIUM: 5m
+  CAMEL_K_TEST_TIMEOUT_LONG: 10m
+
+on:
+  pull_request:
+    branches:
+      - main
+      - "release-*"
+    paths-ignore:
+      - 'docs/**'
+      - 'java/**'
+      - 'proposals/**'
+      - '**.adoc'
+      - '**.md'
+      - 'KEYS'
+      - 'LICENSE'
+      - 'NOTICE'
+  push:
+    branches:
+      - main
+      - "release-*"
+    paths-ignore:
+      - 'docs/**'
+      - 'java/**'
+      - 'proposals/**'
+      - '**.adoc'
+      - '**.md'
+      - 'KEYS'
+      - 'LICENSE'
+      - 'NOTICE'
+  workflow_dispatch:
+
+concurrency:
+  group: ${{ github.workflow }}-${{ github.event.pull_request.number || 
github.sha }}
+  cancel-in-progress: true
+
+jobs:
+  camel-monitor:
+    runs-on: ubuntu-latest
+    steps:
+    - name: Checkout code
+      uses: actions/checkout@v7
+      with:
+        persist-credentials: false
+        submodules: recursive
+
+    - name: Infra setting
+      uses: ./.github/actions/infra-setting
+
+    - name: Install Knative

Review Comment:
   We don't need knative operator



##########
e2e/camelmonitor/camel_monitor_test.go:
##########
@@ -0,0 +1,197 @@
+//go:build integration
+// +build integration
+
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package camelmonitor
+
+import (
+       "context"
+       "testing"
+
+       monitorv1alpha1 
"github.com/camel-tooling/camel-monitor-operator/pkg/apis/camel/v1alpha1"
+       . "github.com/onsi/gomega"
+       appsv1 "k8s.io/api/apps/v1"
+       batchv1 "k8s.io/api/batch/v1"
+       corev1 "k8s.io/api/core/v1"
+       k8serrors "k8s.io/apimachinery/pkg/api/errors"
+       metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+       "k8s.io/utils/ptr"
+       ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+
+       . "github.com/apache/camel-k/v2/e2e/support"
+       v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
+       servingv1 
"github.com/apache/camel-k/v2/pkg/apis/duck/knative/serving/v1"
+)
+
+func TestCamelMonitorDiscovery(t *testing.T) {
+       WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) {
+               const discoveryLabel = "camel.apache.org/monitor"
+               InstallOperator(t, ctx, g, ns)

Review Comment:
   No, we better have the operator installed as part of the infra setting 
procedure, like it happens in the other workflows.



##########
docs/modules/ROOT/pages/contributing/e2e.adoc:
##########
@@ -34,13 +34,31 @@ This is the list of the groups we are using (please, notice 
that they can slight
     * advanced (`make test-advanced`)
     * install (`make test-install`)
     * knative (`make test-knative`)
+    * camelmonitor (`make test-camel-monitor`)
     * native (`make test-quarkus-native`)
     * telemetry (`make test-telemetry`)
 
 Each group tests a specific feature of Camel K. Typically any new test should 
be falling under the `common` group, unless it belongs to any other category or 
it requires some particular customization. As an example, `telemetry` requires 
the configuration of an OTLP Collector, reason why it requires its own group. 
If the test still is a common one but needs to perform customization on the 
Camel K Operator, then, it should be developed under `advanced`: as an example, 
we have there tests which requires the configuration of a Maven proxy.
 
 It's important to know that a subset of `common` named `test-smoke` is used as 
smoke test in the nightly release process. We want to keep this group of test 
as fast as possible.
 
+=== CamelMonitor discovery

Review Comment:
   No need to provide details



##########
docs/modules/ROOT/pages/observability/dashboard.adoc:
##########
@@ -97,3 +97,43 @@ items:
 NOTE: Camel K won't require the availability of Camel Monitor operator to 
work, neither Camel Monitor operator would require Camel K. They are 
independent projects which can cooperate to provide a Build and Monitoring tool 
respectively.
 
 Learn more by reading the official 
https://camel-tooling.github.io/camel-dashboard/[Camel Dashboard documentation].
+
+== Discover monitoring from an Integration

Review Comment:
   We should not provide all that info. Just say there is a condition to mark 
the availability of a `CamelMonitor` when this is found.



##########
e2e/camelmonitor/camel_monitor_test.go:
##########
@@ -0,0 +1,197 @@
+//go:build integration
+// +build integration
+
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package camelmonitor
+
+import (
+       "context"
+       "testing"
+
+       monitorv1alpha1 
"github.com/camel-tooling/camel-monitor-operator/pkg/apis/camel/v1alpha1"
+       . "github.com/onsi/gomega"
+       appsv1 "k8s.io/api/apps/v1"
+       batchv1 "k8s.io/api/batch/v1"
+       corev1 "k8s.io/api/core/v1"
+       k8serrors "k8s.io/apimachinery/pkg/api/errors"
+       metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+       "k8s.io/utils/ptr"
+       ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+
+       . "github.com/apache/camel-k/v2/e2e/support"
+       v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
+       servingv1 
"github.com/apache/camel-k/v2/pkg/apis/duck/knative/serving/v1"
+)
+
+func TestCamelMonitorDiscovery(t *testing.T) {
+       WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) {
+               const discoveryLabel = "camel.apache.org/monitor"
+               InstallOperator(t, ctx, g, ns)
+
+               name := "monitored-integration"
+               g.Expect(KamelRun(t, ctx, ns, "files/timer.yaml", "--name", 
name).Execute()).To(Succeed())
+               g.Eventually(IntegrationPhase(t, ctx, ns, name), 
TestTimeoutLong).Should(Equal(v1.IntegrationPhaseRunning))
+               g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, 
v1.IntegrationConditionReady), TestTimeoutMedium).
+                       Should(Equal(corev1.ConditionTrue))
+               g.Expect(IntegrationCondition(t, ctx, ns, name, 
v1.IntegrationConditionCamelMonitorAvailable)()).To(BeNil())

Review Comment:
   By default we will have the condition filled. We don't really care about the 
rest, as we just want to test that the condition is eventually accomplished. 
You can remove the rest of testing as it would be testing the `CamelMonitor` 
and it's not the goal of the Camel K operator.



##########
go.mod:
##########
@@ -5,6 +5,7 @@ go 1.27.3
 require (
        dario.cat/mergo v1.0.2
        github.com/Masterminds/semver v1.5.0
+       github.com/camel-tooling/camel-monitor-operator v0.2.1

Review Comment:
   v1.0.0 is out already



##########
pkg/controller/integration/monitor.go:
##########
@@ -64,8 +67,36 @@ func (action *monitorAction) CanHandle(integration 
*v1.Integration) bool {
                integration.Status.Phase == v1.IntegrationPhaseError
 }
 
-//nolint:nestif
 func (action *monitorAction) Handle(ctx context.Context, integration 
*v1.Integration) (*v1.Integration, error) {
+       result, err := action.monitorIntegration(ctx, integration)
+       target := result

Review Comment:
   This one can be simplified a lot. The function can be reduced to looking 
(get) a `CamelMonitor` with the Integration name. If that exists, then we set 
the condition. If it does not, then, we remove the condition. Nothing else is 
needed, so, the rest of the logic can be removed.
   
   You may add a `func addCamelMonitorCondition(...)` and call it from the 
existing `monitorIntegration` func when the action was created with a flag to 
set the condition (CamelMonitor CRDs available).



##########
pkg/controller/integration/integration_controller.go:
##########
@@ -312,7 +314,13 @@ func add(mgr manager.Manager, c client.Client, r 
reconcile.Reconciler) error {
                return err
        }
 
-       return b.Complete(r)
+       // Watch for the Camel Monitors conditionally
+       err = watchCamelMonitorResources(c, b)
+       if err != nil {
+               return err
+       }
+
+       return b.Complete(newReconciler(mgr, c))

Review Comment:
   why a `newReconciler`?



##########
pkg/controller/integration/monitor.go:
##########
@@ -64,8 +67,36 @@ func (action *monitorAction) CanHandle(integration 
*v1.Integration) bool {
                integration.Status.Phase == v1.IntegrationPhaseError
 }
 
-//nolint:nestif
 func (action *monitorAction) Handle(ctx context.Context, integration 
*v1.Integration) (*v1.Integration, error) {
+       result, err := action.monitorIntegration(ctx, integration)
+       target := result
+       if target == nil {
+               target = integration
+       }
+       previous := 
target.Status.GetCondition(v1.IntegrationConditionCamelMonitorAvailable).DeepCopy()
+       installed, monitorErr := 
kubernetes.IsAPIResourceInstalled(action.client, 
monitorv1alpha1.SchemeGroupVersion.String(), monitorv1alpha1.AppKind)

Review Comment:
   This check can be done when creating the monitorAction and stored there for 
reuse instead of doing an API call at every reconciliation



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to