Skip to content

Commit

Permalink
Merge branch 'main' into update-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
djnakabaale committed Dec 5, 2023
2 parents 164013c + 909dcc2 commit 5e47205
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
15 changes: 13 additions & 2 deletions controllers/kokumetricsconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,8 +666,14 @@ func (r *MetricsConfigReconciler) setAuthAndUpload(ctx context.Context, cr *metr
return err
}

// only attempt upload when files are available to upload
if uploadFiles == nil {
doUpload := uploadFiles != nil
doSourceCheck := cr.Status.Source.LastSourceCheckTime.IsZero()

if !doUpload && !doSourceCheck {
// if there are no files and a time for source check, we do
// not need to proceed. This will enable source creation
// when the CR is first created.
log.Info("no files to upload and skipping source check")
return nil
}

Expand All @@ -684,6 +690,11 @@ func (r *MetricsConfigReconciler) setAuthAndUpload(ctx context.Context, cr *metr
// Check if source is defined and update the status to confirmed/created
checkSource(r, handler, cr)

if !doUpload {
// only attempt upload when files are available to upload
return nil
}

// attempt upload
if err := r.uploadFiles(authConfig, cr, dirCfg, packager, uploadFiles); err != nil {
log.Info("failed to upload files", "error", err)
Expand Down
7 changes: 6 additions & 1 deletion controllers/kokumetricsconfig_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,6 @@ var _ = Describe("MetricsConfigController - CRD Handling", Ordered, func() {
When("cluster is connected", func() {
BeforeEach(func() {
checkPVC = true
Expect(setup()).Should(Succeed())
})
It("default CR works fine", func() {
instCopy.Spec.APIURL = validTS.URL
Expand Down Expand Up @@ -742,6 +741,7 @@ var _ = Describe("MetricsConfigController - CRD Handling", Ordered, func() {
}, timeout, interval).Should(BeTrue())

Expect(fetched.Status.Source.SourceName).To(Equal(sourceName))
Expect(fetched.Status.Source.LastSourceCheckTime.IsZero()).To(BeFalse())
})
It("should reflect source error when attempting to create source", func() {
instCopy.Spec.Source.SourceName = sourceName
Expand Down Expand Up @@ -893,6 +893,7 @@ var _ = Describe("MetricsConfigController - CRD Handling", Ordered, func() {
Expect(fetched.Status.ClusterID).To(Equal(""))
})
It("should attempt upload due to tar.gz being present", func() {
Expect(setup()).Should(Succeed())
createObject(ctx, instCopy)

fetched := &metricscfgv1beta1.MetricsConfig{}
Expand All @@ -906,6 +907,7 @@ var _ = Describe("MetricsConfigController - CRD Handling", Ordered, func() {
Expect(fetched.Status.Upload.LastUploadStatus).ToNot(BeNil())
})
It("tar.gz being present - upload attempt should 'succeed'", func() {
Expect(setup()).Should(Succeed())
instCopy.Spec.APIURL = validTS.URL
createObject(ctx, instCopy)

Expand All @@ -922,6 +924,7 @@ var _ = Describe("MetricsConfigController - CRD Handling", Ordered, func() {
Expect(fetched.Status.Upload.LastSuccessfulUploadTime.IsZero()).To(BeFalse())
})
It("tar.gz being present - basic auth upload attempt should fail because of bad auth", func() {
Expect(setup()).Should(Succeed())
hourAgo := metav1.Now().Time.Add(-time.Hour)

previousValidation = &previousAuthValidation{
Expand Down Expand Up @@ -953,6 +956,7 @@ var _ = Describe("MetricsConfigController - CRD Handling", Ordered, func() {
Expect(fetched.Status.Upload.LastUploadStatus).To(ContainSubstring("401"))
})
It("should check the last upload time in the upload status", func() {
Expect(setup()).Should(Succeed())
createObject(ctx, instCopy)

fetched := &metricscfgv1beta1.MetricsConfig{}
Expand All @@ -975,6 +979,7 @@ var _ = Describe("MetricsConfigController - CRD Handling", Ordered, func() {
}, timeout, interval).Should(BeFalse())
})
It("old default url - should update status to new default url", func() {
Expect(setup()).Should(Succeed())
instCopy.Spec.APIURL = metricscfgv1beta1.OldDefaultAPIURL
instCopy.Spec.Source.SourceName = "OLD-API-URL"
createObject(ctx, instCopy)
Expand Down

0 comments on commit 5e47205

Please sign in to comment.