Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix/updating-operand-image #396

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/v1/nodefeaturediscovery_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type OperandSpec struct {
// Image defines the image to pull for the
// NFD operand
// [defaults to registry.k8s.io/nfd/node-feature-discovery]
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Pattern=[a-zA-Z0-9\-]+
Image string `json:"image,omitempty"`

Expand Down
32 changes: 16 additions & 16 deletions internal/controllers/mock_nodefeaturediscovery_reconciler.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 25 additions & 17 deletions internal/controllers/nodefeaturediscovery_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"errors"
"fmt"
"os"
"reflect"

appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -99,6 +100,13 @@ func isControlledByNFD(obj client.Object) bool {
return controller.Kind == nfdKind
}

func getOperandImage(nfdInstance *nfdv1.NodeFeatureDiscovery) string {
if nfdInstance.Spec.Operand.Image == "" {
return os.Getenv("NODE_FEATURE_DISCOVERY_IMAGE")
}
return nfdInstance.Spec.Operand.Image
}

// +kubebuilder:rbac:groups=apps,resources=daemonsets,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=core,resources=configmaps,verbs=get;list;watch;create;update;patch;delete
Expand All @@ -115,6 +123,7 @@ func isControlledByNFD(obj client.Object) bool {
func (r *nodeFeatureDiscoveryReconciler) Reconcile(ctx context.Context, nfdInstance *nfdv1.NodeFeatureDiscovery) (ctrl.Result, error) {
res := ctrl.Result{}
logger := ctrl.LoggerFrom(ctx).WithValues("instance namespace", nfdInstance.Namespace, "instance name", nfdInstance.Name)
operandImage := getOperandImage(nfdInstance)

if nfdInstance.DeletionTimestamp != nil {
// NFD CR is being deleted
Expand Down Expand Up @@ -145,25 +154,24 @@ func (r *nodeFeatureDiscoveryReconciler) Reconcile(ctx context.Context, nfdInsta
errs = append(errs, err)

logger.Info("reconciling master component")
err = r.helper.handleMaster(ctx, nfdInstance)
err = r.helper.handleMaster(ctx, nfdInstance, operandImage)
errs = append(errs, err)

logger.Info("reconciling worker component")
err = r.helper.handleWorker(ctx, nfdInstance)
err = r.helper.handleWorker(ctx, nfdInstance, operandImage)
errs = append(errs, err)

logger.Info("reconciling topology components")
err = r.helper.handleTopology(ctx, nfdInstance)
err = r.helper.handleTopology(ctx, nfdInstance, operandImage)
errs = append(errs, err)

logger.Info("reconciling garbage collector")
err = r.helper.handleGC(ctx, nfdInstance)
err = r.helper.handleGC(ctx, nfdInstance, operandImage)
errs = append(errs, err)

logger.Info("reconciling NFD status")
err = r.helper.handleStatus(ctx, nfdInstance)
errs = append(errs, err)

return res, errors.Join(errs...)
}

Expand All @@ -175,10 +183,10 @@ type nodeFeatureDiscoveryHelperAPI interface {
setFinalizer(ctx context.Context, instance *nfdv1.NodeFeatureDiscovery) error
removeFinalizer(ctx context.Context, instance *nfdv1.NodeFeatureDiscovery) error
handleSCCs(ctx context.Context, nfdInstance *nfdv1.NodeFeatureDiscovery) error
handleMaster(ctx context.Context, nfdInstance *nfdv1.NodeFeatureDiscovery) error
handleWorker(ctx context.Context, nfdInstance *nfdv1.NodeFeatureDiscovery) error
handleTopology(ctx context.Context, nfdInstance *nfdv1.NodeFeatureDiscovery) error
handleGC(ctx context.Context, nfdInstance *nfdv1.NodeFeatureDiscovery) error
handleMaster(ctx context.Context, nfdInstance *nfdv1.NodeFeatureDiscovery, operatorImage string) error
handleWorker(ctx context.Context, nfdInstance *nfdv1.NodeFeatureDiscovery, operatorImage string) error
handleTopology(ctx context.Context, nfdInstance *nfdv1.NodeFeatureDiscovery, operatorImage string) error
handleGC(ctx context.Context, nfdInstance *nfdv1.NodeFeatureDiscovery, operatorImage string) error
handlePrune(ctx context.Context, nfdInstance *nfdv1.NodeFeatureDiscovery) (bool, error)
handleStatus(ctx context.Context, nfdInstance *nfdv1.NodeFeatureDiscovery) error
}
Expand Down Expand Up @@ -291,12 +299,12 @@ func (nfdh *nodeFeatureDiscoveryHelper) handleSCCs(ctx context.Context, nfdInsta
return nil
}

func (nfdh *nodeFeatureDiscoveryHelper) handleMaster(ctx context.Context, nfdInstance *nfdv1.NodeFeatureDiscovery) error {
func (nfdh *nodeFeatureDiscoveryHelper) handleMaster(ctx context.Context, nfdInstance *nfdv1.NodeFeatureDiscovery, operandImage string) error {
masterDep := appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{Name: "nfd-master", Namespace: nfdInstance.Namespace},
}
opRes, err := controllerutil.CreateOrPatch(ctx, nfdh.client, &masterDep, func() error {
return nfdh.deploymentAPI.SetMasterDeploymentAsDesired(nfdInstance, &masterDep)
return nfdh.deploymentAPI.SetMasterDeploymentAsDesired(nfdInstance, &masterDep, operandImage)
})

if err != nil {
Expand All @@ -306,7 +314,7 @@ func (nfdh *nodeFeatureDiscoveryHelper) handleMaster(ctx context.Context, nfdIns
return nil
}

func (nfdh *nodeFeatureDiscoveryHelper) handleWorker(ctx context.Context, nfdInstance *nfdv1.NodeFeatureDiscovery) error {
func (nfdh *nodeFeatureDiscoveryHelper) handleWorker(ctx context.Context, nfdInstance *nfdv1.NodeFeatureDiscovery, operandImage string) error {
logger := ctrl.LoggerFrom(ctx)

workerCM := corev1.ConfigMap{
Expand All @@ -324,7 +332,7 @@ func (nfdh *nodeFeatureDiscoveryHelper) handleWorker(ctx context.Context, nfdIns
ObjectMeta: metav1.ObjectMeta{Name: "nfd-worker", Namespace: nfdInstance.Namespace},
}
opRes, err := controllerutil.CreateOrPatch(ctx, nfdh.client, &workerDS, func() error {
return nfdh.daemonsetAPI.SetWorkerDaemonsetAsDesired(ctx, nfdInstance, &workerDS)
return nfdh.daemonsetAPI.SetWorkerDaemonsetAsDesired(ctx, nfdInstance, &workerDS, operandImage)
})
if err != nil {
return fmt.Errorf("failed to reconcile worker DaemonSet %s/%s: %w", nfdInstance.Namespace, nfdInstance.Name, err)
Expand All @@ -335,15 +343,15 @@ func (nfdh *nodeFeatureDiscoveryHelper) handleWorker(ctx context.Context, nfdIns
return nil
}

func (nfdh *nodeFeatureDiscoveryHelper) handleTopology(ctx context.Context, nfdInstance *nfdv1.NodeFeatureDiscovery) error {
func (nfdh *nodeFeatureDiscoveryHelper) handleTopology(ctx context.Context, nfdInstance *nfdv1.NodeFeatureDiscovery, operandImage string) error {
if !nfdInstance.Spec.TopologyUpdater {
return nil
}
topologyDS := appsv1.DaemonSet{
ObjectMeta: metav1.ObjectMeta{Name: "nfd-topology-updater", Namespace: nfdInstance.Namespace},
}
opRes, err := controllerutil.CreateOrPatch(ctx, nfdh.client, &topologyDS, func() error {
return nfdh.daemonsetAPI.SetTopologyDaemonsetAsDesired(ctx, nfdInstance, &topologyDS)
return nfdh.daemonsetAPI.SetTopologyDaemonsetAsDesired(ctx, nfdInstance, &topologyDS, operandImage)
})

if err != nil {
Expand All @@ -353,12 +361,12 @@ func (nfdh *nodeFeatureDiscoveryHelper) handleTopology(ctx context.Context, nfdI
return nil
}

func (nfdh *nodeFeatureDiscoveryHelper) handleGC(ctx context.Context, nfdInstance *nfdv1.NodeFeatureDiscovery) error {
func (nfdh *nodeFeatureDiscoveryHelper) handleGC(ctx context.Context, nfdInstance *nfdv1.NodeFeatureDiscovery, operandImage string) error {
gcDep := appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{Name: "nfd-gc", Namespace: nfdInstance.Namespace},
}
opRes, err := controllerutil.CreateOrPatch(ctx, nfdh.client, &gcDep, func() error {
return nfdh.deploymentAPI.SetGCDeploymentAsDesired(nfdInstance, &gcDep)
return nfdh.deploymentAPI.SetGCDeploymentAsDesired(nfdInstance, &gcDep, operandImage)
})

if err != nil {
Expand Down
Loading