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

detect if the cluster has endpoint slices #2049

Merged
merged 1 commit into from
Feb 16, 2021
Merged
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 @@ -243,22 +242,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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just so I remember in the future. This works because it pulls the client's scheme version and then queries the server to check if it supports whats in the client's schema (and obviously our client has support for endpoint slices).

// 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
}