I want to use golang Kubernetes client SDK to cordon specific nodes in my Kubernetes cluster.
According to other posts, I need to pass the following:
PATCH /api/v1/nodes/node-name
Request Body: {"spec":{"unschedulable":true}} Content-Type: "application/strategic-merge-patch+json"
However, I am not familiar with how to pass that.
I have the following, but not sure if those values are correct
type patchStringValue struct {
Op string `json:"op"`
Path string `json:"path"`
Value string `json:"value"`
}
func k8NodeCordon() {
clientSet := k8ClientInit()
payload := []patchStringValue{{
Op: "replace",
Path: "/spec/unschedulable",
Value: "true",
}}
payloadBytes, _ := json.Marshal(payload)
_, err := clientSet.
CoreV1().Nodes().Patch()
return err
}
Looks like I just needed to add the following:
_, err := clientSet.CoreV1().Nodes().Patch("<node_name>", types.JSONPatchType, payloadBytes)
type patchStringValue struct {
Op string `json:"op"`
Path string `json:"path"`
Value bool `json:"value"`
}
func k8NodeCordon() {
clientSet := k8ClientInit()
payload := []patchStringValue{{
Op: "replace",
Path: "/spec/unschedulable",
Value: true,
}}
payloadBytes, _ := json.Marshal(payload)
_, err := clientSet.CoreV1().Nodes().Patch("<node_name>", types.JSONPatchType, payloadBytes)
return err
}