Skip to content
This repository has been archived by the owner on Apr 28, 2020. It is now read-only.

Commit

Permalink
Update selector to get machine role (#379)
Browse files Browse the repository at this point in the history
* Update selector to get machine role

* rename getHostRole selector to getMachineRole
* move the getMachineRole to machine selectors
* fix the label to identify machine role

* add tests for machine selectors
  • Loading branch information
Jiri Tomasek authored and suomiy committed Apr 17, 2019
1 parent 67b1a22 commit 657b7a4
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/components/BareMetalHosts/BaremetalHostRole.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getHostRole } from '../../selectors';
import { getMachineRole } from '../../selectors';
import { DASHES } from '../../constants';

export const BaremetalHostRole = ({ machine }) => getHostRole(machine) || DASHES;
export const BaremetalHostRole = ({ machine }) => getMachineRole(machine) || DASHES;
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default [
machine: {
metadata: {
labels: {
'machine.openshift.io/cluster-api-machine-role': 'worker',
'sigs.k8s.io/cluster-api-machine-role': 'worker',
},
},
},
Expand Down
4 changes: 0 additions & 4 deletions src/selectors/host/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import { get } from 'lodash';

export const getOperationalStatus = host => get(host, 'status.operationalStatus');
export const getProvisioningState = host => get(host, 'status.provisioning.state');

export const getHostRole = hostMachine =>
get(hostMachine, ['metadata', 'labels', 'machine.openshift.io/cluster-api-machine-role']);

export const getHostMachineName = host => get(host, 'spec.machineRef.name');
export const getHostBmcAddress = host => get(host, 'spec.bmc.address');
export const getHostErrorMessage = host => get(host, 'status.errorMessage');
Expand Down
11 changes: 11 additions & 0 deletions src/selectors/machine/fixtures/selectors.fixture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default [
{
machine: {
metadata: {
labels: {
'sigs.k8s.io/cluster-api-machine-role': 'worker',
},
},
},
},
];
1 change: 1 addition & 0 deletions src/selectors/machine/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './combined';
export * from './selectors';
3 changes: 3 additions & 0 deletions src/selectors/machine/selectors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { get } from 'lodash';

export const getMachineRole = machine => get(machine, ['metadata', 'labels', 'sigs.k8s.io/cluster-api-machine-role']);
8 changes: 8 additions & 0 deletions src/selectors/machine/tests/selectors.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import fixtures from '../fixtures/selectors.fixture';
import { getMachineRole } from '../selectors';

describe('getMachineRole selector', () => {
it('returns machine role', () => {
expect(getMachineRole(fixtures[0].machine)).toEqual('worker');
});
});

0 comments on commit 657b7a4

Please sign in to comment.