Skip to content

Commit

Permalink
add quotas
Browse files Browse the repository at this point in the history
  • Loading branch information
ihiverlet committed Mar 28, 2024
1 parent 20b8cbd commit 07e955a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
42 changes: 30 additions & 12 deletions cmd/mylab-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ type MyServices struct {
Apps []App `apps:"apps"`
}

type Quotas struct {
Spec []Quota `spec:"spec"`
Usage []Quota `usage:"usage"`
}

type Quota struct {
}

// @Summary List the services installed in a namespace.
// @Schemes
// @Description
Expand All @@ -54,15 +46,41 @@ func events(c *gin.Context) {
})
}

// @Summary List the quotas in a namespace.
// @Schemes
// @Description
// @Tags My lab
// @Produce json
// @Success 200
// @Router /my-lab/quota [get]
func quotas(c *gin.Context) {
/*quotas := Quotas{}
for {
quotas.Quota = append
}*/
resourceQuotas := kubernetes.GetOnyxiaResourceQuota(namespace)
c.JSON(http.StatusOK, resourceQuotas.Status)
}

type model struct {
Namespace string `json:"namespace" example:"default" format:"string"` // Namespace of the quota
QuotaName string `json:"quotaName" example:"name" format:"string"` // Name of the quota
NewLimit int `json:"newLimit" example:"100" format:"int"` // New limit for the quota
}


// @Summary Change the quotas for a namespace.
// @Schemes
// @Description
// @Tags My lab
// @Success 200
// @Accept json
// @Produce json
// @Param newQuota body model true "Modify quotas"
// @Router /my-lab/quota [post]
func updateOnyxiaQuota(c *gin.Context) {
// kubernetes.PostOnyxiaResourceQuotas(namespace)
}

func registerMyLabHandlers(r *gin.RouterGroup) {
r.GET("/my-lab/services", myServices)
r.GET("/my-lab/events", events)
r.GET("/my-lab/quota", quotas)
r.POST("/my-lab/quota", updateOnyxiaQuota)
}
12 changes: 12 additions & 0 deletions internal/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,15 @@ func InitNamespace(namespace string) {
}
clientset.CoreV1().Namespaces().Create(context.TODO(), &namespaceToCreate, metav1.CreateOptions{})
}

func GetOnyxiaResourceQuota(namespace string) (*corev1.ResourceQuota) {

resourceQuotas, _ := clientset.CoreV1().ResourceQuotas(namespace).Get(context.TODO(), "onyxia-quota", metav1.GetOptions{})
return resourceQuotas

}

func PostOnyxiaResourceQuotas(namespace string, quota (*corev1.ResourceQuota)) {

clientset.CoreV1().ResourceQuotas(namespace).Update(context.TODO(), quota, metav1.UpdateOptions{})
}

0 comments on commit 07e955a

Please sign in to comment.