Skip to content

Commit

Permalink
feat: Add multi cluster support
Browse files Browse the repository at this point in the history
  • Loading branch information
leoliu committed Apr 22, 2020
1 parent aeb3873 commit b23f831
Show file tree
Hide file tree
Showing 173 changed files with 4,705 additions and 6,216 deletions.
4 changes: 2 additions & 2 deletions cypress/integration/clusters/accounts/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ describe('The Accounts Page', function() {
// delete old data
cy.request({
method: 'GET',
url: `/kapis/iam.kubesphere.io/v1alpha2/users/${account.name}`,
url: `/apis/iam.kubesphere.io/v1alpha2/users/${account.name}`,
headers: { 'x-check-exist': true },
}).then(resp => {
if (resp.body.exist) {
cy.request(
'DELETE',
`/kapis/iam.kubesphere.io/v1alpha2/users/${account.name}`
`/apis/iam.kubesphere.io/v1alpha2/users/${account.name}`
)
}
})
Expand Down
4 changes: 2 additions & 2 deletions cypress/integration/workspaces/members.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ describe('The Workspace Overview Page', function() {
cy.login('admin')
cy.request({
method: 'GET',
url: `/kapis/iam.kubesphere.io/v1alpha2/workspaces/${workspace}/members/${testUser}`,
url: `/apis/iam.kubesphere.io/v1alpha2/workspaces/${workspace}/members/${testUser}`,
headers: { 'x-check-exist': true },
}).then(resp => {
if (resp.body.exist) {
cy.request({
method: 'DELETE',
url: `/kapis/iam.kubesphere.io/v1alpha2/workspaces/${workspace}/members/${testUser}`,
url: `/apis/iam.kubesphere.io/v1alpha2/workspaces/${workspace}/members/${testUser}`,
})
}
})
Expand Down
2 changes: 1 addition & 1 deletion scripts/webpack.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = {
__filename: false, // and __filename return blank or /
},
optimization: {
minimize: true,
minimize: false,
},
externals: { hiredis: 'hiredis' }, // Need this to avoid error when working with Express
module: {
Expand Down
2 changes: 1 addition & 1 deletion server/components/boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module.exports = function(app) {
ctx.url
)
) {
ctx.redirect(`http://localhost:8001${ctx.url}`)
ctx.redirect(`http://${ctx.hostname}:8001${ctx.url}`)
} else {
await next()
}
Expand Down
5 changes: 5 additions & 0 deletions server/components/wsProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,10 @@ module.exports = function(app) {
app.server.on('upgrade', (req, socket, head) => {
const target = serverConfig.apiServer.wsUrl
wsProxy.ws(req, socket, head, { target })

wsProxy.on('proxyReqWs', (proxyReq, _req) => {
const token = _req.headers.cookie.match(/token=(.*);/)[1]
proxyReq.setHeader('Authorization', `Bearer ${token}`)
})
})
}
1 change: 1 addition & 0 deletions server/controllers/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const renderView = async ctx => {
ksConfig: JSON.stringify(ksConfig),
user: JSON.stringify(user),
version: getFileVersion,
hostname: ctx.hostname,
})
} catch (err) {
ctx.app.emit('error', err)
Expand Down
2 changes: 1 addition & 1 deletion server/libs/request.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with KubeSphere Console. If not, see <https://www.gnu.org/licenses/>.
*/

const fetch = require('node-fetch')
const fetch = require('node-fetch').default
const merge = require('lodash/merge')
const qs = require('qs')

Expand Down
2 changes: 1 addition & 1 deletion server/libs/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const send_gateway_request = ({
headers = {},
...rest
}) => {
const options = { ...rest }
const options = { headers, ...rest }

if (token) {
options.headers = {
Expand Down
41 changes: 23 additions & 18 deletions server/services/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
*/

const { parse } = require('qs')
const get = require('lodash/get')
const isEmpty = require('lodash/isEmpty')
const jwtDecode = require('jwt-decode')

const { send_gateway_request } = require('../libs/request')

const { getServerConfig, formatRules, isAppsRoute } = require('../libs/utils')
const { getServerConfig, isAppsRoute } = require('../libs/utils')

const { client: clientConfig } = getServerConfig()

Expand All @@ -32,8 +33,7 @@ const login = async (data, headers) => {
)
const resp = await send_gateway_request({
method: 'GET',
url:
'/oauth/authorize?client_id=kubesphere-console-client&response_type=token',
url: '/oauth/authorize?client_id=default&response_type=token',
headers: {
...headers,
Authorization: `Basic ${base64Str}`,
Expand All @@ -42,7 +42,7 @@ const login = async (data, headers) => {
})

const { access_token } = parse(
resp.headers.get('location').replace(/http.*\?/, '')
resp.headers.get('location').replace(/http.*(\?|#)/, '')
)

if (!access_token) {
Expand All @@ -57,7 +57,7 @@ const login = async (data, headers) => {
const oAuthLogin = async params => {
const resp = await send_gateway_request({
method: 'POST',
url: `/kapis/iam.kubesphere.io/v1alpha2/login/oauth/${params.state}`,
url: `/apis/iam.kubesphere.io/v1alpha2/login/oauth/${params.state}`,
params,
})

Expand All @@ -75,12 +75,17 @@ const getUserDetail = async (username, token) => {

const resp = await send_gateway_request({
method: 'GET',
url: `/kapis/iam.kubesphere.io/v1alpha2/users/${username}`,
url: `/apis/iam.kubesphere.io/v1alpha2/users/${username}`,
token,
})

if (resp) {
user = resp
user = {
username: get(resp, 'metadata.name'),
email: get(resp, 'spec.email'),
groups: get(resp, 'groups', []),
cluster_rules: get(resp, 'groups', {}),
}
} else {
throw new Error(resp)
}
Expand All @@ -91,7 +96,7 @@ const getUserDetail = async (username, token) => {
const formatUserDetail = user => {
user.groups = user.groups || []

user.cluster_rules = formatRules(user.cluster_rules)
// user.cluster_rules = formatRules(user.cluster_rules)

return user
}
Expand All @@ -101,7 +106,7 @@ const getKSConfig = async token => {
try {
resp = await send_gateway_request({
method: 'GET',
url: `/kapis/v1alpha1/configz`,
url: `/kapis/config.kubesphere.io/v1alpha2/configs/configz`,
token,
})
} catch (error) {
Expand Down Expand Up @@ -140,15 +145,15 @@ const getCurrentUser = async ctx => {
}

const getOAuthInfo = async () => {
let resp = []
try {
resp = await send_gateway_request({
method: 'GET',
url: `/kapis/iam.kubesphere.io/v1alpha2/oauth/configs`,
})
} catch (error) {
console.error(error)
}
const resp = []
// try {
// resp = await send_gateway_request({
// method: 'GET',
// url: `/apis/iam.kubesphere.io/v1alpha2/oauth/configs`,
// })
// } catch (error) {
// console.error(error)
// }

const servers = []
if (!isEmpty(resp)) {
Expand Down
2 changes: 1 addition & 1 deletion server/views/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% var bundlePrefix = isDev ? '//localhost:8001' : '/dist' %>
<% var bundlePrefix = isDev ? '//' + hostname + ':8001' : '/dist' %>
<% var mainJS = bundlePrefix + '/main.js' %>
<% var vendorJS = bundlePrefix + '/vendor.js' %>
<% var legoJS = bundlePrefix + '/lego.js' %>
Expand Down
45 changes: 45 additions & 0 deletions src/assets/project-create.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/components/Base/Tag/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@
color: $green-color05;
background-color: $green-color01;
}

&.info {
color: $blue-color05;
background-color: $blue-color01;
}
}
4 changes: 2 additions & 2 deletions src/components/Cards/LimitRange/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ export default class DefaultResource extends React.Component {

componentDidUpdate(prevProps) {
if (prevProps.namespace !== this.props.namespace && this.props.namespace) {
this.store.fetchLimitRanges({ namespace: this.props.namespace })
this.store.fetchLimitRanges(this.props)
}
}

componentDidMount() {
if (this.props.namespace) {
this.store.fetchLimitRanges({ namespace: this.props.namespace })
this.store.fetchLimitRanges(this.props)
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/components/Cards/Pods/index.jsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/components/Cards/ProjectQuota/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ export default class ProjectQuota extends React.Component {

componentDidUpdate(prevProps) {
if (prevProps.namespace !== this.props.namespace && this.props.namespace) {
this.store.fetch({ namespace: this.props.namespace })
this.store.fetch(this.props)
}
}

componentDidMount() {
if (this.props.namespace) {
this.store.fetch({ namespace: this.props.namespace })
this.store.fetch(this.props)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/Forms/GrayRelease/Version/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ export default class Version extends ContainerSettings {
const namespace = get(this.formTemplate, 'metadata.namespace')

Promise.all([
this.configMapStore.fetchByK8s({ namespace }),
this.secretStore.fetchByK8s({ namespace }),
this.configMapStore.fetchListByK8s({ namespace }),
this.secretStore.fetchListByK8s({ namespace }),
]).then(([configMaps, secrets]) => {
this.setState({
configMaps,
Expand Down
4 changes: 2 additions & 2 deletions src/components/Forms/ImageBuilder/B2IForm/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default class S2IForm extends React.Component {
}

fetchData = async () => {
const results = await this.secretStore.fetchByK8s({
const results = await this.secretStore.fetchListByK8s({
namespace: this.namespace,
fieldSelector: `type=kubernetes.io/basic-auth`,
})
Expand All @@ -85,7 +85,7 @@ export default class S2IForm extends React.Component {
}

fetchImageSecrets = async () => {
const results = await this.secretStore.fetchByK8s({
const results = await this.secretStore.fetchListByK8s({
namespace: this.namespace,
fieldSelector: `type=kubernetes.io/dockerconfigjson`,
})
Expand Down
4 changes: 2 additions & 2 deletions src/components/Forms/ImageBuilder/S2IForm/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default class S2IForm extends React.Component {
}

fetchData = async () => {
const results = await this.secretStore.fetchByK8s({
const results = await this.secretStore.fetchListByK8s({
namespace: this.namespace,
fieldSelector: `type=kubernetes.io/basic-auth`,
})
Expand All @@ -94,7 +94,7 @@ export default class S2IForm extends React.Component {
}

fetchImageSecrets = async () => {
const results = await this.secretStore.fetchByK8s({
const results = await this.secretStore.fetchListByK8s({
namespace: this.namespace,
fieldSelector: `type=kubernetes.io/dockerconfigjson`,
})
Expand Down
8 changes: 4 additions & 4 deletions src/components/Forms/Service/BaseInfo/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,17 +203,17 @@ export default class ServiceBaseInfo extends React.Component {
</Column>
</Columns>
<Columns>
<Column>
{!this.props.namespace && (
{!this.props.namespace && (
<Column>
<Form.Item label={t('Project')} desc={t('PROJECT_DESC')}>
<ProjectSelect
name="metadata.namespace"
cluster={this.props.cluster}
defaultValue={this.namespace || 'default'}
/>
</Form.Item>
)}
</Column>
</Column>
)}
<Column>
<Form.Item label={t('Description')}>
<TextArea name="metadata.annotations['kubesphere.io/description']" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default class ContainerSetting extends React.Component {
Promise.all([
this.quotaStore.fetch({ namespace }),
this.projectStore.fetchLimitRanges({ namespace }),
this.secretStore.fetchByK8s({
this.secretStore.fetchListByK8s({
namespace: this.props.namespace,
fieldSelector: `type=kubernetes.io/dockerconfigjson`,
}),
Expand Down
4 changes: 2 additions & 2 deletions src/components/Forms/Service/ContainerSetting/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ export default class ContainerSetting extends React.Component {
const namespace = get(this.formTemplate, 'metadata.namespace')

Promise.all([
this.configMapStore.fetchByK8s({ namespace }),
this.secretStore.fetchByK8s({ namespace }),
this.configMapStore.fetchListByK8s({ namespace }),
this.secretStore.fetchListByK8s({ namespace }),
]).then(([configMaps, secrets]) => {
this.setState({ configMaps, secrets })
})
Expand Down
Loading

0 comments on commit b23f831

Please sign in to comment.