dashanji commented on code in PR #66:
URL: https://github.com/apache/skywalking-swck/pull/66#discussion_r903821085


##########
operator/config/manager/manager.yaml:
##########
@@ -69,10 +70,10 @@ spec:
         # More info: 
https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
         resources:
           limits:
-            cpu: 500m
-            memory: 128Mi
+            cpu: 2
+            memory: 2Gi
           requests:
-            cpu: 10m
-            memory: 64Mi
+            cpu: 2
+            memory: 2Gi

Review Comment:
   How about setting the resources smaller, I guess this should be the reason 
why the e2e test fails.



##########
operator/pkg/operator/injector/webhook.go:
##########
@@ -63,11 +68,35 @@ func (r *JavaagentInjector) Handle(ctx context.Context, req 
admission.Request) a
        // initialize SidecarInjectField and get injected strategy from 
annotations
        s := NewSidecarInjectField()
        // initialize InjectProcess as a call chain
-       ip := NewInjectProcess(ctx, s, anno, ao, pod, req, 
javaagentInjectorLog, r.Client)
+       ip := NewInjectProcess(ctx, s, anno, ao, swAgentL, pod, req, 
javaagentInjectorLog, r.Client)
        // do real injection
        return ip.Run()
 }
 
+func (r *JavaagentInjector) findMatchedSwAgentL(ctx context.Context, req 
admission.Request, pod *corev1.Pod) *v1alpha1.SwAgentList {
+       swAgentList := &v1alpha1.SwAgentList{}
+       if err := r.Client.List(ctx, swAgentList, 
client.InNamespace(req.Namespace)); err != nil {
+               javaagentInjectorLog.Error(err, "get SwAgent error")
+       }
+
+       // selector
+       var availableSwAgentL []v1alpha1.SwAgent
+       for _, swAgent := range swAgentList.Items {
+               isMatch := true
+               if len(swAgent.Spec.Selector) != 0 {
+                       for k, v := range swAgent.Spec.Selector {
+                               if !strings.EqualFold(v, pod.Labels[k]) {
+                                       isMatch = false
+                               }
+                       }
+               }
+               if isMatch {
+                       availableSwAgentL = append(availableSwAgentL, swAgent)
+               }
+       }
+       return swAgentList

Review Comment:
   Do you mean a pod matches multiple SwAgents here? If so, I think you should 
use `append` in the function `OverlaySwAgentCR`. BTW, what do you think about a 
pod matching a SwAgent, which is more user-friendly?



##########
test/e2e/oap-agent-crd/e2e.yaml:
##########
@@ -0,0 +1,104 @@
+# 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.
+
+setup:
+  env: kind
+  file: ../kind.yaml
+  steps:
+    - name: prepare e2e.yaml
+      command: bash hack/prepare-e2e.sh
+    - name: install cert-manager
+      command: |
+        # kind k8s cluster is in $TMPDIR
+        export KUBECONFIG=$TMPDIR/e2e-k8s.config
+        
+        kind load docker-image 
ghcr.io/apache/skywalking-swck-spring-demo:v0.0.1
+        kind load docker-image gcr.io/kubebuilder/kube-rbac-proxy:v0.8.0
+        kind load docker-image quay.io/jetstack/cert-manager-webhook:v1.3.1
+        kind load docker-image quay.io/jetstack/cert-manager-cainjector:v1.3.1
+        kind load docker-image quay.io/jetstack/cert-manager-controller:v1.3.1
+        kind load docker-image apache/skywalking-java-agent:8.10.0-java8
+        kind load docker-image apache/skywalking-java-agent:8.8.0-java8
+        kind load docker-image apache/skywalking-java-agent:8.9.0-java8
+        kind load docker-image apache/skywalking-oap-server:8.8.1
+        kind load docker-image 
ghcr.io/apache/skywalking-swck-spring-demo:v0.0.1

Review Comment:
   Please delete these commands. In the e2e test, we don't need to load the 
Docker image to `kind` as we can pull the Docker image directly in `Github 
Action`.



##########
operator/controllers/operator/swagent_controller.go:
##########
@@ -0,0 +1,71 @@
+// Licensed to 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. Apache Software Foundation (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 operator
+
+import (
+       "context"
+       "fmt"
+
+       corev1 "k8s.io/api/core/v1"
+       "k8s.io/apimachinery/pkg/runtime"
+       ctrl "sigs.k8s.io/controller-runtime"
+       "sigs.k8s.io/controller-runtime/pkg/client"
+       runtimelog "sigs.k8s.io/controller-runtime/pkg/log"
+
+       operatorv1alpha1 
"github.com/apache/skywalking-swck/operator/apis/operator/v1alpha1"
+)
+
+// SwAgentReconciler reconciles a SwAgent object
+type SwAgentReconciler struct {
+       client.Client
+       Scheme *runtime.Scheme
+}
+
+//+kubebuilder:rbac:groups=operator.skywalking.apache.org,resources=swagents,verbs=get;list;watch;create;update;patch;delete
+//+kubebuilder:rbac:groups=operator.skywalking.apache.org,resources=swagents/status,verbs=get;update;patch
+//+kubebuilder:rbac:groups=operator.skywalking.apache.org,resources=swagents/finalizers,verbs=update
+
+// Reconcile is part of the main kubernetes reconciliation loop which aims to
+// move the current state of the cluster closer to the desired state.
+// TODO(user): Modify the Reconcile function to compare the state specified by
+// the SwAgent object against the actual cluster state, and then
+// perform operations to make the cluster state reflect the state specified by
+// the user.
+//
+// For more details, check Reconcile and its Result here:
+// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile

Review Comment:
   Please delete the auto-generated annotations.



##########
test/e2e/oap-agent-crd/e2e.yaml:
##########
@@ -0,0 +1,104 @@
+# 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.
+
+setup:
+  env: kind
+  file: ../kind.yaml
+  steps:
+    - name: prepare e2e.yaml
+      command: bash hack/prepare-e2e.sh
+    - name: install cert-manager
+      command: |
+        # kind k8s cluster is in $TMPDIR
+        export KUBECONFIG=$TMPDIR/e2e-k8s.config
+        
+        kind load docker-image 
ghcr.io/apache/skywalking-swck-spring-demo:v0.0.1
+        kind load docker-image gcr.io/kubebuilder/kube-rbac-proxy:v0.8.0
+        kind load docker-image quay.io/jetstack/cert-manager-webhook:v1.3.1
+        kind load docker-image quay.io/jetstack/cert-manager-cainjector:v1.3.1
+        kind load docker-image quay.io/jetstack/cert-manager-controller:v1.3.1
+        kind load docker-image apache/skywalking-java-agent:8.10.0-java8
+        kind load docker-image apache/skywalking-java-agent:8.8.0-java8
+        kind load docker-image apache/skywalking-java-agent:8.9.0-java8
+        kind load docker-image apache/skywalking-oap-server:8.8.1
+        kind load docker-image 
ghcr.io/apache/skywalking-swck-spring-demo:v0.0.1
+
+        kubectl apply -f 
https://github.com/jetstack/cert-manager/releases/download/v1.3.1/cert-manager.yaml
+      wait:
+        - namespace: cert-manager
+          resource: pod
+          for: condition=Ready
+    - name: install operator
+      command: |
+        export OPERATOR_IMG=controller
+        make -C operator docker-build   
+        kind load docker-image controller
+        make -C operator install
+        make -C operator deploy
+      wait:
+        - namespace: skywalking-swck-system
+          resource: pod
+          for: condition=Ready
+    - name: setup oapserver and swagent cr
+      command: |
+        kubectl create namespace skywalking-system
+        kubectl apply -f test/e2e/skywalking-components-with-swagent.yaml
+      wait:
+        - namespace: skywalking-system
+          resource: OAPServer/skywalking-system
+          for: condition=Available
+    - name: setup java agent demo
+      command: |
+        kubectl label namespace skywalking-system swck-injection=enabled
+        sed '/agent.skywalking.apache.org\/collector.backend_service/d' 
test/e2e/demo.yaml | kubectl create -f -
+      wait:
+        - namespace: skywalking-system
+          resource: deployment/demo
+          for: condition=Available
+  kind:
+    expose-ports:
+      - namespace: skywalking-system
+        resource: service/demo 
+        port: 8085
+      - namespace: skywalking-system
+        resource: service/skywalking-system-oap
+        port: 12800
+  timeout: 20m
+
+cleanup:
+  # always never success failure
+  on: always
+
+trigger:
+  action: http
+  interval: 30s
+  times: 30
+  url: http://${service_demo_host}:${service_demo_8085}/hello
+  method: GET
+
+verify:
+  # verify with retry strategy
+  retry:
+    # max retry count
+    count: 10
+    # the interval between two attempts, e.g. 10s, 1m.
+    interval: 10s
+  cases:
+    - query: 'kubectl get pods -l app=demo -o yaml | yq e 
''.items[0].spec.volumes'''
+      expected: ../verify/crd-demo-volumemount.yaml
+    - query: 'kubectl get pods -l app=demo -o yaml | yq e 
''.items[0].spec.initContainers[0]'''
+      expected: ../verify/crd-demo-initcontainer.yaml
+    - query: 'kubectl get pods -l app=demo -o yaml | yq e 
''.items[0].spec.containers[0]'''
+      expected: ../verify/crd-demo-target-container.yaml

Review Comment:
   What do you think about adding [the oapserver and the UI use 
cases](https://github.com/apache/skywalking-swck/blob/5e7d2879d7a69eed6d3ab30d6b4de957a9449eab/test/e2e/oap-ui-agent/e2e.yaml#L93-L103)
 so we can check it can work fine with skywalking components. 



-- 
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