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: 2 additions & 2 deletions apis/placement/v1beta1/commons.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ const (
// This is used to remember if an "unscheduled" binding was moved from a "bound" state or a "scheduled" state.
PreviousBindingStateAnnotation = FleetPrefix + "previous-binding-state"

// ClusterStagedUpdateRunFinalizer is used by the ClusterStagedUpdateRun controller to make sure that the ClusterStagedUpdateRun
// UpdateRunFinalizer is used by the UpdateRun controller to make sure that the UpdateRun
// object is not deleted until all its dependent resources are deleted.
ClusterStagedUpdateRunFinalizer = FleetPrefix + "stagedupdaterun-finalizer"
UpdateRunFinalizer = FleetPrefix + "stagedupdaterun-finalizer"

// TargetUpdateRunLabel indicates the target update run on a staged run related object.
TargetUpdateRunLabel = FleetPrefix + "targetupdaterun"
Expand Down
203 changes: 107 additions & 96 deletions pkg/controllers/updaterun/controller.go

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion pkg/controllers/updaterun/controller_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ func generateMetricsLabels(
condition, status, reason string,
) []*prometheusclientmodel.LabelPair {
return []*prometheusclientmodel.LabelPair{
{Name: ptr.To("namespace"), Value: &updateRun.Namespace},
{Name: ptr.To("name"), Value: &updateRun.Name},
{Name: ptr.To("generation"), Value: ptr.To(strconv.FormatInt(updateRun.Generation, 10))},
{Name: ptr.To("condition"), Value: ptr.To(condition)},
Expand Down Expand Up @@ -662,7 +663,7 @@ func validateUpdateRunHasFinalizer(ctx context.Context, updateRun *placementv1be
if err := k8sClient.Get(ctx, namespacedName, updateRun); err != nil {
return fmt.Errorf("failed to get clusterStagedUpdateRun %s: %w", namespacedName, err)
}
if !controllerutil.ContainsFinalizer(updateRun, placementv1beta1.ClusterStagedUpdateRunFinalizer) {
if !controllerutil.ContainsFinalizer(updateRun, placementv1beta1.UpdateRunFinalizer) {
return fmt.Errorf("finalizer not added to clusterStagedUpdateRun %s", namespacedName)
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/updaterun/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ func markAfterStageRequestCreated(afterStageTaskStatus *placementv1beta1.AfterSt
Status: metav1.ConditionTrue,
ObservedGeneration: generation,
Reason: condition.AfterStageTaskApprovalRequestCreatedReason,
Message: "ClusterApprovalRequest is created",
Message: "ApprovalRequest object is created",
})
}

Expand All @@ -685,7 +685,7 @@ func markAfterStageRequestApproved(afterStageTaskStatus *placementv1beta1.AfterS
Status: metav1.ConditionTrue,
ObservedGeneration: generation,
Reason: condition.AfterStageTaskApprovalRequestApprovedReason,
Message: "ClusterApprovalRequest is approved",
Message: "ApprovalRequest object is approved",
})
}

Expand Down
11 changes: 6 additions & 5 deletions pkg/controllers/updaterun/initialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,17 +556,18 @@ func (r *Reconciler) recordInitializationSucceeded(ctx context.Context, updateRu
return nil
}

// recordInitializationFailed records the failed initialization condition in the ClusterStagedUpdateRun status.
func (r *Reconciler) recordInitializationFailed(ctx context.Context, updateRun *placementv1beta1.ClusterStagedUpdateRun, message string) error {
meta.SetStatusCondition(&updateRun.Status.Conditions, metav1.Condition{
// recordInitializationFailed records the failed initialization condition in the updateRun status.
func (r *Reconciler) recordInitializationFailed(ctx context.Context, updateRun placementv1beta1.UpdateRunObj, message string) error {
updateRunStatus := updateRun.GetUpdateRunStatus()
meta.SetStatusCondition(&updateRunStatus.Conditions, metav1.Condition{
Type: string(placementv1beta1.StagedUpdateRunConditionInitialized),
Status: metav1.ConditionFalse,
ObservedGeneration: updateRun.Generation,
ObservedGeneration: updateRun.GetGeneration(),
Reason: condition.UpdateRunInitializeFailedReason,
Message: message,
})
if updateErr := r.Client.Status().Update(ctx, updateRun); updateErr != nil {
klog.ErrorS(updateErr, "Failed to update the ClusterStagedUpdateRun status as failed to initialize", "clusterStagedUpdateRun", klog.KObj(updateRun))
klog.ErrorS(updateErr, "Failed to update the updateRun status as failed to initialize", "updateRun", klog.KObj(updateRun))
// updateErr can be retried.
return controller.NewUpdateIgnoreConflictError(updateErr)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ var (
FleetUpdateRunStatusLastTimestampSeconds = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "fleet_workload_update_run_status_last_timestamp_seconds",
Help: "Last update timestamp of update run status in seconds",
}, []string{"name", "generation", "condition", "status", "reason"})
}, []string{"namespace", "name", "generation", "condition", "status", "reason"})
)

var (
Expand Down
44 changes: 44 additions & 0 deletions pkg/utils/controller/updaterun_resolver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright 2025 The KubeFleet Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package controller

import (
"context"

"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

placementv1beta1 "github.com/kubefleet-dev/kubefleet/apis/placement/v1beta1"
)

// FetchUpdateRunFromRequest resolves a controller runtime request to a concrete update run object that implements UpdateRunObj.
func FetchUpdateRunFromRequest(ctx context.Context, c client.Reader, req ctrl.Request) (placementv1beta1.UpdateRunObj, error) {
var updateRun placementv1beta1.UpdateRunObj
if req.NamespacedName.Namespace != "" {
// This is a namespaced StagedUpdateRun
updateRun = &placementv1beta1.StagedUpdateRun{}
} else {
// This is a cluster-scoped ClusterStagedUpdateRun
updateRun = &placementv1beta1.ClusterStagedUpdateRun{}
}

if err := c.Get(ctx, types.NamespacedName{Namespace: req.NamespacedName.Namespace, Name: req.NamespacedName.Name}, updateRun); err != nil {
return nil, err
}
return updateRun, nil
}
Loading
Loading