Skip to content

Commit

Permalink
Merge pull request #113 from pliurh/mco
Browse files Browse the repository at this point in the history
Find the MCP based on the owner of node's desired MC
  • Loading branch information
pliurh authored Apr 15, 2021
2 parents bbc0397 + a58a4ad commit 9b59e4e
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
sninformer "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/client/informers/externalversions"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/utils"
mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
daemonconsts "github.com/openshift/machine-config-operator/pkg/daemon/constants"
mcclientset "github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned"
mcfginformers "github.com/openshift/machine-config-operator/pkg/generated/informers/externalversions"
)
Expand Down Expand Up @@ -529,8 +530,10 @@ func (dn *Daemon) nodeStateSyncHandler(generation int64) error {
}
return nil
}
if err = dn.getNodeMachinePool(); err != nil {
return err
if utils.ClusterType == utils.ClusterTypeOpenshift {
if err = dn.getNodeMachinePool(); err != nil {
return err
}
}

if reqDrain && !dn.disableDrain {
Expand Down Expand Up @@ -768,25 +771,23 @@ func (dn *Daemon) annotateNode(node, value string) error {
}

func (dn *Daemon) getNodeMachinePool() error {
mcpList, err := dn.mcClient.MachineconfigurationV1().MachineConfigPools().List(context.TODO(), metav1.ListOptions{})
desiredConfig, ok := dn.node.Annotations[daemonconsts.DesiredMachineConfigAnnotationKey]
if !ok {
glog.Error("getNodeMachinePool(): Failed to find the the desiredConfig Annotation")
return fmt.Errorf("getNodeMachinePool(): Failed to find the the desiredConfig Annotation")
}
mc, err := dn.mcClient.MachineconfigurationV1().MachineConfigs().Get(context.TODO(), desiredConfig, metav1.GetOptions{})
if err != nil {
glog.Errorf("getNodeMachinePool(): Failed to list Machine Config Pools: %v", err)
glog.Errorf("getNodeMachinePool(): Failed to get the desired Machine Config: %v", err)
return err
}
var mcp mcfgv1.MachineConfigPool
for _, mcp = range mcpList.Items {
selector, err := metav1.LabelSelectorAsSelector(mcp.Spec.NodeSelector)
if err != nil {
glog.Errorf("getNodeMachinePool(): Machine Config Pool %s invalid label selector: %v", mcp.GetName(), err)
return err
}

if selector.Matches(labels.Set(dn.node.Labels)) {
dn.mcpName = mcp.GetName()
glog.Infof("getNodeMachinePool(): find node in MCP %s", dn.mcpName)
for _, owner := range mc.OwnerReferences {
if owner.Kind == "MachineConfigPool" {
dn.mcpName = owner.Name
return nil
}
}
glog.Error("getNodeMachinePool(): Failed to find the MCP of the node")
return fmt.Errorf("getNodeMachinePool(): Failed to find the MCP of the node")
}

Expand Down

0 comments on commit 9b59e4e

Please sign in to comment.