Skip to content
Merged
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
4 changes: 1 addition & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ func main() {
"If set, the metrics endpoint is served securely via HTTPS. Use --metrics-secure=false to use HTTP instead.")
flag.BoolVar(&enableHTTP2, "enable-http2", false,
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
opts := zap.Options{
Development: true,
}
opts := zap.Options{}
opts.BindFlags(flag.CommandLine)
flag.Parse()

Expand Down
10 changes: 9 additions & 1 deletion internal/controller/scalityuicomponentexposer/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import (
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)

Expand Down Expand Up @@ -72,6 +74,8 @@ func (r *ScalityUIComponentExposerReconciler) Reconcile(ctx context.Context, req
return reconcile.Result{}, err
}

currentState.SetOldStatus(cr.Status.DeepCopy())

resourceReconcilers := buildReducerList(r, cr, currentState)
for _, rr := range resourceReconcilers {
res, err := rr.F(cr, currentState, log)
Expand Down Expand Up @@ -104,7 +108,11 @@ func (r *ScalityUIComponentExposerReconciler) SetupWithManager(mgr ctrl.Manager)
For(&uiv1alpha1.ScalityUIComponentExposer{}).
Owns(&networkingv1.Ingress{}).
Watches(&corev1.ConfigMap{}, handler.EnqueueRequestsFromMapFunc(r.findExposersForConfigMap)).
Watches(&uiv1alpha1.ScalityUI{}, handler.EnqueueRequestsFromMapFunc(r.findExposersForScalityUI)).
Watches(
&uiv1alpha1.ScalityUI{},
handler.EnqueueRequestsFromMapFunc(r.findExposersForScalityUI),
builder.WithPredicates(predicate.GenerationChangedPredicate{}),
).
Watches(&uiv1alpha1.ScalityUIComponent{}, handler.EnqueueRequestsFromMapFunc(r.findExposersForScalityUIComponent)).
Complete(r)
}
17 changes: 17 additions & 0 deletions internal/controller/scalityuicomponentexposer/reconcile_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

type reconcileContext struct {
reconciler.BaseReconcileState
oldStatus *uiv1alpha1.ScalityUIComponentExposerStatus
}

var _ reconciler.State = &reconcileContext{}
Expand All @@ -22,10 +23,26 @@ func newReconcileContextWithCtx(ctx context.Context) *reconcileContext {
}
}

// SetOldStatus stores the original status for comparison
func (r *reconcileContext) SetOldStatus(status *uiv1alpha1.ScalityUIComponentExposerStatus) {
r.oldStatus = status
}

// GetOldStatus returns the original status
func (r *reconcileContext) GetOldStatus() *uiv1alpha1.ScalityUIComponentExposerStatus {
return r.oldStatus
}

// Type aliases for better readability
type ScalityUIComponentExposer = *uiv1alpha1.ScalityUIComponentExposer
type State = reconciler.State

// ExtendedState provides access to additional state beyond the base reconciler.State
type ExtendedState interface {
reconciler.State
GetOldStatus() *uiv1alpha1.ScalityUIComponentExposerStatus
}

// StateReducer represents a step in the reconciliation process
type StateReducer struct {
N string // Name of the reducer
Expand Down
13 changes: 12 additions & 1 deletion internal/controller/scalityuicomponentexposer/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/go-logr/logr"
uiv1alpha1 "github.com/scality/ui-operator/api/v1alpha1"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
Expand Down Expand Up @@ -41,8 +42,18 @@ func setStatusCondition(cr *uiv1alpha1.ScalityUIComponentExposer, conditionType
meta.SetStatusCondition(&cr.Status.Conditions, condition)
}

// updateStatus updates the ScalityUIComponentExposer status
// updateStatus updates the ScalityUIComponentExposer status only if it has changed
func updateStatus(ctx context.Context, cr *uiv1alpha1.ScalityUIComponentExposer, currentState State, log logr.Logger) error {
// Check if status actually changed
extState, ok := currentState.(ExtendedState)
if ok {
oldStatus := extState.GetOldStatus()
if oldStatus != nil && equality.Semantic.DeepEqual(oldStatus, &cr.Status) {
log.V(1).Info("Status unchanged, skipping update", "exposer", cr.Name)
return nil
}
}

client := currentState.GetKubeClient()

// Update the status subresource
Expand Down
Loading