Skip to content

Commit 1c3ea3e

Browse files
committed
Update Errorf strings, update error return logic
Signed-off-by: Jonathan West <jonwest@redhat.com>
1 parent 15ba48c commit 1c3ea3e

7 files changed

Lines changed: 20 additions & 20 deletions

File tree

controllers/configmap.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (r *RolloutManagerReconciler) reconcileConfigMap(ctx context.Context, cr *r
5353
log.Info("configMap not found, creating default configmap with openshift route plugin information")
5454
return r.Client.Create(ctx, desiredConfigMap)
5555
}
56-
return fmt.Errorf("failed to get the serviceAccount associated with %s: %s", desiredConfigMap.Name, err)
56+
return fmt.Errorf("failed to get the serviceAccount associated with %s: %w", desiredConfigMap.Name, err)
5757
}
5858

5959
var actualTrafficRouterPlugins []types.PluginItem
@@ -72,7 +72,7 @@ func (r *RolloutManagerReconciler) reconcileConfigMap(ctx context.Context, cr *r
7272

7373
pluginString, err = yaml.Marshal(updatedTrafficRouterPlugins)
7474
if err != nil {
75-
return fmt.Errorf("error marshalling trafficRouterPlugin to string %s", err)
75+
return fmt.Errorf("error marshalling trafficRouterPlugin to string %w", err)
7676
}
7777

7878
actualConfigMap.Data[TrafficRouterPluginConfigMapKey] = string(pluginString)

controllers/deployment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func (r *RolloutManagerReconciler) reconcileRolloutsDeployment(ctx context.Conte
101101

102102
if err := fetchObject(ctx, r.Client, cr.Namespace, DefaultArgoRolloutsResourceName, actualDeployment); err != nil {
103103
if !errors.IsNotFound(err) {
104-
return fmt.Errorf("failed to get the Deployment %s: %s", DefaultArgoRolloutsResourceName, err)
104+
return fmt.Errorf("failed to get the Deployment %s: %w", DefaultArgoRolloutsResourceName, err)
105105
}
106106

107107
if err := controllerutil.SetControllerReference(cr, &desiredDeployment, r.Scheme); err != nil {

controllers/reconcile.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func (r *RolloutManagerReconciler) reconcileRolloutsManager(ctx context.Context,
1616
return createCondition(err.Error(), rolloutsmanagerv1alpha1.RolloutManagerReasonInvalidScoped), nil
1717
}
1818
log.Error(err, "failed to validate RolloutManager's scope.")
19-
return createCondition(err.Error()), nil
19+
return createCondition(err.Error()), err
2020
}
2121

2222
log.Info("searching for existing RolloutManagers")
@@ -25,7 +25,7 @@ func (r *RolloutManagerReconciler) reconcileRolloutsManager(ctx context.Context,
2525
return createCondition(err.Error(), rolloutsmanagerv1alpha1.RolloutManagerReasonMultipleClusterScopedRolloutManager), nil
2626
}
2727
log.Error(err, "failed to validate multiple RolloutManagers.")
28-
return createCondition(err.Error()), nil
28+
return createCondition(err.Error()), err
2929
}
3030

3131
log.Info("reconciling Rollouts ServiceAccount")

controllers/resources.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (r *RolloutManagerReconciler) reconcileRolloutsServiceAccount(ctx context.C
2828

2929
if err := fetchObject(ctx, r.Client, cr.Namespace, sa.Name, sa); err != nil {
3030
if !apierrors.IsNotFound(err) {
31-
return nil, fmt.Errorf("failed to get the ServiceAccount associated with %s: %s", sa.Name, err)
31+
return nil, fmt.Errorf("failed to get the ServiceAccount associated with %s: %w", sa.Name, err)
3232
}
3333

3434
if err := controllerutil.SetControllerReference(cr, sa, r.Scheme); err != nil {
@@ -60,7 +60,7 @@ func (r *RolloutManagerReconciler) reconcileRolloutsRole(ctx context.Context, cr
6060

6161
if err := fetchObject(ctx, r.Client, cr.Namespace, role.Name, role); err != nil {
6262
if !apierrors.IsNotFound(err) {
63-
return nil, fmt.Errorf("failed to reconcile the Role for the ServiceAccount associated with %s: %s", role.Name, err)
63+
return nil, fmt.Errorf("failed to reconcile the Role for the ServiceAccount associated with %s: %w", role.Name, err)
6464
}
6565

6666
if err = controllerutil.SetControllerReference(cr, role, r.Scheme); err != nil {
@@ -152,7 +152,7 @@ func (r *RolloutManagerReconciler) reconcileRolloutsRoleBinding(ctx context.Cont
152152
// Fetch the RoleBinding if exists and store that in actualRoleBinding.
153153
if err := fetchObject(ctx, r.Client, cr.Namespace, expectedRoleBinding.Name, actualRoleBinding); err != nil {
154154
if !apierrors.IsNotFound(err) {
155-
return fmt.Errorf("failed to get the RoleBinding associated with %s: %s", expectedRoleBinding.Name, err)
155+
return fmt.Errorf("failed to get the RoleBinding associated with %s: %w", expectedRoleBinding.Name, err)
156156
}
157157

158158
if err := controllerutil.SetControllerReference(cr, expectedRoleBinding, r.Scheme); err != nil {
@@ -212,7 +212,7 @@ func (r *RolloutManagerReconciler) reconcileRolloutsClusterRoleBinding(ctx conte
212212
// Fetch the ClusterRoleBinding if exists and store that in actualClusterRoleBinding.
213213
if err := fetchObject(ctx, r.Client, "", expectedClusterRoleBinding.Name, actualClusterRoleBinding); err != nil {
214214
if !apierrors.IsNotFound(err) {
215-
return fmt.Errorf("failed to get the ClusterRoleBinding associated with %s: %s", expectedClusterRoleBinding.Name, err)
215+
return fmt.Errorf("failed to get the ClusterRoleBinding associated with %s: %w", expectedClusterRoleBinding.Name, err)
216216
}
217217

218218
log.Info(fmt.Sprintf("Creating ClusterRoleBinding %s", expectedClusterRoleBinding.Name))
@@ -248,7 +248,7 @@ func (r *RolloutManagerReconciler) reconcileRolloutsAggregateToAdminClusterRole(
248248

249249
if err := fetchObject(ctx, r.Client, "", clusterRole.Name, clusterRole); err != nil {
250250
if !apierrors.IsNotFound(err) {
251-
return fmt.Errorf("failed to reconcile the aggregated ClusterRole %s: %s", clusterRole.Name, err)
251+
return fmt.Errorf("failed to reconcile the aggregated ClusterRole %s: %w", clusterRole.Name, err)
252252
}
253253

254254
log.Info(fmt.Sprintf("Creating aggregated ClusterRole %s", clusterRole.Name))
@@ -283,7 +283,7 @@ func (r *RolloutManagerReconciler) reconcileRolloutsAggregateToEditClusterRole(c
283283

284284
if err := fetchObject(ctx, r.Client, "", clusterRole.Name, clusterRole); err != nil {
285285
if !apierrors.IsNotFound(err) {
286-
return fmt.Errorf("failed to reconcile the aggregated ClusterRole %s: %s", clusterRole.Name, err)
286+
return fmt.Errorf("failed to reconcile the aggregated ClusterRole %s: %w", clusterRole.Name, err)
287287
}
288288

289289
log.Info(fmt.Sprintf("Creating aggregated ClusterRole %s", clusterRole.Name))
@@ -318,7 +318,7 @@ func (r *RolloutManagerReconciler) reconcileRolloutsAggregateToViewClusterRole(c
318318

319319
if err := fetchObject(ctx, r.Client, "", clusterRole.Name, clusterRole); err != nil {
320320
if !apierrors.IsNotFound(err) {
321-
return fmt.Errorf("failed to reconcile the aggregated ClusterRole %s: %s", clusterRole.Name, err)
321+
return fmt.Errorf("failed to reconcile the aggregated ClusterRole %s: %w", clusterRole.Name, err)
322322
}
323323

324324
log.Info(fmt.Sprintf("Creating aggregated ClusterRole %s", clusterRole.Name))
@@ -368,7 +368,7 @@ func (r *RolloutManagerReconciler) reconcileRolloutsMetricsService(ctx context.C
368368
// Fetch the Service if exists and store that in actualSvc.
369369
if err := fetchObject(ctx, r.Client, cr.Namespace, expectedSvc.Name, actualSvc); err != nil {
370370
if !apierrors.IsNotFound(err) {
371-
return fmt.Errorf("failed to get the Service %s: %s", expectedSvc.Name, err)
371+
return fmt.Errorf("failed to get the Service %s: %w", expectedSvc.Name, err)
372372
}
373373

374374
if err := controllerutil.SetControllerReference(cr, expectedSvc, r.Scheme); err != nil {
@@ -400,7 +400,7 @@ func (r *RolloutManagerReconciler) reconcileRolloutsSecrets(ctx context.Context,
400400

401401
if err := fetchObject(ctx, r.Client, cr.Namespace, secret.Name, secret); err != nil {
402402
if !apierrors.IsNotFound(err) {
403-
return fmt.Errorf("failed to get the Secret %s: %s", secret.Name, err)
403+
return fmt.Errorf("failed to get the Secret %s: %w", secret.Name, err)
404404
}
405405

406406
if err := controllerutil.SetControllerReference(cr, secret, r.Scheme); err != nil {

controllers/utils.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ import (
1818
)
1919

2020
const (
21-
UnsupportedRolloutManagerConfiguration = "when there exists a cluster-scoped RolloutManager on the cluster, there may not exist another: only a single cluster-scoped RolloutManager is supported."
22-
UnsupportedRolloutManagerClusterScoped = "when Subscription has environment variable NAMESPACE_SCOPED_ARGO_ROLLOUTS set to True, there may not exist any cluster-scoped RolloutManager: only a single namespace-scoped RolloutManager is supported in a namespace."
23-
UnsupportedRolloutManagerNamespaceScoped = "when Subscription has environment variable NAMESPACE_SCOPED_ARGO_ROLLOUTS set to False, there may not exist any namespace-scoped RolloutManager: only cluster-scoped RolloutManager is supported."
21+
UnsupportedRolloutManagerConfiguration = "when there exists a cluster-scoped RolloutManager on the cluster, there may not exist another: only a single cluster-scoped RolloutManager is supported"
22+
UnsupportedRolloutManagerClusterScoped = "when Subscription has environment variable NAMESPACE_SCOPED_ARGO_ROLLOUTS set to True, there may not exist any cluster-scoped RolloutManagers: in this case, only namespace-scoped RolloutManager resources are supported"
23+
UnsupportedRolloutManagerNamespaceScoped = "when Subscription has environment variable NAMESPACE_SCOPED_ARGO_ROLLOUTS set to False, there may not exist any namespace-scoped RolloutManagers: only a single cluster-scoped RolloutManager is supported"
2424
)
2525

2626
func setRolloutsLabels(obj *metav1.ObjectMeta) {

hack/run-rollouts-manager-e2e-tests.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ set +e
2727
if [ -f "/tmp/e2e-operator-run.log" ]; then
2828

2929
# Wait for the controller to flush to the file, before killing the controller
30-
sleep 8
30+
sleep 10
3131
killall main
32-
sleep 3
32+
sleep 5
3333

3434
# Grep the log for unexpected errors
3535
# - Ignore errors that are expected to occur

hack/start-rollouts-manager-for-e2e-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ cd "$SCRIPTPATH/.."
99

1010
killall main
1111

12-
sleep 3s
12+
sleep 5s
1313

1414
rm -f /tmp/e2e-operator-run.log || true
1515

0 commit comments

Comments
 (0)