Skip to content

Commit

Permalink
add missing ingress on DD
Browse files Browse the repository at this point in the history
  • Loading branch information
enrichman committed Nov 28, 2023
1 parent 57dfa6b commit 52e1597
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 46 deletions.
7 changes: 6 additions & 1 deletion ui/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,12 @@ function App() {
</Modal>
</div>

<Credentials enabled={hasKubernetes} credentials={credentials} onCredentialsChanged={setCredentials} installation={installation} />
<Credentials
enabled={hasKubernetes}
credentials={credentials}
onCredentialsChanged={setCredentials}
installation={installation}
domain={domain} />

<Box sx={{ width: '100%' }}>
<Typography variant="subtitle1" component="div" gutterBottom>
Expand Down
60 changes: 26 additions & 34 deletions ui/src/epinio/API.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,52 @@
export default function EpinioClient({
apiDomain,
credentials: {
username,
password
}
apiDomain
}) {
const login = async (username, password) => {
console.info('EpinioClient.login')

try {
await epinio([
'login', '--trust-ca', '-u', username, '-p', password, `${apiDomain}`
])
console.info('EpinioClient.login OK')
} catch (error) {
console.error('EpinioClient.login', error)
throw error
}
await epinio([
'login', '-u', username, '-p', password, '--trust-ca', `epinio.${apiDomain}`
])
}

const logout = async () => {
console.info('EpinioClient.logout')

await epinio(['logout'])
}

const info = async () => {
console.log('EpinioClient.info')

try {
const result = await epinio(['info'])
console.info('EpinioClient.info OK', result)
// TODO: update with '--output json' flag
const result = await epinio(['info'])
const lines = result.split('\n')

// TODO parse info to get version
return { version: 'v1.11.0-rc1' }
} catch (error) {
console.error('EpinioClient.info', error)
throw error
for (const i in lines) {
if (lines[i].indexOf('Epinio Server Version: ') === 0) {
const version = lines[i].replace('Epinio Server Version: ', '')
return { version }
}
}

return { version: 'unknown' }
}

const listApplications = async (namespace) => {
console.log('EpinioClient.listApplications')

try {
const result = await epinio([
'app', 'list', '--output', 'json'
])
console.info('EpinioClient.listApplications OK', result)
return JSON.parse(result)
} catch (error) {
console.error('EpinioClient.listApplications', error)
throw error
}
const result = await epinio([
'app', 'list', '--output', 'json'
])

return JSON.parse(result)
}

const epinio = async (args) => {
try {
const result = await window.ddClient.extension.host.cli.exec('epinio', args)
return result.stdout
} catch (error) {
console.error(error)

if (error.stderr) {
throw Error(error.stderr)
}
Expand All @@ -65,6 +56,7 @@ export default function EpinioClient({

return {
login,
logout,
info,
listApplications
}
Expand Down
35 changes: 25 additions & 10 deletions ui/src/epinio/Credentials.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import EpinioClient from './API'

function credsChanged(creds, update) {
return creds.username !== update.username || creds.password !== update.password
Expand All @@ -11,22 +12,36 @@ export function credentialsOK(creds) {
// Credentials will fetch the default user, when props.enabled is true
function Credentials(props) {
React.useEffect(() => {
const getCredentials = async () => {
const epinioClient = EpinioClient({ apiDomain: props.domain })

const login = async () => {
let u = { username: '-', password: '-' }

try {
await epinioClient.login('admin', 'password')
const u = { username: 'admin', password: 'password' }
if (credsChanged(props.credentials, u)) {
props.onCredentialsChanged(u)
}
u = { username: 'admin', password: 'password' }
} catch (error) {
const u = { username: '-', password: '-' }
if (credsChanged(props.credentials, u)) {
props.onCredentialsChanged(u)
}
// fail
}

if (credsChanged(props.credentials, u)) {
props.onCredentialsChanged(u)
}
}

const logout = async () => {
await epinioClient.logout()

const u = { username: '-', password: '-' }
if (credsChanged(props.credentials, u)) {
props.onCredentialsChanged(u)
}
}

if (props.enabled) {
getCredentials()
login()
} else {
logout()
}
}, [props])

Expand Down
62 changes: 61 additions & 1 deletion ui/src/epinio/Installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ export default function EpinioInstaller({
return result?.stdout
}

const kubectl = async (args) => {
const result = await window.ddClient.extension.host.cli.exec('kubectl', args)
console.debug(JSON.stringify(result))

if (result.stderr) {
throw Error(result?.stderr)
}

return result.parseJsonObject()
}

const isEpinioInstalled = async () => {
console.debug('check Epinio installation')

Expand Down Expand Up @@ -52,6 +63,13 @@ export default function EpinioInstaller({
async function install() {
try {
setProgress(10)
const isInstalled = await checkTraefik()
if (!isInstalled) {
await installTraefik()
}
setProgress(30)

setProgress(40)
await installCertManager()
setProgress(50)

Expand Down Expand Up @@ -79,8 +97,12 @@ export default function EpinioInstaller({
await uninstallEpinio()
setProgress(25)

setProgress(50)
setProgress(30)
await uninstallCertManager()
setProgress(50)

setProgress(60)
await uninstallTraefik()
setProgress(100)

onInstallationChanged(true)
Expand All @@ -93,6 +115,33 @@ export default function EpinioInstaller({
}
}

const checkTraefik = async () => {
console.log('checking traefik installation')

const result = await kubectl([
'get', 'svc', '-A',
'-l', 'app.kubernetes.io/name=traefik',
'-o', 'json'
])

const isInstalled = result.items.length > 0
console.log(`traefik already installed: ${isInstalled}`)

return isInstalled
}

const installTraefik = async () => {
console.log('installing traefik chart')

await helm([
'upgrade', '--install', '--atomic', 'traefik',
'--create-namespace', '--namespace', 'ingress-traefik',
'https://traefik.github.io/charts/traefik/traefik-19.0.3.tgz'
])

console.log('installed: traefik')
}

const installCertManager = async () => {
console.log('installing cert-manager chart')

Expand Down Expand Up @@ -121,6 +170,17 @@ export default function EpinioInstaller({
console.log('installed: epinio')
}

const uninstallTraefik = async () => {
console.log('uninstalling traefik chart')

await helm([
'uninstall', '--namespace', 'ingress-traefik',
'--wait', 'traefik'
])

console.log('uninstalled: traefik')
}

const uninstallEpinio = async () => {
console.log('uninstalling epinio chart')

Expand Down

0 comments on commit 52e1597

Please sign in to comment.