Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1929314: detect if the cluster has endpoint slices #436

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 3 additions & 15 deletions go-controller/pkg/util/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package util
import (
"encoding/json"
"fmt"
"strconv"
"strings"

kapi "k8s.io/api/core/v1"
Expand Down Expand Up @@ -240,22 +239,11 @@ func EventRecorder(kubeClient kubernetes.Interface) record.EventRecorder {
return recorder
}

// UseEndpointSlices if the EndpointSlice API is available
// and if the kubernetes versions supports DualStack (Kubernetes >= 1.20)
// UseEndpointSlices detect if Endpoints Slices are enabled in the cluster
func UseEndpointSlices(kubeClient kubernetes.Interface) bool {
endpointSlicesEnabled := false
if _, err := kubeClient.Discovery().ServerResourcesForGroupVersion(discovery.SchemeGroupVersion.String()); err == nil {
// The EndpointSlice API is enabled check if is running in a supported version
klog.V(2).Infof("Kubernetes Endpoint Slices enabled on the cluster: %s", discovery.SchemeGroupVersion.String())
endpointSlicesEnabled = true
return true
}
// We only use Slices if > 1.19 since we only need them for Dual Stack
sv, _ := kubeClient.Discovery().ServerVersion()
major, _ := strconv.Atoi(sv.Major)
minor, _ := strconv.Atoi(sv.Minor)
klog.Infof("Kubernetes running with version %d.%d", major, minor)
if major <= 1 && minor < 20 || !endpointSlicesEnabled {
return false
}
return true
return false
}