Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
sgalsaleh committed Nov 5, 2024
1 parent f583a9c commit b41515b
Show file tree
Hide file tree
Showing 8 changed files with 237 additions and 165 deletions.
2 changes: 1 addition & 1 deletion e2e/playwright/tests/@change-license/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ test('change license', async ({ page }) => {
await login(page);
await uploadLicense(page, expect, "community-license.yaml");
await expect(page.locator('#app')).toContainText('Change License', { timeout: 10000 });
await expect(page.locator('#app')).toContainText('Currently deployed version', { timeout: 15000 });
await expect(page.locator('#app')).toContainText('Ready', { timeout: 30000 });
await expect(page.locator('#app')).toContainText('Currently deployed version');
await page.getByRole('link', { name: 'License', exact: true }).click();
await expect(page.locator('#app')).toContainText('change-license-community', { timeout: 10000 });
await expect(page.locator('#app')).toContainText('Community license');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ test('multi app backup and restore', async ({ page }) => {
await login(page);
await uploadLicense(page, expect, "app1-license.yaml");
await expect(page.locator('#app')).toContainText('Multi App Backup and Restore 1', { timeout: 10000 });
await expect(page.locator('#app')).toContainText('Currently deployed version', { timeout: 15000 });
await expect(page.locator('#app')).toContainText('Ready', { timeout: 30000 });
await expect(page.locator('#app')).toContainText('Currently deployed version');
await page.locator('div').filter({ hasText: /^Change passwordAdd new applicationLog out$/ }).getByRole('img').click();
await page.getByText('Add new application').click();
await uploadLicense(page, expect, "app2-license.yaml");
await expect(page.locator('#app')).toContainText('Multi App Backup and Restore 2', { timeout: 10000 });
await expect(page.locator('#app')).toContainText('Currently deployed version', { timeout: 15000 });
await expect(page.locator('#app')).toContainText('Ready', { timeout: 30000 });
await expect(page.locator('#app')).toContainText('Currently deployed version');
await page.locator('.NavItem').getByText('Snapshots', { exact: true }).click();
await page.getByRole('link', { name: 'Partial Snapshots' }).click({ timeout: 10000 });
await page.getByRole('button', { name: 'Start a snapshot' }).click({ timeout: 15000 });
Expand Down
4 changes: 2 additions & 2 deletions e2e/playwright/tests/@multi-app-install/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ test('multi app install', async ({ page }) => {
await expect(page.locator('#app')).toContainText('Your cluster meets the recommended and required versions of Kubernetes');
await page.getByRole('button', { name: 'Deploy' }).click();
await expect(page.locator('#app')).toContainText('Multi App Install 1');
await expect(page.locator('#app')).toContainText('Currently deployed version', { timeout: 15000 });
await expect(page.locator('#app')).toContainText('Ready', { timeout: 30000 });
await expect(page.locator('#app')).toContainText('Currently deployed version');
await expect(page.locator('#app')).toContainText('0.1.3');
const app1Status = execSync(`kubectl kots get apps -n ${process.env.NAMESPACE} | grep mutli-app-install | awk '{print $2}'`).toString().trim();
expect(app1Status).toBe('ready');
Expand All @@ -27,8 +27,8 @@ test('multi app install', async ({ page }) => {
await expect(page.locator('#app')).toContainText('Your cluster meets the recommended and required versions of Kubernetes');
await page.getByRole('button', { name: 'Deploy' }).click();
await expect(page.locator('#app')).toContainText('Multi App Install 2');
await expect(page.locator('#app')).toContainText('Currently deployed version', { timeout: 15000 });
await expect(page.locator('#app')).toContainText('Ready', { timeout: 30000 });
await expect(page.locator('#app')).toContainText('Currently deployed version');
await expect(page.locator('#app')).toContainText('2.1.2');
const app2Status = execSync(`kubectl kots get apps -n ${process.env.NAMESPACE} | grep multi-app-install-2 | awk '{print $2}'`).toString().trim();
expect(app2Status).toBe('ready');
Expand Down
2 changes: 1 addition & 1 deletion e2e/playwright/tests/@no-required-config/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ test('no required config', async ({ page }) => {
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.locator('#app')).toContainText('Ready', { timeout: 30000 });
await page.getByRole('link', { name: 'Version history' }).click();
await expect(page.locator('#app')).toContainText('Currently deployed version');
await expect(page.locator('#app')).toContainText('Currently deployed version', { timeout: 15000 });
});
32 changes: 29 additions & 3 deletions pkg/kotsutil/kots.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
kotsscheme "github.com/replicatedhq/kotskinds/client/kotsclientset/scheme"
kurlscheme "github.com/replicatedhq/kurlkinds/client/kurlclientset/scheme"
kurlv1beta1 "github.com/replicatedhq/kurlkinds/pkg/apis/cluster/v1beta1"
troubleshootanalyze "github.com/replicatedhq/troubleshoot/pkg/analyze"
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
troubleshootscheme "github.com/replicatedhq/troubleshoot/pkg/client/troubleshootclientset/scheme"
"github.com/replicatedhq/troubleshoot/pkg/collect"
Expand Down Expand Up @@ -89,7 +90,8 @@ type KotsKinds struct {
V1Beta2HelmCharts *kotsv1beta2.HelmChartList

Collector *troubleshootv1beta2.Collector
Preflight *troubleshootv1beta2.Preflight
Preflight *troubleshootv1beta2.Preflight // TODO: consolidate this with Preflights
Preflights []troubleshootv1beta2.Preflight
Analyzer *troubleshootv1beta2.Analyzer
SupportBundle *troubleshootv1beta2.SupportBundle
Redactor *troubleshootv1beta2.Redactor
Expand Down Expand Up @@ -235,10 +237,28 @@ func (k *KotsKinds) IsConfigurable() bool {
}

func (k *KotsKinds) HasPreflights() bool {
if k == nil || k.Preflight == nil {
if k == nil {
return false
}
return len(k.Preflight.Spec.Analyzers) > 0
numAnalyzers := 0
for _, p := range k.AllPreflights() {
for _, a := range p.Spec.Analyzers {
exclude := troubleshootanalyze.GetExcludeFlag(a).BoolOrDefaultFalse()
if !exclude {
numAnalyzers += 1
}
}
}
return numAnalyzers > 0
}

func (k *KotsKinds) AllPreflights() []troubleshootv1beta2.Preflight {
all := []troubleshootv1beta2.Preflight{}
if k.Preflight != nil {
all = append(all, *k.Preflight)
}
all = append(all, k.Preflights...)
return all
}

func (o KotsKinds) Marshal(g string, v string, k string) (string, error) {
Expand Down Expand Up @@ -725,6 +745,12 @@ func LoadKotsKindsWithOpts(archive string, opts LoadKotsKindsOptions) (*KotsKind
return nil, errors.Wrap(err, "failed to walk upstream dir")
}

tsKinds, err := LoadTSKindsFromPath(fromDir)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to load troubleshoot kinds from: %s", fromDir))
}
kotsKinds.Preflights = append(kotsKinds.Preflights, tsKinds.PreflightsV1Beta2...)

return &kotsKinds, nil
}

Expand Down
123 changes: 122 additions & 1 deletion pkg/kotsutil/kots_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
kotsv1beta2 "github.com/replicatedhq/kotskinds/apis/kots/v1beta2"
kurlv1beta1 "github.com/replicatedhq/kurlkinds/pkg/apis/cluster/v1beta1"
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
"github.com/replicatedhq/troubleshoot/pkg/multitype"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
Expand Down Expand Up @@ -567,7 +568,32 @@ var _ = Describe("Kots", func() {
Expect(preflightResult).To(BeFalse())
})

It("returns true when there are more than one analyzers defined in the preflight spec", func() {
It("returns false when the client-side object does not have analyzers", func() {
kotsKind := &kotsutil.KotsKinds{
Preflight: &troubleshootv1beta2.Preflight{
Spec: troubleshootv1beta2.PreflightSpec{
Analyzers: []*troubleshootv1beta2.Analyze{},
},
},
Preflights: []troubleshootv1beta2.Preflight{
{
Spec: troubleshootv1beta2.PreflightSpec{
Analyzers: []*troubleshootv1beta2.Analyze{},
},
},
{
Spec: troubleshootv1beta2.PreflightSpec{
Analyzers: []*troubleshootv1beta2.Analyze{},
},
},
},
}
preflightResult := kotsKind.HasPreflights()
Expect(preflightResult).To(BeFalse())
})

It("returns true when there are analyzers defined in the preflight spec", func() {
// single spec
kotsKind := &kotsutil.KotsKinds{
Preflight: &troubleshootv1beta2.Preflight{
Spec: troubleshootv1beta2.PreflightSpec{
Expand All @@ -579,6 +605,101 @@ var _ = Describe("Kots", func() {
}
preflightResult := kotsKind.HasPreflights()
Expect(preflightResult).To(BeTrue())

// multiple specs
kotsKind = &kotsutil.KotsKinds{
Preflights: []troubleshootv1beta2.Preflight{
{
Spec: troubleshootv1beta2.PreflightSpec{
Analyzers: []*troubleshootv1beta2.Analyze{
{},
},
},
},
{
Spec: troubleshootv1beta2.PreflightSpec{},
},
},
}
preflightResult = kotsKind.HasPreflights()
Expect(preflightResult).To(BeTrue())
})

It("returns false when all analyzers are excluded", func() {
kotsKind := &kotsutil.KotsKinds{
Preflight: &troubleshootv1beta2.Preflight{
Spec: troubleshootv1beta2.PreflightSpec{
Analyzers: []*troubleshootv1beta2.Analyze{
{
ClusterVersion: &troubleshootv1beta2.ClusterVersion{
AnalyzeMeta: troubleshootv1beta2.AnalyzeMeta{
Exclude: multitype.FromBool(true),
},
},
},
},
},
},
Preflights: []troubleshootv1beta2.Preflight{
{
Spec: troubleshootv1beta2.PreflightSpec{
Analyzers: []*troubleshootv1beta2.Analyze{
{
ClusterVersion: &troubleshootv1beta2.ClusterVersion{
AnalyzeMeta: troubleshootv1beta2.AnalyzeMeta{
Exclude: multitype.FromBool(true),
},
},
},
{
ClusterVersion: &troubleshootv1beta2.ClusterVersion{
AnalyzeMeta: troubleshootv1beta2.AnalyzeMeta{
Exclude: multitype.FromBool(true),
},
},
},
},
},
},
},
}
preflightResult := kotsKind.HasPreflights()
Expect(preflightResult).To(BeFalse())
})

It("returns true when a single analyzer is not excluded", func() {
kotsKind := &kotsutil.KotsKinds{
Preflight: &troubleshootv1beta2.Preflight{
Spec: troubleshootv1beta2.PreflightSpec{
Analyzers: []*troubleshootv1beta2.Analyze{
{
ClusterVersion: &troubleshootv1beta2.ClusterVersion{
AnalyzeMeta: troubleshootv1beta2.AnalyzeMeta{
Exclude: multitype.FromBool(true),
},
},
},
},
},
},
Preflights: []troubleshootv1beta2.Preflight{
{
Spec: troubleshootv1beta2.PreflightSpec{
Analyzers: []*troubleshootv1beta2.Analyze{
{
ClusterVersion: &troubleshootv1beta2.ClusterVersion{
AnalyzeMeta: troubleshootv1beta2.AnalyzeMeta{
Exclude: multitype.FromBool(false),
},
},
},
},
},
},
},
}
preflightResult := kotsKind.HasPreflights()
Expect(preflightResult).To(BeTrue())
})
})

Expand Down
Loading

0 comments on commit b41515b

Please sign in to comment.