diff --git a/charts/crds/kdoctor.io_apphttphealthies.yaml b/charts/crds/kdoctor.io_apphttphealthies.yaml index 203dcf6b..5d52fdfc 100644 --- a/charts/crds/kdoctor.io_apphttphealthies.yaml +++ b/charts/crds/kdoctor.io_apphttphealthies.yaml @@ -58,6 +58,23 @@ spec: type: object spec: properties: + expect: + properties: + meanAccessDelayInMs: + default: 5000 + format: int64 + minimum: 1 + type: integer + statusCode: + maximum: 599 + minimum: 100 + type: integer + successRate: + default: 1 + maximum: 1 + minimum: 0 + type: number + type: object request: properties: durationInSecond: @@ -92,22 +109,11 @@ spec: - roundNumber - roundTimeoutMinute type: object - success: - properties: - meanAccessDelayInMs: - default: 5000 - format: int64 - minimum: 1 - type: integer - successRate: - default: 1 - maximum: 1 - minimum: 0 - type: number - type: object target: properties: - body: + bodyConfigmapName: + type: string + bodyConfigmapNamespace: type: string header: items: @@ -129,7 +135,9 @@ spec: - PATCH - HEAD type: string - tls-secret: + tlsSecretName: + type: string + tlsSecretNamespace: type: string required: - host diff --git a/charts/crds/kdoctor.io_netdnses.yaml b/charts/crds/kdoctor.io_netdnses.yaml index 459e2097..33c007fe 100644 --- a/charts/crds/kdoctor.io_netdnses.yaml +++ b/charts/crds/kdoctor.io_netdnses.yaml @@ -56,6 +56,23 @@ spec: type: object spec: properties: + expect: + properties: + meanAccessDelayInMs: + default: 5000 + format: int64 + minimum: 1 + type: integer + statusCode: + maximum: 599 + minimum: 100 + type: integer + successRate: + default: 1 + maximum: 1 + minimum: 0 + type: number + type: object request: properties: domain: @@ -71,6 +88,13 @@ spec: format: int64 minimum: 1 type: integer + protocol: + default: udp + enum: + - udp + - tcp + - tcp-tls + type: string qps: default: 5 format: int64 @@ -144,31 +168,13 @@ spec: type: object type: object x-kubernetes-map-type: atomic - success: - properties: - meanAccessDelayInMs: - default: 5000 - format: int64 - minimum: 1 - type: integer - successRate: - default: 1 - maximum: 1 - minimum: 0 - type: number - type: object target: properties: - protocol: - default: udp - enum: - - udp - - tcp - - tcp-tls - type: string targetDns: properties: - serviceNamespaceName: + serviceName: + type: string + serviceNamespace: type: string testIPv4: default: true diff --git a/charts/crds/kdoctor.io_netreaches.yaml b/charts/crds/kdoctor.io_netreaches.yaml index be9fc80b..b0753c80 100644 --- a/charts/crds/kdoctor.io_netreaches.yaml +++ b/charts/crds/kdoctor.io_netreaches.yaml @@ -58,6 +58,23 @@ spec: type: object spec: properties: + expect: + properties: + meanAccessDelayInMs: + default: 5000 + format: int64 + minimum: 1 + type: integer + statusCode: + maximum: 599 + minimum: 100 + type: integer + successRate: + default: 1 + maximum: 1 + minimum: 0 + type: number + type: object request: properties: durationInSecond: @@ -92,19 +109,6 @@ spec: - roundNumber - roundTimeoutMinute type: object - success: - properties: - meanAccessDelayInMs: - default: 5000 - format: int64 - minimum: 1 - type: integer - successRate: - default: 1 - maximum: 1 - minimum: 0 - type: number - type: object target: properties: clusterIP: diff --git a/docs/usage/apphttphealthy.md b/docs/usage/apphttphealthy.md index b5dc08db..1bcf95f6 100644 --- a/docs/usage/apphttphealthy.md +++ b/docs/usage/apphttphealthy.md @@ -21,17 +21,20 @@ spec: roundNumber: 2 roundTimeoutMinute: 1 schedule: 1 1 - success: + expect: meanAccessDelayInMs: 10000 successRate: 1 + statusCode: 200 target: - body: kube-system/http-body + bodyConfigmapName: http-body + bodyConfigmapNamespace: kube-system header: - Accept:text/html host: https://10.6.172.20:9443 http2: false method: PUT - tls-secret: kube-system/https-cert + tlsSecretName: https-cert + tlsSecretNamespace: kube-system status: doneRound: 2 expectedRound: 2 @@ -77,9 +80,13 @@ status: method: http method, must be one of GET POST PUT DELETE CONNECT OPTIONS PATCH HEAD - body: The configmap format for logging HTTP requests is namespace/configmap-name + bodyConfigmapName: The body configmap name +* + bodyConfigmapNamespace: The body configmap namespace - tls-cert: The secret format for logging HTTPS request certificates is namespace/configmap-name + tlsSecretName: The tls secret name +* + tlsSecretNamespace: The tls secret namespace header: HTTP request header @@ -87,22 +94,26 @@ status: >notice: when test targetAgent case, it will send http request to all targets at the same time with spec.request.qps for each one. That meaning, the actually QPS may be bigger than spec.request.qps -* spec.success: define the success condition of the task result +* spec.expect: define the success condition of the task result - meanAccessDelayInMs: mean access delay in MS, if the actual delay is bigger than this, it results to be failure + meanAccessDelayInMs: mean access delay in MS, if the actual delay is bigger than this, it results to be failure - successRate: the success rate of all http requests. Notice, when a http response code is >=200 and < 400, it's treated as success. if the actual whole success rate is smaller than successRate, the task results to be failure + successRate: the success rate of all http requests. Notice, when a http response code is >=200 and < 400, it's treated as success. if the actual whole success rate is smaller than successRate, the task results to be failure + + statusCode: Expect the HTTP status code returned by each request * status: the status of the task - doneRound: how many rounds have finished - expectedRound: how many rounds the task expect + doneRound: how many rounds have finished - finish: whether all rounds of this task have finished + expectedRound: how many rounds the task expect - lastRoundStatus: the result of last round + finish: whether all rounds of this task have finished + + lastRoundStatus: the result of last round history: + roundNumber: the round number status: the status of this round @@ -142,17 +153,20 @@ spec: roundNumber: 2 roundTimeoutMinute: 1 schedule: 1 1 - success: + expect: meanAccessDelayInMs: 10000 successRate: 1 + statusCode: 200 target: - body: kube-system/http-body + bodyConfigmapName: http-body + bodyConfigmapNamespace: kube-system header: - Accept:text/html host: https://10.6.172.20:9443 http2: false method: PUT - tls-secret: kube-system/https-cert + tlsSecretName: https-cert + tlsSecretNamespace: kube-system EOF kubectl apply -f test-httpapphealthy.yaml @@ -198,7 +212,7 @@ kubectl apply -f https-cert.yaml when something wrong happen, see the log for your task with following command ```shell #get log -CRD_KIND="httpapphealthy" +CRD_KIND="apphttphealthy" CRD_NAME="httphealthy" kubectl logs -n kube-system kdoctor-agent-v4vzx | grep -i "${CRD_KIND}.${CRD_NAME}" @@ -210,7 +224,7 @@ kubectl logs -n kube-system kdoctor-agent-v4vzx | grep -i "${CRD_KIND}.${CRD_NA when the kdoctor is not enabled to aggerate reports, all reports will be printed in the stdout of kdoctor agent. Use the following command to get its report ```shell -kubectl logs -n kube-system kdoctor-agent-v4vzx | jq 'select( .TaskName=="httpapphealthy.httphealthy" )' +kubectl logs -n kube-system kdoctor-agent-v4vzx | jq 'select( .TaskName=="apphttphealthy.httphealthy" )' ``` when the kdoctor is enabled to aggregate reports, all reports will be collected in the PVC or hostPath of kdoctor controller. diff --git a/docs/usage/netdns.md b/docs/usage/netdns.md index bef661a8..18f727b7 100644 --- a/docs/usage/netdns.md +++ b/docs/usage/netdns.md @@ -24,17 +24,18 @@ spec: targetDns: testIPv4: true testIPv6: false - serviceNamespaceName: kube-system/test-app + serviceName: coredns + serviceNamespace: kube-system targetUser: server: 172.18.0.1 port: 53 - protocol: udp request: durationInSecond: 10 qps: 20 perRequestTimeoutInMS: 500 domain: "kube-dns.kube-system.svc.cluster.local" - success: + protocol: udp + expect: successRate: 1 meanAccessDelayInMs: 10000 EOF @@ -79,11 +80,13 @@ kubectl apply -f netdns.yaml testIPv6: test DNS server IPv6 address and request is type AAAA. - serviceNamespaceName: Specify the namespace and name of the DNS to be tested, do not fill in the default test cluster for all DNS servers + serviceName: Specify the name of the DNS to be tested +* + serviceNamespace: Specify the namespace of the DNS to be tested protocol: Specify request protocol,Optional value udp,tcp,tcp-tls,default udp. -* spec.success: define the success condition of the task result +* spec.expect: define the success condition of the task result meanAccessDelayInMs: mean access delay in MS, if the actual delay is bigger than this, it results to be failure @@ -134,7 +137,6 @@ spec: roundNumber: 2 roundTimeoutMinute: 1 target: - protocol: udp targetUser: server: 172.18.0.1 port: 53 @@ -143,7 +145,8 @@ spec: qps: 10 perRequestTimeoutInMS: 500 domain: "baidu.com" - success: + protocol: udp + expect: successRate: 1 meanAccessDelayInMs: 1000 EOF @@ -176,7 +179,7 @@ spec: qps: 10 perRequestTimeoutInMS: 500 domain: "baidu.com" - success: + expect: successRate: 1 meanAccessDelayInMs: 1000 EOF @@ -210,7 +213,7 @@ spec: qps: 20 perRequestTimeoutInMS: 500 domain: "kube-dns.kube-system.svc.cluster.local" - success: + expect: successRate: 1 meanAccessDelayInMs: 10000 EOF @@ -244,7 +247,7 @@ spec: qps: 20 perRequestTimeoutInMS: 500 domain: "kube-dns.kube-system.svc.cluster.local" - success: + expect: successRate: 1 meanAccessDelayInMs: 10000 EOF diff --git a/docs/usage/netreach.md b/docs/usage/netreach.md index 14efa249..2d3298fa 100644 --- a/docs/usage/netreach.md +++ b/docs/usage/netreach.md @@ -25,7 +25,7 @@ spec: roundNumber: 2 roundTimeoutMinute: 1 schedule: 1 1 - success: + expect: meanAccessDelayInMs: 10000 successRate: 1 target: @@ -96,7 +96,7 @@ status: >notice: when test targetAgent case, it will send http request to all targets at the same time with spec.request.qps for each one. That meaning, the actually QPS may be bigger than spec.request.qps -* spec.success: define the success condition of the task result +* spec.expect: define the success condition of the task result meanAccessDelayInMs: mean access delay in MS, if the actual delay is bigger than this, it results to be failure @@ -152,7 +152,7 @@ spec: roundNumber: 2 roundTimeoutMinute: 1 schedule: 1 1 - success: + expect: meanAccessDelayInMs: 10000 successRate: 1 target: diff --git a/pkg/k8s/apis/kdoctor.io/v1beta1/apphttphealthy_types.go b/pkg/k8s/apis/kdoctor.io/v1beta1/apphttphealthy_types.go index b9ed867f..2a4f5863 100644 --- a/pkg/k8s/apis/kdoctor.io/v1beta1/apphttphealthy_types.go +++ b/pkg/k8s/apis/kdoctor.io/v1beta1/apphttphealthy_types.go @@ -18,7 +18,7 @@ type AppHttpHealthySpec struct { Request *NetHttpRequest `json:"request,omitempty"` // +kubebuilder:validation:Optional - SuccessCondition *NetSuccessCondition `json:"success,omitempty"` + SuccessCondition *NetSuccessCondition `json:"expect,omitempty"` } type AppHttpHealthyTarget struct { @@ -32,15 +32,23 @@ type AppHttpHealthyTarget struct { // +kubebuilder:default=false // +kubebuilder:validation:Optional - Http2 bool `json:"http2"` + + // +kubebuilder:validation:Type:=string + // +kubebuilder:validation:Optional + BodyConfigName *string `json:"bodyConfigmapName,omitempty"` + + // +kubebuilder:validation:Type:=string + // +kubebuilder:validation:Optional + BodyConfigNamespace *string `json:"bodyConfigmapNamespace,omitempty"` + // +kubebuilder:validation:Type:=string // +kubebuilder:validation:Optional - Body *string `json:"body,omitempty"` + TlsSecretName *string `json:"tlsSecretName,omitempty"` // +kubebuilder:validation:Type:=string // +kubebuilder:validation:Optional - TlsSecret *string `json:"tls-secret,omitempty"` + TlsSecretNamespace *string `json:"tlsSecretNamespace,omitempty"` // +kubebuilder:validation:Optional Header []string `json:"header,omitempty"` diff --git a/pkg/k8s/apis/kdoctor.io/v1beta1/common_types.go b/pkg/k8s/apis/kdoctor.io/v1beta1/common_types.go index 2066de53..64024d91 100644 --- a/pkg/k8s/apis/kdoctor.io/v1beta1/common_types.go +++ b/pkg/k8s/apis/kdoctor.io/v1beta1/common_types.go @@ -93,6 +93,11 @@ type NetSuccessCondition struct { // +kubebuilder:validation:Minimum=1 // +kubebuilder:validation:Optional MeanAccessDelayInMs *int64 `json:"meanAccessDelayInMs,omitempty"` + + // +kubebuilder:validation:Minimum=100 + // +kubebuilder:validation:Maximum=599 + // +kubebuilder:validation:Optional + StatusCode *int `json:"statusCode,omitempty"` } type NetHttpRequest struct { diff --git a/pkg/k8s/apis/kdoctor.io/v1beta1/netdns_types.go b/pkg/k8s/apis/kdoctor.io/v1beta1/netdns_types.go index 7c80a498..da447f08 100644 --- a/pkg/k8s/apis/kdoctor.io/v1beta1/netdns_types.go +++ b/pkg/k8s/apis/kdoctor.io/v1beta1/netdns_types.go @@ -21,7 +21,7 @@ type NetdnsSpec struct { Request *NetdnsRequest `json:"request,omitempty"` // +kubebuilder:validation:Optional - SuccessCondition *NetSuccessCondition `json:"success,omitempty"` + SuccessCondition *NetSuccessCondition `json:"expect,omitempty"` } type NetDnsTarget struct { @@ -29,12 +29,6 @@ type NetDnsTarget struct { NetDnsTargetUser *NetDnsTargetUserSpec `json:"targetUser,omitempty"` // +kubebuilder:validation:Optional NetDnsTargetDns *NetDnsTargetDnsSpec `json:"targetDns,omitempty"` - - // +kubebuilder:validation:Optional - // +kubebuilder:default=udp - // +kubebuilder:validation:Type:=string - // +kubebuilder:validation:Enum=udp;tcp;tcp-tls - Protocol *string `json:"protocol,omitempty"` } type NetDnsTargetUserSpec struct { @@ -47,7 +41,11 @@ type NetDnsTargetUserSpec struct { type NetDnsTargetDnsSpec struct { // +kubebuilder:validation:Optional - ServiceNamespacedName *string `json:"serviceNamespaceName,omitempty"` + ServiceName *string `json:"serviceName,omitempty"` + + // +kubebuilder:validation:Optional + ServiceNamespace *string `json:"serviceNamespace,omitempty"` + // +kubebuilder:default=true // +kubebuilder:validation:Optional TestIPv4 *bool `json:"testIPv4,omitempty"` @@ -77,6 +75,12 @@ type NetdnsRequest struct { // +kubebuilder:default=kubernetes.default.svc.cluster.local // +kubebuilder:validation:Optional Domain string `json:"domain"` + + // +kubebuilder:validation:Optional + // +kubebuilder:default=udp + // +kubebuilder:validation:Type:=string + // +kubebuilder:validation:Enum=udp;tcp;tcp-tls + Protocol *string `json:"protocol,omitempty"` } // scope(Namespaced or Cluster) diff --git a/pkg/k8s/apis/kdoctor.io/v1beta1/netreach_types.go b/pkg/k8s/apis/kdoctor.io/v1beta1/netreach_types.go index c27b13b9..615a81e8 100644 --- a/pkg/k8s/apis/kdoctor.io/v1beta1/netreach_types.go +++ b/pkg/k8s/apis/kdoctor.io/v1beta1/netreach_types.go @@ -18,7 +18,7 @@ type NetReachSpec struct { Request *NetHttpRequest `json:"request,omitempty"` // +kubebuilder:validation:Optional - SuccessCondition *NetSuccessCondition `json:"success,omitempty"` + SuccessCondition *NetSuccessCondition `json:"expect,omitempty"` } type NetReachTarget struct { diff --git a/pkg/k8s/apis/kdoctor.io/v1beta1/zz_generated.deepcopy.go b/pkg/k8s/apis/kdoctor.io/v1beta1/zz_generated.deepcopy.go index e12bfece..3cd697b8 100644 --- a/pkg/k8s/apis/kdoctor.io/v1beta1/zz_generated.deepcopy.go +++ b/pkg/k8s/apis/kdoctor.io/v1beta1/zz_generated.deepcopy.go @@ -107,13 +107,23 @@ func (in *AppHttpHealthySpec) DeepCopy() *AppHttpHealthySpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *AppHttpHealthyTarget) DeepCopyInto(out *AppHttpHealthyTarget) { *out = *in - if in.Body != nil { - in, out := &in.Body, &out.Body + if in.BodyConfigName != nil { + in, out := &in.BodyConfigName, &out.BodyConfigName *out = new(string) **out = **in } - if in.TlsSecret != nil { - in, out := &in.TlsSecret, &out.TlsSecret + if in.BodyConfigNamespace != nil { + in, out := &in.BodyConfigNamespace, &out.BodyConfigNamespace + *out = new(string) + **out = **in + } + if in.TlsSecretName != nil { + in, out := &in.TlsSecretName, &out.TlsSecretName + *out = new(string) + **out = **in + } + if in.TlsSecretNamespace != nil { + in, out := &in.TlsSecretNamespace, &out.TlsSecretNamespace *out = new(string) **out = **in } @@ -147,11 +157,6 @@ func (in *NetDnsTarget) DeepCopyInto(out *NetDnsTarget) { *out = new(NetDnsTargetDnsSpec) (*in).DeepCopyInto(*out) } - if in.Protocol != nil { - in, out := &in.Protocol, &out.Protocol - *out = new(string) - **out = **in - } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NetDnsTarget. @@ -167,8 +172,13 @@ func (in *NetDnsTarget) DeepCopy() *NetDnsTarget { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *NetDnsTargetDnsSpec) DeepCopyInto(out *NetDnsTargetDnsSpec) { *out = *in - if in.ServiceNamespacedName != nil { - in, out := &in.ServiceNamespacedName, &out.ServiceNamespacedName + if in.ServiceName != nil { + in, out := &in.ServiceName, &out.ServiceName + *out = new(string) + **out = **in + } + if in.ServiceNamespace != nil { + in, out := &in.ServiceNamespace, &out.ServiceNamespace *out = new(string) **out = **in } @@ -366,6 +376,11 @@ func (in *NetSuccessCondition) DeepCopyInto(out *NetSuccessCondition) { *out = new(int64) **out = **in } + if in.StatusCode != nil { + in, out := &in.StatusCode, &out.StatusCode + *out = new(int) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NetSuccessCondition. @@ -455,6 +470,11 @@ func (in *NetdnsRequest) DeepCopyInto(out *NetdnsRequest) { *out = new(uint64) **out = **in } + if in.Protocol != nil { + in, out := &in.Protocol, &out.Protocol + *out = new(string) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NetdnsRequest. diff --git a/pkg/loadRequest/loadHttp/http.go b/pkg/loadRequest/loadHttp/http.go index b5eaa3a8..21480019 100644 --- a/pkg/loadRequest/loadHttp/http.go +++ b/pkg/loadRequest/loadHttp/http.go @@ -41,6 +41,7 @@ type HttpRequestData struct { Http2 bool DisableKeepAlives bool DisableCompression bool + ExpectStatusCode *int } func HttpRequest(logger *zap.Logger, reqData *HttpRequestData) *v1beta1.HttpMetrics { @@ -65,6 +66,7 @@ func HttpRequest(logger *zap.Logger, reqData *HttpRequestData) *v1beta1.HttpMetr Cert: reqData.ClientCert, CertPool: reqData.CaCertPool, RequestBody: []byte(reqData.Body), + ExpectStatusCode: reqData.ExpectStatusCode, } logger.Sugar().Infof("do http requests work=%v", w) w.Init() diff --git a/pkg/loadRequest/loadHttp/http_requester.go b/pkg/loadRequest/loadHttp/http_requester.go index 9f04e598..887d9054 100644 --- a/pkg/loadRequest/loadHttp/http_requester.go +++ b/pkg/loadRequest/loadHttp/http_requester.go @@ -23,6 +23,7 @@ import ( "context" "crypto/tls" "crypto/x509" + "fmt" "github.com/kdoctor-io/kdoctor/pkg/k8s/apis/system/v1beta1" "golang.org/x/net/http2" "io" @@ -129,6 +130,10 @@ type Work struct { // Optional. ProxyAddr *url.URL + // ExpectStatusCode is the expect request return http code + // Optional. + ExpectStatusCode *int + initOnce sync.Once results chan *result stopCh chan struct{} @@ -221,7 +226,13 @@ func (b *Work) makeRequest(c *http.Client, wg *sync.WaitGroup) { } else { statusCode = 0 } - + if b.ExpectStatusCode != nil { + if statusCode != *b.ExpectStatusCode { + if err == nil { + err = fmt.Errorf("The %d status code returned is not the expected %d ", statusCode, *b.ExpectStatusCode) + } + } + } b.results <- &result{ duration: finish, statusCode: statusCode, diff --git a/pkg/pluginManager/apphttphealthy/agentExecuteTask.go b/pkg/pluginManager/apphttphealthy/agentExecuteTask.go index b7c67ffb..cf6a7802 100644 --- a/pkg/pluginManager/apphttphealthy/agentExecuteTask.go +++ b/pkg/pluginManager/apphttphealthy/agentExecuteTask.go @@ -13,7 +13,6 @@ import ( "github.com/kdoctor-io/kdoctor/pkg/k8s/apis/system/v1beta1" "github.com/kdoctor-io/kdoctor/pkg/loadRequest/loadHttp" "github.com/kdoctor-io/kdoctor/pkg/pluginManager/types" - "github.com/kdoctor-io/kdoctor/pkg/utils" "go.uber.org/zap" "k8s.io/apimachinery/pkg/runtime" "k8s.io/utils/pointer" @@ -99,14 +98,15 @@ func (s *PluginAppHttpHealthy) AgentExecuteTask(logger *zap.Logger, ctx context. PerRequestTimeoutMS: request.PerRequestTimeoutInMS, RequestTimeSecond: request.DurationInSecond, Http2: target.Http2, + ExpectStatusCode: instance.Spec.SuccessCondition.StatusCode, } // https cert - if target.TlsSecret != nil { - name, namespace, _ := utils.GetObjNameNamespace(*target.TlsSecret) - tlsData, err := k8sObjManager.GetK8sObjManager().GetSecret(context.Background(), name, namespace) + if target.TlsSecretName != nil { + + tlsData, err := k8sObjManager.GetK8sObjManager().GetSecret(context.Background(), *target.TlsSecretName, *target.TlsSecretNamespace) if err != nil { - msg := fmt.Sprintf("failed get [%s] secret err : %v", *target.TlsSecret, err) + msg := fmt.Sprintf("failed get [%s/%s] secret err : %v", *target.TlsSecretNamespace, *target.TlsSecretName, err) logger.Sugar().Errorf(msg) err = fmt.Errorf(msg) return finalfailureReason, task, err @@ -133,18 +133,17 @@ func (s *PluginAppHttpHealthy) AgentExecuteTask(logger *zap.Logger, ctx context. } // body - if target.Body != nil { - name, namespace, _ := utils.GetObjNameNamespace(*target.Body) - bodyCM, err := k8sObjManager.GetK8sObjManager().GetConfigMap(context.Background(), name, namespace) + if target.BodyConfigName != nil { + bodyCM, err := k8sObjManager.GetK8sObjManager().GetConfigMap(context.Background(), *target.BodyConfigName, *target.BodyConfigNamespace) if err != nil { - msg := fmt.Sprintf("failed get [%s] configmap err : %v", *target.Body, err) + msg := fmt.Sprintf("failed get [%s/%s] configmap err : %v", *target.BodyConfigNamespace, *target.BodyConfigName, err) logger.Sugar().Errorf(msg) err = fmt.Errorf(msg) return finalfailureReason, task, err } body, ok := bodyCM.Data["body"] if !ok { - msg := fmt.Sprintf("failed get body from [%s] configmap err : %v", *target.Body, err) + msg := fmt.Sprintf("failed get body from [%s/%s] configmap err : %v", *target.BodyConfigNamespace, *target.BodyConfigName, err) logger.Sugar().Errorf(msg) err = fmt.Errorf(msg) return finalfailureReason, task, err diff --git a/pkg/pluginManager/apphttphealthy/webhook.go b/pkg/pluginManager/apphttphealthy/webhook.go index 488d4ca6..fbf6cc49 100644 --- a/pkg/pluginManager/apphttphealthy/webhook.go +++ b/pkg/pluginManager/apphttphealthy/webhook.go @@ -10,7 +10,6 @@ import ( crd "github.com/kdoctor-io/kdoctor/pkg/k8s/apis/kdoctor.io/v1beta1" "github.com/kdoctor-io/kdoctor/pkg/pluginManager/tools" "github.com/kdoctor-io/kdoctor/pkg/types" - "github.com/kdoctor-io/kdoctor/pkg/utils" "go.uber.org/zap" apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" @@ -98,16 +97,10 @@ func (s *PluginAppHttpHealthy) WebhookValidateCreate(logger *zap.Logger, ctx con } // tls - if r.Spec.Target.TlsSecret != nil { - name, namespace, err := utils.GetObjNameNamespace(*r.Spec.Target.TlsSecret) + if r.Spec.Target.TlsSecretName != nil { + tlsData, err := k8sObjManager.GetK8sObjManager().GetSecret(ctx, *r.Spec.Target.TlsSecretName, *r.Spec.Target.TlsSecretNamespace) if err != nil { - s := fmt.Sprintf("HttpAppHealthy %v requires Target.TlsCert enter correctly err: %v", r.Name, err) - logger.Error(s) - return apierrors.NewBadRequest(s) - } - tlsData, err := k8sObjManager.GetK8sObjManager().GetSecret(ctx, name, namespace) - if err != nil { - s := fmt.Sprintf("HttpAppHealthy %v failed get secret %s err: %v", r.Name, *r.Spec.Target.TlsSecret, err) + s := fmt.Sprintf("HttpAppHealthy %v failed get secret %s/%s err: %v", r.Name, *r.Spec.Target.TlsSecretNamespace, *r.Spec.Target.TlsSecretName, err) logger.Error(s) return apierrors.NewBadRequest(s) } @@ -116,24 +109,24 @@ func (s *PluginAppHttpHealthy) WebhookValidateCreate(logger *zap.Logger, ctx con switch k { case "ca.crt": if len(v) == 0 { - s := fmt.Sprintf("HttpAppHealthy %v get tls secret %s ca.crt value is nil", r.Name, *r.Spec.Target.TlsSecret) + s := fmt.Sprintf("HttpAppHealthy %v get tls secret %s/%s ca.crt value is nil", r.Name, *r.Spec.Target.TlsSecretNamespace, *r.Spec.Target.TlsSecretName) logger.Error(s) return apierrors.NewBadRequest(s) } case "tls.crt": if len(v) == 0 { - s := fmt.Sprintf("HttpAppHealthy %v get tls secret %s tls.crt value is nil", r.Name, *r.Spec.Target.TlsSecret) + s := fmt.Sprintf("HttpAppHealthy %v get tls secret %s/%s tls.crt value is nil", r.Name, *r.Spec.Target.TlsSecretNamespace, *r.Spec.Target.TlsSecretName) logger.Error(s) return apierrors.NewBadRequest(s) } case "tls.key": if len(v) == 0 { - s := fmt.Sprintf("HttpAppHealthy %v get tls secret %s tls.key value is nil", r.Name, *r.Spec.Target.TlsSecret) + s := fmt.Sprintf("HttpAppHealthy %v get tls secret %s/%s tls.key value is nil", r.Name, *r.Spec.Target.TlsSecretNamespace, *r.Spec.Target.TlsSecretName) logger.Error(s) return apierrors.NewBadRequest(s) } default: - s := fmt.Sprintf("HttpAppHealthy %v get tls secret %s key %s,keys other than ca.crt, tls.crt, and tls.key cannot be used", r.Name, v, *r.Spec.Target.TlsSecret) + s := fmt.Sprintf("HttpAppHealthy %v get tls secret %s/%s key %s,keys other than ca.crt, tls.crt, and tls.key cannot be used", r.Name, *r.Spec.Target.TlsSecretNamespace, *r.Spec.Target.TlsSecretName, v) logger.Error(s) return apierrors.NewBadRequest(s) } diff --git a/pkg/pluginManager/netdns/agentExecuteTask.go b/pkg/pluginManager/netdns/agentExecuteTask.go index cd1b5f5f..5f659e77 100644 --- a/pkg/pluginManager/netdns/agentExecuteTask.go +++ b/pkg/pluginManager/netdns/agentExecuteTask.go @@ -8,7 +8,6 @@ import ( "fmt" "net" "strconv" - "strings" "sync" "github.com/miekg/dns" @@ -102,7 +101,7 @@ func (s *PluginNetDns) AgentExecuteTask(logger *zap.Logger, ctx context.Context, ip := net.ParseIP(*instance.Spec.Target.NetDnsTargetUser.Server) if ip.To4() != nil { testTargetList = append(testTargetList, &testTarget{Name: "typeA_" + server + "_" + instance.Spec.Request.Domain, Request: &loadDns.DnsRequestData{ - Protocol: loadDns.RequestProtocol(*instance.Spec.Target.Protocol), + Protocol: loadDns.RequestProtocol(*instance.Spec.Request.Protocol), DnsType: dns.TypeA, TargetDomain: instance.Spec.Request.Domain, DnsServerAddr: server, @@ -112,7 +111,7 @@ func (s *PluginNetDns) AgentExecuteTask(logger *zap.Logger, ctx context.Context, }}) } else { testTargetList = append(testTargetList, &testTarget{Name: "typeAAAA_" + server + "_" + instance.Spec.Request.Domain, Request: &loadDns.DnsRequestData{ - Protocol: loadDns.RequestProtocol(*instance.Spec.Target.Protocol), + Protocol: loadDns.RequestProtocol(*instance.Spec.Request.Protocol), DnsType: dns.TypeAAAA, TargetDomain: instance.Spec.Request.Domain, DnsServerAddr: server, @@ -125,7 +124,7 @@ func (s *PluginNetDns) AgentExecuteTask(logger *zap.Logger, ctx context.Context, if instance.Spec.Target.NetDnsTargetDns != nil { // When DNS service is not specified, search for DNS services within the cluster - if instance.Spec.Target.NetDnsTargetDns.ServiceNamespacedName == nil { + if instance.Spec.Target.NetDnsTargetDns.ServiceName == nil { dnsServiceIPs, err := k8sObjManager.GetK8sObjManager().ListServicesDnsIP(ctx) if err != nil { finalfailureReason = fmt.Sprintf("ListServicesDnsIP err: %v", err) @@ -136,7 +135,7 @@ func (s *PluginNetDns) AgentExecuteTask(logger *zap.Logger, ctx context.Context, server = net.JoinHostPort(serviceIP, "53") if ip.To4() != nil && *instance.Spec.Target.NetDnsTargetDns.TestIPv4 { testTargetList = append(testTargetList, &testTarget{Name: "typeA_" + server + "_" + instance.Spec.Request.Domain, Request: &loadDns.DnsRequestData{ - Protocol: loadDns.RequestProtocol(*instance.Spec.Target.Protocol), + Protocol: loadDns.RequestProtocol(*instance.Spec.Request.Protocol), DnsType: dns.TypeA, TargetDomain: instance.Spec.Request.Domain, DnsServerAddr: server, @@ -146,7 +145,7 @@ func (s *PluginNetDns) AgentExecuteTask(logger *zap.Logger, ctx context.Context, }}) } else if ip.To4() == nil && *instance.Spec.Target.NetDnsTargetDns.TestIPv6 { testTargetList = append(testTargetList, &testTarget{Name: "typeAAAA_" + server + "_" + instance.Spec.Request.Domain, Request: &loadDns.DnsRequestData{ - Protocol: loadDns.RequestProtocol(*instance.Spec.Target.Protocol), + Protocol: loadDns.RequestProtocol(*instance.Spec.Request.Protocol), DnsType: dns.TypeAAAA, TargetDomain: instance.Spec.Request.Domain, DnsServerAddr: server, @@ -157,18 +156,16 @@ func (s *PluginNetDns) AgentExecuteTask(logger *zap.Logger, ctx context.Context, } } } else { - // eg: kube-system/coredns - namespacedName := strings.Split(*instance.Spec.Target.NetDnsTargetDns.ServiceNamespacedName, "/") - dnsServices, err := k8sObjManager.GetK8sObjManager().GetService(ctx, namespacedName[1], namespacedName[0]) + dnsServices, err := k8sObjManager.GetK8sObjManager().GetService(ctx, *instance.Spec.Target.NetDnsTargetDns.ServiceName, *instance.Spec.Target.NetDnsTargetDns.ServiceNamespace) if err != nil { - finalfailureReason = fmt.Sprintf("GetService name: %s namespace: %s err: %v", namespacedName[1], namespacedName[0], err) + finalfailureReason = fmt.Sprintf("GetService name: %s namespace: %s err: %v", *instance.Spec.Target.NetDnsTargetDns.ServiceName, *instance.Spec.Target.NetDnsTargetDns.ServiceNamespace, err) } for _, serviceIP := range dnsServices.Spec.ClusterIPs { ip := net.ParseIP(serviceIP) server = net.JoinHostPort(serviceIP, "53") if ip.To4() != nil && *instance.Spec.Target.NetDnsTargetDns.TestIPv4 { testTargetList = append(testTargetList, &testTarget{Name: "typeA_" + server + "_" + instance.Spec.Request.Domain, Request: &loadDns.DnsRequestData{ - Protocol: loadDns.RequestProtocol(*instance.Spec.Target.Protocol), + Protocol: loadDns.RequestProtocol(*instance.Spec.Request.Protocol), DnsType: dns.TypeA, TargetDomain: instance.Spec.Request.Domain, DnsServerAddr: server, @@ -178,7 +175,7 @@ func (s *PluginNetDns) AgentExecuteTask(logger *zap.Logger, ctx context.Context, }}) } else if ip.To4() == nil && *instance.Spec.Target.NetDnsTargetDns.TestIPv6 { testTargetList = append(testTargetList, &testTarget{Name: "typeAAAA_" + server + "_" + instance.Spec.Request.Domain, Request: &loadDns.DnsRequestData{ - Protocol: loadDns.RequestProtocol(*instance.Spec.Target.Protocol), + Protocol: loadDns.RequestProtocol(*instance.Spec.Request.Protocol), DnsType: dns.TypeAAAA, TargetDomain: instance.Spec.Request.Domain, DnsServerAddr: server,