Skip to content

Commit

Permalink
packet: make controller node label configurable
Browse files Browse the repository at this point in the history
Currently the label to identify controller/master node is hard coded to
`node-role.kubernetes.io/master`.

There have been some conversations centered around replacing the label
with `node-role.kubernetes.io/control-plane`.

In [Lokomotive](github.com/kinvolk/lokomotive), the label to identify
the controller/master node is `node.kubernetes.io/master`, the reasons
for this is mentioned in this [issue](kinvolk/lokomotive#227)

This commit makes the label configurable by setting an env variable in
the deployment `CONTROLLER_NODE_IDENTIFIER_LABEL`, if set then the value
in the env variable is used for identifying controller/master nodes, if
not set/passed, then the existing behaviour is followed choosing the
existing label.

Signed-off-by: Imran Pochi <imran@kinvolk.io>
  • Loading branch information
ipochi committed Aug 19, 2021
1 parent a4079d4 commit aaf147b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion cluster-autoscaler/cloudprovider/packet/packet_cloud_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ const (
ProviderName = "packet"
// GPULabel is the label added to nodes with GPU resource.
GPULabel = "cloud.google.com/gke-accelerator"
// DefaultControllerNodeLabelKey is the label added to Master/Controller to identify as
// master/controller node.
DefaultControllerNodeLabelKey = "node-role.kubernetes.io/master"
// ControllerNodeIdentifierEnv is the string for the environment variable.
ControllerNodeIdentifierEnv = "PACKET_CONTROLLER_NODE_IDENTIFIER_LABEL"
)

var (
Expand Down Expand Up @@ -94,7 +99,13 @@ func (pcp *packetCloudProvider) AddNodeGroup(group packetNodeGroup) {
//
// Since only a single node group is currently supported, the first node group is always returned.
func (pcp *packetCloudProvider) NodeGroupForNode(node *apiv1.Node) (cloudprovider.NodeGroup, error) {
if _, found := node.ObjectMeta.Labels["node-role.kubernetes.io/master"]; found {
controllerNodeLabel := os.Getenv(ControllerNodeIdentifierEnv)
if controllerNodeLabel == "" {
klog.V(3).Infof("env %s not set, using default: %s", ControllerNodeIdentifierEnv, DefaultControllerNodeLabelKey)
controllerNodeLabel = DefaultControllerNodeLabelKey
}

if _, found := node.ObjectMeta.Labels[controllerNodeLabel]; found {
return nil, nil
}
nodeGroupId, err := pcp.packetManager.NodeGroupForNode(node.ObjectMeta.Labels, node.Spec.ProviderID)
Expand Down

0 comments on commit aaf147b

Please sign in to comment.