in internal/version.go [65:92]
func findOperatorStatefulSet(c *kubernetes.Clientset, namespace string) (*appsv1.StatefulSet, error) {
// we use the control-plane label since ECK version 1.0
ssets, err := c.AppsV1().StatefulSets(namespace).List(context.Background(), metav1.ListOptions{LabelSelector: "control-plane=elastic-operator"})
if err != nil {
return nil, err
}
// there is the possibility that users have deployed multiple ECK operators into the same namespace which we are
// ignoring here by assuming exactly one
if len(ssets.Items) == 1 {
return &ssets.Items[0], nil
}
// when deployed via Helm we don't have the control-plan label
ssets, err = c.AppsV1().StatefulSets(namespace).List(context.Background(), metav1.ListOptions{LabelSelector: "app.kubernetes.io/managed-by=Helm"})
if err != nil {
return nil, err
}
for _, set := range ssets.Items {
// unfortunately the chart name also encodes the version which is what we are trying to find out
// that's why we are doing a substring match here
if chart, ok := set.Labels["helm.sh/chart"]; ok && strings.Contains(chart, "eck-operator") {
return &set, nil
}
}
return nil, nil
}