Skip to content

Commit

Permalink
WIP: consume kloglevel at runtime
Browse files Browse the repository at this point in the history
Signed-off-by: Francesco Romani <[email protected]>
  • Loading branch information
ffromani committed Sep 24, 2024
1 parent f30ee1f commit 271fc4b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
12 changes: 12 additions & 0 deletions api/numaresourcesoperator/v1/numaresourcesoperator_normalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,20 @@ import (
"sort"

corev1 "k8s.io/api/core/v1"

operatorv1 "github.com/openshift/api/operator/v1"
)

func NormalizeSpec(spec *NUMAResourcesOperatorSpec) {
defaultLog := operatorv1.Normal
if spec.LogLevel == "" {
spec.LogLevel = defaultLog
}
if spec.OperatorLogLevel == nil {
spec.OperatorLogLevel = &defaultLog
}
}

func (nodeGroup NodeGroup) NormalizeConfig() NodeGroupConfig {
conf := DefaultNodeGroupConfig()
if nodeGroup.Config == nil {
Expand Down
9 changes: 9 additions & 0 deletions api/numaresourcesoperator/v1/numaresourcesoperator_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ type NUMAResourcesOperatorSpec struct {
// +optional
//+operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Optional ignore pod namespace/name glob patterns"
PodExcludes []NamespacedName `json:"podExcludes,omitempty"`
// Valid values are: "Normal", "Debug", "Trace", "TraceAll".
// Defaults to "Normal".
// +optional
// +kubebuilder:default=Normal
//+operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Operator log verbosity"
OperatorLogLevel *operatorv1.LogLevel `json:"operatorLogLevel,omitempty"`
}

// +kubebuilder:validation:Enum=Disabled;Enabled;EnabledExclusiveResources
Expand Down Expand Up @@ -136,6 +142,9 @@ type NUMAResourcesOperatorStatus struct {
// RelatedObjects list of objects of interest for this operator
//+operator-sdk:csv:customresourcedefinitions:type=status,displayName="Related Objects"
RelatedObjects []configv1.ObjectReference `json:"relatedObjects,omitempty"`
// OperatorLogLevel is the current log verbosity of the operator.
//+operator-sdk:csv:customresourcedefinitions:type=status,displayName="Operator log verbosity"
OperatorLogLevel operatorv1.LogLevel `json:"operatorLogLevel,omitempty"`
}

// MachineConfigPool defines the observed state of each MachineConfigPool selected by node groups
Expand Down
6 changes: 6 additions & 0 deletions api/numaresourcesoperator/v1/zz_generated.deepcopy.go

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

15 changes: 15 additions & 0 deletions controllers/numaresourcesoperator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ import (
rteupdate "github.com/openshift-kni/numaresources-operator/pkg/objectupdate/rte"
"github.com/openshift-kni/numaresources-operator/pkg/status"
"github.com/openshift-kni/numaresources-operator/pkg/validation"

intkloglevel "github.com/openshift-kni/numaresources-operator/internal/kloglevel"
)

const numaResourcesRetryPeriod = 1 * time.Minute
Expand Down Expand Up @@ -132,6 +134,16 @@ func (r *NUMAResourcesOperatorReconciler) Reconcile(ctx context.Context, req ctr
return r.updateStatus(ctx, instance, status.ConditionDegraded, status.ConditionTypeIncorrectNUMAResourcesOperatorResourceName, message)
}

needStatusUpdate := false
nropv1.NormalizeSpec(&instance.Spec)

// do as early as possible, so we don't miss log messages
if lev := *instance.Spec.OperatorLogLevel; lev != instance.Status.OperatorLogLevel {
intkloglevel.Set(loglevel.ToKlog(lev))

Check failure on line 142 in controllers/numaresourcesoperator_controller.go

View workflow job for this annotation

GitHub Actions / golangci-lint

Error return value of `intkloglevel.Set` is not checked (errcheck)

Check failure on line 142 in controllers/numaresourcesoperator_controller.go

View workflow job for this annotation

GitHub Actions / build

Error return value of `intkloglevel.Set` is not checked (errcheck)
instance.Status.OperatorLogLevel = lev
needStatusUpdate = true
}

if err := validation.NodeGroups(instance.Spec.NodeGroups); err != nil {
return r.updateStatus(ctx, instance, status.ConditionDegraded, validation.NodeGroupsError, err.Error())
}
Expand All @@ -152,6 +164,9 @@ func (r *NUMAResourcesOperatorReconciler) Reconcile(ctx context.Context, req ctr

result, condition, err := r.reconcileResource(ctx, instance, trees)
if condition != "" {
needStatusUpdate = true
}
if needStatusUpdate {
// TODO: use proper reason
reason, message := condition, messageFromError(err)
_, _ = r.updateStatus(ctx, instance, condition, reason, message)
Expand Down

0 comments on commit 271fc4b

Please sign in to comment.