Skip to content

Commit

Permalink
feat: use clusterip instead of DNS for service status check
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlJi committed Sep 17, 2023
1 parent a7c4ff7 commit f3b1f2e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion controllers/k6_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/http"
"strings"
"time"

"github.com/go-logr/logr"
Expand All @@ -16,8 +17,20 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

// Simplified distinguish between IPv4 and IPv6 addresses
func isIPv6(ip string) bool {
return strings.Contains(ip, ":")
}

func serviceStatusURI(service *v1.Service) string {
if isIPv6(service.Spec.ClusterIP) {
return fmt.Sprintf("http://[%s]:6565/v1/status", service.Spec.ClusterIP)
}
return fmt.Sprintf("http://%s:6565/v1/status", service.Spec.ClusterIP)
}

func isServiceReady(log logr.Logger, service *v1.Service) bool {
resp, err := http.Get(fmt.Sprintf("http://%v.%v.svc.cluster.local:6565/v1/status", service.ObjectMeta.Name, service.ObjectMeta.Namespace))
resp, err := http.Get(serviceStatusURI(service))

if err != nil {
log.Error(err, fmt.Sprintf("failed to get status from %v", service.ObjectMeta.Name))
Expand Down
2 changes: 1 addition & 1 deletion controllers/k6_stopped_jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

func isJobRunning(log logr.Logger, service *v1.Service) bool {
resp, err := http.Get(fmt.Sprintf("http://%v.%v.svc.cluster.local:6565/v1/status", service.ObjectMeta.Name, service.ObjectMeta.Namespace))
resp, err := http.Get(serviceStatusURI(service))
if err != nil {
return false
}
Expand Down

0 comments on commit f3b1f2e

Please sign in to comment.