Files
my-rook-config/pkg/operator/ceph/cluster/mon/node.go
T
Travis Nielsen e90ed3b912 mon: allow overriding the mon endpoint with annotation
For an advanced network configuration, the mon endpoints
expected for the ceph public network may be different from
the public IP address that is set on the K8s node. When
host networking is enabled in rook, the IP address of the
node was only allowed previously. Now, the IP address
used for a mon when scheduled on a node can be determined
by setting an annotation on each node where mons can run:
    network.rook.io/mon-ip: <ip-address>
This annotation must be set before the mons are created.
Mon endpoints cannot be changed after they are already
running.

Signed-off-by: Travis Nielsen <tnielsen@redhat.com>
2024-06-05 10:32:55 -06:00

67 lines
1.8 KiB
Go

/*
Copyright 2016 The Rook Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package mon
import (
"github.com/pkg/errors"
opcontroller "github.com/rook/rook/pkg/operator/ceph/controller"
v1 "k8s.io/api/core/v1"
)
const (
monIPAnnotation = "network.rook.io/mon-ip"
)
func getNodeInfoFromNode(n v1.Node) (*opcontroller.MonScheduleInfo, error) {
nr := &opcontroller.MonScheduleInfo{
Name: n.Name,
Hostname: n.Labels[v1.LabelHostname],
}
// If the host networking is setup such that a different IP should be used
// than the one that is to the K8s node.
if customIP, ok := n.Annotations[monIPAnnotation]; ok {
logger.Infof("found %s annotation on node %q --> %q", monIPAnnotation, n.Name, customIP)
nr.Address = customIP
return nr, nil
}
for _, ip := range n.Status.Addresses {
if ip.Type == v1.NodeInternalIP {
logger.Debugf("using internal IP %s for node %s", ip.Address, n.Name)
nr.Address = ip.Address
break
}
}
// If no internal IP found try to use an external IP
if nr.Address == "" {
for _, ip := range n.Status.Addresses {
if ip.Type == v1.NodeExternalIP {
logger.Debugf("using external IP %s for node %s", ip.Address, n.Name)
nr.Address = ip.Address
break
}
}
}
if nr.Address == "" {
return nil, errors.Errorf("failed to find any IP on node %s", nr.Name)
}
return nr, nil
}