Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions internal/controller/catalog/catalog_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
continue
}

ready, _ := sourcer.objectReadiness(ctx, externalArtifact)

Check failure on line 263 in internal/controller/catalog/catalog_controller.go

View workflow job for this annotation

GitHub Actions / lint

assignment mismatch: 2 variables but sourcer.objectReadiness returns 3 values (typecheck)

Check failure on line 263 in internal/controller/catalog/catalog_controller.go

View workflow job for this annotation

GitHub Actions / test

assignment mismatch: 2 variables but sourcer.objectReadiness returns 3 values

Check failure on line 263 in internal/controller/catalog/catalog_controller.go

View workflow job for this annotation

GitHub Actions / build

assignment mismatch: 2 variables but sourcer.objectReadiness returns 3 values

Check failure on line 263 in internal/controller/catalog/catalog_controller.go

View workflow job for this annotation

GitHub Actions / codeql / Analyze (ubuntu-latest, go, 1.25, node)

assignment mismatch: 2 variables but sourcer.objectReadiness returns 3 values
if ready != metav1.ConditionTrue {
r.Log.Info("external artifact not ready yet, retry in next reconciliation loop", "namespace", catalog.Namespace, "name", sourcer.getArtifactName())
continue
Expand Down Expand Up @@ -393,28 +393,38 @@
gitRepo := &sourcev1.GitRepository{}
gitRepo.SetName(sourcer.getGitRepoName())
gitRepo.SetNamespace(catalog.Namespace)
ready, msg := sourcer.objectReadiness(ctx, gitRepo)
ready, msg, err := sourcer.objectReadiness(ctx, gitRepo)
if err != nil {
// check if there was a not found error in getting GitRepository
if apierrors.IsNotFound(err) && source.SecretName != nil {
// if not found, then check if it is related to secret error
_, secretErr := sourcer.getSourceSecret(ctx)
if secretErr != nil {
msg = msg + "; " + secretErr.Error()
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is done inside the objectReadiness method, it would avoid the missing error checks from below.

}
allInventoryReady = append(allInventoryReady, ready)
sourcer.setInventory(sourcev1.GitRepositoryKind, gitRepo.Name, msg, ready)

artifactGen := &sourcev2.ArtifactGenerator{}
artifactGen.SetName(sourcer.getGeneratorName())
artifactGen.SetNamespace(catalog.Namespace)
ready, msg = sourcer.objectReadiness(ctx, artifactGen)
ready, msg, _ = sourcer.objectReadiness(ctx, artifactGen)
allInventoryReady = append(allInventoryReady, ready)
sourcer.setInventory(sourcev2.ArtifactGeneratorKind, artifactGen.Name, msg, ready)

extArtifact := &sourcev1.ExternalArtifact{}
extArtifact.SetName(sourcer.getArtifactName())
extArtifact.SetNamespace(catalog.Namespace)
ready, msg = sourcer.objectReadiness(ctx, extArtifact)
ready, msg, _ = sourcer.objectReadiness(ctx, extArtifact)
allInventoryReady = append(allInventoryReady, ready)
sourcer.setInventory(sourcev1.ExternalArtifactKind, extArtifact.Name, msg, ready)

kustomization := &kustomizev1.Kustomization{}
kustomization.SetName(sourcer.getKustomizationName())
kustomization.SetNamespace(catalog.Namespace)
ready, msg = sourcer.objectReadiness(ctx, kustomization)
ready, msg, _ = sourcer.objectReadiness(ctx, kustomization)
allInventoryReady = append(allInventoryReady, ready)
sourcer.setInventory(kustomizev1.KustomizationKind, kustomization.Name, msg, ready)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/controller/catalog/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,10 +515,10 @@ func (s *source) findPluginDefinition(manifestBytes []byte, name string) (spec *

// objectReadiness - checks the Ready condition of a catalog object (GitRepository, ArtifactGenerator, ExternalArtifact, Kustomization)
// if not Ready, then the controller adds the Catalog object to requeue
func (s *source) objectReadiness(ctx context.Context, obj client.Object) (ready metav1.ConditionStatus, msg string) {
func (s *source) objectReadiness(ctx context.Context, obj client.Object) (ready metav1.ConditionStatus, msg string, err error) {
ready = metav1.ConditionFalse
key := client.ObjectKeyFromObject(obj)
if err := s.Get(ctx, key, obj); err != nil {
if err = s.Get(ctx, key, obj); err != nil {
s.log.Error(err, "failed to get object", "key", key)
msg = err.Error()
return
Expand All @@ -527,7 +527,7 @@ func (s *source) objectReadiness(ctx context.Context, obj client.Object) (ready
kind := obj.GetObjectKind().GroupVersionKind().Kind
cObj, ok := obj.(lifecycle.CatalogObject)
if !ok {
err := fmt.Errorf("failed to assert catalog object kind %s - %s/%s", kind, key.Namespace, key.Name)
err = fmt.Errorf("failed to assert catalog object kind %s - %s/%s", kind, key.Namespace, key.Name)
s.log.Error(err, "failed to assert catalog object", "key", key)
msg = err.Error()
return
Expand Down
Loading