Skip to content

Commit 5c223b7

Browse files
authored
Merge pull request #162 from Fedosin/conditions
🐛 use correct conditions for reporting errors after preflight checks
2 parents 5ebe5dc + 3a23112 commit 5c223b7

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

internal/controller/manifests_downloader.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (p *phaseReconciler) downloadManifests(ctx context.Context) (reconcile.Resu
5959

6060
exists, err := p.checkConfigMapExists(ctx, labelSelector)
6161
if err != nil {
62-
return reconcile.Result{}, wrapPhaseError(err, "failed to check that config map with manifests exists", operatorv1.PreflightCheckCondition)
62+
return reconcile.Result{}, wrapPhaseError(err, "failed to check that config map with manifests exists")
6363
}
6464

6565
if exists {
@@ -72,28 +72,28 @@ func (p *phaseReconciler) downloadManifests(ctx context.Context) (reconcile.Resu
7272
if err != nil {
7373
err = fmt.Errorf("failed to create repo from provider url for provider %q: %w", p.provider.GetName(), err)
7474

75-
return reconcile.Result{}, wrapPhaseError(err, operatorv1.ComponentsFetchErrorReason, operatorv1.PreflightCheckCondition)
75+
return reconcile.Result{}, wrapPhaseError(err, operatorv1.ComponentsFetchErrorReason)
7676
}
7777

7878
// Fetch the provider metadata and components yaml files from the provided repository GitHub/GitLab.
7979
metadataFile, err := repo.GetFile(p.options.Version, metadataFile)
8080
if err != nil {
8181
err = fmt.Errorf("failed to read %q from the repository for provider %q: %w", metadataFile, p.provider.GetName(), err)
8282

83-
return reconcile.Result{}, wrapPhaseError(err, operatorv1.ComponentsFetchErrorReason, operatorv1.PreflightCheckCondition)
83+
return reconcile.Result{}, wrapPhaseError(err, operatorv1.ComponentsFetchErrorReason)
8484
}
8585

8686
componentsFile, err := repo.GetFile(p.options.Version, repo.ComponentsPath())
8787
if err != nil {
8888
err = fmt.Errorf("failed to read %q from the repository for provider %q: %w", componentsFile, p.provider.GetName(), err)
8989

90-
return reconcile.Result{}, wrapPhaseError(err, operatorv1.ComponentsFetchErrorReason, operatorv1.PreflightCheckCondition)
90+
return reconcile.Result{}, wrapPhaseError(err, operatorv1.ComponentsFetchErrorReason)
9191
}
9292

9393
if err := p.createManifestsConfigMap(ctx, string(metadataFile), string(componentsFile)); err != nil {
9494
err = fmt.Errorf("failed to create config map for provider %q: %w", p.provider.GetName(), err)
9595

96-
return reconcile.Result{}, wrapPhaseError(err, operatorv1.ComponentsFetchErrorReason, operatorv1.PreflightCheckCondition)
96+
return reconcile.Result{}, wrapPhaseError(err, operatorv1.ComponentsFetchErrorReason)
9797
}
9898

9999
return reconcile.Result{}, nil

internal/controller/phases.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ func (p *PhaseError) Error() string {
8181
return p.Err.Error()
8282
}
8383

84-
func wrapPhaseError(err error, reason string, ctype clusterv1.ConditionType) error {
84+
func wrapPhaseError(err error, reason string) error {
8585
if err == nil {
8686
return nil
8787
}
8888

8989
return &PhaseError{
9090
Err: err,
91-
Type: ctype,
91+
Type: operatorv1.ProviderInstalledCondition,
9292
Reason: reason,
9393
Severity: clusterv1.ConditionSeverityWarning,
9494
}
@@ -115,7 +115,7 @@ func (p *phaseReconciler) initializePhaseReconciler(ctx context.Context) (reconc
115115
// Load provider's secret and config url.
116116
reader, err := p.secretReader(ctx)
117117
if err != nil {
118-
return reconcile.Result{}, wrapPhaseError(err, "failed to load the secret reader", operatorv1.PreflightCheckCondition)
118+
return reconcile.Result{}, wrapPhaseError(err, "failed to load the secret reader")
119119
}
120120

121121
// Initialize a client for interacting with the clusterctl configuration.
@@ -128,7 +128,7 @@ func (p *phaseReconciler) initializePhaseReconciler(ctx context.Context) (reconc
128128
// This is done using clusterctl internal API types.
129129
p.providerConfig, err = p.configClient.Providers().Get(p.provider.GetName(), util.ClusterctlProviderType(p.provider))
130130
if err != nil {
131-
return reconcile.Result{}, wrapPhaseError(err, operatorv1.UnknownProviderReason, operatorv1.PreflightCheckCondition)
131+
return reconcile.Result{}, wrapPhaseError(err, operatorv1.UnknownProviderReason)
132132
}
133133

134134
spec := p.provider.GetSpec()
@@ -164,7 +164,7 @@ func (p *phaseReconciler) load(ctx context.Context) (reconcile.Result, error) {
164164

165165
p.repo, err = p.configmapRepository(ctx, labelSelector)
166166
if err != nil {
167-
return reconcile.Result{}, wrapPhaseError(err, "failed to load the repository", operatorv1.PreflightCheckCondition)
167+
return reconcile.Result{}, wrapPhaseError(err, "failed to load the repository")
168168
}
169169

170170
// Store some provider specific inputs for passing it to clusterctl library
@@ -175,7 +175,7 @@ func (p *phaseReconciler) load(ctx context.Context) (reconcile.Result, error) {
175175
}
176176

177177
if err := p.validateRepoCAPIVersion(); err != nil {
178-
return reconcile.Result{}, wrapPhaseError(err, operatorv1.CAPIVersionIncompatibilityReason, operatorv1.PreflightCheckCondition)
178+
return reconcile.Result{}, wrapPhaseError(err, operatorv1.CAPIVersionIncompatibilityReason)
179179
}
180180

181181
return reconcile.Result{}, nil
@@ -319,7 +319,7 @@ func (p *phaseReconciler) fetch(ctx context.Context) (reconcile.Result, error) {
319319
if err != nil {
320320
err = fmt.Errorf("failed to read %q from provider's repository %q: %w", p.repo.ComponentsPath(), p.providerConfig.ManifestLabel(), err)
321321

322-
return reconcile.Result{}, wrapPhaseError(err, operatorv1.ComponentsFetchErrorReason, operatorv1.PreflightCheckCondition)
322+
return reconcile.Result{}, wrapPhaseError(err, operatorv1.ComponentsFetchErrorReason)
323323
}
324324

325325
// Generate a set of new objects using the clusterctl library. NewComponents() will do the yaml processing,
@@ -333,17 +333,17 @@ func (p *phaseReconciler) fetch(ctx context.Context) (reconcile.Result, error) {
333333
Options: p.options,
334334
})
335335
if err != nil {
336-
return reconcile.Result{}, wrapPhaseError(err, operatorv1.ComponentsFetchErrorReason, operatorv1.PreflightCheckCondition)
336+
return reconcile.Result{}, wrapPhaseError(err, operatorv1.ComponentsFetchErrorReason)
337337
}
338338

339339
// ProviderSpec provides fields for customizing the provider deployment options.
340340
// We can use clusterctl library to apply this customizations.
341341
err = repository.AlterComponents(p.components, customizeObjectsFn(p.provider))
342342
if err != nil {
343-
return reconcile.Result{}, wrapPhaseError(err, operatorv1.ComponentsFetchErrorReason, operatorv1.PreflightCheckCondition)
343+
return reconcile.Result{}, wrapPhaseError(err, operatorv1.ComponentsFetchErrorReason)
344344
}
345345

346-
conditions.Set(p.provider, conditions.TrueCondition(operatorv1.PreflightCheckCondition))
346+
conditions.Set(p.provider, conditions.TrueCondition(operatorv1.ProviderInstalledCondition))
347347

348348
return reconcile.Result{}, nil
349349
}
@@ -355,7 +355,7 @@ func (p *phaseReconciler) preInstall(ctx context.Context) (reconcile.Result, err
355355

356356
needPreDelete, err := p.versionChanged()
357357
if err != nil {
358-
return reconcile.Result{}, wrapPhaseError(err, "failed getting clusterctl Provider version", operatorv1.ProviderInstalledCondition)
358+
return reconcile.Result{}, wrapPhaseError(err, "failed getting clusterctl Provider version")
359359
}
360360

361361
// we need to delete existing components only if their version changes and something has already been installed.
@@ -397,7 +397,7 @@ func (p *phaseReconciler) install(ctx context.Context) (reconcile.Result, error)
397397

398398
versionChanged, err := p.versionChanged()
399399
if err != nil {
400-
return reconcile.Result{}, wrapPhaseError(err, "failed getting clusterctl Provider version", operatorv1.ProviderInstalledCondition)
400+
return reconcile.Result{}, wrapPhaseError(err, "failed getting clusterctl Provider version")
401401
}
402402

403403
// skip installation if the version hasn't changed.
@@ -416,7 +416,7 @@ func (p *phaseReconciler) install(ctx context.Context) (reconcile.Result, error)
416416
reason = "Timed out waiting for deployment to become ready"
417417
}
418418

419-
return reconcile.Result{}, wrapPhaseError(err, reason, operatorv1.ProviderInstalledCondition)
419+
return reconcile.Result{}, wrapPhaseError(err, reason)
420420
}
421421

422422
status := p.provider.GetStatus()
@@ -455,7 +455,7 @@ func (p *phaseReconciler) delete(ctx context.Context) (reconcile.Result, error)
455455
IncludeCRDs: false,
456456
})
457457

458-
return reconcile.Result{}, wrapPhaseError(err, operatorv1.OldComponentsDeletionErrorReason, operatorv1.ProviderInstalledCondition)
458+
return reconcile.Result{}, wrapPhaseError(err, operatorv1.OldComponentsDeletionErrorReason)
459459
}
460460

461461
func clusterctlProviderName(provider genericprovider.GenericProvider) client.ObjectKey {

0 commit comments

Comments
 (0)