Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change how xhr urls are structured #351

Merged
merged 4 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions controller/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ $().ready(() => {
$("#botlist").hide()

$("#shutdownConfirm").on('click', confirmShutdown)
fetch("./regions", { method: "GET", headers: getHeaders()}).then((response) => response.json()).then(gotRegions)
fetch(getUrl("./regions"), { method: "GET",mode: 'cors', headers: getHeaders()}).then((response) => response.json()).then(gotRegions)
syncData()
})


function syncData() {
fetch("./tasks", { method: "GET", headers: getHeaders()}).then((response) => response.json()).then(gotTasks)
fetch(getUrl("./tasks"), { method: "GET", mode: 'cors', headers: getHeaders()}).then((response) => response.json()).then(gotTasks)
}

function operate(val, row) {
Expand Down Expand Up @@ -143,7 +143,7 @@ function gotRegions(data) {
$("#regionList .list-group-item").removeClass("active")
$(this).addClass("active")
currentRegion = regionList[reg]
fetch(`./regions/${regionList[reg]}`, { method: "GET", headers: getHeaders()}).then((response) => response.json()).then(gotDaemons)
fetch(getUrl(`./regions/${regionList[reg]}`), { method: "GET", mode: 'cors', headers: getHeaders()}).then((response) => response.json()).then(gotDaemons)
})
.appendTo($("#regionlist"));
$('<option/>')
Expand Down Expand Up @@ -246,7 +246,7 @@ function drain(e, value, row, index) {
e.preventDefault()
}
let url = `./drain/${row.id}`
fetch(url, { method: "POST", headers: getHeaders()}).then((response) => {
fetch(getUrl(url), { method: "POST", mode: 'cors', headers: getHeaders()}).then((response) => {
if (response.ok) {
successToast(`Daemon ${row.id} will receive no new tasks`)
} else {
Expand All @@ -260,7 +260,7 @@ function reset(e, value, row, index) {
e.preventDefault()
}
let url = `./reset-worker/${row.id}`
fetch(url, { method: "POST", headers: getHeaders()}).then((response) => {
fetch(getUrl(url), { method: "POST", mode: 'cors', headers: getHeaders()}).then((response) => {
if (response.ok) {
successToast(`All tasks on daemon ${row.id} will be reset to unstarted`)
} else {
Expand All @@ -274,7 +274,7 @@ function complete(e, value, row, index) {
e.preventDefault()
}
let url = `./complete/${row.id}`
fetch(url, { method: "POST", headers: getHeaders()}).then((response) => {
fetch(getUrl(url), { method: "POST", mode: 'cors', headers: getHeaders()}).then((response) => {
if (response.ok) {
successToast(`Tasks for daemon ${row.id} will be published`)
} else {
Expand All @@ -296,7 +296,7 @@ function shutdown(e, value, row, index) {
function confirmShutdown(e) {
modal.hide()
let url = `./regions/${currentRegion}/${shutdownDaemonID}`
fetch(url, { method: "DELETE", headers: getHeaders()}).then((response) => {
fetch(getUrl(url), { method: "DELETE",mode: 'cors', headers: getHeaders()}).then((response) => {
if (response.ok) {
$("#botdetail").bootstrapTable('hideRow', { index: shutdownDaemonIndex })
successToast(`Daemon ${row.id} has been shutdown`)
Expand All @@ -312,7 +312,7 @@ function cancel(e, value, row, index) {
e.preventDefault()
}
let url = `./tasks/${row.UUID}`
fetch(url, { method: "DELETE", headers: getHeaders()}).then((response) => {
fetch(getUrl(url), { method: "DELETE", mode: 'cors', headers: getHeaders()}).then((response) => {
if (response.ok) {
$("#taskTable").bootstrapTable('hideRow', { index })
successToast(`Task ${row.UUID} has been cancelled`)
Expand All @@ -332,6 +332,10 @@ function getHeaders() {
return headers
}

function getUrl(rsrc) {
return "https://" + window.location.host + window.location.pathname + rsrc
}

function doSubmit(e) {
if (e.preventDefault) {
e.preventDefault()
Expand Down Expand Up @@ -377,7 +381,7 @@ function doSubmit(e) {
data.Tag = $('#newScheduleTag').val()
}

requests.push(fetch(url, {method: "POST", headers: getHeaders(), body: JSON.stringify(data)}))
requests.push(fetch(getUrl(url), {method: "POST", mode: 'cors', headers: getHeaders(), body: JSON.stringify(data)}))
}

Promise.all(requests).then((_) => {
Expand All @@ -403,7 +407,7 @@ function doCreateBot(e) {
"exported": $("#newBotWalletExported").val(),
},
}
fetch(url, {method: "POST", headers: getHeaders(), body: JSON.stringify(data)}).then(() => {
fetch(getUrl(url), {method: "POST", mode: 'cors', headers: getHeaders(), body: JSON.stringify(data)}).then(() => {
successToast("Bot created!")
})
}
15 changes: 7 additions & 8 deletions controller/spawn/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,13 @@ application:
name: dealbot
secrets: []
configMaps: []
service:
enabled: true
type: ClusterIP
ports:
- protocol: TCP
port: 8764
targetPort: 8764
name: dealbot
services:
- type: ClusterIP
ports:
- protocol: TCP
port: 8764
targetPort: 8764
name: dealbot
ingress:
enabled: false
storage:
Expand Down
15 changes: 8 additions & 7 deletions controller/spawn/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type KubernetesSpawner struct {
}

func (s *KubernetesSpawner) Spawn(d *Daemon) error {
actionConfig, err := s.actionConfig(d.Region)
actionConfig, namespace, err := s.actionConfig(d.Region)
if err != nil {
log.Infow("could not create actionConfig during Spawn", "err", err)
return err
Expand All @@ -52,6 +52,7 @@ func (s *KubernetesSpawner) Spawn(d *Daemon) error {
client.ReleaseName = d.Id
client.UseReleaseName = true
client.CreateNamespace = false
client.Namespace = namespace

vals, err := dealbotValues(d)
if err != nil {
Expand All @@ -67,7 +68,7 @@ func (s *KubernetesSpawner) Spawn(d *Daemon) error {
}

func (s *KubernetesSpawner) Get(regionid string, daemonid string) (daemon *Daemon, err error) {
actionConfig, err := s.actionConfig(regionid)
actionConfig, _, err := s.actionConfig(regionid)
if err != nil {
log.Infow("could not create actionConfig during daemon Get", "err", err)
return daemon, err
Expand All @@ -82,7 +83,7 @@ func (s *KubernetesSpawner) Get(regionid string, daemonid string) (daemon *Daemo
}

func (s *KubernetesSpawner) Shutdown(regionid string, daemonid string) error {
actionConfig, err := s.actionConfig(regionid)
actionConfig, _, err := s.actionConfig(regionid)
if err != nil {
log.Infow("could not create actionConfig during daemon Get", "err", err)
return err
Expand All @@ -96,7 +97,7 @@ func (s *KubernetesSpawner) Shutdown(regionid string, daemonid string) error {
}

func (s *KubernetesSpawner) List(regionid string) (daemons []*Daemon, err error) {
actionConfig, err := s.actionConfig(regionid)
actionConfig, _, err := s.actionConfig(regionid)
if err != nil {
log.Infow("could not create actionConfig during daemon List", "err", err)
return daemons, err
Expand Down Expand Up @@ -125,15 +126,15 @@ func (s *KubernetesSpawner) Regions() []string {
return regions
}

func (s *KubernetesSpawner) actionConfig(regionid string) (*action.Configuration, error) {
func (s *KubernetesSpawner) actionConfig(regionid string) (*action.Configuration, string, error) {
getter, ok := s.getters[regionid]
if !ok {
return nil, RegionNotFound
return nil, "", RegionNotFound
}
c := s.rawConfig.Contexts[regionid]
actionConfig := new(action.Configuration)
actionConfig.Init(getter, c.Namespace, "", log.Debugw)
return actionConfig, actionConfig.KubeClient.IsReachable()
return actionConfig, c.Namespace, actionConfig.KubeClient.IsReachable()
}

func NewKubernetes() *KubernetesSpawner {
Expand Down