Skip to content

Commit 64c8f1d

Browse files
committed
set retryAfter for missing configmap/secret refs to 10s
1 parent 2db628a commit 64c8f1d

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

pkg/component/component.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ func (s *Status) SetState(state State, reason string, message string) {
226226
}
227227
if status != cond.Status {
228228
cond.Status = status
229-
cond.LastTransitionTime = &[]metav1.Time{metav1.Now()}[0]
229+
cond.LastTransitionTime = ref(metav1.Now())
230230
}
231231
cond.Reason = reason
232232
cond.Message = message

pkg/component/reconcile.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import (
4444
// TODO: allow some timeout feature, such that component will go into error state if not ready within the given timeout
4545
// (e.g. through a TimeoutConfiguration interface that components could optionally implement)
4646
// TODO: run admission webhooks (if present) in reconcile (e.g. as post-read hook)
47+
// TODO: improve overall log output
4748

4849
const (
4950
readyConditionReasonNew = "FirstSeen"
@@ -114,18 +115,18 @@ type Reconciler[T Component] struct {
114115
// resourceGenerator must be an implementation of the manifests.Generator interface.
115116
func NewReconciler[T Component](name string, resourceGenerator manifests.Generator, options ReconcilerOptions) *Reconciler[T] {
116117
if options.CreateMissingNamespaces == nil {
117-
options.CreateMissingNamespaces = &[]bool{true}[0]
118+
options.CreateMissingNamespaces = ref(true)
118119
}
119120
if options.AdoptionPolicy == nil {
120-
options.AdoptionPolicy = &[]AdoptionPolicy{AdoptionPolicyAdoptUnowned}[0]
121+
options.AdoptionPolicy = ref(AdoptionPolicyAdoptUnowned)
121122
}
122123
// TOOD: validate adoption policy
123124

124125
return &Reconciler[T]{
125126
name: name,
126127
resourceGenerator: resourceGenerator,
127128
options: options,
128-
backoff: backoff.NewBackoff(5 * time.Second),
129+
backoff: backoff.NewBackoff(10 * time.Second),
129130
postReadHooks: []HookFunc[T]{resolveReferences[T]},
130131
}
131132
}

pkg/component/reference.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"fmt"
1212
"reflect"
1313
"strings"
14+
"time"
1415

1516
corev1 "k8s.io/api/core/v1"
1617
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -30,6 +31,8 @@ const (
3031
tagFallbackKeys = "fallbackKeys"
3132

3233
notFoundPolicyIgnoreOnDeletion = "ignoreOnDeletion"
34+
35+
retryAfter = 10 * time.Second
3336
)
3437

3538
// +kubebuilder:object:generate=true
@@ -50,7 +53,7 @@ func (r *ConfigMapReference) load(ctx context.Context, clnt client.Client, names
5053
if ignoreNotFound {
5154
return nil
5255
}
53-
return types.NewRetriableError(errors.Wrapf(err, "error loading configmap %s/%s", namespace, r.Name), nil)
56+
return types.NewRetriableError(errors.Wrapf(err, "error loading configmap %s/%s", namespace, r.Name), ref(retryAfter))
5457
} else {
5558
return errors.Wrapf(err, "error loading configmap %s/%s", namespace, r.Name)
5659
}
@@ -102,7 +105,7 @@ func (r *ConfigMapKeyReference) load(ctx context.Context, clnt client.Client, na
102105
if ignoreNotFound {
103106
return nil
104107
}
105-
return types.NewRetriableError(errors.Wrapf(err, "error loading configmap %s/%s", namespace, r.Name), nil)
108+
return types.NewRetriableError(errors.Wrapf(err, "error loading configmap %s/%s", namespace, r.Name), ref(retryAfter))
106109
} else {
107110
return errors.Wrapf(err, "error loading configmap %s/%s", namespace, r.Name)
108111
}
@@ -113,7 +116,7 @@ func (r *ConfigMapKeyReference) load(ctx context.Context, clnt client.Client, na
113116
r.loaded = true
114117
return nil
115118
} else {
116-
return types.NewRetriableError(fmt.Errorf("key %s not found in configmap %s/%s", r.Key, namespace, r.Name), nil)
119+
return types.NewRetriableError(fmt.Errorf("key %s not found in configmap %s/%s", r.Key, namespace, r.Name), ref(retryAfter))
117120
}
118121
} else {
119122
for _, key := range fallbackKeys {
@@ -123,7 +126,7 @@ func (r *ConfigMapKeyReference) load(ctx context.Context, clnt client.Client, na
123126
return nil
124127
}
125128
}
126-
return types.NewRetriableError(fmt.Errorf("no matching key found in configmap %s/%s", namespace, r.Name), nil)
129+
return types.NewRetriableError(fmt.Errorf("no matching key found in configmap %s/%s", namespace, r.Name), ref(retryAfter))
127130
}
128131
}
129132

@@ -161,7 +164,7 @@ func (r *SecretReference) load(ctx context.Context, clnt client.Client, namespac
161164
if ignoreNotFound {
162165
return nil
163166
}
164-
return types.NewRetriableError(errors.Wrapf(err, "error loading secret %s/%s", namespace, r.Name), nil)
167+
return types.NewRetriableError(errors.Wrapf(err, "error loading secret %s/%s", namespace, r.Name), ref(retryAfter))
165168
} else {
166169
return errors.Wrapf(err, "error loading secret %s/%s", namespace, r.Name)
167170
}
@@ -213,7 +216,7 @@ func (r *SecretKeyReference) load(ctx context.Context, clnt client.Client, names
213216
if ignoreNotFound {
214217
return nil
215218
}
216-
return types.NewRetriableError(errors.Wrapf(err, "error loading secret %s/%s", namespace, r.Name), nil)
219+
return types.NewRetriableError(errors.Wrapf(err, "error loading secret %s/%s", namespace, r.Name), ref(retryAfter))
217220
} else {
218221
return errors.Wrapf(err, "error loading secret %s/%s", namespace, r.Name)
219222
}
@@ -224,7 +227,7 @@ func (r *SecretKeyReference) load(ctx context.Context, clnt client.Client, names
224227
r.loaded = true
225228
return nil
226229
} else {
227-
return types.NewRetriableError(fmt.Errorf("key %s not found in secret %s/%s", r.Key, namespace, r.Name), nil)
230+
return types.NewRetriableError(fmt.Errorf("key %s not found in secret %s/%s", r.Key, namespace, r.Name), ref(retryAfter))
228231
}
229232
} else {
230233
for _, key := range fallbackKeys {
@@ -234,7 +237,7 @@ func (r *SecretKeyReference) load(ctx context.Context, clnt client.Client, names
234237
return nil
235238
}
236239
}
237-
return types.NewRetriableError(fmt.Errorf("no matching key found in secret %s/%s", namespace, r.Name), nil)
240+
return types.NewRetriableError(fmt.Errorf("no matching key found in secret %s/%s", namespace, r.Name), ref(retryAfter))
238241
}
239242
}
240243

pkg/component/target.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -752,10 +752,10 @@ func (t *reconcileTarget[T]) deleteObject(ctx context.Context, key types.ObjectK
752752
object.SetGroupVersionKind(key.GetObjectKind().GroupVersionKind())
753753
object.SetNamespace(key.GetNamespace())
754754
object.SetName(key.GetName())
755-
deleteOptions := &client.DeleteOptions{PropagationPolicy: &[]metav1.DeletionPropagation{metav1.DeletePropagationBackground}[0]}
755+
deleteOptions := &client.DeleteOptions{PropagationPolicy: ref(metav1.DeletePropagationBackground)}
756756
if existingObject != nil {
757757
deleteOptions.Preconditions = &metav1.Preconditions{
758-
ResourceVersion: &[]string{existingObject.GetResourceVersion()}[0],
758+
ResourceVersion: ref(existingObject.GetResourceVersion()),
759759
}
760760
}
761761
if err := t.client.Delete(ctx, object, deleteOptions); err != nil {

pkg/component/util.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ import (
2525
"github.com/sap/component-operator-runtime/pkg/types"
2626
)
2727

28+
func ref[T any](x T) *T {
29+
return &x
30+
}
31+
2832
func sha256hex(data []byte) string {
2933
sum := sha256.Sum256(data)
3034
return hex.EncodeToString(sum[:])

0 commit comments

Comments
 (0)