You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2021/10/04 16:43:24 UTC

[GitHub] [skywalking-swck] dashanji opened a new pull request #34: [feature]add JavaAgent CRD and controller

dashanji opened a new pull request #34:
URL: https://github.com/apache/skywalking-swck/pull/34


   Add JavaAgent CRD and controller so that we can see the injected agent's configuration easily.
   
   Demo:
   
   The ServiceName and BackendService of the agent can be observed through `kubectl get` as follow.
   ```shell
   $ kubectl get JavaAgent -A
   NAMESPACE   NAME                POD       SERVICENAME            BACKENDSERVICE
   default     inject3-javaagent   inject3   e                      127.0.0.1:11800
   default     test-javaagent      test      Your_ApplicationName   127.0.0.1:11800
   ```
   If you want to see all congiuration of the injected agent, you can see the agentConfiguration of the Spec, just like following.
   ```shell
   $ kubectl get JavaAgent inject3-javaagent -o jsonpath={.spec.agentConfiguration}
   {"agent.class_cache_mode":"MEMORY","agent.ignore_suffix":"'jpg,.jpeg'","agent.sample_n_per_3_secs":"6","agent.service_name":"e","collector.backend_service":"127.0.0.1:11800","optional-plugin":"trace|webflux|cloud-gateway-2.1.x","optional-reporter-plugin":"kafka","plugin.influxdb.trace_influxql":"false","plugin.mongodb.trace_param":"true","plugin.mount":"'plugins,activations'"}
   ```
   or
   
   ```shell
   $ kubectl get JavaAgent inject3-javaagent -oyaml
   ......
   spec:
     agentConfiguration:
       agent.class_cache_mode: MEMORY
       agent.ignore_suffix: '''jpg,.jpeg'''
       agent.sample_n_per_3_secs: "6"
       agent.service_name: e
       collector.backend_service: 127.0.0.1:11800
       optional-plugin: trace|webflux|cloud-gateway-2.1.x
       optional-reporter-plugin: kafka
       plugin.influxdb.trace_influxql: "false"
       plugin.mongodb.trace_param: "true"
       plugin.mount: '''plugins,activations'''
   ......
   ```


-- 
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: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-swck] dashanji commented on a change in pull request #34: [feature]add JavaAgent CRD and controller

Posted by GitBox <gi...@apache.org>.
dashanji commented on a change in pull request #34:
URL: https://github.com/apache/skywalking-swck/pull/34#discussion_r725110468



##########
File path: apis/operator/v1alpha1/javaagent_types.go
##########
@@ -0,0 +1,60 @@
+// 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 v1alpha1
+
+import (
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+)
+
+// JavaAgentSpec defines the desired state of JavaAgent
+type JavaAgentSpec struct {
+	// Pod is the name of injected Pod
+	Pod string `json:"pod,omitempty"`
+	// ServiceName is the name of service in the injected agent, which need to be printed
+	ServiceName string `json:"serviceName,omitempty"`
+	// backend_service is the backend service in the injected agent, which need to be printed
+	BackendService string `json:"backendService,omitempty"`
+	// AgentConfiguration is the injected agent's final configuration
+	AgentConfiguration map[string]string `json:"agentConfiguration,omitempty"`
+}
+
+// +kubebuilder:object:root=true
+// +kubebuilder:printcolumn:name="Pod",type="string",JSONPath=".spec.pod",description="The name of injected Pod"
+// +kubebuilder:printcolumn:name="ServiceName",type="string",JSONPath=".spec.serviceName",description="The name of service in the injected agent"
+// +kubebuilder:printcolumn:name="BackendService",type="string",JSONPath=".spec.backendService",description="The backend service in the injected agent"
+
+// JavaAgent is the Schema for the javaagents API
+type JavaAgent struct {
+	metav1.TypeMeta   `json:",inline"`
+	metav1.ObjectMeta `json:"metadata,omitempty"`
+
+	Spec JavaAgentSpec `json:"spec,omitempty"`

Review comment:
       OK.




-- 
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: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-swck] hanahmily merged pull request #34: [feature]add JavaAgent CRD and controller

Posted by GitBox <gi...@apache.org>.
hanahmily merged pull request #34:
URL: https://github.com/apache/skywalking-swck/pull/34


   


-- 
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: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-swck] dashanji commented on pull request #34: [feature]add JavaAgent CRD and controller

Posted by GitBox <gi...@apache.org>.
dashanji commented on pull request #34:
URL: https://github.com/apache/skywalking-swck/pull/34#issuecomment-943077844


   Demo:
   ```shell
   $ kubectl get javaagent -A
   NAMESPACE   NAME                  PODSELECTOR   SERVICENAME            BACKENDSERVICE
   default     app-demo1-javaagent   app=demo1     Your_ApplicationName   127.0.0.1:11800
   default     app-demo2-javaagent   app=demo2     Your_ApplicationName   127.0.0.1:11800
   $ kubectl get pod -l app=demo1
   NAME                    READY   STATUS    RESTARTS   AGE
   demo1-bb97b8b4d-bkwm4   1/1     Running   0          28s
   demo1-bb97b8b4d-wxgs2   1/1     Running   0          28s
   $ kubectl get pod -l app=demo2
   NAME     READY   STATUS    RESTARTS   AGE
   app2-0   1/1     Running   0          27s
   app2-1   1/1     Running   0          25s
   app2-2   1/1     Running   0          23s
   ```
   You can see more infomation in the spec and status as below:
   ```shell
   $ kubectl get javaagent app-demo1-javaagent -oyaml
   apiVersion: operator.skywalking.apache.org/v1alpha1
   kind: JavaAgent
   metadata:
     creationTimestamp: "2021-10-14T07:07:12Z"
     generation: 1
     name: app-demo1-javaagent
     namespace: default
     ownerReferences:
     - apiVersion: apps/v1
       blockOwnerDeletion: true
       controller: true
       kind: ReplicaSet
       name: demo1-bb97b8b4d
       uid: c712924f-4652-4c07-8332-b3938ad72392
     resourceVersion: "330808"
     selfLink: /apis/operator.skywalking.apache.org/v1alpha1/namespaces/default/javaagents/app-demo1-javaagent
     uid: 9350338f-15a5-4832-84d1-530f8d0e1c3b
   spec:
     agentConfiguration:
       agent.namespace: default-namespace
       agent.service_name: Your_ApplicationName
       collector.backend_service: 127.0.0.1:11800
     backendService: 127.0.0.1:11800
     podSelector: app=demo1
     serviceName: Your_ApplicationName
   status:
     creationTime: "2021-10-14T07:07:12Z"
     expectedInjectiedNum: 2
     lastUpdateTime: "2021-10-14T07:07:14Z"
     realInjectedNum: 2
   ``` 


-- 
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: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-swck] hanahmily commented on a change in pull request #34: [feature]add JavaAgent CRD and controller

Posted by GitBox <gi...@apache.org>.
hanahmily commented on a change in pull request #34:
URL: https://github.com/apache/skywalking-swck/pull/34#discussion_r728885695



##########
File path: apis/operator/v1alpha1/javaagent_webhook.go
##########
@@ -18,63 +18,91 @@
 package v1alpha1
 
 import (
-	"context"
-	"net/http"
+	"fmt"
 
-	corev1 "k8s.io/api/core/v1"
-	"sigs.k8s.io/controller-runtime/pkg/client"
+	"k8s.io/apimachinery/pkg/runtime"
+	ctrl "sigs.k8s.io/controller-runtime"
 	logf "sigs.k8s.io/controller-runtime/pkg/log"
-	"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
+	"sigs.k8s.io/controller-runtime/pkg/webhook"
 
 	"github.com/apache/skywalking-swck/pkg/operator/injector"
 )
 
+const (
+	AbsentName = "NotFound"
+)
+
 // log is for logging in this package.
-var javaagentlog = logf.Log.WithName("javaagent")
+var javaagentlog = logf.Log.WithName("javaagent-resource")
+
+func (r *JavaAgent) SetupWebhookWithManager(mgr ctrl.Manager) error {
+	return ctrl.NewWebhookManagedBy(mgr).
+		For(r).
+		Complete()
+}
 
 // nolint: lll
-// +kubebuilder:webhook:path=/mutate-v1-pod,mutating=true,failurePolicy=fail,groups="",resources=pods,verbs=create;update,versions=v1,name=mpod.kb.io
+// +kubebuilder:webhook:path=/mutate-operator-skywalking-apache-org-v1alpha1-javaagent,mutating=true,failurePolicy=fail,groups=operator.skywalking.apache.org,resources=javaagents,verbs=create;update,versions=v1alpha1,name=mjavaagent.kb.io
 
-// Javaagent injects java agent into Pods
-type Javaagent struct {
-	Client  client.Client
-	decoder *admission.Decoder
-}
+var _ webhook.Defaulter = &JavaAgent{}
 
-// Handle will process every coming pod under the
-// specified namespace which labeled "swck-injection=enabled"
-func (r *Javaagent) Handle(ctx context.Context, req admission.Request) admission.Response {
-	pod := &corev1.Pod{}
+// Default implements webhook.Defaulter so a webhook will be registered for the type
+func (r *JavaAgent) Default() {
+	javaagentlog.Info("default", "name", r.Name)
 
-	err := r.decoder.Decode(req, pod)
-	if err != nil {
-		return admission.Errored(http.StatusBadRequest, err)
+	config := r.Spec.AgentConfiguration
+	if config == nil {
+		r.Spec.ServiceName = AbsentName
+		r.Spec.BackendService = AbsentName
+		return

Review comment:
       We should not provide default values to them since they are mandatory.




-- 
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: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-swck] dashanji commented on pull request #34: [feature]add JavaAgent CRD and controller

Posted by GitBox <gi...@apache.org>.
dashanji commented on pull request #34:
URL: https://github.com/apache/skywalking-swck/pull/34#issuecomment-934057273


   OKļ¼Œthanks for reminding.


-- 
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: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-swck] dashanji commented on a change in pull request #34: [feature]add JavaAgent CRD and controller

Posted by GitBox <gi...@apache.org>.
dashanji commented on a change in pull request #34:
URL: https://github.com/apache/skywalking-swck/pull/34#discussion_r728903469



##########
File path: apis/operator/v1alpha1/javaagent_webhook.go
##########
@@ -18,63 +18,91 @@
 package v1alpha1
 
 import (
-	"context"
-	"net/http"
+	"fmt"
 
-	corev1 "k8s.io/api/core/v1"
-	"sigs.k8s.io/controller-runtime/pkg/client"
+	"k8s.io/apimachinery/pkg/runtime"
+	ctrl "sigs.k8s.io/controller-runtime"
 	logf "sigs.k8s.io/controller-runtime/pkg/log"
-	"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
+	"sigs.k8s.io/controller-runtime/pkg/webhook"
 
 	"github.com/apache/skywalking-swck/pkg/operator/injector"
 )
 
+const (
+	AbsentName = "NotFound"
+)
+
 // log is for logging in this package.
-var javaagentlog = logf.Log.WithName("javaagent")
+var javaagentlog = logf.Log.WithName("javaagent-resource")
+
+func (r *JavaAgent) SetupWebhookWithManager(mgr ctrl.Manager) error {
+	return ctrl.NewWebhookManagedBy(mgr).
+		For(r).
+		Complete()
+}
 
 // nolint: lll
-// +kubebuilder:webhook:path=/mutate-v1-pod,mutating=true,failurePolicy=fail,groups="",resources=pods,verbs=create;update,versions=v1,name=mpod.kb.io
+// +kubebuilder:webhook:path=/mutate-operator-skywalking-apache-org-v1alpha1-javaagent,mutating=true,failurePolicy=fail,groups=operator.skywalking.apache.org,resources=javaagents,verbs=create;update,versions=v1alpha1,name=mjavaagent.kb.io
 
-// Javaagent injects java agent into Pods
-type Javaagent struct {
-	Client  client.Client
-	decoder *admission.Decoder
-}
+var _ webhook.Defaulter = &JavaAgent{}
 
-// Handle will process every coming pod under the
-// specified namespace which labeled "swck-injection=enabled"
-func (r *Javaagent) Handle(ctx context.Context, req admission.Request) admission.Response {
-	pod := &corev1.Pod{}
+// Default implements webhook.Defaulter so a webhook will be registered for the type
+func (r *JavaAgent) Default() {
+	javaagentlog.Info("default", "name", r.Name)
 
-	err := r.decoder.Decode(req, pod)
-	if err != nil {
-		return admission.Errored(http.StatusBadRequest, err)
+	config := r.Spec.AgentConfiguration
+	if config == nil {
+		r.Spec.ServiceName = AbsentName
+		r.Spec.BackendService = AbsentName
+		return

Review comment:
       OK




-- 
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: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-swck] hanahmily commented on a change in pull request #34: [feature]add JavaAgent CRD and controller

Posted by GitBox <gi...@apache.org>.
hanahmily commented on a change in pull request #34:
URL: https://github.com/apache/skywalking-swck/pull/34#discussion_r724673164



##########
File path: apis/operator/v1alpha1/javaagent_types.go
##########
@@ -0,0 +1,60 @@
+// 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 v1alpha1
+
+import (
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+)
+
+// JavaAgentSpec defines the desired state of JavaAgent
+type JavaAgentSpec struct {
+	// Pod is the name of injected Pod
+	Pod string `json:"pod,omitempty"`
+	// ServiceName is the name of service in the injected agent, which need to be printed
+	ServiceName string `json:"serviceName,omitempty"`
+	// backend_service is the backend service in the injected agent, which need to be printed

Review comment:
       ```suggestion
   	// BackendService is the backend service in the injected agent, which need to be printed
   ```

##########
File path: apis/operator/v1alpha1/javaagent_types.go
##########
@@ -0,0 +1,60 @@
+// 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 v1alpha1
+
+import (
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+)
+
+// JavaAgentSpec defines the desired state of JavaAgent
+type JavaAgentSpec struct {
+	// Pod is the name of injected Pod
+	Pod string `json:"pod,omitempty"`
+	// ServiceName is the name of service in the injected agent, which need to be printed
+	ServiceName string `json:"serviceName,omitempty"`

Review comment:
       Could you add a validation webhook to validate ServiceName and BackService?

##########
File path: apis/operator/v1alpha1/javaagent_types.go
##########
@@ -0,0 +1,60 @@
+// 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 v1alpha1
+
+import (
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+)
+
+// JavaAgentSpec defines the desired state of JavaAgent
+type JavaAgentSpec struct {
+	// Pod is the name of injected Pod
+	Pod string `json:"pod,omitempty"`

Review comment:
       Pod selector is a more conventional path to filter pods. Pods are generated by a high level workload, for example, Deployment and Statefulset. The name varies in such scenarios. 
   

##########
File path: apis/operator/v1alpha1/javaagent_types.go
##########
@@ -0,0 +1,60 @@
+// 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 v1alpha1
+
+import (
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+)
+
+// JavaAgentSpec defines the desired state of JavaAgent
+type JavaAgentSpec struct {
+	// Pod is the name of injected Pod
+	Pod string `json:"pod,omitempty"`
+	// ServiceName is the name of service in the injected agent, which need to be printed
+	ServiceName string `json:"serviceName,omitempty"`
+	// backend_service is the backend service in the injected agent, which need to be printed
+	BackendService string `json:"backendService,omitempty"`
+	// AgentConfiguration is the injected agent's final configuration
+	AgentConfiguration map[string]string `json:"agentConfiguration,omitempty"`
+}
+
+// +kubebuilder:object:root=true
+// +kubebuilder:printcolumn:name="Pod",type="string",JSONPath=".spec.pod",description="The name of injected Pod"
+// +kubebuilder:printcolumn:name="ServiceName",type="string",JSONPath=".spec.serviceName",description="The name of service in the injected agent"
+// +kubebuilder:printcolumn:name="BackendService",type="string",JSONPath=".spec.backendService",description="The backend service in the injected agent"
+
+// JavaAgent is the Schema for the javaagents API
+type JavaAgent struct {
+	metav1.TypeMeta   `json:",inline"`
+	metav1.ObjectMeta `json:"metadata,omitempty"`
+
+	Spec JavaAgentSpec `json:"spec,omitempty"`

Review comment:
       Could you add a `Status` field here?
   
   This field could contain below items:
   
    * need to injected pods number
    * successful injected pods number
    * creation time
    * last updated time
    * ....




-- 
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: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking-swck] wu-sheng commented on pull request #34: [feature]add JavaAgent CRD and controller

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on pull request #34:
URL: https://github.com/apache/skywalking-swck/pull/34#issuecomment-933931735


   Thank you for submitting this on public holidays, we will review ASAP after back from holidays.


-- 
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: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org