Skip to content

Commit

Permalink
e2e: Optimize installation and replacement of kdoctor
Browse files Browse the repository at this point in the history
Signed-off-by: ty-dc <[email protected]>
  • Loading branch information
ty-dc committed Nov 23, 2023
1 parent 1f524b6 commit b500b6a
Show file tree
Hide file tree
Showing 55 changed files with 1,742 additions and 1,013 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ e2e_init:

.PHONY: e2e_init_underlay
e2e_init_underlay:
$(QUIET) make e2e_init -e INSTALL_OVERLAY_CNI=false -e E2E_SPIDERPOOL_ENABLE_SUBNET=true
$(QUIET) make e2e_init -e INSTALL_OVERLAY_CNI=false -e E2E_SPIDERPOOL_ENABLE_SUBNET=true -e INSTALL_KRUISE=true

.PHONY: e2e_init_cilium_with_ebpf
e2e_init_cilium_with_ebpf:
Expand Down
21 changes: 11 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/go-openapi/strfmt v0.21.7
github.com/go-openapi/swag v0.22.4
github.com/go-openapi/validate v0.22.1
github.com/go-swagger/go-swagger v0.30.3
github.com/go-swagger/go-swagger v0.30.4
github.com/gogo/protobuf v1.3.2
github.com/golang/mock v1.6.0
github.com/google/gops v0.3.27
Expand All @@ -34,7 +34,6 @@ require (
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/spidernet-io/e2eframework v0.0.0-20230724150324-2eee77078275
github.com/spidernet-io/spiderdoctor v0.3.0
github.com/tigera/operator v1.30.5
github.com/vishvananda/netlink v1.2.1-beta.2.0.20230621221334-77712cff8739
go.opentelemetry.io/otel v1.20.0
Expand All @@ -46,7 +45,7 @@ require (
go.uber.org/atomic v1.10.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.25.0
golang.org/x/net v0.13.0
golang.org/x/net v0.17.0
golang.org/x/sync v0.3.0
golang.org/x/sys v0.14.0
golang.org/x/tools v0.11.0
Expand All @@ -71,10 +70,12 @@ require (
k8s.io/klog/v2 v2.100.1 // indirect
)

require github.com/kdoctor-io/kdoctor v0.2.0

require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.1.1 // indirect
github.com/Masterminds/sprig/v3 v3.2.2 // indirect
github.com/Masterminds/semver/v3 v3.2.0 // indirect
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
Expand Down Expand Up @@ -107,7 +108,7 @@ require (
github.com/gorilla/handlers v1.5.1 // indirect
github.com/grafana/pyroscope-go/godeltaprof v0.1.3 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
Expand Down Expand Up @@ -163,12 +164,12 @@ require (
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.mongodb.org/mongo-driver v1.11.3 // indirect
go.uber.org/dig v1.17.0 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand Down
60 changes: 35 additions & 25 deletions go.sum

Large diffs are not rendered by default.

15 changes: 7 additions & 8 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ kind-init: check_env prepare
E2E_IP_FAMILY=$(E2E_IP_FAMILY) \
E2E_CLUSTER_NAME=$(E2E_CLUSTER_NAME) \
E2E_KUBECONFIG=$(E2E_KUBECONFIG) \
INSTALL_NETTOOLS=$(INSTALL_NETTOOLS) \
E2E_VLAN_GATEWAY_IMAGE=$(E2E_VLAN_GATEWAY_IMAGE) \
VLAN_GATEWAY_CONTAINER=$(VLAN_GATEWAY_CONTAINER) \
$(QUIET) bash scripts/config-network.sh
Expand Down Expand Up @@ -47,7 +46,7 @@ endif
@echo -e "\033[35m [Step 7] Install Spiderpool \033[0m"
@ make setup_spiderpool
ifeq ($(INSTALL_MULTUS),true)
@echo -e "\033[35m [Step 8] Install Multus \033[0m"
@echo -e "\033[35m [Step 8] Install Multus CR and IPPool CR \033[0m"
@ IMAGE_MULTUS=$(IMAGE_MULTUS_NAME) \
E2E_IP_FAMILY=$(E2E_IP_FAMILY) \
MULTUS_DEFAULT_CNI_NAME=$(MULTUS_DEFAULT_CNI_VLAN0) \
Expand All @@ -70,16 +69,16 @@ ifeq ($(INSTALL_KRUISE),true)
@echo -e "\033[35m [Step 9] Install third-party controllers: kurise \033[0m"
@ make setup_kurise
endif
ifeq ($(INSTALL_SPIDERDOCTOR),true)
@echo -e "\033[35m [Step 10] Install SpiderDoctor \033[0m"
ifeq ($(INSTALL_KDOCTOR),true)
@echo -e "\033[35m [Step 10] Install kdoctor \033[0m"
E2E_KUBECONFIG=$(E2E_KUBECONFIG) \
E2E_IP_FAMILY=$(E2E_IP_FAMILY) \
E2E_CLUSTER_NAME=$(E2E_CLUSTER_NAME) \
SPIDERDOCTOR_VERSION=$(SPIDERDOCTOR_VERSION) \
SPIDERDOCTOR_REPORT_PATH=$(SPIDERDOCTOR_REPORT_PATH) \
E2E_SPIDERDOCTOR_IMAGE_REPO=$(E2E_SPIDERDOCTOR_IMAGE_REPO) \
KDOCTOR_VERSION=$(KDOCTOR_VERSION) \
KDOCTOR_REPORT_PATH=$(KDOCTOR_REPORT_PATH) \
E2E_KDOCTOR_IMAGE_REPO=$(E2E_KDOCTOR_IMAGE_REPO) \
HTTP_PROXY=$(HTTP_PROXY) \
$(QUIET) bash scripts/install-spiderdoctor.sh
$(QUIET) bash scripts/install-kdoctor.sh
endif
ifeq ($(INSTALL_KUBEVIRT),true)
@echo -e "\033[35m [Step 10] Install kubevirt \033[0m"
Expand Down
16 changes: 7 additions & 9 deletions test/Makefile.defs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ INSTALL_MACVLAN ?= true

INSTALL_MULTUS ?= true

INSTALL_KRUISE ?= true
INSTALL_KRUISE ?= false

INSTALL_OVERLAY_CNI ?= false

Expand All @@ -51,9 +51,7 @@ INSTALL_CILIUM ?= true

DISABLE_KUBE_PROXY ?= false

INSTALL_NETTOOLS ?= false

INSTALL_SPIDERDOCTOR ?= true
INSTALL_KDOCTOR ?= true

INSTALL_KUBEVIRT ?= false

Expand Down Expand Up @@ -150,16 +148,16 @@ endif

CILIUM_VERSION ?=

#================= spiderdoctor
SPIDERDOCTOR_VERSION ?= v0.3.0
#================= kdoctor
KDOCTOR_VERSION ?= v0.2.0

ifeq ($(E2E_CHINA_IMAGE_REGISTRY),true)
E2E_SPIDERDOCTOR_IMAGE_REPO ?= ghcr.m.daocloud.io
E2E_KDOCTOR_IMAGE_REPO ?= ghcr.m.daocloud.io
else
E2E_SPIDERDOCTOR_IMAGE_REPO ?= ghcr.io
E2E_KDOCTOR_IMAGE_REPO ?= ghcr.io
endif

SPIDERDOCTOR_REPORT_PATH=/var/log/spiderdoctor/controller
KDOCTOR_REPORT_PATH=/var/log/kdoctor/controller

#====== pyroscope
PYROSCOPE_CONTAINER_NAME := e2e-pyroscope
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/common/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ var (
SpiderPoolIPv4SubnetVlan200 string = "vlan200-v4"
SpiderPoolIPv6SubnetVlan200 string = "vlan200-v6"

MultusNs = "kube-system"
SpiderDoctorAgentNs = "kube-system"
SpiderDoctorAgentDSName = "spiderdoctor-agent"
MultusNs = "kube-system"
KDoctorAgentNs = "kube-system"
KDoctorAgentDSName = "kdoctor-agent"

// gateway and check for ip conflicting machines
VlanGatewayContainer = "vlan-gateway"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"testing"

multus_v1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
kdoctorV1beta1 "github.com/kdoctor-io/kdoctor/pkg/k8s/apis/kdoctor.io/v1beta1"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
e2e "github.com/spidernet-io/e2eframework/framework"
spiderdoctorV1 "github.com/spidernet-io/spiderdoctor/pkg/k8s/apis/spiderdoctor.spidernet.io/v1"
spiderpool "github.com/spidernet-io/spiderpool/pkg/k8s/apis/spiderpool.spidernet.io/v2beta1"
"github.com/spidernet-io/spiderpool/test/e2e/common"
appsv1 "k8s.io/api/apps/v1"
Expand All @@ -24,24 +24,24 @@ func TestMacvlanOverlayOne(t *testing.T) {
var frame *e2e.Framework

// var name string
var spiderDoctorAgent *appsv1.DaemonSet
var kdoctorAgent *appsv1.DaemonSet

var successRate = float64(1)
var name string
var err error
var delayMs = int64(15000)
var (
task *spiderdoctorV1.Nethttp
plan *spiderdoctorV1.SchedulePlan
target *spiderdoctorV1.NethttpTarget
targetAgent *spiderdoctorV1.TargetAgentSepc
request *spiderdoctorV1.NethttpRequest
condition *spiderdoctorV1.NetSuccessCondition
task *kdoctorV1beta1.NetReach
plan *kdoctorV1beta1.SchedulePlan
targetAgent *kdoctorV1beta1.NetReachTarget
request *kdoctorV1beta1.NetHttpRequest
schedule *kdoctorV1beta1.SchedulePlan
condition *kdoctorV1beta1.NetSuccessCondition
run = true
)

var _ = BeforeSuite(func() {
frame, err = e2e.NewFramework(GinkgoT(), []func(*runtime.Scheme) error{multus_v1.AddToScheme, spiderpool.AddToScheme, spiderdoctorV1.AddToScheme})
frame, err = e2e.NewFramework(GinkgoT(), []func(*runtime.Scheme) error{multus_v1.AddToScheme, spiderpool.AddToScheme, kdoctorV1beta1.AddToScheme})
Expect(err).NotTo(HaveOccurred())

if !common.CheckRunOverlayCNI() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

"k8s.io/utils/pointer"

spiderdoctorV1 "github.com/spidernet-io/spiderdoctor/pkg/k8s/apis/spiderdoctor.spidernet.io/v1"
kdoctorV1beta1 "github.com/kdoctor-io/kdoctor/pkg/k8s/apis/kdoctor.io/v1beta1"
"github.com/spidernet-io/spiderpool/pkg/constant"
"github.com/spidernet-io/spiderpool/pkg/ip"
spiderpoolv2beta1 "github.com/spidernet-io/spiderpool/pkg/k8s/apis/spiderpool.spidernet.io/v2beta1"
Expand All @@ -39,12 +39,12 @@ var _ = Describe("MacvlanOverlayOne", Label("overlay", "one-nic", "coordinator")
defer GinkgoRecover()
var annotations = make(map[string]string)

task = new(spiderdoctorV1.Nethttp)
plan = new(spiderdoctorV1.SchedulePlan)
target = new(spiderdoctorV1.NethttpTarget)
targetAgent = new(spiderdoctorV1.TargetAgentSepc)
request = new(spiderdoctorV1.NethttpRequest)
condition = new(spiderdoctorV1.NetSuccessCondition)
task = new(kdoctorV1beta1.NetReach)
plan = new(kdoctorV1beta1.SchedulePlan)
targetAgent = new(kdoctorV1beta1.NetReachTarget)
request = new(kdoctorV1beta1.NetHttpRequest)
schedule = new(kdoctorV1beta1.SchedulePlan)
condition = new(kdoctorV1beta1.NetSuccessCondition)
name = "one-macvlan-overlay-" + tools.RandomName()

annotations[common.MultusNetworks] = fmt.Sprintf("%s/%s", common.MultusNs, common.MacvlanVlan100)
Expand All @@ -56,17 +56,17 @@ var _ = Describe("MacvlanOverlayOne", Label("overlay", "one-nic", "coordinator")
annotations[constant.AnnoPodIPPool] = `{"interface": "net1", "ipv6": ["vlan100-v6"]}`
}

GinkgoWriter.Printf("update spiderdoctoragent annotation: %v/%v annotation: %v \n", common.SpiderDoctorAgentNs, common.SpiderDoctorAgentDSName, annotations)
spiderDoctorAgent, err = frame.GetDaemonSet(common.SpiderDoctorAgentDSName, common.SpiderDoctorAgentNs)
GinkgoWriter.Printf("update kdoctoragent annotation: %v/%v annotation: %v \n", common.KDoctorAgentNs, common.KDoctorAgentDSName, annotations)
kdoctorAgent, err = frame.GetDaemonSet(common.KDoctorAgentDSName, common.KDoctorAgentNs)
Expect(err).NotTo(HaveOccurred())
Expect(spiderDoctorAgent).NotTo(BeNil())
Expect(kdoctorAgent).NotTo(BeNil())

GinkgoWriter.Printf("remove old spiderdoctor %v/%v \n", common.SpiderDoctorAgentNs, common.SpiderDoctorAgentDSName)
err = frame.DeleteDaemonSet(common.SpiderDoctorAgentDSName, common.SpiderDoctorAgentNs)
GinkgoWriter.Printf("remove old kdoctor %v/%v \n", common.KDoctorAgentNs, common.KDoctorAgentDSName)
err = frame.DeleteDaemonSet(common.KDoctorAgentDSName, common.KDoctorAgentNs)
Expect(err).NotTo(HaveOccurred())

Eventually(func() bool {
spiderDoctorAgentPodList, err := frame.GetPodListByLabel(spiderDoctorAgent.Spec.Template.Labels)
spiderDoctorAgentPodList, err := frame.GetPodListByLabel(kdoctorAgent.Spec.Template.Labels)
if err != nil {
GinkgoWriter.Printf("failed to get pod list %v,error is: %v \n", err)
return false
Expand All @@ -78,72 +78,76 @@ var _ = Describe("MacvlanOverlayOne", Label("overlay", "one-nic", "coordinator")
}, common.ResourceDeleteTimeout, common.ForcedWaitingTime).Should(BeTrue())

// issue: the object has been modified; please apply your changes to the latest version and try again
spiderDoctorAgent.ResourceVersion = ""
spiderDoctorAgent.CreationTimestamp = v1.Time{}
spiderDoctorAgent.UID = apitypes.UID("")
spiderDoctorAgent.Spec.Template.Annotations = annotations
kdoctorAgent.ResourceVersion = ""
kdoctorAgent.CreationTimestamp = v1.Time{}
kdoctorAgent.UID = apitypes.UID("")
kdoctorAgent.Spec.Template.Annotations = annotations

GinkgoWriter.Printf("create spiderdoctor %v/%v \n", common.SpiderDoctorAgentNs, common.SpiderDoctorAgentDSName)
err = frame.CreateDaemonSet(spiderDoctorAgent)
GinkgoWriter.Printf("create kdoctor %v/%v \n", common.KDoctorAgentNs, common.KDoctorAgentDSName)
err = frame.CreateDaemonSet(kdoctorAgent)
Expect(err).NotTo(HaveOccurred())

nodeList, err := frame.GetNodeList()
Expect(err).NotTo(HaveOccurred())

ctx, cancel := context.WithTimeout(context.Background(), common.PodReStartTimeout)
defer cancel()
err = frame.WaitPodListRunning(spiderDoctorAgent.Spec.Selector.MatchLabels, len(nodeList.Items), ctx)
err = frame.WaitPodListRunning(kdoctorAgent.Spec.Selector.MatchLabels, len(nodeList.Items), ctx)
Expect(err).NotTo(HaveOccurred())
})

It("spiderdoctor connectivity should be succeed", Serial, Label("C00002"), Label("ebpf"), func() {
It("kdoctor connectivity should be succeed", Serial, Label("C00002"), Label("ebpf"), func() {

// create task spiderdoctor crd
enable := true
disable := false
// create task kdoctor crd
task.Name = name
// schedule
plan.StartAfterMinute = 0
plan.RoundNumber = 2
plan.IntervalMinute = 2
plan.TimeoutMinute = 2
task.Spec.Schedule = plan
// target
targetAgent.TestIngress = false
targetAgent.TestEndpoint = true
targetAgent.TestClusterIp = true
targetAgent.TestMultusInterface = frame.Info.MultusEnabled
targetAgent.TestNodePort = true
targetAgent.Ingress = &disable
targetAgent.Endpoint = &enable
targetAgent.ClusterIP = &enable
targetAgent.MultusInterface = &frame.Info.MultusEnabled
targetAgent.NodePort = &enable

targetAgent.TestIPv4 = &frame.Info.IpV4Enabled
targetAgent.IPv4 = &frame.Info.IpV4Enabled
if common.CheckCiliumFeatureOn() {
// TODO(tao.yang), set testIPv6 to false, reference issue: https://github.com/spidernet-io/spiderpool/issues/2007
testIPv6 := false
targetAgent.TestIPv6 = &testIPv6
targetAgent.IPv6 = &disable
} else {
targetAgent.TestIPv6 = &frame.Info.IpV6Enabled
targetAgent.IPv6 = &frame.Info.IpV6Enabled
}

GinkgoWriter.Printf("targetAgent for spiderdoctor %+v", targetAgent)
target.TargetAgent = targetAgent
task.Spec.Target = target
GinkgoWriter.Printf("targetAgent for kdoctor %+v", targetAgent)
task.Spec.Target = targetAgent

// request
request.DurationInSecond = 5
request.QPS = 1
request.PerRequestTimeoutInMS = 15000
task.Spec.Request = request

// Schedule
crontab := "0 1"
schedule.Schedule = &crontab
schedule.RoundNumber = 1
schedule.RoundTimeoutMinute = 1
task.Spec.Schedule = schedule

// success condition
condition.SuccessRate = &successRate
condition.MeanAccessDelayInMs = &delayMs
task.Spec.SuccessCondition = condition

taskCopy := task
GinkgoWriter.Printf("spiderdoctor task: %+v", task)
GinkgoWriter.Printf("kdoctor task: %+v", task)
err := frame.CreateResource(task)
Expect(err).NotTo(HaveOccurred(), " spiderdoctor nethttp crd create failed")
Expect(err).NotTo(HaveOccurred(), " kdoctor nethttp crd create failed")

err = frame.GetResource(apitypes.NamespacedName{Name: name}, taskCopy)
Expect(err).NotTo(HaveOccurred(), " spiderdoctor nethttp crd get failed")
Expect(err).NotTo(HaveOccurred(), " kdoctor nethttp crd get failed")

ctx, cancel := context.WithTimeout(context.Background(), common.KdoctorCheckTime)
defer cancel()
Expand All @@ -152,13 +156,13 @@ var _ = Describe("MacvlanOverlayOne", Label("overlay", "one-nic", "coordinator")
select {
case <-ctx.Done():
run = false
Expect(errors.New("wait nethttp test timeout")).NotTo(HaveOccurred(), " running spiderdoctor task timeout")
Expect(errors.New("wait nethttp test timeout")).NotTo(HaveOccurred(), " running kdoctor task timeout")
default:
err = frame.GetResource(apitypes.NamespacedName{Name: name}, taskCopy)
Expect(err).NotTo(HaveOccurred(), "spiderdoctor nethttp crd get failed,err is %v", err)
Expect(err).NotTo(HaveOccurred(), "kdoctor nethttp crd get failed,err is %v", err)

if taskCopy.Status.Finish == true {
GinkgoWriter.Printf("spiderdoctor's nethttp execution result %+v", taskCopy)
GinkgoWriter.Printf("kdoctor's nethttp execution result %+v", taskCopy)
for _, v := range taskCopy.Status.History {
if v.Status != "succeed" {
err = errors.New("error has occurred")
Expand Down
Loading

0 comments on commit b500b6a

Please sign in to comment.