diff --git a/controllers/bucket_controller.go b/controllers/bucket_controller.go index 002c95c68..86911102e 100644 --- a/controllers/bucket_controller.go +++ b/controllers/bucket_controller.go @@ -170,7 +170,7 @@ func (r *BucketReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr r.recordReadiness(ctx, reconciledBucket) log.Info(fmt.Sprintf("Reconciliation finished in %s, next run in %s", - time.Now().Sub(start).String(), + time.Since(start).String(), bucket.GetInterval().Duration.String(), )) diff --git a/controllers/gitrepository_controller.go b/controllers/gitrepository_controller.go index be8a0a004..9dd92290f 100644 --- a/controllers/gitrepository_controller.go +++ b/controllers/gitrepository_controller.go @@ -192,7 +192,7 @@ func (r *GitRepositoryReconciler) Reconcile(ctx context.Context, req ctrl.Reques r.recordReadiness(ctx, reconciledRepository) log.Info(fmt.Sprintf("Reconciliation finished in %s, next run in %s", - time.Now().Sub(start).String(), + time.Since(start).String(), repository.GetInterval().Duration.String(), )) diff --git a/controllers/helmchart_controller.go b/controllers/helmchart_controller.go index 899b5389e..ddc149f45 100644 --- a/controllers/helmchart_controller.go +++ b/controllers/helmchart_controller.go @@ -247,7 +247,7 @@ func (r *HelmChartReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( r.recordReadiness(ctx, reconciledChart) log.Info(fmt.Sprintf("Reconciliation finished in %s, next run in %s", - time.Now().Sub(start).String(), + time.Since(start).String(), chart.GetInterval().Duration.String(), )) return ctrl.Result{RequeueAfter: chart.GetInterval().Duration}, nil @@ -307,6 +307,7 @@ func (r *HelmChartReconciler) fromHelmRepository(ctx context.Context, repo sourc authDir := filepath.Join(workDir, "creds") if err := os.Mkdir(authDir, 0700); err != nil { err = fmt.Errorf("failed to create temporary directory for repository credentials: %w", err) + return sourcev1.HelmChartNotReady(c, sourcev1.StorageOperationFailedReason, err.Error()), err } opts, err := getter.ClientOptionsFromSecret(authDir, *secret) if err != nil { diff --git a/controllers/helmrepository_controller.go b/controllers/helmrepository_controller.go index 5a29a7734..e4cee4360 100644 --- a/controllers/helmrepository_controller.go +++ b/controllers/helmrepository_controller.go @@ -89,6 +89,9 @@ func (r *HelmRepositoryReconciler) Reconcile(ctx context.Context, req ctrl.Reque return ctrl.Result{}, client.IgnoreNotFound(err) } + // Record suspended status metric + defer r.recordSuspension(ctx, repository) + // Add our finalizer if it does not exist if !controllerutil.ContainsFinalizer(&repository, sourcev1.SourceFinalizer) { controllerutil.AddFinalizer(&repository, sourcev1.SourceFinalizer) @@ -163,7 +166,7 @@ func (r *HelmRepositoryReconciler) Reconcile(ctx context.Context, req ctrl.Reque r.recordReadiness(ctx, reconciledRepository) log.Info(fmt.Sprintf("Reconciliation finished in %s, next run in %s", - time.Now().Sub(start).String(), + time.Since(start).String(), repository.GetInterval().Duration.String(), )) diff --git a/internal/helm/chart/builder_remote_test.go b/internal/helm/chart/builder_remote_test.go index 56c1fd855..015b1bdac 100644 --- a/internal/helm/chart/builder_remote_test.go +++ b/internal/helm/chart/builder_remote_test.go @@ -357,8 +357,8 @@ func Test_validatePackageAndWriteToPath(t *testing.T) { g.Expect(chartPath).To(BeARegularFile()) emptyF, err := os.Open("./../testdata/charts/empty.tgz") - defer emptyF.Close() g.Expect(err).ToNot(HaveOccurred()) + defer emptyF.Close() err = validatePackageAndWriteToPath(emptyF, filepath.Join(tmpDir, "out.tgz")) g.Expect(err).To(HaveOccurred()) } diff --git a/main.go b/main.go index 7853f224b..67f00a920 100644 --- a/main.go +++ b/main.go @@ -125,11 +125,10 @@ func main() { var eventRecorder *events.Recorder if eventsAddr != "" { - if er, err := events.NewRecorder(eventsAddr, controllerName); err != nil { + var err error + if eventRecorder, err = events.NewRecorder(eventsAddr, controllerName); err != nil { setupLog.Error(err, "unable to create event recorder") os.Exit(1) - } else { - eventRecorder = er } } diff --git a/pkg/git/libgit2/transport.go b/pkg/git/libgit2/transport.go index e609fcb39..ab36130b6 100644 --- a/pkg/git/libgit2/transport.go +++ b/pkg/git/libgit2/transport.go @@ -266,7 +266,7 @@ func (k knownKey) matches(host string, hostkey git2go.HostkeyCertificate) bool { return false } hasher.Write(k.key.Marshal()) - return bytes.Compare(hasher.Sum(nil), fingerprint) == 0 + return bytes.Equal(hasher.Sum(nil), fingerprint) } func containsHost(hosts []string, host string) bool { diff --git a/pkg/sourceignore/sourceignore.go b/pkg/sourceignore/sourceignore.go index f4d98e471..38327d38a 100644 --- a/pkg/sourceignore/sourceignore.go +++ b/pkg/sourceignore/sourceignore.go @@ -100,7 +100,7 @@ func ReadIgnoreFile(path string, domain []string) ([]gitignore.Pattern, error) { return ps, nil } -// LoadIgnorePatterns recursively loads the the IgnoreFile patterns found +// LoadIgnorePatterns recursively loads the IgnoreFile patterns found // in the directory. func LoadIgnorePatterns(dir string, domain []string) ([]gitignore.Pattern, error) { ps, err := ReadIgnoreFile(filepath.Join(dir, IgnoreFile), domain) @@ -114,7 +114,9 @@ func LoadIgnorePatterns(dir string, domain []string) ([]gitignore.Pattern, error for _, fi := range fis { if fi.IsDir() && fi.Name() != ".git" { var subps []gitignore.Pattern - subps, err = LoadIgnorePatterns(filepath.Join(dir, fi.Name()), append(domain, fi.Name())) + if subps, err = LoadIgnorePatterns(filepath.Join(dir, fi.Name()), append(domain, fi.Name())); err != nil { + return nil, err + } if len(subps) > 0 { ps = append(ps, subps...) }