Skip to content

Commit

Permalink
Adapt scheduler e2e
Browse files Browse the repository at this point in the history
Signed-off-by: ii2day <ji.li@daocloud.io>
  • Loading branch information
ii2day authored and Icarus9913 committed Aug 11, 2023
1 parent e3254e2 commit 1240af1
Show file tree
Hide file tree
Showing 16 changed files with 132 additions and 79 deletions.
2 changes: 0 additions & 2 deletions charts/templates/configmap-app-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ data:
targetPort: metrics
protocol: TCP
{{- end }}
{{- if .Values.feature.enableIPv4 }}
- name: http
port: {{ .Values.kdoctorAgent.httpServer.appHttpPort }}
targetPort: http
Expand All @@ -305,7 +304,6 @@ data:
port: {{ .Values.kdoctorAgent.httpServer.appHttpsPort }}
targetPort: https
protocol: TCP
{{- end }}
ipFamilyPolicy: SingleStack
ipFamilies:
- IPv4
Expand Down
2 changes: 1 addition & 1 deletion cmd/agent/cmd/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func checkServiceReady(logger *zap.Logger) {

if types.AgentConfig.Configmap.EnableIPv6 {
for {
_, err := k8sObjManager.GetK8sObjManager().GetService(ctx, types.AgentConfig.ServiceV4Name, types.AgentConfig.PodNamespace)
_, err := k8sObjManager.GetK8sObjManager().GetService(ctx, types.AgentConfig.ServiceV6Name, types.AgentConfig.PodNamespace)
if nil != err {
if errors.IsNotFound(err) {
logger.Sugar().Errorf("agent runtime IPv6 service %s/%s not exists, wait for controller to create it", types.AgentConfig.PodNamespace, types.AgentConfig.ServiceV6Name)
Expand Down
6 changes: 0 additions & 6 deletions cmd/agent/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,6 @@ func init() {
globalFlag.StringVar(&types.AgentConfig.TaskName, "task-name", "", "task name")
globalFlag.StringVar(&types.AgentConfig.ServiceV4Name, "service-ipv4-name", "", "agent IPv4 service name")
globalFlag.StringVar(&types.AgentConfig.ServiceV6Name, "service-ipv6-name", "", "agent IPv6 service name")
if err := rootCmd.MarkPersistentFlagRequired("task-kind"); nil != err {
logger.Sugar().Fatalf("failed to mark persistentFlag 'task-kind' as required, error: %v", err)
}
if err := rootCmd.MarkPersistentFlagRequired("task-name"); nil != err {
logger.Sugar().Fatalf("failed to mark persistentFlag 'task-name' as required, error: %v", err)
}

globalFlag.BoolVarP(&types.AgentConfig.AppMode, "app-mode", "A", false, "app mode")
globalFlag.BoolVarP(&types.AgentConfig.TlsInsecure, "tls-insecure", "K", true, "skip verify tls")
Expand Down
4 changes: 2 additions & 2 deletions pkg/grpcManager/server_implement.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import (
"context"
"fmt"
"github.com/kdoctor-io/kdoctor/api/v1/agentGrpc"
"github.com/kdoctor-io/kdoctor/pkg/utils"
"go.uber.org/zap"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"io"
"time"

"github.com/kdoctor-io/kdoctor/pkg/utils"
)

// ------ implement
Expand All @@ -31,6 +30,7 @@ func (s *myGrpcServer) ExecRemoteCmd(stream agentGrpc.CmdService_ExecRemoteCmdSe
logger.Error("grpc server ExecRemoteCmd: got empty command \n")
return nil, status.Error(codes.InvalidArgument, "request command is empty")
}

if r.Timeoutsecond == 0 {
logger.Error("grpc server ExecRemoteCmd: got empty timeout \n")
return nil, status.Error(codes.InvalidArgument, "request command is empty")
Expand Down
7 changes: 4 additions & 3 deletions pkg/pluginManager/controllerTools.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import (
)

func (s *pluginControllerReconciler) GetSpiderAgentNodeNotInRecord(ctx context.Context, succeedNodeList []string, podMatchLabel client.MatchingLabels) ([]string, error) {
var allNodeList, failNodeList []string
allNodeList, failNodeList := []string{}, []string{}

podList := corev1.PodList{}

err := s.client.List(ctx, &podList,
Expand All @@ -50,7 +51,7 @@ func (s *pluginControllerReconciler) GetSpiderAgentNodeNotInRecord(ctx context.C
s.logger.Sugar().Debugf("all agent nodes: %v", allNodeList)

// gather the failure Node list
slices.Filter(failNodeList, allNodeList, func(s string) bool {
failNodeList = slices.Filter(failNodeList, allNodeList, func(s string) bool {
return !slices.Contains(succeedNodeList, s)
})

Expand Down Expand Up @@ -347,7 +348,7 @@ func (s *pluginControllerReconciler) TaskResourceReconcile(ctx context.Context,
logger.Sugar().Debugf("task '%s/%s' just created, try to initial its corresponding runtime resource", taskKind, ownerTask.GetName())
newScheduler := scheduler.NewScheduler(s.client, s.apiReader, taskKind, ownerTask.GetName(), s.runtimeUniqueMatchLabelKey, logger)
// create the task corresponding resources(runtime,service) and record them to the task CR object subresource with 'Creating' status
resource, err = newScheduler.CreateTaskRuntimeIfNotExist(ctx, ownerTask, agentSpec, taskKind)
resource, err = newScheduler.CreateTaskRuntimeIfNotExist(ctx, ownerTask, agentSpec)
if nil != err {
return nil, err
}
Expand Down
26 changes: 4 additions & 22 deletions pkg/pluginManager/netreach/agentExecuteTask.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (s *PluginNetReach) AgentExecuteTask(logger *zap.Logger, ctx context.Contex
if agentV6Url != nil && len(agentV6Url.ClusterIPUrl) > 0 {
testTargetList = append(testTargetList, &TestTarget{
Name: "AgentClusterV6IP_" + agentV6Url.ClusterIPUrl[0],
Url: fmt.Sprintf("http://[%s]", agentV6Url.ClusterIPUrl[0]),
Url: fmt.Sprintf("http://%s", agentV6Url.ClusterIPUrl[0]),
Method: loadHttp.HttpMethodGet,
})
} else {
Expand Down Expand Up @@ -235,7 +235,7 @@ func (s *PluginNetReach) AgentExecuteTask(logger *zap.Logger, ctx context.Contex
if agentV6Url != nil && len(agentV6Url.LoadBalancerUrl) > 0 {
testTargetList = append(testTargetList, &TestTarget{
Name: "AgentLoadbalancerV6IP_" + agentV6Url.LoadBalancerUrl[0],
Url: fmt.Sprintf("http://[%s]", agentV6Url.LoadBalancerUrl[0]),
Url: fmt.Sprintf("http://%s", agentV6Url.LoadBalancerUrl[0]),
Method: loadHttp.HttpMethodGet,
})
} else {
Expand Down Expand Up @@ -266,28 +266,10 @@ func (s *PluginNetReach) AgentExecuteTask(logger *zap.Logger, ctx context.Contex
} else {
finalfailureReason = "failed to get agent v4 ingress address"
}
} else {
logger.Sugar().Debugf("ignore test agent ingress ipv6")
}

if runtimeResource.ServiceNameV6 != nil {
agentIngress, e := k8sObjManager.GetK8sObjManager().GetIngress(ctx, *runtimeResource.ServiceNameV6, config.AgentConfig.PodNamespace)
if e != nil {
logger.Sugar().Errorf("failed to get v6 ingress , error=%v", e)
}
if agentIngress != nil && len(agentIngress.Status.LoadBalancer.Ingress) > 0 {
http := "http"
if len(agentIngress.Spec.TLS) > 0 {
http = "https"
}
url := fmt.Sprintf("%s://%s%s", http, agentIngress.Status.LoadBalancer.Ingress[0].IP, agentIngress.Spec.Rules[0].HTTP.Paths[0].Path)
testTargetList = append(testTargetList, &TestTarget{
Name: "AgentIngress_v6_" + url,
Url: url,
Method: loadHttp.HttpMethodGet,
})
} else {
finalfailureReason = "failed to get agent v6 ingress address"
}
}
}

// ------------------------ implement for agent case and selected-pod case
Expand Down
5 changes: 5 additions & 0 deletions pkg/reportManager/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ func (s *reportManager) syncReportFromOneAgent(ctx context.Context, logger *zap.
// --
v := strings.Split(remoteFileName, "_")
timeSuffix := v[len(v)-1]
taskName := v[1]
if !strings.Contains(podName, taskName) {
logger.Sugar().Debugf("task %s not task of pod %s ,skip sync report %s", taskName, podName, remoteFileName)
continue

Check warning on line 72 in pkg/reportManager/worker.go

View check run for this annotation

Codecov / codecov/patch

pkg/reportManager/worker.go#L69-L72

Added lines #L69 - L72 were not covered by tests
}
remoteFilePre := strings.TrimSuffix(remoteFileName, "_"+timeSuffix)
// file name format: fmt.Sprintf("%s_%s_round%d_%s_%s", kindName, taskName, roundNumber, nodeName, suffix)
t := time.Duration(types.ControllerConfig.ReportAgeInDay*24) * time.Hour
Expand Down
19 changes: 8 additions & 11 deletions pkg/scheduler/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func NewScheduler(client client.Client, apiReader client.Reader, taskKind, taskN
return s
}

func (s *Scheduler) CreateTaskRuntimeIfNotExist(ctx context.Context, ownerTask metav1.Object, agentSpec v1beta1.AgentSpec, taskKind string) (v1beta1.TaskResource, error) {
func (s *Scheduler) CreateTaskRuntimeIfNotExist(ctx context.Context, ownerTask metav1.Object, agentSpec v1beta1.AgentSpec) (v1beta1.TaskResource, error) {
taskRuntimeName := TaskRuntimeName(s.taskKind, s.taskName)
resource := v1beta1.TaskResource{
RuntimeName: taskRuntimeName,
Expand Down Expand Up @@ -132,10 +132,13 @@ func (s *Scheduler) CreateTaskRuntimeIfNotExist(ctx context.Context, ownerTask m
}
resource.ServiceNameV4 = pointer.String(serviceNameV4)

if taskKind == types.KindNameNetReach {
err = s.createIngress(ctx, serviceNameV4, runtime)
if nil != err {
return v1beta1.TaskResource{}, fmt.Errorf("failed to create runtime IPv4 ingress for task '%s/%s', error: %w", s.taskKind, s.taskName, err)
if s.taskKind == types.KindNameNetReach {
nr := ownerTask.(*v1beta1.NetReach)
if nr.Spec.Target.Ingress {
err = s.createIngress(ctx, serviceNameV4, runtime)
if nil != err {
return v1beta1.TaskResource{}, fmt.Errorf("failed to create runtime IPv4 ingress for task '%s/%s', error: %w", s.taskKind, s.taskName, err)
}
}
}
}
Expand All @@ -146,12 +149,6 @@ func (s *Scheduler) CreateTaskRuntimeIfNotExist(ctx context.Context, ownerTask m
}
resource.ServiceNameV6 = pointer.String(serviceNameV6)

if taskKind == types.KindNameNetReach {
err = s.createIngress(ctx, serviceNameV6, runtime)
if nil != err {
return v1beta1.TaskResource{}, fmt.Errorf("failed to create runtime IPv4 ingress for task '%s/%s', error: %w", s.taskKind, s.taskName, err)
}
}
}

return resource, nil
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/apphttphealth/apphttphealth_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ var _ = BeforeSuite(func() {
e = frame.KClient.Get(context.Background(), key, caSecret)
Expect(e).NotTo(HaveOccurred(), "get kdoctor ca secret")

ds, e := frame.GetDaemonSet(common.KDoctorAgentDSName, common.TestNameSpace)
Expect(e).NotTo(HaveOccurred(), "get kdoctor-agent daemonset")
reportNum = int(ds.Status.NumberReady)
nodeLIst, e := frame.GetNodeList()
Expect(e).NotTo(HaveOccurred(), "get node list")
reportNum = len(nodeLIst.Items)

testAppName = "app-" + tools.RandomName()
testAppNamespace = "ns-" + tools.RandomName()
Expand Down
Loading

0 comments on commit 1240af1

Please sign in to comment.