Skip to content

Commit f14ffe9

Browse files
committed
Add New condition for OCI
If implemented the Helmrepository_oci reconciler will have a new negative polarity condition addFailedCondition. Signed-off-by: Soule BA <[email protected]>
1 parent a6f19b3 commit f14ffe9

File tree

5 files changed

+31
-18
lines changed

5 files changed

+31
-18
lines changed

api/v1beta2/condition_types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ package v1beta2
1919
const SourceFinalizer = "finalizers.fluxcd.io"
2020

2121
const (
22+
// AddFailedCondition indicates a transient or persistent failure
23+
// to add an upstream Source.
24+
// If True, the reconciliation failed while adding the source.
25+
// This is a "negative polarity" or "abnormal-true" type, and is only
26+
// present on the resource if it is True.
27+
AddFailedCondition = "AddFailed"
28+
2229
// ArtifactInStorageCondition indicates the availability of the Artifact in
2330
// the storage.
2431
// If True, the Artifact is stored successfully.

config/manager/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ resources:
66
images:
77
- name: fluxcd/source-controller
88
newName: fluxcd/source-controller
9-
newTag: v0.24.4
9+
newTag: latest

controllers/helmrepository_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,8 @@ func (r *HelmRepositoryReconciler) garbageCollect(ctx context.Context, obj *sour
577577
// Clean status sub-resource
578578
obj.Status.Artifact = nil
579579
obj.Status.URL = ""
580-
// Remove the condition as the artifact doesn't exist.
581-
conditions.Delete(obj, sourcev1.ArtifactInStorageCondition)
580+
// Remove any stale conditions
581+
obj.Status.Conditions = nil
582582
return nil
583583
}
584584
if obj.GetArtifact() != nil {

controllers/helmrepository_controller_oci.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,18 @@ import (
5151
var helmRepositoryOCIReadyCondition = summarize.Conditions{
5252
Target: meta.ReadyCondition,
5353
Owned: []string{
54-
sourcev1.FetchFailedCondition,
54+
sourcev1.AddFailedCondition,
5555
meta.ReadyCondition,
5656
meta.ReconcilingCondition,
5757
meta.StalledCondition,
5858
},
5959
Summarize: []string{
60-
sourcev1.FetchFailedCondition,
60+
sourcev1.AddFailedCondition,
6161
meta.StalledCondition,
6262
meta.ReconcilingCondition,
6363
},
6464
NegativePolarity: []string{
65-
sourcev1.FetchFailedCondition,
65+
sourcev1.AddFailedCondition,
6666
meta.StalledCondition,
6767
meta.ReconcilingCondition,
6868
},
@@ -71,7 +71,7 @@ var helmRepositoryOCIReadyCondition = summarize.Conditions{
7171
// helmRepositoryOCIFailConditions contains the conditions that represent a
7272
// failure.
7373
var helmRepositoryOCIFailConditions = []string{
74-
sourcev1.FetchFailedCondition,
74+
sourcev1.AddFailedCondition,
7575
}
7676

7777
// +kubebuilder:rbac:groups=source.toolkit.fluxcd.io,resources=helmrepositories,verbs=get;list;watch;create;update;patch;delete
@@ -188,7 +188,8 @@ func (r *HelmRepositoryOCIReconciler) Reconcile(ctx context.Context, req ctrl.Re
188188

189189
// Examine if a type change has happened and act accordingly
190190
if obj.Spec.Type != sourcev1.HelmRepositoryTypeOCI {
191-
// just ignore the object if the type has changed
191+
// remove any stale condition and ignore the object if the type has changed
192+
obj.Status.Conditions = nil
192193
recResult, retErr = sreconcile.ResultEmpty, nil
193194
return
194195
}
@@ -258,10 +259,10 @@ func (r *HelmRepositoryOCIReconciler) reconcile(ctx context.Context, obj *source
258259
func (r *HelmRepositoryOCIReconciler) reconcileSource(ctx context.Context, obj *sourcev1.HelmRepository) (sreconcile.Result, error) {
259260
if !helmreg.IsOCI(obj.Spec.URL) {
260261
e := &serror.Stalling{
261-
Err: fmt.Errorf("the url scheme is not supported: %s", obj.Spec.URL),
262+
Err: fmt.Errorf("the URL scheme is not supported: %s", obj.Spec.URL),
262263
Reason: sourcev1.URLInvalidReason,
263264
}
264-
conditions.MarkFalse(obj, meta.ReadyCondition, e.Reason, e.Err.Error())
265+
conditions.MarkTrue(obj, sourcev1.AddFailedCondition, e.Reason, e.Err.Error())
265266
return sreconcile.ResultEmpty, e
266267
}
267268

@@ -279,7 +280,7 @@ func (r *HelmRepositoryOCIReconciler) reconcileSource(ctx context.Context, obj *
279280
Err: fmt.Errorf("failed to get secret '%s': %w", name.String(), err),
280281
Reason: sourcev1.AuthenticationFailedReason,
281282
}
282-
conditions.MarkTrue(obj, sourcev1.FetchFailedCondition, e.Reason, e.Err.Error())
283+
conditions.MarkTrue(obj, sourcev1.AddFailedCondition, e.Reason, e.Err.Error())
283284
return sreconcile.ResultEmpty, e
284285
}
285286

@@ -290,7 +291,7 @@ func (r *HelmRepositoryOCIReconciler) reconcileSource(ctx context.Context, obj *
290291
Err: fmt.Errorf("failed to configure Helm client with secret data: %w", err),
291292
Reason: sourcev1.AuthenticationFailedReason,
292293
}
293-
conditions.MarkTrue(obj, sourcev1.FetchFailedCondition, e.Reason, e.Err.Error())
294+
conditions.MarkTrue(obj, sourcev1.AddFailedCondition, e.Reason, e.Err.Error())
294295
// Return err as the content of the secret may change.
295296
return sreconcile.ResultEmpty, e
296297
}
@@ -309,10 +310,10 @@ func (r *HelmRepositoryOCIReconciler) validateSource(ctx context.Context, obj *s
309310
registryClient, file, err := r.RegistryClientGenerator(logOpts != nil)
310311
if err != nil {
311312
e := &serror.Event{
312-
Err: fmt.Errorf("failed to create registry client:: %w", err),
313+
Err: fmt.Errorf("failed to create registry client: %w", err),
313314
Reason: meta.FailedReason,
314315
}
315-
conditions.MarkFalse(obj, meta.ReadyCondition, e.Reason, e.Err.Error())
316+
conditions.MarkTrue(obj, sourcev1.AddFailedCondition, e.Reason, e.Err.Error())
316317
return sreconcile.ResultEmpty, e
317318
}
318319

@@ -331,23 +332,25 @@ func (r *HelmRepositoryOCIReconciler) validateSource(ctx context.Context, obj *s
331332
Err: fmt.Errorf("failed to parse URL '%s': %w", obj.Spec.URL, err),
332333
Reason: sourcev1.URLInvalidReason,
333334
}
334-
conditions.MarkFalse(obj, meta.ReadyCondition, e.Reason, e.Err.Error())
335+
conditions.MarkTrue(obj, sourcev1.AddFailedCondition, e.Reason, e.Err.Error())
335336
return sreconcile.ResultEmpty, e
336337
}
337338

338-
// Attempt to login to the registry if credentials are provided.
339339
if logOpts != nil {
340340
err = chartRepo.Login(logOpts...)
341341
if err != nil {
342342
e := &serror.Event{
343-
Err: fmt.Errorf("failed to create temporary file: %w", err),
343+
Err: fmt.Errorf("failed to login to repository '%s': %w", obj.Spec.URL, err),
344344
Reason: meta.FailedReason,
345345
}
346-
conditions.MarkFalse(obj, meta.ReadyCondition, e.Reason, e.Err.Error())
346+
conditions.MarkTrue(obj, sourcev1.AddFailedCondition, e.Reason, e.Err.Error())
347347
return sreconcile.ResultEmpty, e
348348
}
349349
}
350350

351+
// Delete any stale failure observation
352+
conditions.Delete(obj, sourcev1.AddFailedCondition)
353+
351354
conditions.MarkTrue(obj, meta.ReadyCondition, meta.SucceededReason, "Helm repository %q is ready", obj.Name)
352355

353356
return sreconcile.ResultSuccess, nil

controllers/helmrepository_controller_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,9 @@ func TestHelmRepositoryReconciler_ReconcileTypeUpdatePredicateFilter(t *testing.
11791179
return false
11801180
}
11811181
readyCondition := conditions.Get(obj, meta.ReadyCondition)
1182+
if readyCondition == nil {
1183+
return false
1184+
}
11821185
return readyCondition.Status == metav1.ConditionTrue &&
11831186
newGen == readyCondition.ObservedGeneration &&
11841187
newGen == obj.Status.ObservedGeneration

0 commit comments

Comments
 (0)