Skip to content

Commit

Permalink
operator v1: improve readability of GetNodePools
Browse files Browse the repository at this point in the history
  • Loading branch information
birdayz committed Nov 15, 2024
1 parent 4ace3cf commit 385cee7
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions operator/pkg/nodepools/pools.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand Down Expand Up @@ -61,10 +62,13 @@ outer:
for i := range stsList.Items {
sts := stsList.Items[i]

for _, ownerRef := range sts.OwnerReferences {
if ownerRef.UID != cluster.UID {
continue outer
}
// Extra paranoid sanity check so we don't touch STS we don't own.
if !slices.ContainsFunc(
sts.OwnerReferences,
func(ownerRef metav1.OwnerReference) bool {
return ownerRef.UID == cluster.UID
}) {
continue outer
}

var npName string
Expand All @@ -77,7 +81,8 @@ outer:
npName = strings.TrimPrefix(sts.Name, fmt.Sprintf("%s-", cluster.Name))
}

// Have seen it in NodePoolSpec
// Have seen it in NodePoolSpec - therefore, it's not a deleted NodePool,
// so we don't need to reconstruct it based on the STS.
if slices.ContainsFunc(nps, func(np vectorizedv1alpha1.NodePoolSpec) bool {
return np.Name == npName
}) {
Expand Down

0 comments on commit 385cee7

Please sign in to comment.