Skip to content
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

Ignore old default API URL in Spec with new default API URL in Status #194

Merged
merged 1 commit into from
Jun 23, 2023
Merged
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
24 changes: 24 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,27 @@ jobs:
flags: unittests
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true

sonarcloud:
name: SonarCloud
needs: [golangci-lint,unit-tests]
runs-on: ubuntu-20.04
steps:

- name: Checkout
# this checkout is required for the coverage report. If we don't do this, then
# the uploaded report is invalid and codecov doesn't know how to process it.
uses: actions/checkout@v3.1.0
with:
fetch-depth: 0

- name: Download coverage result from unit-tests
uses: actions/download-artifact@v3
with:
name: coverage

- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
3 changes: 3 additions & 0 deletions api/v1beta1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ const (

// DefaultPrometheusContextTimeout The default context timeout for Prometheus Queries
DefaultPrometheusContextTimeout int64 = 120

// OldDefaultAPIURL The old default ingress path.
OldDefaultAPIURL string = "https://cloud.redhat.com"
)
7 changes: 6 additions & 1 deletion controllers/kokumetricsconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ func StringReflectSpec(r *MetricsConfigReconciler, cr *metricscfgv1beta1.Metrics
// ReflectSpec Determine if the Status item reflects the Spec item if not empty, otherwise set a default value if applicable.
func ReflectSpec(r *MetricsConfigReconciler, cr *metricscfgv1beta1.MetricsConfig) {

StringReflectSpec(r, cr, &cr.Spec.APIURL, &cr.Status.APIURL, metricscfgv1beta1.DefaultAPIURL)
if cr.Spec.APIURL == metricscfgv1beta1.OldDefaultAPIURL {
defaultAPIURL := metricscfgv1beta1.DefaultAPIURL
StringReflectSpec(r, cr, &defaultAPIURL, &cr.Status.APIURL, metricscfgv1beta1.DefaultAPIURL)
} else {
StringReflectSpec(r, cr, &cr.Spec.APIURL, &cr.Status.APIURL, metricscfgv1beta1.DefaultAPIURL)
}
StringReflectSpec(r, cr, &cr.Spec.Authentication.AuthenticationSecretName, &cr.Status.Authentication.AuthenticationSecretName, "")

if !reflect.DeepEqual(cr.Spec.Authentication.AuthType, cr.Status.Authentication.AuthType) {
Expand Down
20 changes: 20 additions & 0 deletions controllers/kokumetricsconfig_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,26 @@ var _ = Describe("MetricsConfigController - CRD Handling", func() {
return refetched.Status.Upload.LastSuccessfulUploadTime.IsZero()
}, 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)

fetched := &metricscfgv1beta1.MetricsConfig{}

Eventually(func() bool {
_ = k8sClient.Get(ctx, types.NamespacedName{Name: instCopy.Name, Namespace: namespace}, fetched)
return fetched.Status.Authentication.AuthenticationCredentialsFound != nil
}, timeout, interval).Should(BeTrue())

Expect(fetched.Status.Authentication.AuthType).To(Equal(metricscfgv1beta1.DefaultAuthenticationType))
Expect(*fetched.Status.Authentication.AuthenticationCredentialsFound).To(BeTrue())
Expect(fetched.Status.Authentication.ValidBasicAuth).To(BeNil())
Expect(fetched.Status.APIURL).To(Equal(metricscfgv1beta1.DefaultAPIURL))
Expect(fetched.Status.ClusterID).To(Equal(clusterID))
})
})
})

Expand Down
4 changes: 3 additions & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ sonar.test.exclusions=**/vendor/**

sonar.go.golint.reportPaths=golint-report.out
sonar.go.tests.reportPaths=report.json
sonar.go.coverage.reportPaths=coverage.out
sonar.go.coverage.reportPaths=cover.out

sonar.cpd.exclusions=**/*_test.go,**/vendor/**,**/test_files/**,**/mocks/*.go,**/scripts/*.py,**/testutils/**