Hi team, We are transitioning from terraform to pu...
# general
a
Hi team, We are transitioning from terraform to pulumi for some of our workload but we are stuck trying to get nodes running for a nodegroup. We want to taint those nodes ultimately.
Copy code
nodes, err := v1.GetNodeList(ctx, "allnodes", nil, nil, pulumi.Provider(n.KubernetesProvider))
	if err != nil {
		fmt.Printf("failed to get NODE LIST: %w", err)
		return err
	}

	nodes.Items.ApplyT(func(items []v1.Node) error {
		for _, node := range items {
			pulumi.Printf("Node Name: %s\n", node.Metadata.Name)
		}
		return nil
	})
Above is code i am trying but unsuccessful. Any help would be appreciated . Thanks!
m
What exactly does "unsuccessful" mean? What do you want to achieve (probably not printing node names 😉), and what does the code do instead?
a
Ultimately, I want to taint the running nodes of a nodegroup. In this code i am trying to list nodes to see if it works.
Currently this gives error
resource ID is required for lookup and cannot be empty
m
Where does
v1.GetNodeList
come from? I can't find it in the Pulumi docs or code.
a
Copy code
"<http://github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/core/v1|github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/core/v1>"
Copy code
package main

import (
	"<http://github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/core/v1|github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/core/v1>"
	"<http://github.com/pulumi/pulumi/sdk/v3/go/pulumi|github.com/pulumi/pulumi/sdk/v3/go/pulumi>"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		// Lookup the NodeList
		nodeList, err := v1.GetNodeList(ctx, &v1.GetNodeListArgs{})
		if err != nil {
			return err
		}

		// Export the nodes' names
		for _, node := range nodeList.Items {
			ctx.Export("nodeName", pulumi.String(node.Metadata.Name))
		}

		return nil
	})
}
This is the code generated by pulumi AI
m
Ah, I see. For some reason, GitHub code search didn't find it.
a
I also couldn’t find it in the docs. But pulumi AI gives it
m
a
Yeah. So how do i fetch list of nodes of a nodegroup
Do you just need the names of the nodes? Or are you looking to import the nodes as resources into your Pulumi state? How are you going to taint the nodes?
a
So in terraform we fetch nodes for a nodegroup using
data "kubernetes_nodes"
and passing nodegroup as the label after which we apply taint to those nodes using
resource "kubernetes_node_taint"
I wanted something similar if possible
m
TF's
data
is similar to Pulumi's
Get...
, it gives you access to a read-only resource representation.
I'm not sure if there's an equivalent to
kubernetes_nodes
and
kubernetes_node_taint
in the Pulumi Kubernetes provider. As far as I know, these do not directly correspond to Kubernetes resources.
If you get a node via
GetNode
, you cannot modify it (just like you cannot modify a TF
data
object).
a
Does
GetNode
works? Like if i pass nodegroup name as the parameter or match label it gives nodes?
m
Great that you found that, this looks like what you need.
GetNode
is equivalent to
data "kubernetes_node"
, so it will give you a specific node resource but you have to know its name
a
Yeah but is there any way to get list of nodes running in kubernetes cluster or maybe get nodes running for an nodegroup
m
You can use the Kubernetes SDK to look up the node information in your Pulumi program.
GetNode
only works if you know the name of the node already.
a
yeah looks like thats the way to go . I will check out kubernetes SDK
m
Some Pulumi packages have convenience functions that wrap a client or SDK to look up information, but it doesn't look like the Kubernetes package does.
a
Yeah for AWS package there are few but couldn’t find for kubernetes
Maybe we should have one for this(fetch nodes of a nodegroup).👀
m
Yes, I agree that some utilities would be nice. Perhaps even a "give me a list of resources X in namespace Y" for all patchable resource types.
a
Agreed! FYI @big-piano-35669