Skip to content

Commit

Permalink
fix: GetInstalledDashboard should support nil Chart
Browse files Browse the repository at this point in the history
  • Loading branch information
erikgb committed Dec 9, 2024
1 parent 379395c commit 6864d6b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 42 deletions.
12 changes: 3 additions & 9 deletions pkg/run/install/install_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,9 @@ func GetInstalledDashboard(ctx context.Context, kubeClient client.Client, namesp
dashboardName := ""

for _, helmRelease := range helmReleaseList.Items {
chart := helmRelease.Spec.Chart

if shouldDetectEnterpriseDashboard && chart != nil && chart.Spec.Chart == enterpriseDashboardHelmChartName &&
chart.Spec.SourceRef.Name == enterpriseDashboardHelmRepositoryName {
return DashboardTypeEnterprise, helmRelease.Name, nil
}

if shouldDetectOSSDashboard && chart == nil {
return DashboardTypeOSS, dashboardName, nil
// TODO(Flux 2.4 migration): We might want to also check the new ChartRef sibling field.
if helmRelease.Spec.Chart == nil {
continue
}

chartSpec := helmRelease.Spec.Chart.Spec
Expand Down
66 changes: 33 additions & 33 deletions pkg/run/install/install_dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,51 +194,51 @@ var _ = Describe("InstallDashboard", func() {

var _ = Describe("GetInstalledDashboard", func() {
var (
fakeContext context.Context
// fakeClientWithHelmReleases client.WithWatch
fakeClientWithDeployments client.WithWatch
blankClient client.WithWatch
errorClient ErroringFakeClient
fakeContext context.Context
fakeClientWithHelmReleases client.WithWatch
fakeClientWithDeployments client.WithWatch
blankClient client.WithWatch
errorClient ErroringFakeClient
)

BeforeEach(func() {
fakeContext = context.Background()
scheme, err := kube.CreateScheme()
Expect(err).NotTo(HaveOccurred())

// fakeClientWithHelmReleases = fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(helmReleaseFixtures...).Build()
fakeClientWithHelmReleases = fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(helmReleaseFixtures...).Build()
fakeClientWithDeployments = fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(deploymentFixtures...).Build()
blankClient = fake.NewClientBuilder().WithScheme(scheme).Build()
errorClient = ErroringFakeClient{}
})

// It("returns the oss dashboard type if the dashboard is installed with a helmrelease", func() {
// dashboardType, dashboardName, err := GetInstalledDashboard(fakeContext, fakeClientWithHelmReleases, testNamespace, map[DashboardType]bool{
// DashboardTypeOSS: true,
// })
// Expect(err).ToNot(HaveOccurred())
// Expect(dashboardType).To(Equal(DashboardTypeOSS))
// Expect(dashboardName).To(Equal("dashboard-2"))
// })
//
// It("returns the enterprise dashboard type if the dashboard is installed with a helmrelease", func() {
// dashboardType, dashboardName, err := GetInstalledDashboard(fakeContext, fakeClientWithHelmReleases, testNamespace, map[DashboardType]bool{
// DashboardTypeEnterprise: true,
// })
// Expect(err).ToNot(HaveOccurred())
// Expect(dashboardType).To(Equal(DashboardTypeEnterprise))
// Expect(dashboardName).To(Equal("dashboard-3"))
// })
//
// It("returns the enterprise dashboard type if both dashboards are installed with a helmrelease", func() {
// dashboardType, dashboardName, err := GetInstalledDashboard(fakeContext, fakeClientWithHelmReleases, testNamespace, map[DashboardType]bool{
// DashboardTypeOSS: true,
// DashboardTypeEnterprise: true,
// })
// Expect(err).ToNot(HaveOccurred())
// Expect(dashboardType).To(Equal(DashboardTypeEnterprise))
// Expect(dashboardName).To(Equal("dashboard-3"))
// })
It("returns the oss dashboard type if the dashboard is installed with a helmrelease", func() {
dashboardType, dashboardName, err := GetInstalledDashboard(fakeContext, fakeClientWithHelmReleases, testNamespace, map[DashboardType]bool{
DashboardTypeOSS: true,
})
Expect(err).ToNot(HaveOccurred())
Expect(dashboardType).To(Equal(DashboardTypeOSS))
Expect(dashboardName).To(Equal("dashboard-2"))
})

It("returns the enterprise dashboard type if the dashboard is installed with a helmrelease", func() {
dashboardType, dashboardName, err := GetInstalledDashboard(fakeContext, fakeClientWithHelmReleases, testNamespace, map[DashboardType]bool{
DashboardTypeEnterprise: true,
})
Expect(err).ToNot(HaveOccurred())
Expect(dashboardType).To(Equal(DashboardTypeEnterprise))
Expect(dashboardName).To(Equal("dashboard-3"))
})

It("returns the enterprise dashboard type if both dashboards are installed with a helmrelease", func() {
dashboardType, dashboardName, err := GetInstalledDashboard(fakeContext, fakeClientWithHelmReleases, testNamespace, map[DashboardType]bool{
DashboardTypeOSS: true,
DashboardTypeEnterprise: true,
})
Expect(err).ToNot(HaveOccurred())
Expect(dashboardType).To(Equal(DashboardTypeEnterprise))
Expect(dashboardName).To(Equal("dashboard-3"))
})

It("returns the oss dashboard type if the dashboard is installed with a deployment only", func() {
dashboardType, dashboardName, err := GetInstalledDashboard(fakeContext, fakeClientWithDeployments, testNamespace, map[DashboardType]bool{
Expand Down

0 comments on commit 6864d6b

Please sign in to comment.