Skip to content

Commit

Permalink
Merge pull request #4 from natrontech/TASK-115-optimizations
Browse files Browse the repository at this point in the history
Task 115 optimizations
  • Loading branch information
janlauber authored Jun 18, 2023
2 parents 1a9e7cc + a08cfdf commit e59e45b
Show file tree
Hide file tree
Showing 44 changed files with 1,219 additions and 447 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Built with:
- [pocketbase](https://pocketbase.io)

<p align="center">
<img height="400px" src="assets/screenshots/exercise.gif" />
<img height="400px" src="assets/screenshots/terminal.png" />
</p>

---
Expand Down
Binary file added assets/screenshots/dashboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/screenshots/exercise.png
Binary file not shown.
Binary file modified assets/screenshots/exercises.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/screenshots/labs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/screenshots/login.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/screenshots/terminal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/screenshots/terminal_done.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 20 additions & 2 deletions kubelab-backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ func main() {
StorageClasses struct {
Enabled bool `yaml:"enabled"`
} `yaml:"storageclasses"`
Ingresses struct {
Enabled bool `yaml:"enabled"`
} `yaml:"ingresses"`
VolumeSnapshots struct {
Enabled bool `yaml:"enabled"`
} `yaml:"volumesnapshots"`
PodDisruptionBudgets struct {
Enabled bool `yaml:"enabled"`
} `yaml:"poddisruptionbudgets"`
} `yaml:"sync"`
Storage struct {
Persistence bool `yaml:"persistence"`
Expand All @@ -111,6 +120,9 @@ func main() {
// convert to string
yamlValues.Sync.PersistentVolumes.Enabled = true
yamlValues.Sync.StorageClasses.Enabled = true
yamlValues.Sync.Ingresses.Enabled = true
yamlValues.Sync.VolumeSnapshots.Enabled = true
yamlValues.Sync.PodDisruptionBudgets.Enabled = true
yamlValues.Storage.Persistence = false

// convert to yaml
Expand All @@ -133,7 +145,13 @@ func main() {
return err
}

time.Sleep(20 * time.Second)
err = k8s.CreateResourceQuota(helm.GetNamespaceName(e.Record.GetString("lab"), e.Record.GetString("user")), env.Config.ResourceName, env.Config.PodsLimit, env.Config.StorageLimit)
if err != nil {
fmt.Println(err)
return err
}

time.Sleep(15 * time.Second)

} else {
// delete the namespace
Expand All @@ -143,7 +161,7 @@ func main() {
return err
}

time.Sleep(20 * time.Second)
time.Sleep(15 * time.Second)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
migrate((db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("qj6ssich32lcxru")

// update
collection.schema.addField(new SchemaField({
"system": false,
"id": "g8s5seza",
"name": "startTime",
"type": "date",
"required": false,
"unique": false,
"options": {
"min": "",
"max": ""
}
}))

return dao.saveCollection(collection)
}, (db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("qj6ssich32lcxru")

// update
collection.schema.addField(new SchemaField({
"system": false,
"id": "g8s5seza",
"name": "startTime",
"type": "date",
"required": true,
"unique": false,
"options": {
"min": "",
"max": ""
}
}))

return dao.saveCollection(collection)
})
39 changes: 39 additions & 0 deletions kubelab-backend/pb_migrations/1686990524_updated_lab_sessions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
migrate((db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("n7tne53bbobf2bt")

// update
collection.schema.addField(new SchemaField({
"system": false,
"id": "thwhdlu1",
"name": "startTime",
"type": "date",
"required": false,
"unique": false,
"options": {
"min": "",
"max": ""
}
}))

return dao.saveCollection(collection)
}, (db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("n7tne53bbobf2bt")

// update
collection.schema.addField(new SchemaField({
"system": false,
"id": "thwhdlu1",
"name": "startTime",
"type": "date",
"required": true,
"unique": false,
"options": {
"min": "",
"max": ""
}
}))

return dao.saveCollection(collection)
})
17 changes: 17 additions & 0 deletions kubelab-backend/pb_migrations/1687092568_updated_labs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
migrate((db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("a1s1vqlm7141lcr")

collection.listRule = null
collection.viewRule = null

return dao.saveCollection(collection)
}, (db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("a1s1vqlm7141lcr")

collection.listRule = ""
collection.viewRule = ""

return dao.saveCollection(collection)
})
17 changes: 17 additions & 0 deletions kubelab-backend/pb_migrations/1687092574_updated_exercises.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
migrate((db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("s4f0lpy3ibkgfqp")

collection.listRule = null
collection.viewRule = null

return dao.saveCollection(collection)
}, (db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("s4f0lpy3ibkgfqp")

collection.listRule = ""
collection.viewRule = ""

return dao.saveCollection(collection)
})
23 changes: 23 additions & 0 deletions kubelab-backend/pb_migrations/1687092614_updated_exercises.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
migrate((db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("s4f0lpy3ibkgfqp")

collection.listRule = ""
collection.viewRule = ""
collection.createRule = null
collection.updateRule = null
collection.deleteRule = null

return dao.saveCollection(collection)
}, (db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("s4f0lpy3ibkgfqp")

collection.listRule = null
collection.viewRule = null
collection.createRule = ""
collection.updateRule = ""
collection.deleteRule = ""

return dao.saveCollection(collection)
})
23 changes: 23 additions & 0 deletions kubelab-backend/pb_migrations/1687092623_updated_labs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
migrate((db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("a1s1vqlm7141lcr")

collection.listRule = ""
collection.viewRule = ""
collection.createRule = null
collection.updateRule = null
collection.deleteRule = null

return dao.saveCollection(collection)
}, (db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("a1s1vqlm7141lcr")

collection.listRule = null
collection.viewRule = null
collection.createRule = ""
collection.updateRule = ""
collection.deleteRule = ""

return dao.saveCollection(collection)
})
16 changes: 16 additions & 0 deletions kubelab-backend/pkg/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ type config struct {
Local bool `env:"LOCAL"`
KubelabImage string `env:"KUBELAB_IMAGE"`
AllowedHosts string `env:"ALLOWED_HOSTS"`
ResourceName string `env:"RESOURCE_NAME"`
PodsLimit string `env:"PODS_LIMIT"`
StorageLimit string `env:"STORAGE_LIMIT"`
}

var Config config
Expand All @@ -30,4 +33,17 @@ func Init() {
if Config.AllowedHosts == "" {
Config.AllowedHosts = "kubelab.swisscom.k8s.natron.cloud"
}

if Config.ResourceName == "" {
Config.ResourceName = "kubelab"
}

if Config.PodsLimit == "" {
Config.PodsLimit = "70"
}

if Config.StorageLimit == "" {
Config.StorageLimit = "10Gi"
}

}
25 changes: 25 additions & 0 deletions kubelab-backend/pkg/k8s/resourcequota.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package k8s

import (
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func CreateResourceQuota(namespace string, name string, pods string, storage string) error {
resourceQuota := &v1.ResourceQuota{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
Spec: v1.ResourceQuotaSpec{
Hard: v1.ResourceList{
v1.ResourcePods: resource.MustParse(pods),
v1.ResourceRequestsStorage: resource.MustParse(storage),
},
},
}

_, err := Clientset.CoreV1().ResourceQuotas(namespace).Create(Ctx, resourceQuota, metav1.CreateOptions{})
return err
}
22 changes: 21 additions & 1 deletion kubelab-ui/package-lock.json

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

3 changes: 3 additions & 0 deletions kubelab-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@tailwindcss/typography": "^0.5.9",
"@types/marked": "^5.0.0",
"@types/node": "^20.2.3",
"@types/prismjs": "^1.26.0",
"@typescript-eslint/eslint-plugin": "^5.45.0",
"@typescript-eslint/parser": "^5.45.0",
"autoprefixer": "^10.4.13",
Expand All @@ -40,6 +41,7 @@
"svelte-check": "^3.0.1",
"svelte-preprocess": "^5.0.1",
"svelte-splitpanes": "^0.7.14",
"tailwind-scrollbar": "^3.0.4",
"tailwindcss": "^3.2.7",
"tslib": "^2.4.1",
"typescript": "^4.9.3",
Expand All @@ -56,6 +58,7 @@
"lucide-svelte": "^0.242.0",
"marked": "^5.0.4",
"pocketbase-typegen": "^1.1.9",
"prismjs": "^1.29.0",
"svelte-chartjs": "^3.1.2",
"svelte-confetti": "^1.2.2",
"svelte-french-toast": "^1.0.4-beta.0",
Expand Down
10 changes: 0 additions & 10 deletions kubelab-ui/src/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,3 @@ td, th {
border: 1px solid #ddd;
padding: 0.5em;
}

code {
background-color: #bababa;
border-radius: 5px;
color: #000;
padding: 0.25em;
/* block */
display: inline-block;
}

Loading

0 comments on commit e59e45b

Please sign in to comment.