Skip to content

Commit

Permalink
ensure machine config and machine config pool operations are toggled …
Browse files Browse the repository at this point in the history
…off when interacting with hypershift clusters
  • Loading branch information
relyt0925 committed Aug 22, 2022
1 parent a6bee60 commit f0ca3a7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 18 deletions.
13 changes: 13 additions & 0 deletions cmd/sriov-network-config-daemon/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net"
"net/url"
"os"
"sigs.k8s.io/controller-runtime/pkg/client"
"strings"
"time"

Expand Down Expand Up @@ -127,6 +128,17 @@ func runStartCmd(cmd *cobra.Command, args []string) {
snclient := snclientset.NewForConfigOrDie(config)
kubeclient := kubernetes.NewForConfigOrDie(config)
mcclient := mcclientset.NewForConfigOrDie(config)
isHypershift := false
if utils.ClusterType == utils.ClusterTypeOpenshift {
infraClient, err := client.New(config, client.Options{})
if err != nil {
panic(err)
}
isHypershift, err = utils.IsHypershiftCluster(infraClient)
if err != nil {
panic(err)
}
}

config.Timeout = 5 * time.Second
writerclient := snclientset.NewForConfigOrDie(config)
Expand Down Expand Up @@ -179,6 +191,7 @@ func runStartCmd(cmd *cobra.Command, args []string) {
snclient,
kubeclient,
mcclient,
isHypershift,
exitCh,
stopCh,
syncCh,
Expand Down
20 changes: 16 additions & 4 deletions controllers/sriovnetworkpoolconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,33 @@ func (r *SriovNetworkPoolConfigReconciler) Reconcile(ctx context.Context, req ct
}
}
if utils.ClusterType == utils.ClusterTypeOpenshift {
if err = r.syncOvsHardwareOffloadMachineConfigs(instance, false); err != nil {
isHypershift, err := utils.IsHypershiftCluster(r.Client)
if err != nil {
return reconcile.Result{}, err
}
if !isHypershift {
if err = r.syncOvsHardwareOffloadMachineConfigs(instance, false); err != nil {
return reconcile.Result{}, err
}
}
}
} else {
// The object is being deleted
if sriovnetworkv1.StringInArray(sriovnetworkv1.POOLCONFIGFINALIZERNAME, instance.ObjectMeta.Finalizers) {
// our finalizer is present, so lets handle any external dependency
logger.Info("delete SriovNetworkPoolConfig CR", "Namespace", instance.Namespace, "Name", instance.Name)
if utils.ClusterType == utils.ClusterTypeOpenshift {
if err = r.syncOvsHardwareOffloadMachineConfigs(instance, true); err != nil {
// if fail to delete the external dependency here, return with error
// so that it can be retried
isHypershift, err := utils.IsHypershiftCluster(r.Client)
if err != nil {
return reconcile.Result{}, err
}
if !isHypershift {
if err = r.syncOvsHardwareOffloadMachineConfigs(instance, true); err != nil {
// if fail to delete the external dependency here, return with error
// so that it can be retried
return reconcile.Result{}, err
}
}
}
// remove our finalizer from the list and update it.
var found bool
Expand Down
31 changes: 17 additions & 14 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ type Daemon struct {
workqueue workqueue.RateLimitingInterface

mcpName string

isHypershift bool
}

const (
Expand Down Expand Up @@ -129,23 +131,25 @@ func New(
client snclientset.Interface,
kubeClient *kubernetes.Clientset,
mcClient *mcclientset.Clientset,
isHypershift bool,
exitCh chan<- error,
stopCh <-chan struct{},
syncCh <-chan struct{},
refreshCh chan<- Message,
platformType utils.PlatformType,
) *Daemon {
return &Daemon{
name: nodeName,
platform: platformType,
client: client,
kubeClient: kubeClient,
mcClient: mcClient,
exitCh: exitCh,
stopCh: stopCh,
syncCh: syncCh,
refreshCh: refreshCh,
nodeState: &sriovnetworkv1.SriovNetworkNodeState{},
name: nodeName,
platform: platformType,
client: client,
kubeClient: kubeClient,
mcClient: mcClient,
isHypershift: isHypershift,
exitCh: exitCh,
stopCh: stopCh,
syncCh: syncCh,
refreshCh: refreshCh,
nodeState: &sriovnetworkv1.SriovNetworkNodeState{},
drainer: &drain.Helper{
Client: kubeClient,
Force: true,
Expand Down Expand Up @@ -477,12 +481,11 @@ func (dn *Daemon) nodeStateSyncHandler(generation int64) error {
}
}
}
if utils.ClusterType == utils.ClusterTypeOpenshift {
if utils.ClusterType == utils.ClusterTypeOpenshift && !dn.isHypershift {
if err = dn.getNodeMachinePool(); err != nil {
return err
}
}

if reqDrain {
if !dn.isNodeDraining() {
if !dn.disableDrain {
Expand All @@ -495,7 +498,7 @@ func (dn *Daemon) nodeStateSyncHandler(generation int64) error {
<-done
}

if utils.ClusterType == utils.ClusterTypeOpenshift {
if utils.ClusterType == utils.ClusterTypeOpenshift && !dn.isHypershift {
glog.Infof("nodeStateSyncHandler(): pause MCP")
if err := dn.pauseMCP(); err != nil {
return err
Expand Down Expand Up @@ -579,7 +582,7 @@ func (dn *Daemon) completeDrain() error {
}
}

if utils.ClusterType == utils.ClusterTypeOpenshift {
if utils.ClusterType == utils.ClusterTypeOpenshift && !dn.isHypershift {
glog.Infof("completeDrain(): resume MCP %s", dn.mcpName)
pausePatch := []byte("{\"spec\":{\"paused\":false}}")
if _, err := dn.mcClient.MachineconfigurationV1().MachineConfigPools().Patch(context.Background(), dn.mcpName, types.MergePatchType, pausePatch, metav1.PatchOptions{}); err != nil {
Expand Down

0 comments on commit f0ca3a7

Please sign in to comment.