Skip to content

Commit

Permalink
Merge pull request #13372 from torchiaf/7824-expose-polling
Browse files Browse the repository at this point in the history
Fleet: expose Polling Interval for GitRepos
  • Loading branch information
torchiaf authored Feb 21, 2025
2 parents 7e37210 + 166fbae commit 8a0e784
Show file tree
Hide file tree
Showing 8 changed files with 302 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"@aws-sdk/client-kms": "3.8.1",
"@novnc/novnc": "1.2.0",
"@popperjs/core": "2.11.8",
"@rancher/icons": "2.0.29",
"@rancher/icons": "2.0.32",
"ansi_up": "5.0.0",
"axios": "0.21.4",
"axios-retry": "3.1.9",
Expand Down
8 changes: 8 additions & 0 deletions shell/assets/translations/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2479,6 +2479,14 @@ fleet:
keepResourcesTooltip: When enabled, resources will be kept when deleting a GitRepo or Bundle - only Helm release secrets will be deleted.
correctDrift: Enable Self-Healing
correctDriftTooltip: When enabled, Fleet will ensure that the cluster resources are kept in sync with the git repository. All resource changes made on the cluster will be lost.
polling:
label: Polling
enable: Enable Polling
pollingInterval:
label: Polling Interval
tooltip: Polling Interval is the time between a push to the Repository and Fleet's reaction to it.
webhookWarning: Warning, a webhook is configured in Rancher to reconcile Git updates and GitRepo resources. The Polling Interval will automatically be adjusted to 1 hour.
minimumValuewarning: Warning, the recommended minimum Polling Interval is 15 seconds. To avoid performance issues with GitRepos that contain a large amount of resources please consider increasing this value.
add:
steps:
repoInfo:
Expand Down
2 changes: 1 addition & 1 deletion shell/detail/fleet.cattle.io.gitrepo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default {
},
computed: {
gitRepoHasClusters() {
return this.value.status.desiredReadyClusters;
return this.value.status?.desiredReadyClusters;
},
clusterSchema() {
return this.$store.getters['management/schemaFor'](FLEET.CLUSTER);
Expand Down
163 changes: 149 additions & 14 deletions shell/edit/__tests__/fleet.cattle.io.gitrepo.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import { mount } from '@vue/test-utils';
import { _CREATE, _EDIT } from '@shell/config/query-params';
import GitRepo from '@shell/edit/fleet.cattle.io.gitrepo.vue';

describe('view: fleet.cattle.io.gitrepo should', () => {
const values = {
metadata: { namespace: 'test' },
spec: {
template: {},
correctDrift: { enabled: false },
},
targetInfo: { mode: 'all' },
};

describe.each([
_CREATE,
_EDIT
])('view: fleet.cattle.io.gitrepo, mode: %p - should', (mode) => {
const mockStore = {
dispatch: jest.fn(),
getters: {
Expand All @@ -25,35 +38,32 @@ describe('view: fleet.cattle.io.gitrepo should', () => {
}
},
};
const values = {
metadata: { namespace: 'test' }, spec: { template: {}, correctDrift: { enabled: false } }, targetInfo: { mode: 'all' },
};
const wrapper = mount(GitRepo, {
props: { value: values },
props: { value: values, mode },
global: { mocks }
});

it('should have self-healing checkbox and tooltip', () => {
const correctDriftCheckbox = wrapper.find('[data-testid="GitRepo-correctDrift-checkbox"]');
const tooltip = wrapper.find('[data-testid="GitRepo-correctDrift-checkbox"]');
it('have self-healing checkbox and tooltip', () => {
const correctDriftCheckbox = wrapper.find('[data-testid="gitRepo-correctDrift-checkbox"]');
const tooltip = wrapper.find('[data-testid="gitRepo-correctDrift-checkbox"]');

expect(tooltip.element.classList).toContain('v-popper--has-tooltip');
expect(correctDriftCheckbox.exists()).toBeTruthy();
expect(correctDriftCheckbox.attributes().value).toBeFalsy();
});

it('should have keep-resources checkbox and tooltip', () => {
const correctDriftCheckbox = wrapper.find('[data-testid="GitRepo-keepResources-checkbox"]');
const tooltip = wrapper.find('[data-testid="GitRepo-keepResources-checkbox"]');
it('have keep-resources checkbox and tooltip', () => {
const correctDriftCheckbox = wrapper.find('[data-testid="gitRepo-keepResources-checkbox"]');
const tooltip = wrapper.find('[data-testid="gitRepo-keepResources-checkbox"]');

expect(tooltip.element.classList).toContain('v-popper--has-tooltip');
expect(correctDriftCheckbox.exists()).toBeTruthy();
expect(correctDriftCheckbox.attributes().value).toBeFalsy();
});

it('should enable drift if self-healing is checked', async() => {
const correctDriftCheckbox = wrapper.findComponent('[data-testid="GitRepo-correctDrift-checkbox"]');
const correctDriftContainer = wrapper.find('[data-testid="GitRepo-correctDrift-checkbox"] .checkbox-container');
it('enable drift if self-healing is checked', async() => {
const correctDriftCheckbox = wrapper.findComponent('[data-testid="gitRepo-correctDrift-checkbox"]');
const correctDriftContainer = wrapper.find('[data-testid="gitRepo-correctDrift-checkbox"] .checkbox-container');

expect(correctDriftContainer.exists()).toBeTruthy();

Expand All @@ -63,4 +73,129 @@ describe('view: fleet.cattle.io.gitrepo should', () => {
expect(correctDriftCheckbox.emitted('update:value')![0][0]).toBe(true);
expect(correctDriftCheckbox.props().value).toBeTruthy();
});

it.each([
['show Polling Interval and warnings', 'enabled', undefined, true],
['show Polling Interval and warnings', 'enabled', false, true],
['hide Polling Interval and warnings', 'disabled', true, false],
])('show Enable Polling checkbox and %p if %p, with spec.disablePolling: %p', (
descr1,
descr2,
disablePolling,
enabled
) => {
const wrapper = mount(GitRepo, {
props: {
value: {
...values,
spec: {
disablePolling,
pollingInterval: 10
},
status: { webhookCommit: 'sha' },
},
realMode: mode
},
global: { mocks },
});

const pollingCheckbox = wrapper.findComponent('[data-testid="gitRepo-enablePolling-checkbox"]') as any;
const pollingIntervalInput = wrapper.find('[data-testid="gitRepo-pollingInterval-input"]');
const pollingIntervalMinimumValueWarning = wrapper.find('[data-testid="gitRepo-pollingInterval-minimumValueWarning"]');
const pollingIntervalWebhookWarning = wrapper.find('[data-testid="gitRepo-pollingInterval-webhookWarning"]');

expect(pollingIntervalMinimumValueWarning.exists()).toBe(enabled);
expect(pollingIntervalWebhookWarning.exists()).toBe(enabled);
expect(pollingCheckbox.exists()).toBeTruthy();
expect(pollingCheckbox.vm.value).toBe(enabled);
expect(pollingIntervalInput.exists()).toBe(enabled);
});

const defaultPollingInterval = mode === _CREATE ? '60' : '15';

it.each([
['null', `default ${ defaultPollingInterval } seconds`, null, defaultPollingInterval],
['0', `default ${ defaultPollingInterval } seconds`, 0, defaultPollingInterval],
['1', 'custom 1 second', 1, '1'],
['60', 'custom 60 seconds', 60, '60'],
['15', 'custom 15 seconds', 15, '15'],
])('show Polling Interval input with source: %p, value: %p', async(
descr1,
descr2,
pollingInterval,
unitValue,
) => {
const wrapper = mount(GitRepo, {
props: {
value: {
...values,
spec: { pollingInterval }
},
realMode: mode
},
global: { mocks },
});

const pollingIntervalInput = wrapper.find('[data-testid="gitRepo-pollingInterval-input"]').element as any;

expect(pollingIntervalInput).toBeDefined();
expect(pollingIntervalInput.value).toBe(unitValue);
});

it.each([
['hide', 'source: null, value: equal to 60', null, false],
['hide', 'source: 0, value: equal to 60', 0, false],
['hide', 'source: 15, value: equal to 15', 15, false],
['hide', 'source: 60, value: equal to 60', 60, false],
['hide', 'source: 16, value: higher than 15', 16, false],
['show', 'source: 1, value: lower than 15', 1, true],
])('%p Polling Interval warning if %p', async(
descr1,
descr2,
pollingInterval,
visible,
) => {
const wrapper = mount(GitRepo, {
props: {
value: {
...values,
spec: { pollingInterval }
},
realMode: mode
},
global: { mocks },
});

const pollingIntervalMinimumValueWarning = wrapper.find('[data-testid="gitRepo-pollingInterval-minimumValueWarning"]');

expect(pollingIntervalMinimumValueWarning.exists()).toBe(visible);
});

it.each([
['hide', 'disabled', null, false],
['hide', 'disabled', false, false],
['hide', 'disabled', '', false],
['show', 'enabled', 'sha', true],
])('%p Webhook configured warning if webhook is %p', (
descr1,
descr2,
webhookCommit,
visible
) => {
const wrapper = mount(GitRepo, {
props: {
value: {
...values,
spec: { pollingInterval: 60 },
status: { webhookCommit },
},
realMode: mode
},
global: { mocks },
});

const pollingIntervalWebhookWarning = wrapper.find('[data-testid="gitRepo-pollingInterval-webhookWarning"]');

expect(pollingIntervalWebhookWarning.exists()).toBe(visible);
});
});
Loading

0 comments on commit 8a0e784

Please sign in to comment.