Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into dssync-20231222
Browse files Browse the repository at this point in the history
  • Loading branch information
zeeke committed Dec 22, 2023
2 parents 97e5e76 + e7fd641 commit 7c990b6
Show file tree
Hide file tree
Showing 14 changed files with 333 additions and 62 deletions.
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ kustomize: ## Download kustomize locally if necessary.

ENVTEST = $(BIN_DIR)/setup-envtest
envtest: ## Download envtest-setup locally if necessary.
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@release-0.16)

GOMOCK = $(shell pwd)/bin/mockgen
gomock:
Expand All @@ -176,12 +176,11 @@ skopeo:
fakechroot:
if ! which fakechroot; then if [ -f /etc/redhat-release ]; then dnf -y install fakechroot; elif [ -f /etc/lsb-release ]; then sudo apt-get -y update; sudo apt-get -y install fakechroot; fi; fi

deploy-setup: export ENABLE_ADMISSION_CONTROLLER?=true
deploy-setup: export ENABLE_ADMISSION_CONTROLLER?=false
deploy-setup: skopeo install
hack/deploy-setup.sh $(NAMESPACE)

deploy-setup-k8s: export NAMESPACE=sriov-network-operator
deploy-setup-k8s: export ENABLE_ADMISSION_CONTROLLER?=false
deploy-setup-k8s: export CNI_BIN_PATH=/opt/cni/bin
deploy-setup-k8s: export OPERATOR_EXEC=kubectl
deploy-setup-k8s: export CLUSTER_TYPE=kubernetes
Expand Down
2 changes: 1 addition & 1 deletion api/v1/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func IsVfSupportedModel(vendorID, deviceID string) bool {
return true
}
}
log.Info("IsVfSupportedModel():", "Unsupported VF model:", "vendorId:", vendorID, "deviceId:", deviceID)
log.Info("IsVfSupportedModel(): found unsupported VF model", "vendorId:", vendorID, "deviceId:", deviceID)
return false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ contents:
exit
fi
which jq
append_to_file(){
content="$1"
file_name="$2"
Expand Down
48 changes: 24 additions & 24 deletions controllers/sriovnetworknodepolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func (r *SriovNetworkNodePolicyReconciler) Reconcile(ctx context.Context, req ct
reqLogger.Error(err, "Failed to create default Policy", "Namespace", namespace, "Name", constants.DefaultPolicyName)
return reconcile.Result{}, err
}
reqLogger.Info("Default policy created")
return reconcile.Result{}, nil
}
// Error reading the object - requeue the request.
Expand Down Expand Up @@ -197,7 +198,7 @@ func (r *SriovNetworkNodePolicyReconciler) SetupWithManager(mgr ctrl.Manager) er

func (r *SriovNetworkNodePolicyReconciler) syncDevicePluginConfigMap(ctx context.Context, pl *sriovnetworkv1.SriovNetworkNodePolicyList, nl *corev1.NodeList) error {
logger := log.Log.WithName("syncDevicePluginConfigMap")
logger.Info("Start to sync device plugin ConfigMap")
logger.V(1).Info("Start to sync device plugin ConfigMap")

configData := make(map[string]string)
for _, node := range nl.Items {
Expand Down Expand Up @@ -231,12 +232,12 @@ func (r *SriovNetworkNodePolicyReconciler) syncDevicePluginConfigMap(ctx context
if err != nil {
return fmt.Errorf("couldn't create ConfigMap: %v", err)
}
logger.Info("Created ConfigMap for", cm.Namespace, cm.Name)
logger.V(1).Info("Created ConfigMap for", cm.Namespace, cm.Name)
} else {
return fmt.Errorf("failed to get ConfigMap: %v", err)
}
} else {
logger.Info("ConfigMap already exists, updating")
logger.V(1).Info("ConfigMap already exists, updating")
err = r.Update(ctx, cm)
if err != nil {
return fmt.Errorf("couldn't update ConfigMap: %v", err)
Expand All @@ -247,36 +248,35 @@ func (r *SriovNetworkNodePolicyReconciler) syncDevicePluginConfigMap(ctx context

func (r *SriovNetworkNodePolicyReconciler) syncAllSriovNetworkNodeStates(ctx context.Context, np *sriovnetworkv1.SriovNetworkNodePolicy, npl *sriovnetworkv1.SriovNetworkNodePolicyList, nl *corev1.NodeList) error {
logger := log.Log.WithName("syncAllSriovNetworkNodeStates")
logger.Info("Start to sync all SriovNetworkNodeState custom resource")
logger.V(1).Info("Start to sync all SriovNetworkNodeState custom resource")
found := &corev1.ConfigMap{}
if err := r.Get(ctx, types.NamespacedName{Namespace: namespace, Name: constants.ConfigMapName}, found); err != nil {
logger.Info("Fail to get", "ConfigMap", constants.ConfigMapName)
logger.V(1).Info("Fail to get", "ConfigMap", constants.ConfigMapName)
}
for _, node := range nl.Items {
logger.Info("Sync SriovNetworkNodeState CR", "name", node.Name)
logger.V(1).Info("Sync SriovNetworkNodeState CR", "name", node.Name)
ns := &sriovnetworkv1.SriovNetworkNodeState{}
ns.Name = node.Name
ns.Namespace = namespace
j, _ := json.Marshal(ns)
logger.Info("SriovNetworkNodeState CR", "content", j)
logger.V(2).Info("SriovNetworkNodeState CR", "content", j)
if err := r.syncSriovNetworkNodeState(ctx, np, npl, ns, &node, utils.HashConfigMap(found)); err != nil {
logger.Error(err, "Fail to sync", "SriovNetworkNodeState", ns.Name)
return err
}
}
logger.Info("Remove SriovNetworkNodeState custom resource for unselected node")
logger.V(1).Info("Remove SriovNetworkNodeState custom resource for unselected node")
nsList := &sriovnetworkv1.SriovNetworkNodeStateList{}
err := r.List(ctx, nsList, &client.ListOptions{})
if err != nil {
if !errors.IsNotFound(err) {
logger.Info("Fail to list SriovNetworkNodeState CRs")
logger.Error(err, "Fail to list SriovNetworkNodeState CRs")
return err
}
} else {
for _, ns := range nsList.Items {
found := false
for _, node := range nl.Items {
logger.Info("validate", "SriovNetworkNodeState", ns.GetName(), "node", node.GetName())
if ns.GetName() == node.GetName() {
found = true
break
Expand All @@ -285,7 +285,7 @@ func (r *SriovNetworkNodePolicyReconciler) syncAllSriovNetworkNodeStates(ctx con
if !found {
err := r.Delete(ctx, &ns, &client.DeleteOptions{})
if err != nil {
logger.Info("Fail to Delete", "SriovNetworkNodeState CR:", ns.GetName())
logger.Error(err, "Fail to Delete", "SriovNetworkNodeState CR:", ns.GetName())
return err
}
}
Expand All @@ -296,15 +296,15 @@ func (r *SriovNetworkNodePolicyReconciler) syncAllSriovNetworkNodeStates(ctx con

func (r *SriovNetworkNodePolicyReconciler) syncSriovNetworkNodeState(ctx context.Context, np *sriovnetworkv1.SriovNetworkNodePolicy, npl *sriovnetworkv1.SriovNetworkNodePolicyList, ns *sriovnetworkv1.SriovNetworkNodeState, node *corev1.Node, cksum string) error {
logger := log.Log.WithName("syncSriovNetworkNodeState")
logger.Info("Start to sync SriovNetworkNodeState", "Name", ns.Name, "cksum", cksum)
logger.V(1).Info("Start to sync SriovNetworkNodeState", "Name", ns.Name, "cksum", cksum)

if err := controllerutil.SetControllerReference(np, ns, r.Scheme); err != nil {
return err
}
found := &sriovnetworkv1.SriovNetworkNodeState{}
err := r.Get(ctx, types.NamespacedName{Namespace: ns.Namespace, Name: ns.Name}, found)
if err != nil {
logger.Info("Fail to get SriovNetworkNodeState", "namespace", ns.Namespace, "name", ns.Name)
logger.Error(err, "Fail to get SriovNetworkNodeState", "namespace", ns.Namespace, "name", ns.Name)
if errors.IsNotFound(err) {
ns.Spec.DpConfigVersion = cksum
err = r.Create(ctx, ns)
Expand All @@ -322,7 +322,7 @@ func (r *SriovNetworkNodePolicyReconciler) syncSriovNetworkNodeState(ctx context
return nil
}

logger.Info("SriovNetworkNodeState already exists, updating")
logger.V(1).Info("SriovNetworkNodeState already exists, updating")
newVersion := found.DeepCopy()
newVersion.Spec = ns.Spec

Expand Down Expand Up @@ -351,7 +351,7 @@ func (r *SriovNetworkNodePolicyReconciler) syncSriovNetworkNodeState(ctx context
}
newVersion.Spec.DpConfigVersion = cksum
if equality.Semantic.DeepEqual(newVersion.Spec, found.Spec) {
logger.Info("SriovNetworkNodeState did not change, not updating")
logger.V(1).Info("SriovNetworkNodeState did not change, not updating")
return nil
}
err = r.Update(ctx, newVersion)
Expand All @@ -364,7 +364,7 @@ func (r *SriovNetworkNodePolicyReconciler) syncSriovNetworkNodeState(ctx context

func (r *SriovNetworkNodePolicyReconciler) syncPluginDaemonObjs(ctx context.Context, operatorConfig *sriovnetworkv1.SriovOperatorConfig, dp *sriovnetworkv1.SriovNetworkNodePolicy, pl *sriovnetworkv1.SriovNetworkNodePolicyList) error {
logger := log.Log.WithName("syncPluginDaemonObjs")
logger.Info("Start to sync sriov daemons objects")
logger.V(1).Info("Start to sync sriov daemons objects")

// render plugin manifests
data := render.MakeRenderData()
Expand Down Expand Up @@ -487,7 +487,7 @@ func (r *SriovNetworkNodePolicyReconciler) deleteK8sResource(ctx context.Context
func (r *SriovNetworkNodePolicyReconciler) syncDsObject(ctx context.Context, dp *sriovnetworkv1.SriovNetworkNodePolicy, pl *sriovnetworkv1.SriovNetworkNodePolicyList, obj *uns.Unstructured) error {
logger := log.Log.WithName("syncDsObject")
kind := obj.GetKind()
logger.Info("Start to sync Objects", "Kind", kind)
logger.V(1).Info("Start to sync Objects", "Kind", kind)
switch kind {
case "ServiceAccount", "Role", "RoleBinding":
if err := controllerutil.SetControllerReference(dp, obj, r.Scheme); err != nil {
Expand All @@ -511,7 +511,7 @@ func (r *SriovNetworkNodePolicyReconciler) syncDsObject(ctx context.Context, dp

func (r *SriovNetworkNodePolicyReconciler) syncDaemonSet(ctx context.Context, cr *sriovnetworkv1.SriovNetworkNodePolicy, pl *sriovnetworkv1.SriovNetworkNodePolicyList, in *appsv1.DaemonSet) error {
logger := log.Log.WithName("syncDaemonSet")
logger.Info("Start to sync DaemonSet", "Namespace", in.Namespace, "Name", in.Name)
logger.V(1).Info("Start to sync DaemonSet", "Namespace", in.Namespace, "Name", in.Name)
var err error

if pl != nil {
Expand All @@ -537,7 +537,7 @@ func (r *SriovNetworkNodePolicyReconciler) syncDaemonSet(ctx context.Context, cr
return err
}
} else {
logger.Info("DaemonSet already exists, updating")
logger.V(1).Info("DaemonSet already exists, updating")
// DeepDerivative checks for changes only comparing non zero fields in the source struct.
// This skips default values added by the api server.
// References in https://github.com/kubernetes-sigs/kubebuilder/issues/592#issuecomment-625738183
Expand All @@ -546,7 +546,7 @@ func (r *SriovNetworkNodePolicyReconciler) syncDaemonSet(ctx context.Context, cr
// https://bugzilla.redhat.com/show_bug.cgi?id=1914066
if equality.Semantic.DeepEqual(in.Spec.Template.Spec.Affinity.NodeAffinity,
ds.Spec.Template.Spec.Affinity.NodeAffinity) {
logger.Info("Daemonset spec did not change, not updating")
logger.V(1).Info("Daemonset spec did not change, not updating")
return nil
}
}
Expand Down Expand Up @@ -605,7 +605,7 @@ func nodeSelectorTermsForPolicyList(policies []sriovnetworkv1.SriovNetworkNodePo
// renderDsForCR returns a busybox pod with the same name/namespace as the cr
func renderDsForCR(path string, data *render.RenderData) ([]*uns.Unstructured, error) {
logger := log.Log.WithName("renderDsForCR")
logger.Info("Start to render objects")
logger.V(1).Info("Start to render objects")

objs, err := render.RenderDir(path, data)
if err != nil {
Expand All @@ -616,7 +616,7 @@ func renderDsForCR(path string, data *render.RenderData) ([]*uns.Unstructured, e

func (r *SriovNetworkNodePolicyReconciler) renderDevicePluginConfigData(ctx context.Context, pl *sriovnetworkv1.SriovNetworkNodePolicyList, node *corev1.Node) (dptypes.ResourceConfList, error) {
logger := log.Log.WithName("renderDevicePluginConfigData")
logger.Info("Start to render device plugin config data", "node", node.Name)
logger.V(1).Info("Start to render device plugin config data", "node", node.Name)
rcl := dptypes.ResourceConfList{}
for _, p := range pl.Items {
if p.Name == constants.DefaultPolicyName {
Expand All @@ -641,14 +641,14 @@ func (r *SriovNetworkNodePolicyReconciler) renderDevicePluginConfigData(ctx cont
if err != nil {
return rcl, err
}
logger.Info("Update resource", "Resource", rcl.ResourceList[i])
logger.V(1).Info("Update resource", "Resource", rcl.ResourceList[i])
} else {
rc, err := createDevicePluginResource(ctx, &p, nodeState)
if err != nil {
return rcl, err
}
rcl.ResourceList = append(rcl.ResourceList, *rc)
logger.Info("Add resource", "Resource", *rc)
logger.V(1).Info("Add resource", "Resource", *rc)
}
}
return rcl, nil
Expand Down
11 changes: 7 additions & 4 deletions controllers/sriovoperatorconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
sriovnetworkv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1"
apply "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/apply"
constants "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/consts"
snolog "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/log"
render "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/render"
utils "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/utils"
)
Expand Down Expand Up @@ -124,6 +125,8 @@ func (r *SriovOperatorConfigReconciler) Reconcile(ctx context.Context, req ctrl.
return reconcile.Result{}, err
}

snolog.SetLogLevel(defaultConfig.Spec.LogLevel)

// For Openshift we need to create the systemd files using a machine config
if utils.ClusterType == utils.ClusterTypeOpenshift {
// TODO: add support for hypershift as today there is no MCO on hypershift clusters
Expand All @@ -149,7 +152,7 @@ func (r *SriovOperatorConfigReconciler) SetupWithManager(mgr ctrl.Manager) error

func (r *SriovOperatorConfigReconciler) syncPluginDaemonSet(ctx context.Context, dc *sriovnetworkv1.SriovOperatorConfig) error {
logger := log.Log.WithName("syncConfigDaemonset")
logger.Info("Start to sync SRIOV plugin daemonsets nodeSelector")
logger.V(1).Info("Start to sync SRIOV plugin daemonsets nodeSelector")
ds := &appsv1.DaemonSet{}

names := []string{"sriov-cni", "sriov-device-plugin"}
Expand Down Expand Up @@ -180,7 +183,7 @@ func (r *SriovOperatorConfigReconciler) syncPluginDaemonSet(ctx context.Context,

func (r *SriovOperatorConfigReconciler) syncConfigDaemonSet(ctx context.Context, dc *sriovnetworkv1.SriovOperatorConfig) error {
logger := log.Log.WithName("syncConfigDaemonset")
logger.Info("Start to sync config daemonset")
logger.V(1).Info("Start to sync config daemonset")

data := render.MakeRenderData()
data.Data["Image"] = os.Getenv("SRIOV_NETWORK_CONFIG_DAEMON_IMAGE")
Expand All @@ -201,7 +204,7 @@ func (r *SriovOperatorConfigReconciler) syncConfigDaemonSet(ctx context.Context,
if envCniBinPath == "" {
data.Data["CNIBinPath"] = "/var/lib/cni/bin"
} else {
logger.Info("New cni bin found", "CNIBinPath", envCniBinPath)
logger.V(1).Info("New cni bin found", "CNIBinPath", envCniBinPath)
data.Data["CNIBinPath"] = envCniBinPath
}
objs, err := render.RenderDir(constants.ConfigDaemonPath, &data)
Expand Down Expand Up @@ -237,7 +240,7 @@ func (r *SriovOperatorConfigReconciler) syncConfigDaemonSet(ctx context.Context,

func (r *SriovOperatorConfigReconciler) syncWebhookObjs(ctx context.Context, dc *sriovnetworkv1.SriovOperatorConfig) error {
logger := log.Log.WithName("syncWebhookObjs")
logger.Info("Start to sync webhook objects")
logger.V(1).Info("Start to sync webhook objects")

for name, path := range webhooks {
// Render Webhook manifests
Expand Down
10 changes: 0 additions & 10 deletions pkg/apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package apply
import (
"context"
"fmt"
"log"

"github.com/pkg/errors"

Expand All @@ -24,7 +23,6 @@ func DeleteObject(ctx context.Context, client k8sclient.Client, obj *uns.Unstruc
gvk := obj.GroupVersionKind()
// used for logging and errors
objDesc := fmt.Sprintf("(%s) %s/%s", gvk.String(), namespace, name)
log.Printf("reconciling %s", objDesc)

if err := IsObjectSupported(obj); err != nil {
return errors.Wrapf(err, "object %s unsupported", objDesc)
Expand All @@ -36,7 +34,6 @@ func DeleteObject(ctx context.Context, client k8sclient.Client, obj *uns.Unstruc
err := client.Get(ctx, types.NamespacedName{Name: obj.GetName(), Namespace: obj.GetNamespace()}, existing)

if err != nil && apierrors.IsNotFound(err) {
log.Printf("does not exist, do nothing %s", objDesc)
return nil
}
if err != nil {
Expand All @@ -45,8 +42,6 @@ func DeleteObject(ctx context.Context, client k8sclient.Client, obj *uns.Unstruc

if err = client.Delete(ctx, existing); err != nil {
return errors.Wrapf(err, "could not delete object %s", objDesc)
} else {
log.Printf("delete was successful")
}
return nil
}
Expand All @@ -62,7 +57,6 @@ func ApplyObject(ctx context.Context, client k8sclient.Client, obj *uns.Unstruct
gvk := obj.GroupVersionKind()
// used for logging and errors
objDesc := fmt.Sprintf("(%s) %s/%s", gvk.String(), namespace, name)
log.Printf("reconciling %s", objDesc)

if err := IsObjectSupported(obj); err != nil {
return errors.Wrapf(err, "object %s unsupported", objDesc)
Expand All @@ -74,12 +68,10 @@ func ApplyObject(ctx context.Context, client k8sclient.Client, obj *uns.Unstruct
err := client.Get(ctx, types.NamespacedName{Name: obj.GetName(), Namespace: obj.GetNamespace()}, existing)

if err != nil && apierrors.IsNotFound(err) {
log.Printf("does not exist, creating %s", objDesc)
err := client.Create(ctx, obj)
if err != nil {
return errors.Wrapf(err, "could not create %s", objDesc)
}
log.Printf("successfully created %s", objDesc)
return nil
}
if err != nil {
Expand All @@ -93,8 +85,6 @@ func ApplyObject(ctx context.Context, client k8sclient.Client, obj *uns.Unstruct
if !equality.Semantic.DeepEqual(existing, obj) {
if err := client.Update(ctx, obj); err != nil {
return errors.Wrapf(err, "could not update object %s", objDesc)
} else {
log.Printf("update was successful %s", objDesc)
}
}

Expand Down
13 changes: 1 addition & 12 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
daemonconsts "github.com/openshift/machine-config-operator/pkg/daemon/constants"
mcfginformers "github.com/openshift/machine-config-operator/pkg/generated/informers/externalversions"
"go.uber.org/zap"
"golang.org/x/time/rate"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -426,7 +425,7 @@ func (dn *Daemon) operatorConfigAddHandler(obj interface{}) {

func (dn *Daemon) operatorConfigChangeHandler(old, new interface{}) {
newCfg := new.(*sriovnetworkv1.SriovOperatorConfig)
dn.handleLogLevelChange(newCfg.Spec.LogLevel)
snolog.SetLogLevel(newCfg.Spec.LogLevel)

newDisableDrain := newCfg.Spec.DisableDrain
if dn.disableDrain != newDisableDrain {
Expand All @@ -435,16 +434,6 @@ func (dn *Daemon) operatorConfigChangeHandler(old, new interface{}) {
}
}

// handleLogLevelChange handles log level change
func (dn *Daemon) handleLogLevelChange(logLevel int) {
newLevel := int8(logLevel * -1)
currLevel := int8(snolog.Options.Level.(zap.AtomicLevel).Level())
if newLevel != currLevel {
log.Log.Info("Set log verbose level", "new-level", newLevel, "current-level", currLevel)
snolog.SetLogLevel(newLevel)
}
}

func (dn *Daemon) nodeStateSyncHandler() error {
var err error
// Get the latest NodeState
Expand Down
Loading

0 comments on commit 7c990b6

Please sign in to comment.