-
Notifications
You must be signed in to change notification settings - Fork 108
✨Fetch latest provider version if it's not set in the spec #180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ import ( | |
"fmt" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/labels" | ||
operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha1" | ||
|
@@ -75,15 +76,25 @@ func (p *phaseReconciler) downloadManifests(ctx context.Context) (reconcile.Resu | |
return reconcile.Result{}, wrapPhaseError(err, operatorv1.ComponentsFetchErrorReason) | ||
} | ||
|
||
spec := p.provider.GetSpec() | ||
|
||
if spec.Version == "" { | ||
// User didn't set the version, try to get repository default. | ||
spec.Version = repo.DefaultVersion() | ||
|
||
// Add version to the provider spec. | ||
p.provider.SetSpec(spec) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why provider spec is set twice? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason spec is set twice is because it accommodates two distinct workflows:
For the first workflow, the version is set during the manifest download process when a fetch URL is used. In the case of config maps, the version setting occurs in the load phase. Regardless of the workflow, the spec update is executed only once. |
||
} | ||
|
||
// Fetch the provider metadata and components yaml files from the provided repository GitHub/GitLab. | ||
metadataFile, err := repo.GetFile(p.options.Version, metadataFile) | ||
metadataFile, err := repo.GetFile(spec.Version, metadataFile) | ||
if err != nil { | ||
err = fmt.Errorf("failed to read %q from the repository for provider %q: %w", metadataFile, p.provider.GetName(), err) | ||
|
||
return reconcile.Result{}, wrapPhaseError(err, operatorv1.ComponentsFetchErrorReason) | ||
} | ||
|
||
componentsFile, err := repo.GetFile(p.options.Version, repo.ComponentsPath()) | ||
componentsFile, err := repo.GetFile(spec.Version, repo.ComponentsPath()) | ||
if err != nil { | ||
err = fmt.Errorf("failed to read %q from the repository for provider %q: %w", componentsFile, p.provider.GetName(), err) | ||
|
||
|
@@ -156,5 +167,9 @@ func (p *phaseReconciler) createManifestsConfigMap(ctx context.Context, metadata | |
}, | ||
}) | ||
|
||
return p.ctrlClient.Create(ctx, configMap) | ||
if err := p.ctrlClient.Create(ctx, configMap); err != nil && !apierrors.IsAlreadyExists(err) { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
Uh oh!
There was an error while loading. Please reload this page.