Skip to content

Commit

Permalink
Merge pull request #1 from kloudlite/fix/nodes-listing-via-api
Browse files Browse the repository at this point in the history
fix: updates nodes listing for a nodepool
  • Loading branch information
nxtcoder17 authored Mar 10, 2024
2 parents 280983c + eb6c91f commit 04057b9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
10 changes: 7 additions & 3 deletions cluster-autoscaler/cloudprovider/kloudlite/cloud-provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ func (k *kloudliteCloudProvider) NodeGroupForNode(node *apiv1.Node) (cloudprovid
return nil, err
}

if nodepool == nil {
return nil, nil
}

for i := range k.nodeGroups {
if k.nodeGroups[i].Id() == nodepool.Name {
return k.nodeGroups[i], nil
Expand All @@ -61,17 +65,17 @@ func (k *kloudliteCloudProvider) HasInstance(node *apiv1.Node) (bool, error) {
}

func (k *kloudliteCloudProvider) Pricing() (cloudprovider.PricingModel, errors.AutoscalerError) {
//TODO implement me
// TODO implement me
panic("implement me")
}

func (k *kloudliteCloudProvider) GetAvailableMachineTypes() ([]string, error) {
//TODO implement me
// TODO implement me
panic("implement me")
}

func (k *kloudliteCloudProvider) NewNodeGroup(machineType string, labels map[string]string, systemLabels map[string]string, taints []apiv1.Taint, extraResources map[string]resource.Quantity) (cloudprovider.NodeGroup, error) {
//TODO implement me
// TODO implement me
panic("implement me")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"time"

corev1 "k8s.io/api/core/v1"
Expand All @@ -20,6 +21,8 @@ import (
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client"

apiErrors "k8s.io/apimachinery/pkg/api/errors"
)

type Client struct {
Expand Down Expand Up @@ -106,16 +109,31 @@ func (k *Client) getNode(ctx context.Context, nodeName string) (*corev1.Node, er
}

func (k *Client) ListNodes(ctx context.Context, poolName string) ([]corev1.Node, error) {
var nodesList corev1.NodeList
if err := k.k8sCli.List(ctx, &nodesList, &client.ListOptions{
LabelSelector: apiLabels.SelectorFromValidatedSet(map[string]string{
constants.NodepoolNameLabel: poolName,
}),
}); err != nil {
return nil, err
nodesList := unstructured.UnstructuredList{
Object: map[string]any{
"apiVersion": "clusters.kloudlite.io/v1",
"kind": "Node",
},
}

nodes := make([]corev1.Node, len(nodesList.Items))
for i := range nodesList.Items {
n, err := k.getNode(ctx, nodesList.Items[i].GetName())
if err != nil {
if !apiErrors.IsNotFound(err) {
return nil, err
}
n = &corev1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: nodesList.Items[i].GetName(),
Namespace: nodesList.Items[i].GetNamespace(),
},
}
}
nodes[i] = *n
}

return nodesList.Items, nil
return nodes, nil
}

func (k *Client) TargetSize(nodepoolName string) (int, error) {
Expand Down Expand Up @@ -181,6 +199,9 @@ func (k *Client) CreateNode(ctx context.Context, nodepoolName string) error {
"kind": "Node",
"metadata": map[string]any{
"generateName": fmt.Sprintf("%s-node-", nodepoolName),
"labels": map[string]string{
"kloudlite.io/nodepool.name": nodepoolName,
},
"finalizers": []string{
"kloudlite.io/nodepool-node-finalizer",
},
Expand Down

0 comments on commit 04057b9

Please sign in to comment.